mirror of
https://github.com/chshersh/github-tui.git
synced 2024-09-11 10:35:35 +03:00
Clone any repository
This commit is contained in:
parent
2cba1ab3fb
commit
43f1cb0b5d
@ -8,10 +8,11 @@ let path_arg =
|
|||||||
let doc = "Path to a local directory of a GitHub repository" in
|
let doc = "Path to a local directory of a GitHub repository" in
|
||||||
Arg.(
|
Arg.(
|
||||||
value
|
value
|
||||||
& opt string "."
|
& opt (some string) None
|
||||||
& info [ "d"; "directory" ] ~docv:"DIRECTORY_PATH" ~doc)
|
& info [ "d"; "directory" ] ~docv:"DIRECTORY_PATH" ~doc)
|
||||||
|
|
||||||
let gh_tui_term = Term.(const Tui.start $ repo_arg $ path_arg)
|
let run repo local_path = Tui.start ~repo ~local_path
|
||||||
|
let gh_tui_term = Term.(const run $ repo_arg $ path_arg)
|
||||||
|
|
||||||
let cmd =
|
let cmd =
|
||||||
let doc = "TUI of a GitHub repository" in
|
let doc = "TUI of a GitHub repository" in
|
||||||
|
@ -7,4 +7,5 @@
|
|||||||
extra
|
extra
|
||||||
fs
|
fs
|
||||||
pretty
|
pretty
|
||||||
scroll))
|
scroll
|
||||||
|
shell))
|
||||||
|
@ -1,4 +1,23 @@
|
|||||||
let init ~repo ~root_dir_path : Model.initial_data =
|
let clone_repo ~repo ~local_path =
|
||||||
|
match local_path with
|
||||||
|
| Some path -> path
|
||||||
|
| None ->
|
||||||
|
let owner, repo =
|
||||||
|
match String.split_on_char '/' repo with
|
||||||
|
| [ owner; repo ] -> (owner, repo)
|
||||||
|
| _ -> ("chshersh", "zbg")
|
||||||
|
in
|
||||||
|
let temp_dir =
|
||||||
|
Filename.temp_dir "github-tui-" (Printf.sprintf "%s-%s" owner repo)
|
||||||
|
in
|
||||||
|
let cmd =
|
||||||
|
Printf.sprintf "git clone git@github.com:%s/%s.git %s" owner repo
|
||||||
|
temp_dir
|
||||||
|
in
|
||||||
|
let _ = Shell.proc_stdout cmd in
|
||||||
|
temp_dir
|
||||||
|
|
||||||
|
let read_root_tree ~root_dir_path =
|
||||||
let tree = Fs.read_tree root_dir_path in
|
let tree = Fs.read_tree root_dir_path in
|
||||||
let files =
|
let files =
|
||||||
match tree with
|
match tree with
|
||||||
@ -7,14 +26,28 @@ let init ~repo ~root_dir_path : Model.initial_data =
|
|||||||
exit 1
|
exit 1
|
||||||
| Fs.Dir (_, files) -> files
|
| Fs.Dir (_, files) -> files
|
||||||
in
|
in
|
||||||
let height = Option.value (Terminal_size.get_rows ()) ~default:120 in
|
files
|
||||||
|
|
||||||
|
type terminal = {
|
||||||
|
height : int;
|
||||||
|
width : int;
|
||||||
|
}
|
||||||
|
|
||||||
|
let get_terminal_dimensions () =
|
||||||
|
let height = Option.value (Terminal_size.get_rows ()) ~default:40 in
|
||||||
let width = Option.value (Terminal_size.get_columns ()) ~default:140 in
|
let width = Option.value (Terminal_size.get_columns ()) ~default:140 in
|
||||||
|
{ height; width }
|
||||||
|
|
||||||
|
let init ~repo ~local_path : Model.initial_data =
|
||||||
|
let root_dir_path = clone_repo ~repo ~local_path in
|
||||||
|
let files = read_root_tree ~root_dir_path in
|
||||||
|
let { height; width } = get_terminal_dimensions () in
|
||||||
{ repo; root_dir_path; files; width; height }
|
{ repo; root_dir_path; files; width; height }
|
||||||
|
|
||||||
let app = Minttea.app ~init:Init.init ~update:Update.update ~view:View.view ()
|
let app = Minttea.app ~init:Init.init ~update:Update.update ~view:View.view ()
|
||||||
|
|
||||||
let start repo root_dir_path =
|
let start ~repo ~local_path =
|
||||||
let initial_data = init ~repo ~root_dir_path in
|
let initial_data = init ~repo ~local_path in
|
||||||
let initial_model = Model.initial_model initial_data in
|
let initial_model = Model.initial_model initial_data in
|
||||||
let config = Minttea.make_config ~fps:1 () in
|
let config = Minttea.make_config ~fps:1 () in
|
||||||
Minttea.start ~config app ~initial_model
|
Minttea.start ~config app ~initial_model
|
||||||
|
@ -1 +1 @@
|
|||||||
val start : string -> string -> unit
|
val start : repo:string -> local_path:string option -> unit
|
||||||
|
@ -28,7 +28,7 @@ let update event (model : Model.t) =
|
|||||||
match event with
|
match event with
|
||||||
(* if we press `q` or the escape key, we exit *)
|
(* if we press `q` or the escape key, we exit *)
|
||||||
| Event.KeyDown ((Key "q" | Escape), _modifier) ->
|
| Event.KeyDown ((Key "q" | Escape), _modifier) ->
|
||||||
(model, Command.Seq [ Command.Exit_alt_screen; Command.Quit ])
|
(model, Command.(Seq [ Exit_alt_screen; Quit ]))
|
||||||
(* if we press a digit, we switch to the corresponding tab *)
|
(* if we press a digit, we switch to the corresponding tab *)
|
||||||
| Event.KeyDown (Key "1", _modifier) ->
|
| Event.KeyDown (Key "1", _modifier) ->
|
||||||
({ model with current_tab = Model.Code }, Command.Noop)
|
({ model with current_tab = Model.Code }, Command.Noop)
|
||||||
|
Loading…
Reference in New Issue
Block a user