mirror of
https://github.com/chshersh/github-tui.git
synced 2024-09-11 18:37:56 +03:00
Rename doc elements, change to a list
This commit is contained in:
parent
77fac2dbe6
commit
9ce06264bd
@ -3,21 +3,14 @@
|
|||||||
type styles = ANSITerminal.style list
|
type styles = ANSITerminal.style list
|
||||||
|
|
||||||
type doc =
|
type doc =
|
||||||
| Empty
|
|
||||||
| Str of styles * string
|
| Str of styles * string
|
||||||
| Vertical of doc * doc
|
| Vertical of doc list
|
||||||
| Horizontal of doc * doc
|
| Horizontal of doc list
|
||||||
|
|
||||||
let str string = Str ([], string)
|
let str string = Str ([], string)
|
||||||
let fmt styles string = Str (styles, string)
|
let fmt styles string = Str (styles, string)
|
||||||
|
let horizontal cols = Horizontal cols
|
||||||
let row = function
|
let vertical rows = Vertical rows
|
||||||
| [] -> Empty
|
|
||||||
| hd :: tl -> List.fold_left (fun l r -> Horizontal (l, r)) hd tl
|
|
||||||
|
|
||||||
let col = function
|
|
||||||
| [] -> Empty
|
|
||||||
| hd :: tl -> List.fold_left (fun l r -> Vertical (l, r)) hd tl
|
|
||||||
|
|
||||||
type chunk = {
|
type chunk = {
|
||||||
styles : styles;
|
styles : styles;
|
||||||
@ -69,11 +62,16 @@ let zip_lines (l : line list) (r : line list) =
|
|||||||
zip l r
|
zip l r
|
||||||
|
|
||||||
let rec render_to_lines = function
|
let rec render_to_lines = function
|
||||||
| Empty -> []
|
|
||||||
| Str (styles, string) -> [ { chunks = [ { styles; string } ] } ]
|
| Str (styles, string) -> [ { chunks = [ { styles; string } ] } ]
|
||||||
| Vertical (top, bottom) -> render_to_lines top @ render_to_lines bottom
|
| Vertical rows -> List.concat_map render_to_lines rows
|
||||||
| Horizontal (left, right) ->
|
| Horizontal cols -> (
|
||||||
zip_lines (render_to_lines left) (render_to_lines right)
|
match cols with
|
||||||
|
| [] -> []
|
||||||
|
(* TODO: This is potentially really slow; optimise *)
|
||||||
|
| hd :: tl ->
|
||||||
|
List.fold_left
|
||||||
|
(fun acc col -> zip_lines acc (render_to_lines col))
|
||||||
|
(render_to_lines hd) tl)
|
||||||
|
|
||||||
let render doc =
|
let render doc =
|
||||||
doc |> render_to_lines |> List.map fmt_line |> String_extra.unlines
|
doc |> render_to_lines |> List.map fmt_line |> String_extra.unlines
|
||||||
|
@ -11,10 +11,10 @@ val str : string -> doc
|
|||||||
val fmt : styles -> string -> doc
|
val fmt : styles -> string -> doc
|
||||||
|
|
||||||
(** Put all documents in a list horizontally, automatically adding required padding. *)
|
(** Put all documents in a list horizontally, automatically adding required padding. *)
|
||||||
val row : doc list -> doc
|
val horizontal : doc list -> doc
|
||||||
|
|
||||||
(** Put all documents in a list vertically after each other with a line separator. *)
|
(** Put all documents in a list vertically after each other with a line separator. *)
|
||||||
val col : doc list -> doc
|
val vertical : doc list -> doc
|
||||||
|
|
||||||
(** Render the resulting document. *)
|
(** Render the resulting document. *)
|
||||||
val render : doc -> string
|
val render : doc -> string
|
||||||
|
@ -10,8 +10,8 @@ let debug_section (model : Model.t) =
|
|||||||
|
|
||||||
let tabs_section cur_tab =
|
let tabs_section cur_tab =
|
||||||
let open Pretty in
|
let open Pretty in
|
||||||
let sep = col [ str " "; str " "; str "─" ] in
|
let sep = vertical [ str " "; str " "; str "─" ] in
|
||||||
row
|
horizontal
|
||||||
[
|
[
|
||||||
Widget.code_tab ~is_selected:(cur_tab = Model.Code);
|
Widget.code_tab ~is_selected:(cur_tab = Model.Code);
|
||||||
sep;
|
sep;
|
||||||
@ -25,7 +25,7 @@ let code_section (code_tab : Model.code_tab) =
|
|||||||
Widget.pwd code_tab.root_dir_path (Fs.zipper_parents code_tab.fs)
|
Widget.pwd code_tab.root_dir_path (Fs.zipper_parents code_tab.fs)
|
||||||
in
|
in
|
||||||
let fs_doc = Widget.fs code_tab in
|
let fs_doc = Widget.fs code_tab in
|
||||||
Pretty.col [ current_path_doc; fs_doc ]
|
Pretty.vertical [ current_path_doc; fs_doc ]
|
||||||
|
|
||||||
let tab_content_section (model : Model.t) =
|
let tab_content_section (model : Model.t) =
|
||||||
match model.current_tab with
|
match model.current_tab with
|
||||||
@ -40,6 +40,6 @@ let to_doc (model : Model.t) =
|
|||||||
let tabs = tabs_section model.current_tab in
|
let tabs = tabs_section model.current_tab in
|
||||||
let content = tab_content_section model in
|
let content = tab_content_section model in
|
||||||
|
|
||||||
col [ row [ repo; str " "; debug ]; empty; tabs; content; empty ]
|
vertical [ horizontal [ repo; str " "; debug ]; empty; tabs; content; empty ]
|
||||||
|
|
||||||
let view (model : Model.t) = model |> to_doc |> Pretty.render
|
let view (model : Model.t) = model |> to_doc |> Pretty.render
|
||||||
|
@ -4,7 +4,7 @@ let style_directory = ANSITerminal.[ Bold; magenta ]
|
|||||||
let tab_doc ~is_selected tab_lines =
|
let tab_doc ~is_selected tab_lines =
|
||||||
let open Pretty in
|
let open Pretty in
|
||||||
let format = if is_selected then fmt style_selected else str in
|
let format = if is_selected then fmt style_selected else str in
|
||||||
tab_lines |> List.map format |> col
|
tab_lines |> List.map format |> vertical
|
||||||
|
|
||||||
let code_tab ~is_selected =
|
let code_tab ~is_selected =
|
||||||
tab_doc ~is_selected
|
tab_doc ~is_selected
|
||||||
@ -48,9 +48,9 @@ let file_contents_to_doc ~file_name:_ ~file_contents =
|
|||||||
|> String.split_on_char '\n'
|
|> String.split_on_char '\n'
|
||||||
|> List_extra.take 30
|
|> List_extra.take 30
|
||||||
|> List.map Pretty.str
|
|> List.map Pretty.str
|
||||||
|> Pretty.col
|
|> Pretty.vertical
|
||||||
in
|
in
|
||||||
Pretty.(row [ str " "; file_contents_preview ])
|
Pretty.(horizontal [ str " "; file_contents_preview ])
|
||||||
|
|
||||||
(* Extra padding for:
|
(* Extra padding for:
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ let current_level_to_doc (cursor : Fs.cursor) ~has_next =
|
|||||||
if i = hi_pos - 1 || i = hi_pos || i = hi_pos + 1 then
|
if i = hi_pos - 1 || i = hi_pos || i = hi_pos + 1 then
|
||||||
fmt style_selected s
|
fmt style_selected s
|
||||||
else str s)
|
else str s)
|
||||||
|> col
|
|> vertical
|
||||||
|
|
||||||
let children_to_doc ~prev_total ~pos children =
|
let children_to_doc ~prev_total ~pos children =
|
||||||
let open Pretty in
|
let open Pretty in
|
||||||
@ -121,7 +121,7 @@ let children_to_doc ~prev_total ~pos children =
|
|||||||
List_extra.generate prev_rows_count (fun i ->
|
List_extra.generate prev_rows_count (fun i ->
|
||||||
let is_current_pos = i = connect_pos in
|
let is_current_pos = i = connect_pos in
|
||||||
if is_current_pos then str "─" else str " ")
|
if is_current_pos then str "─" else str " ")
|
||||||
|> col
|
|> vertical
|
||||||
in
|
in
|
||||||
|
|
||||||
(* Formatting single file name *)
|
(* Formatting single file name *)
|
||||||
@ -150,10 +150,10 @@ let children_to_doc ~prev_total ~pos children =
|
|||||||
in
|
in
|
||||||
pad_before @ lines)
|
pad_before @ lines)
|
||||||
|> List.map str
|
|> List.map str
|
||||||
|> col
|
|> vertical
|
||||||
in
|
in
|
||||||
|
|
||||||
row [ connector_doc; files_doc ]
|
horizontal [ connector_doc; files_doc ]
|
||||||
|
|
||||||
type next_level =
|
type next_level =
|
||||||
| Empty_directory
|
| Empty_directory
|
||||||
@ -191,4 +191,4 @@ let fs (code_tab : Model.code_tab) =
|
|||||||
match next_level_doc with
|
match next_level_doc with
|
||||||
| Empty_directory -> current_level_doc
|
| Empty_directory -> current_level_doc
|
||||||
| Directory_contents next_level_doc | File_contents next_level_doc ->
|
| Directory_contents next_level_doc | File_contents next_level_doc ->
|
||||||
Pretty.row [ current_level_doc; next_level_doc ]
|
Pretty.horizontal [ current_level_doc; next_level_doc ]
|
||||||
|
Loading…
Reference in New Issue
Block a user