From 3d1957dc729cbc09e3b165c6aa8d78c56362d7f0 Mon Sep 17 00:00:00 2001 From: Heath Henley Date: Tue, 11 Feb 2025 23:25:54 -0500 Subject: [PATCH 1/2] Add a cli arg to toggle icons --- lib/cli.ml | 16 ++++++++--- lib/pretty/dune | 1 + lib/pretty/icon.ml | 54 ++++++++++++++++++++++++++++++-------- lib/pretty/icon.mli | 23 ++++++++++++++++ lib/pretty/pretty.mli | 4 --- lib/tui/init/init.ml | 8 +++--- lib/tui/init/init.mli | 1 + lib/tui/model/dune | 1 + lib/tui/model/issue.ml | 4 +-- lib/tui/model/issue.mli | 2 +- lib/tui/model/model.ml | 9 +++++-- lib/tui/render/render.ml | 18 ++++++------- lib/tui/render/render.mli | 2 +- lib/tui/view.ml | 7 ++--- lib/tui/widget/code.ml | 49 ++++++++++++++++++---------------- lib/tui/widget/code.mli | 2 +- lib/tui/widget/common.ml | 10 +++---- lib/tui/widget/common.mli | 2 +- lib/tui/widget/generic.ml | 4 +-- lib/tui/widget/generic.mli | 6 ++++- lib/tui/widget/issue.ml | 10 +++---- lib/tui/widget/issue.mli | 2 +- lib/tui/widget/pr.ml | 10 +++---- lib/tui/widget/pr.mli | 2 +- 24 files changed, 163 insertions(+), 84 deletions(-) create mode 100644 lib/pretty/icon.mli diff --git a/lib/cli.ml b/lib/cli.ml index 93f31da..b0ab7fe 100644 --- a/lib/cli.ml +++ b/lib/cli.ml @@ -22,12 +22,22 @@ let ignore_size_warning_arg = let doc = "Ignore the minimum size warning." in Arg.(value & flag & info [ "i"; "ignore-size-warning" ] ~doc) -let run owner_repo local_path log_file ignore_size_warning = - Tui.start { owner_repo; local_path; log_file; ignore_size_warning } +let no_nerd_font_arg = + let doc = "Don't try to use Nerd Font Icons." in + Arg.(value & flag & info [ "n"; "no-nerd-font" ] ~doc) + +let run owner_repo local_path log_file ignore_size_warning no_nerd_font = + Tui.start + { owner_repo; local_path; log_file; ignore_size_warning; no_nerd_font } let gh_tui_term = Term.( - const run $ owner_repo_arg $ path_arg $ log_arg $ ignore_size_warning_arg) + const run + $ owner_repo_arg + $ path_arg + $ log_arg + $ ignore_size_warning_arg + $ no_nerd_font_arg) let cmd = let doc = "TUI of a GitHub repository" in diff --git a/lib/pretty/dune b/lib/pretty/dune index ff0a01f..e6a451c 100644 --- a/lib/pretty/dune +++ b/lib/pretty/dune @@ -3,5 +3,6 @@ (libraries ansifmt shell + str ;; Internal dependencies extra)) diff --git a/lib/pretty/icon.ml b/lib/pretty/icon.ml index 1467968..fd01785 100644 --- a/lib/pretty/icon.ml +++ b/lib/pretty/icon.ml @@ -1,11 +1,43 @@ -let closed_char = "\u{ebda}" -let open_char = "\u{ea64}" -let merged_char = "\u{e725}" -let arrow_left_char = "\u{f0a8}" -let pwd_char = "\u{e5fd}" -let dir_char = "\u{f4d4}" -let empty_dir_char = "\u{f413}" -let file_char = "\u{f4a5}" -let bin_char = "\u{eae8}" -let warning = "\u{26A0}" -let issue_char = "\u{f41b}" +type t = { + closed_char : string; + open_char : string; + merged_char : string; + arrow_left_char : string; + pwd_char : string; + dir_char : string; + empty_dir_char : string; + file_char : string; + bin_char : string; + warning : string; + issue_char : string; +} + +let get_icons no_nerd_font = + if no_nerd_font = false then + { + closed_char = "\u{ebda}"; + open_char = "\u{ea64}"; + merged_char = "\u{e725}"; + arrow_left_char = "\u{f0a8}"; + pwd_char = "\u{e5fd}"; + dir_char = "\u{f4d4}"; + empty_dir_char = "\u{f413}"; + file_char = "\u{f4a5}"; + bin_char = "\u{eae8}"; + warning = "\u{26A0}"; + issue_char = "\u{f41b}"; + } + else + { + closed_char = "x"; + open_char = "o"; + merged_char = "m"; + arrow_left_char = "<-"; + pwd_char = "*"; + dir_char = "/"; + empty_dir_char = "/"; + file_char = "f"; + bin_char = "b"; + warning = "!"; + issue_char = "i"; + } diff --git a/lib/pretty/icon.mli b/lib/pretty/icon.mli new file mode 100644 index 0000000..0abe179 --- /dev/null +++ b/lib/pretty/icon.mli @@ -0,0 +1,23 @@ +(** A record representing the Icons and symbols used for identifying different + parts. Symbols from Hack Nerd Font Mono are used when it's not explicitly + disabled. + + Symbols list: + + - https://www.nerdfonts.com/cheat-sheet *) +type t = { + closed_char : string; + open_char : string; + merged_char : string; + arrow_left_char : string; + pwd_char : string; + dir_char : string; + empty_dir_char : string; + file_char : string; + bin_char : string; + warning : string; + issue_char : string; +} + +(* Get the icon set - either nerd font or text icons *) +val get_icons : bool -> t diff --git a/lib/pretty/pretty.mli b/lib/pretty/pretty.mli index c961dd7..6f65c72 100644 --- a/lib/pretty/pretty.mli +++ b/lib/pretty/pretty.mli @@ -13,10 +13,6 @@ module Doc = Doc {!Layout.t} is the output of {!Doc.render} with all the sizes calculated. *) module Layout = Layout -(** Icons and symbols used for identifying different parts. Symbols from Hack - Nerd Font Mono are used when it's available. Symbols list: - - - https://www.nerdfonts.com/cheat-sheet *) module Icon = Icon (** Render a document into the final string diff --git a/lib/tui/init/init.ml b/lib/tui/init/init.ml index 4245592..6c645b4 100644 --- a/lib/tui/init/init.ml +++ b/lib/tui/init/init.ml @@ -71,12 +71,14 @@ type t = { local_path : string option; log_file : string option; ignore_size_warning : bool; + no_nerd_font : bool; } -let init { owner_repo; local_path; ignore_size_warning; log_file = _ } : - Model.initial_data = +let init + { owner_repo; local_path; ignore_size_warning; log_file = _; no_nerd_font } + : Model.initial_data = let ({ owner; repo } as owner_repo) = parse_owner_repo owner_repo in let root_dir_path = clone_repo ~owner_repo ~local_path in let files = Lazy.force (read_root_tree ~root_dir_path) in let { height; width } = get_terminal_dimensions ignore_size_warning in - { owner; repo; root_dir_path; files; width; height } + { owner; repo; root_dir_path; files; width; height; no_nerd_font } diff --git a/lib/tui/init/init.mli b/lib/tui/init/init.mli index efdcecb..c8a6ded 100644 --- a/lib/tui/init/init.mli +++ b/lib/tui/init/init.mli @@ -3,6 +3,7 @@ type t = { local_path : string option; log_file : string option; ignore_size_warning : bool; + no_nerd_font : bool; } val init : t -> Model.initial_data diff --git a/lib/tui/model/dune b/lib/tui/model/dune index 65031ce..bedc64f 100644 --- a/lib/tui/model/dune +++ b/lib/tui/model/dune @@ -4,4 +4,5 @@ ;; Internal dependencies fs gh + pretty render)) diff --git a/lib/tui/model/issue.ml b/lib/tui/model/issue.ml index d289cd2..9ee2f60 100644 --- a/lib/tui/model/issue.ml +++ b/lib/tui/model/issue.ml @@ -39,12 +39,12 @@ let apply_filter filter t = let scroll_start = 0 in { t with filter; issues; offset; scroll_start } -let make ~owner ~repo = +let make ~owner ~repo icons = let issues_and_errors = lazy (match Gh.Issue.issues ~owner ~repo with | Ok issues -> - let rendered = Render.issues issues in + let rendered = Render.issues issues icons in (rendered, None) | Error err -> ([], Some err)) in diff --git a/lib/tui/model/issue.mli b/lib/tui/model/issue.mli index 97f577d..3a3abca 100644 --- a/lib/tui/model/issue.mli +++ b/lib/tui/model/issue.mli @@ -22,7 +22,7 @@ and filter = val filter_all : filter val filter_open : filter val filter_closed : filter -val make : owner:string -> repo:string -> t +val make : owner:string -> repo:string -> Pretty.Icon.t -> t (** Change the filter to a new one and update currently selected issues. *) val apply_filter : filter -> t -> t diff --git a/lib/tui/model/model.ml b/lib/tui/model/model.ml index 843c6f8..11cf841 100644 --- a/lib/tui/model/model.ml +++ b/lib/tui/model/model.ml @@ -24,6 +24,7 @@ type t = { code_tab : code_tab; issues_tab : Issue.t; pull_requests_tab : Pr.t; + no_nerd_font : bool; } type initial_data = { @@ -33,9 +34,12 @@ type initial_data = { files : Fs.tree array; width : int; height : int; + no_nerd_font : bool; } -let initial_model { owner; repo; root_dir_path; files; width; height } = +let initial_model + { owner; repo; root_dir_path; files; width; height; no_nerd_font } = + let icons = Pretty.Icon.get_icons no_nerd_font in { width; height; @@ -43,6 +47,7 @@ let initial_model { owner; repo; root_dir_path; files; width; height } = repo; current_tab = Code; code_tab = { root_dir_path; fs = Fs.zip_it files }; - issues_tab = Issue.make ~owner ~repo; + issues_tab = Issue.make ~owner ~repo icons; pull_requests_tab = Pr.make ~owner ~repo; + no_nerd_font; } diff --git a/lib/tui/render/render.ml b/lib/tui/render/render.ml index 00911fa..786c52e 100644 --- a/lib/tui/render/render.ml +++ b/lib/tui/render/render.ml @@ -6,16 +6,16 @@ type 'a t = { layout : Pretty.Layout.t; } -let fmt_issue_state (state : Gh.Issue.state) = +let fmt_issue_state (state : Gh.Issue.state) (icons : Pretty.Icon.t) = match state with - | Open -> Layout.(fmt Style.issue_open Pretty.Icon.issue_char) - | Closed -> Layout.(fmt Style.issue_closed Pretty.Icon.issue_char) + | Open -> Layout.(fmt Style.issue_open icons.issue_char) + | Closed -> Layout.(fmt Style.issue_closed icons.issue_char) -let fmt_title (issue : Gh.Issue.t) = +let fmt_title (issue : Gh.Issue.t) (icons : Pretty.Icon.t) = let open Layout in horizontal [ - fmt_issue_state issue.state; + fmt_issue_state issue.state icons; str " "; fmt Style.secondary (Printf.sprintf "#%d " issue.number); str issue.title; @@ -33,11 +33,11 @@ let fmt_labels labels = in labels |> List.map fmt_label |> fun labels -> horizontal (str " " :: labels) -let fmt_issue (issue : Gh.Issue.t) = - Layout.vertical [ fmt_title issue; fmt_labels issue.labels ] +let fmt_issue (issue : Gh.Issue.t) (icons : Pretty.Icon.t) = + Layout.vertical [ fmt_title issue icons; fmt_labels issue.labels ] -let issues issue_list = - let layouts = List.map fmt_issue issue_list in +let issues issue_list icons = + let layouts = List.map (fun issue -> fmt_issue issue icons) issue_list in let max_issue_width = Extra.List.max_on Layout.width layouts in ListLabels.map2 issue_list layouts ~f:(fun issue layout -> let width = Layout.width layout in diff --git a/lib/tui/render/render.mli b/lib/tui/render/render.mli index 84bf9f6..a4fee34 100644 --- a/lib/tui/render/render.mli +++ b/lib/tui/render/render.mli @@ -12,4 +12,4 @@ type 'a t = { } (** [issue_items issues] renders issues*) -val issues : Gh.Issue.t list -> Gh.Issue.t t list +val issues : Gh.Issue.t list -> Pretty.Icon.t -> Gh.Issue.t t list diff --git a/lib/tui/view.ml b/lib/tui/view.ml index b2fe290..1ed4f06 100644 --- a/lib/tui/view.ml +++ b/lib/tui/view.ml @@ -20,10 +20,11 @@ let tabs_section cur_tab = let tab_content_section (model : Model.t) = let tab_doc = + let icons = Pretty.Icon.get_icons model.no_nerd_font in match model.current_tab with - | Code -> Widget.Code.section model.code_tab - | Issues -> Widget.Issue.section model.issues_tab - | PullRequests -> Widget.Pr.section model.pull_requests_tab + | Code -> Widget.Code.section model.code_tab icons + | Issues -> Widget.Issue.section model.issues_tab icons + | PullRequests -> Widget.Pr.section model.pull_requests_tab icons in tab_doc diff --git a/lib/tui/widget/code.ml b/lib/tui/widget/code.ml index f5dddf2..e44a9a1 100644 --- a/lib/tui/widget/code.ml +++ b/lib/tui/widget/code.ml @@ -10,12 +10,12 @@ let scroll ~lines ~span ~offset = let parents_path parents = List.fold_left (fun acc cur -> Filename.concat acc cur) "" (List.rev parents) -let pwd root_dir_path (fs : Fs.zipper) = +let pwd root_dir_path (fs : Fs.zipper) (icons : Pretty.Icon.t) = let parents = Fs.zipper_parents fs in let pwd_path = parents_path parents in let root_dir_name = Filename.basename root_dir_path in let full_path = - Pretty.Icon.pwd_char ^ " " ^ Filename.concat root_dir_name pwd_path + icons.pwd_char ^ " " ^ Filename.concat root_dir_name pwd_path in Pretty.Doc.(fmt Style.directory full_path) @@ -47,19 +47,20 @@ let max_file_name_len files = |> 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 fmt_file ~max_name_len (tree : Fs.tree) (icons : Pretty.Icon.t) = let pad = Extra.String.fill_right max_name_len in match tree with | File { name; file_type; _ } -> ( match Lazy.force file_type with - | Fs.Filec.Text -> Pretty.Icon.file_char ^ " " ^ pad name - | Fs.Filec.Binary -> Pretty.Icon.bin_char ^ " " ^ pad name) + | Fs.Filec.Text -> icons.file_char ^ " " ^ pad name + | Fs.Filec.Binary -> icons.bin_char ^ " " ^ pad name) | Dir { name; children = (lazy children) } -> ( match children with - | [||] -> Pretty.Icon.empty_dir_char ^ " " ^ pad name - | _ -> Pretty.Icon.dir_char ^ " " ^ pad name) + | [||] -> icons.empty_dir_char ^ " " ^ pad name + | _ -> icons.dir_char ^ " " ^ pad name) -let current_level_to_doc (cursor : Fs.dir_cursor) ~has_next ~is_file_chosen = +let current_level_to_doc (cursor : Fs.dir_cursor) ~has_next ~is_file_chosen + icons = let open Pretty.Doc in let max_name_len = max_file_name_len cursor.files in let max_len = max_name_len + file_name_padding in @@ -70,8 +71,10 @@ let current_level_to_doc (cursor : Fs.dir_cursor) ~has_next ~is_file_chosen = let bot = "╰" ^ Extra.String.repeat_txt (max_len - 2) "─" ^ "╯" in (* Line *) - let fmt_selected_name file = "│ " ^ fmt_file ~max_name_len file ^ " ├" in - let fmt_name file = "│ " ^ fmt_file ~max_name_len file ^ " │" in + let fmt_selected_name file = + "│ " ^ fmt_file ~max_name_len file icons ^ " ├" + in + let fmt_name file = "│ " ^ fmt_file ~max_name_len file icons ^ " │" in let hi_pos = (2 * cursor.pos) + 1 in let style = if is_file_chosen then Style.chosen else Style.selected in @@ -89,7 +92,7 @@ let current_level_to_doc (cursor : Fs.dir_cursor) ~has_next ~is_file_chosen = else str s) |> vertical -let children_to_doc ~prev_total ~pos children = +let children_to_doc ~prev_total ~pos children icons = let open Pretty.Doc in let max_name_len = max_file_name_len children in let max_len = max_name_len + file_name_padding in @@ -110,7 +113,7 @@ let children_to_doc ~prev_total ~pos children = in (* Formatting single file name *) - let fmt_name i file = + let fmt_name i file icons = let is_first_pos = i = 0 in let is_last_pos = i = Array.length children - 1 in let has_more_than_one = Array.length children > 1 in @@ -119,14 +122,14 @@ let children_to_doc ~prev_total ~pos children = else if is_last_pos then "└" else "├" in - prefix ^ "─┤ " ^ fmt_file ~max_name_len file ^ " │" + prefix ^ "─┤ " ^ fmt_file ~max_name_len file icons ^ " │" in (* Next level files *) let files_doc = children |> Array.to_list - |> List.mapi fmt_name + |> List.mapi (fun i f -> fmt_name i f icons) |> Extra.List.in_between ~sep:mid |> (fun lines -> [ top ] @ lines @ [ bot ]) |> (fun lines -> @@ -135,7 +138,6 @@ let children_to_doc ~prev_total ~pos children = |> List.map str |> vertical in - horizontal [ connector_doc; files_doc ] type next_level = @@ -155,7 +157,7 @@ type selected_node = children : Fs.tree array Lazy.t; } -let next_level_to_doc selected_node = +let next_level_to_doc selected_node icons = (* Get the next level files *) match selected_node with | File_selected file_contents -> @@ -166,7 +168,8 @@ let next_level_to_doc selected_node = (* No children of a directory without children *) | [||] -> Empty_directory (* Non-empty array of children *) - | _ -> Directory_contents (children_to_doc ~prev_total ~pos children)) + | _ -> + Directory_contents (children_to_doc ~prev_total ~pos children icons)) type fs_view = { left : Fs.dir_cursor; @@ -202,22 +205,22 @@ let fs_to_view (fs : Fs.zipper) = { left; right; is_file_chosen } -let file_view (fs : Fs.zipper) = +let file_view (fs : Fs.zipper) icons = let view = fs_to_view fs in - let next_level_doc = next_level_to_doc view.right in + let next_level_doc = next_level_to_doc view.right icons in let current_level_doc = current_level_to_doc view.left ~has_next:(is_directory_contents next_level_doc) - ~is_file_chosen:view.is_file_chosen + ~is_file_chosen:view.is_file_chosen icons in match next_level_doc with | Empty_directory -> current_level_doc | Directory_contents next_level_doc | File_contents next_level_doc -> Pretty.Doc.horizontal [ current_level_doc; next_level_doc ] -let section (code_tab : Model.code_tab) = - let current_path_doc = pwd code_tab.root_dir_path code_tab.fs in - let fs_doc = file_view code_tab.fs in +let section (code_tab : Model.code_tab) icons = + let current_path_doc = pwd code_tab.root_dir_path code_tab.fs icons in + let fs_doc = file_view code_tab.fs icons in Pretty.Doc.vertical [ current_path_doc; fs_doc ] diff --git a/lib/tui/widget/code.mli b/lib/tui/widget/code.mli index 137a543..07d8a1b 100644 --- a/lib/tui/widget/code.mli +++ b/lib/tui/widget/code.mli @@ -1,2 +1,2 @@ (** Format a Code tab into a pretty looking doc. **) -val section : Model.code_tab -> Pretty.Doc.t +val section : Model.code_tab -> Pretty.Icon.t -> Pretty.Doc.t diff --git a/lib/tui/widget/common.ml b/lib/tui/widget/common.ml index 51831db..6994ddd 100644 --- a/lib/tui/widget/common.ml +++ b/lib/tui/widget/common.ml @@ -1,10 +1,10 @@ -let fmt_error (error : Gh.Client.error) = +let fmt_error (error : Gh.Client.error) (icons : Pretty.Icon.t) = let open Pretty.Doc in match error with | No_github_token -> [ str - (Pretty.Icon.warning + (icons.warning ^ " GITHUB_TOKEN not found. Make sure it's configured in your \ environment."); str ""; @@ -13,15 +13,15 @@ let fmt_error (error : Gh.Client.error) = ] | Bad_credentials { msg; doc_url; code } -> [ - str (Format.sprintf "%s [%d] %s" Pretty.Icon.warning code msg); + str (Format.sprintf "%s [%d] %s" icons.warning code msg); str ""; str ("Documentation url: " ^ doc_url); ] | Curl_error { code; msg } -> [ str - (Format.sprintf "%s GitHub API returned error code: %d" - Pretty.Icon.warning code); + (Format.sprintf "%s GitHub API returned error code: %d" icons.warning + code); str ""; str msg; ] diff --git a/lib/tui/widget/common.mli b/lib/tui/widget/common.mli index 33f3132..995f811 100644 --- a/lib/tui/widget/common.mli +++ b/lib/tui/widget/common.mli @@ -1 +1 @@ -val fmt_error : Gh.Client.error -> Pretty.Doc.t list +val fmt_error : Gh.Client.error -> Pretty.Icon.t -> Pretty.Doc.t list diff --git a/lib/tui/widget/generic.ml b/lib/tui/widget/generic.ml index ae83de7..91b305e 100644 --- a/lib/tui/widget/generic.ml +++ b/lib/tui/widget/generic.ml @@ -34,7 +34,7 @@ let issues_height n = if n = 0 then 0 else (3 * n) + 1 let height = issues_height Model.Issue.max_issues let span = height -let vlist_border ~scroll_start ~selected items = +let vlist_border ~scroll_start ~selected items (icons : Pretty.Icon.t) = (* Create the scroll element *) let lines = items |> Array.length |> issues_height in let scroll = Scroll.make ~height ~span ~lines ~offset:(3 * scroll_start) in @@ -66,7 +66,7 @@ let vlist_border ~scroll_start ~selected items = let first_line = Doc.( horizontal - [ fmt_selected_line hd; str " "; str Pretty.Icon.arrow_left_char ]) + [ fmt_selected_line hd; str " "; str icons.arrow_left_char ]) in let other_lines = List.map fmt_selected_line tl in first_line :: other_lines diff --git a/lib/tui/widget/generic.mli b/lib/tui/widget/generic.mli index 7d18d2c..258b3b5 100644 --- a/lib/tui/widget/generic.mli +++ b/lib/tui/widget/generic.mli @@ -21,4 +21,8 @@ This function takes values of type {!Pretty.Layout.t}, so it could efficiently calculate the size of element per line. *) val vlist_border : - scroll_start:int -> selected:int -> Pretty.Layout.t array -> Pretty.Doc.t + scroll_start:int -> + selected:int -> + Pretty.Layout.t array -> + Pretty.Icon.t -> + Pretty.Doc.t diff --git a/lib/tui/widget/issue.ml b/lib/tui/widget/issue.ml index e3d0402..2d96cd6 100644 --- a/lib/tui/widget/issue.ml +++ b/lib/tui/widget/issue.ml @@ -37,13 +37,13 @@ let fmt_filters current_filter = let pad = Doc.str " " in Doc.horizontal [ filter_open; pad; filter_closed; pad; filter_all ] -let fmt_issues ~selected issues = +let fmt_issues ~scroll_start ~selected issues icons = issues |> Lazy.force |> Array.map (fun (rendered : _ Render.t) -> rendered.layout) - |> Generic.vlist_border ~selected + |> fun i -> Generic.vlist_border ~scroll_start ~selected i icons -let section (issues_tab : Model.Issue.t) = +let section (issues_tab : Model.Issue.t) icons = let docs = match issues_tab.error |> Lazy.force with | None -> @@ -51,8 +51,8 @@ let section (issues_tab : Model.Issue.t) = fmt_filters issues_tab.filter; Doc.str ""; fmt_issues ~scroll_start:issues_tab.scroll_start - ~selected:issues_tab.offset issues_tab.issues; + ~selected:issues_tab.offset issues_tab.issues icons; ] - | Some error -> Common.fmt_error error + | Some error -> Common.fmt_error error icons in Doc.vertical docs diff --git a/lib/tui/widget/issue.mli b/lib/tui/widget/issue.mli index 36fb2bf..34cd967 100644 --- a/lib/tui/widget/issue.mli +++ b/lib/tui/widget/issue.mli @@ -1,2 +1,2 @@ (** Format an Issue tab into a pretty looking doc. **) -val section : Model.Issue.t -> Pretty.Doc.t +val section : Model.Issue.t -> Pretty.Icon.t -> Pretty.Doc.t diff --git a/lib/tui/widget/pr.ml b/lib/tui/widget/pr.ml index 9611fb3..6832460 100644 --- a/lib/tui/widget/pr.ml +++ b/lib/tui/widget/pr.ml @@ -1,15 +1,15 @@ module Style = Pretty.Style -let section (tab : Model.Pr.t) = +let section (tab : Model.Pr.t) (icons : Pretty.Icon.t) = let open Pretty.Doc in let docs = match tab.error with | None -> let fmt_state = function | None -> str "" - | Some Gh.Pr.Merged -> fmt Style.pr_merged Pretty.Icon.merged_char - | Some Gh.Pr.Open -> fmt Style.pr_open Pretty.Icon.open_char - | Some Gh.Pr.Closed -> fmt Style.pr_closed Pretty.Icon.closed_char + | Some Gh.Pr.Merged -> fmt Style.pr_merged icons.merged_char + | Some Gh.Pr.Open -> fmt Style.pr_open icons.open_char + | Some Gh.Pr.Closed -> fmt Style.pr_closed icons.closed_char in let fmt_pr (pr : Gh.Pr.t) = Pretty.Doc.( @@ -24,6 +24,6 @@ let section (tab : Model.Pr.t) = ]) in tab.pull_requests |> Lazy.force |> List.map fmt_pr - | Some error -> Common.fmt_error error + | Some error -> Common.fmt_error error icons in vertical docs diff --git a/lib/tui/widget/pr.mli b/lib/tui/widget/pr.mli index 2e67dec..0c4c90a 100644 --- a/lib/tui/widget/pr.mli +++ b/lib/tui/widget/pr.mli @@ -1,2 +1,2 @@ (** Format a PR tab into a pretty looking doc **) -val section : Model.Pr.t -> Pretty.Doc.t +val section : Model.Pr.t -> Pretty.Icon.t -> Pretty.Doc.t From f5fbd1e3779b9c8c72ccc82531b5fa287826837d Mon Sep 17 00:00:00 2001 From: Heath Henley Date: Sat, 1 Mar 2025 18:50:06 -0500 Subject: [PATCH 2/2] Add docs back --- lib/pretty/pretty.mli | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/pretty/pretty.mli b/lib/pretty/pretty.mli index 6f65c72..3ce2677 100644 --- a/lib/pretty/pretty.mli +++ b/lib/pretty/pretty.mli @@ -13,6 +13,9 @@ module Doc = Doc {!Layout.t} is the output of {!Doc.render} with all the sizes calculated. *) module Layout = Layout +(** Icons and symbols used for identifying different parts. Symbols from Hack + Nerd Font Mono are used when it's available. Symbols list: + - https://www.nerdfonts.com/cheat-sheet *) module Icon = Icon (** Render a document into the final string