Skip to content

Commit

Permalink
big refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
faldor20 committed Jun 19, 2024
1 parent aace34e commit eefd8df
Show file tree
Hide file tree
Showing 13 changed files with 1,094 additions and 1,030 deletions.
9 changes: 4 additions & 5 deletions jj_tui/bin/global_vars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ type cmd_args = string list

type ui_state_t = {
view :
[ `Main
| `Cmd_I of cmd_args
[ `Main (**Normal Mode*)
| `Cmd_I of cmd_args (**Indicates we are running a JJ command that is interactive*)
| `RunCmd of
cmd_args
(* | `Prompt of string * [ `Cmd of cmd_args | `Cmd_I of cmd_args ] *)
Expand All @@ -24,7 +24,7 @@ type ui_state_t = {
; jj_change_files : (string * string) list Lwd.var
}

(** Global variables for the ui*)
(** Global variables for the ui. Here we keep anything that's just a pain to pipe around*)
module type Vars = sig
type eio_vars = {
env : Eio_unix.Stdenv.base
Expand All @@ -40,8 +40,7 @@ module type Vars = sig
val get_eio_vars : unit -> eio_vars
val get_term : unit -> Notty_unix.Term.t
val ui_state : ui_state_t
val update_ui_state: (ui_state_t->unit)->unit

val update_ui_state : (ui_state_t -> unit) -> unit
val render_mutex : Eio.Mutex.t
end

Expand Down
256 changes: 256 additions & 0 deletions jj_tui/bin/graph_view.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@

module Make (Vars : Global_vars.Vars) = struct
open Lwd_infix
open Vars
open Jj_process.Make (Vars)
open Notty
open Jj_tui
module W = Nottui_widgets
open Nottui
open! Jj_tui.Util
module Wd = Widgets
open Jj_commands.Make (Vars)

let rec command_mapping : command list =
[
{
key = 'h'
; description = "Show help"
; cmd =
Fun
(fun _ ->
ui_state.show_popup $= Some (commands_list_ui command_mapping, "Help");
ui_state.input $= `Mode (fun _ -> `Unhandled))
}
; {
key = '5'
; description = "Show help2"
; cmd =
SubCmd
[
{
key = '1'
; description = "Show help2"
; cmd =
Fun
(fun _ ->
ui_state.show_popup
$= Some (commands_list_ui command_mapping, "Help");
ui_state.input $= `Mode (fun _ -> `Unhandled))
}
]
}
; {
key = 'P'
; description = "Move the working copy to the previous child "
; cmd = Cmd [ "prev" ]
}
; {
key = 'p'
; description = "Edit the previous child change"
; cmd = Cmd [ "prev"; "--edit" ]
}
; {
key = 'N'
; description = "Move the working copy to the next child "
; cmd = Cmd [ "next" ]
}
; {
key = 'n'
; description = "Edit the next child change"
; cmd = Cmd [ "next"; "--edit" ]
}
; {
key = 'i'
; cmd =
SubCmd
[
{ key = 'i'; description = "Make a new empty change"; cmd = Cmd [ "new" ] }
; {
key = 'a'
; description = "Insert a new empty change after a specific revision"
; cmd = Prompt ("New change after commit:", [ "new" ])
}
]
; description = "Make a new empty change"
}
; {
key = 'c'
; description = "Describe this change and move on (same as `describe` then `new`) "
; cmd = Prompt ("commit msg", [ "commit"; "-m" ])
}
; {
key = 'S'
; description = "Split the current commit interacively"
; cmd = Cmd_I [ "split"; "-i" ]
}
; {
key = 's'
; description = "Squash/unsquash (has subcommands)"
; cmd =
SubCmd
[
{
key = 'S'
; cmd = Cmd_I [ "unsquash"; "-i" ]
; description = "Interactivaly unsquash"
}
; {
key = 's'
; description = "Squash into parent"
; cmd =
Fun
(fun _ ->
let curr_msg, prev_msg = get_messages () in
let new_msg = prev_msg ^ curr_msg in
jj [ "squash"; "--quiet"; "-m"; new_msg ] |> ignore)
}
; {
key = 'S'
; description = "Squash into any commit"
; cmd =
PromptThen
( "target revision"
, fun str ->
let curr_msg, prev_msg = get_messages () in
let new_msg = prev_msg ^ curr_msg in
Cmd [ "squash"; "--quiet"; "-m"; new_msg; "--into"; str ] )
}
; {
key = 'i'
; description = "Interactively choose what to squash into parent"
; cmd = Cmd_I [ "squash"; "-i" ]
}
; {
key = 'I'
; description = "Interactively choose what to squash into a commit"
; cmd = Prompt_I ("target revision", [ "squash"; "-i"; "--into" ])
}
]
}
; {
key = 'e'
; cmd = Prompt ("revision", [ "edit" ])
; description = "Edit a particular revision"
}
; {
key = 'd'
; cmd = Prompt ("description", [ "describe"; "-m" ])
; description = "Describe this revision"
}
; {
key = 'R'
; cmd = Cmd_I [ "resolve" ]
; description = "Resolve conflicts at this revision"
}
; {
key = 'r'
; description = "Rebase revision "
; cmd =
SubCmd
[
{
key = 'r'
; description = "Rebase single revision"
; cmd =
Prompt ("destination for revision rebase", [ "rebase"; "-r"; "@"; "-d" ])
}
; {
key = 's'
; description = "Rebase revision and its decendents"
; cmd =
Prompt
("Destination for decendent rebase", [ "rebase"; "-s"; "@"; "-d" ])
}
; {
key = 'b'
; description = "Rebase revision and all other revissions on its branch"
; cmd =
Prompt ("Destination for branch rebase", [ "rebase"; "-b"; "@"; "-d" ])
}
]
}
; {
key = 'g'
; description = "Git commands"
; cmd =
SubCmd
[
{ key = 'p'; description = "git push branch"; cmd = Cmd [ "git"; "push" ] }
; { key = 'f'; description = "git fetch"; cmd = Cmd [ "git"; "fetch" ] }
]
}
; {
key = 'z'
; description =
"Parallelize commits. Takes 2 commits and makes them have the\n\
same parent and child. Run `jj parallelize` --help for details"
; cmd =
PromptThen
( "list commits to parallelize"
, fun x -> Cmd ([ "paralellize" ] @ (x |> String.split_on_char ' ')) )
}
; {
key = 'a'
; description = "Abandon this change(removes just this change and rebases parents)"
; cmd = Cmd [ "abandon" ] |> confirm_prompt "abandon the change"
}
; {
key = 'b'
; description = "Branch commands"
; cmd =
SubCmd
[
{
key = 'c'
; description = "Create new branches"
; cmd =
PromptThen
( "Branch names to create"
, fun x ->
Cmd ([ "branch"; "create" ] @ (x |> String.split_on_char ' ')) )
}
; {
key = 'd'
; description = "Delete branches"
; cmd = Prompt ("Branch names to delete", [ "branch"; "delete" ])
}
; {
key = 'r'
; description = "Rename branch"
; cmd =
PromptThen
( "Branch to rename"
, fun curr_name ->
Prompt ("New branch name", [ "branch"; "rename"; curr_name ]) )
}
; {
key = 's'
; description = "set branch to this change"
; cmd = Prompt ("Branch to set to this commit ", [ "branch"; "set"; "-B" ])
}
; {
key = 't'
; description = "track given remote branch"
; cmd = Prompt ("Branch to track 'branch@remote'", [ "branch"; "track" ])
}
; {
key = 'u'
; description = "untrack given remote branch"
; cmd = Prompt ("Branch to untrack 'branch@remote'", [ "branch"; "untrack" ])
}
]
}
]
;;

(*Renders the commit graph from the UI state*)
let graph_view =
Wd.scroll_area (ui_state.jj_tree $-> Ui.atom)
|>$ Ui.keyboard_area (function
| `ASCII k, [] ->
handleInputs command_mapping k
| _ ->
`Unhandled)
;;
end
Loading

0 comments on commit eefd8df

Please sign in to comment.