mirror of
https://github.com/chshersh/github-tui.git
synced 2024-08-16 22:10:34 +03:00
Organise modules into a nice structure
This commit is contained in:
parent
6cc0915c77
commit
f6610ea77b
@ -21,14 +21,10 @@
|
||||
dune
|
||||
(ANSITerminal (>= "0.8.5"))
|
||||
(cmdliner (>= "1.2.0"))
|
||||
core_unix
|
||||
(ezcurl (>= "0.2.4"))
|
||||
(minttea (>= "0.0.2"))
|
||||
shape-the-term
|
||||
(terminal_size (>= "0.2.0"))
|
||||
uuseg
|
||||
)
|
||||
(tags
|
||||
(tui cli git github)))
|
||||
|
||||
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project
|
||||
|
@ -13,12 +13,10 @@ depends: [
|
||||
"dune" {>= "3.12"}
|
||||
"ANSITerminal" {>= "0.8.5"}
|
||||
"cmdliner" {>= "1.2.0"}
|
||||
"core_unix"
|
||||
"ezcurl" {>= "0.2.4"}
|
||||
"minttea" {>= "0.0.2"}
|
||||
"shape-the-term"
|
||||
"terminal_size" {>= "0.2.0"}
|
||||
"uuseg"
|
||||
"odoc" {with-doc}
|
||||
]
|
||||
build: [
|
||||
|
@ -11,7 +11,7 @@ let path_arg =
|
||||
& opt string "."
|
||||
& info [ "d"; "directory" ] ~docv:"DIRECTORY_PATH" ~doc)
|
||||
|
||||
let gh_tui_term = Term.(const Tui.App.start $ repo_arg $ path_arg)
|
||||
let gh_tui_term = Term.(const Tui.start $ repo_arg $ path_arg)
|
||||
|
||||
let cmd =
|
||||
let doc = "TUI of a GitHub repository" in
|
||||
|
10
lib/dune
10
lib/dune
@ -1,13 +1,7 @@
|
||||
(include_subdirs qualified)
|
||||
|
||||
(library
|
||||
(name github_tui)
|
||||
(libraries
|
||||
ANSITerminal
|
||||
cmdliner
|
||||
core_unix.command_unix
|
||||
ezcurl
|
||||
minttea
|
||||
shape-the-term
|
||||
terminal_size
|
||||
uuseg.string))
|
||||
;; Internal dependencies
|
||||
tui))
|
||||
|
3
lib/extra/dune
Normal file
3
lib/extra/dune
Normal file
@ -0,0 +1,3 @@
|
||||
(library
|
||||
(name extra)
|
||||
(libraries shape-the-term))
|
2
lib/extra/extra.ml
Normal file
2
lib/extra/extra.ml
Normal file
@ -0,0 +1,2 @@
|
||||
module List = List_extra
|
||||
module String = String_extra
|
5
lib/fs/dune
Normal file
5
lib/fs/dune
Normal file
@ -0,0 +1,5 @@
|
||||
(library
|
||||
(name fs)
|
||||
(libraries
|
||||
;; Internal dependencies
|
||||
pretty))
|
7
lib/pretty/dune
Normal file
7
lib/pretty/dune
Normal file
@ -0,0 +1,7 @@
|
||||
(library
|
||||
(name pretty)
|
||||
(libraries
|
||||
ANSITerminal
|
||||
shell
|
||||
;; Internal dependencies
|
||||
extra))
|
@ -10,7 +10,7 @@ let fmt_chunk { styles; string } = ANSITerminal.sprintf styles "%s" string
|
||||
let replicate_chunk width s =
|
||||
if width <= 0 then { styles = []; string = "" }
|
||||
else
|
||||
let filling = String_extra.repeat_txt width s in
|
||||
let filling = Extra.String.repeat_txt width s in
|
||||
{ styles = []; string = filling }
|
||||
|
||||
type t = {
|
||||
@ -23,14 +23,14 @@ let length line = line.length
|
||||
let of_chunks chunks =
|
||||
let length =
|
||||
List.fold_left
|
||||
(fun acc { string; _ } -> acc + String_extra.width string)
|
||||
(fun acc { string; _ } -> acc + Extra.String.width string)
|
||||
0 chunks
|
||||
in
|
||||
{ chunks; length }
|
||||
|
||||
let prepend_chunk chunk line =
|
||||
let chunks = chunk :: line.chunks in
|
||||
let length = String_extra.width chunk.string + line.length in
|
||||
let length = Extra.String.width chunk.string + line.length in
|
||||
{ chunks; length }
|
||||
|
||||
let append line1 line2 =
|
@ -64,7 +64,7 @@ and horizontal_to_lines ~width cols =
|
||||
(* WARNING: The leftmost horizontal fill will consume all the remaining width *)
|
||||
let remaining_width = width - size_taken in
|
||||
let rendered = render_to_lines ~width:remaining_width other in
|
||||
let max_line_width = List_extra.max_on Line.length rendered in
|
||||
let max_line_width = Extra.List.max_on Line.length rendered in
|
||||
(size_taken + max_line_width, Rendered rendered)
|
||||
in
|
||||
(* TODO: Adding to the end of the list is suboptimal *)
|
||||
@ -99,4 +99,4 @@ and horizontal_to_lines ~width cols =
|
||||
| hd :: tl -> List.fold_left zip_lines hd tl
|
||||
|
||||
let render ~width doc =
|
||||
doc |> render_to_lines ~width |> List.map Line.fmt |> String_extra.unlines
|
||||
doc |> render_to_lines ~width |> List.map Line.fmt |> Extra.String.unlines
|
2
lib/shell/dune
Normal file
2
lib/shell/dune
Normal file
@ -0,0 +1,2 @@
|
||||
(library
|
||||
(name shell))
|
11
lib/tui/dune
Normal file
11
lib/tui/dune
Normal file
@ -0,0 +1,11 @@
|
||||
(library
|
||||
(name tui)
|
||||
(libraries
|
||||
ANSITerminal
|
||||
minttea
|
||||
terminal_size
|
||||
;; Internal dependencies
|
||||
extra
|
||||
fs
|
||||
pretty
|
||||
scroll))
|
2
lib/tui/scroll/dune
Normal file
2
lib/tui/scroll/dune
Normal file
@ -0,0 +1,2 @@
|
||||
(library
|
||||
(name scroll))
|
1
lib/tui/tui.mli
Normal file
1
lib/tui/tui.mli
Normal file
@ -0,0 +1 @@
|
||||
val start : string -> string -> unit
|
@ -76,7 +76,7 @@ let file_contents_to_doc ~(file_contents : Fs.file_contents) =
|
||||
let offset = file_contents.offset in
|
||||
|
||||
let contents_span =
|
||||
List_extra.of_sub_array ~offset ~len:span file_contents.lines
|
||||
Extra.List.of_sub_array ~offset ~len:span file_contents.lines
|
||||
in
|
||||
|
||||
let scroll_doc = scroll ~lines ~span ~offset in
|
||||
@ -96,11 +96,11 @@ let file_name_padding = 6
|
||||
|
||||
let max_file_name_len files =
|
||||
files
|
||||
|> Array.map (fun file -> file |> Fs.file_name |> String_extra.width)
|
||||
|> Array.map (fun file -> file |> Fs.file_name |> Extra.String.width)
|
||||
|> Array.fold_left max 0
|
||||
|
||||
let fmt_file ~max_name_len (tree : Fs.tree) =
|
||||
let pad = String_extra.fill_right max_name_len in
|
||||
let pad = Extra.String.fill_right max_name_len in
|
||||
match tree with
|
||||
| File (name, _) -> file_char ^ " " ^ pad name
|
||||
| Dir (name, [||]) -> empty_dir_char ^ " " ^ pad name
|
||||
@ -112,9 +112,9 @@ let current_level_to_doc (cursor : Fs.dir_cursor) ~has_next ~is_file_chosen =
|
||||
let max_len = max_name_len + file_name_padding in
|
||||
|
||||
(* Frame *)
|
||||
let top = "╭" ^ String_extra.repeat_txt (max_len - 2) "─" ^ "╮" in
|
||||
let mid = "├" ^ String_extra.repeat_txt (max_len - 2) "─" ^ "┤" in
|
||||
let bot = "╰" ^ String_extra.repeat_txt (max_len - 2) "─" ^ "╯" in
|
||||
let top = "╭" ^ Extra.String.repeat_txt (max_len - 2) "─" ^ "╮" in
|
||||
let mid = "├" ^ Extra.String.repeat_txt (max_len - 2) "─" ^ "┤" in
|
||||
let bot = "╰" ^ Extra.String.repeat_txt (max_len - 2) "─" ^ "╯" in
|
||||
|
||||
(* Line *)
|
||||
let fmt_selected_name file = "│ " ^ fmt_file ~max_name_len file ^ " ├" in
|
||||
@ -129,7 +129,7 @@ let current_level_to_doc (cursor : Fs.dir_cursor) ~has_next ~is_file_chosen =
|
||||
|> List.mapi (fun i file ->
|
||||
if i = cursor.pos && has_next then fmt_selected_name file
|
||||
else fmt_name file)
|
||||
|> List_extra.in_between ~sep:mid
|
||||
|> Extra.List.in_between ~sep:mid
|
||||
|> (fun lines -> [ top ] @ lines @ [ bot ])
|
||||
|> List.mapi (fun i s ->
|
||||
if i = hi_pos - 1 || i = hi_pos || i = hi_pos + 1 then fmt style s
|
||||
@ -142,9 +142,9 @@ let children_to_doc ~prev_total ~pos children =
|
||||
let max_len = max_name_len + file_name_padding in
|
||||
|
||||
(* Frame *)
|
||||
let top = " ╭" ^ String_extra.repeat_txt (max_len - 2) "─" ^ "╮" in
|
||||
let mid = "│ ├" ^ String_extra.repeat_txt (max_len - 2) "─" ^ "┤" in
|
||||
let bot = " ╰" ^ String_extra.repeat_txt (max_len - 2) "─" ^ "╯" in
|
||||
let top = " ╭" ^ Extra.String.repeat_txt (max_len - 2) "─" ^ "╮" in
|
||||
let mid = "│ ├" ^ Extra.String.repeat_txt (max_len - 2) "─" ^ "┤" in
|
||||
let bot = " ╰" ^ Extra.String.repeat_txt (max_len - 2) "─" ^ "╯" in
|
||||
|
||||
(* Connector arrow *)
|
||||
let prev_rows_count = (2 * prev_total) + 1 in
|
||||
@ -174,7 +174,7 @@ let children_to_doc ~prev_total ~pos children =
|
||||
children
|
||||
|> Array.to_list
|
||||
|> List.mapi fmt_name
|
||||
|> List_extra.in_between ~sep:mid
|
||||
|> Extra.List.in_between ~sep:mid
|
||||
|> (fun lines -> [ top ] @ lines @ [ bot ])
|
||||
|> (fun lines ->
|
||||
let pad_before = List.init (max (connect_pos - 1) 0) (fun _ -> "") in
|
||||
|
Loading…
Reference in New Issue
Block a user