From 8d1e951ce389329c66067d0995b08be2fee0afa2 Mon Sep 17 00:00:00 2001 From: Heath Henley Date: Mon, 10 Feb 2025 18:48:25 -0500 Subject: [PATCH 1/5] Move all the icons into Pretty.Icon --- lib/pretty/icon.ml | 10 ++++++++++ lib/pretty/pretty.ml | 1 + lib/pretty/pretty.mli | 2 ++ lib/tui/widget/code.ml | 18 +++++++----------- lib/tui/widget/common.ml | 11 +++++++---- lib/tui/widget/generic.ml | 4 ++-- lib/tui/widget/pr.ml | 10 +++------- 7 files changed, 32 insertions(+), 24 deletions(-) create mode 100644 lib/pretty/icon.ml diff --git a/lib/pretty/icon.ml b/lib/pretty/icon.ml new file mode 100644 index 0000000..ed05a3c --- /dev/null +++ b/lib/pretty/icon.ml @@ -0,0 +1,10 @@ +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}" diff --git a/lib/pretty/pretty.ml b/lib/pretty/pretty.ml index c43a716..397a8e5 100644 --- a/lib/pretty/pretty.ml +++ b/lib/pretty/pretty.ml @@ -1,6 +1,7 @@ module Doc = Doc module Layout = Layout module Style = Style +module Icon = Icon let render ~width ~height doc = doc |> Doc.render ~width ~height |> Layout.to_lines |> Extra.String.unlines diff --git a/lib/pretty/pretty.mli b/lib/pretty/pretty.mli index 8369690..6f65c72 100644 --- a/lib/pretty/pretty.mli +++ b/lib/pretty/pretty.mli @@ -13,6 +13,8 @@ module Doc = Doc {!Layout.t} is the output of {!Doc.render} with all the sizes calculated. *) module Layout = Layout +module Icon = Icon + (** Render a document into the final string All notes from {!Doc.render} apply. *) diff --git a/lib/tui/widget/code.ml b/lib/tui/widget/code.ml index c4581df..95dfa82 100644 --- a/lib/tui/widget/code.ml +++ b/lib/tui/widget/code.ml @@ -7,12 +7,6 @@ let scroll ~lines ~span ~offset = | None -> Pretty.Doc.str " " | Some scroll -> scroll |> Scroll.to_sections |> Scroll.render -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 parents_path parents = List.fold_left (fun acc cur -> Filename.concat acc cur) "" (List.rev parents) @@ -20,7 +14,9 @@ let pwd root_dir_path (fs : Fs.zipper) = 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 = pwd_char ^ " " ^ Filename.concat root_dir_name pwd_path in + let full_path = + Pretty.Icon.pwd_char ^ " " ^ Filename.concat root_dir_name pwd_path + in Pretty.Doc.(fmt Style.directory full_path) let file_contents_to_doc ~(file_contents : Fs.Filec.t) = @@ -56,12 +52,12 @@ let fmt_file ~max_name_len (tree : Fs.tree) = match tree with | File (name, _, file_type) -> ( match Lazy.force file_type with - | Fs.Filec.Text -> file_char ^ " " ^ pad name - | Fs.Filec.Binary -> bin_char ^ " " ^ pad name) + | Fs.Filec.Text -> Pretty.Icon.file_char ^ " " ^ pad name + | Fs.Filec.Binary -> Pretty.Icon.bin_char ^ " " ^ pad name) | Dir (name, (lazy children)) -> ( match children with - | [||] -> empty_dir_char ^ " " ^ pad name - | _ -> dir_char ^ " " ^ pad name) + | [||] -> Pretty.Icon.empty_dir_char ^ " " ^ pad name + | _ -> Pretty.Icon.dir_char ^ " " ^ pad name) let current_level_to_doc (cursor : Fs.dir_cursor) ~has_next ~is_file_chosen = let open Pretty.Doc in diff --git a/lib/tui/widget/common.ml b/lib/tui/widget/common.ml index fb456c1..30879f9 100644 --- a/lib/tui/widget/common.ml +++ b/lib/tui/widget/common.ml @@ -4,21 +4,24 @@ let fmt_error (error : Gh.Client.error) = | No_github_token -> [ str - "\u{26A0} GITHUB_TOKEN not found. Make sure it's configured in your \ - environment."; + (Pretty.Icon.warning + ^ " GITHUB_TOKEN not found. Make sure it's configured in your \ + environment."); str ""; str "If you don't have a token, visit the following page to create one:"; str " • https://github.com/settings/tokens"; ] | Bad_credentials { msg; doc_url; code } -> [ - str (Format.sprintf "\u{26A0} [%d] %s" code msg); + str (Pretty.Icon.warning ^ Format.sprintf " [%d] %s" code msg); str ""; str ("Documentation url: " ^ doc_url); ] | Curl_error { code; msg } -> [ - str (Format.sprintf "\u{26A0} GitHub API returned error code %d: " code); + str + (Pretty.Icon.warning + ^ Format.sprintf " GitHub API returned error code: %d" code); str ""; str msg; ] diff --git a/lib/tui/widget/generic.ml b/lib/tui/widget/generic.ml index 105d6bd..ae83de7 100644 --- a/lib/tui/widget/generic.ml +++ b/lib/tui/widget/generic.ml @@ -22,7 +22,6 @@ let of_lines lines = { is_selected = false; item_type = Lines lines } * 1: Unicode box character (right) *) let item_padding = 4 -let arrow_left_char = "\u{f0a8}" (* Calculate the number of lines it takes to render [n] issues. @@ -66,7 +65,8 @@ let vlist_border ~scroll_start ~selected items = | hd :: tl -> let first_line = Doc.( - horizontal [ fmt_selected_line hd; str " "; str arrow_left_char ]) + horizontal + [ fmt_selected_line hd; str " "; str Pretty.Icon.arrow_left_char ]) in let other_lines = List.map fmt_selected_line tl in first_line :: other_lines diff --git a/lib/tui/widget/pr.ml b/lib/tui/widget/pr.ml index 3ee4d8b..9611fb3 100644 --- a/lib/tui/widget/pr.ml +++ b/lib/tui/widget/pr.ml @@ -1,9 +1,5 @@ module Style = Pretty.Style -let closed_char = "\u{ebda}" -let open_char = "\u{ea64}" -let merged_char = "\u{e725}" - let section (tab : Model.Pr.t) = let open Pretty.Doc in let docs = @@ -11,9 +7,9 @@ let section (tab : Model.Pr.t) = | None -> let fmt_state = function | None -> str "" - | Some Gh.Pr.Merged -> fmt Style.pr_merged merged_char - | Some Gh.Pr.Open -> fmt Style.pr_open open_char - | Some Gh.Pr.Closed -> fmt Style.pr_closed closed_char + | 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 in let fmt_pr (pr : Gh.Pr.t) = Pretty.Doc.( From 2ef07e55f84c0101b29a273198d68617c0a0e90a Mon Sep 17 00:00:00 2001 From: Heath Henley Date: Mon, 10 Feb 2025 19:02:30 -0500 Subject: [PATCH 2/5] Forgot to move issue_char --- lib/pretty/icon.ml | 1 + lib/tui/render/render.ml | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/pretty/icon.ml b/lib/pretty/icon.ml index ed05a3c..1467968 100644 --- a/lib/pretty/icon.ml +++ b/lib/pretty/icon.ml @@ -8,3 +8,4 @@ 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}" diff --git a/lib/tui/render/render.ml b/lib/tui/render/render.ml index 154f319..00911fa 100644 --- a/lib/tui/render/render.ml +++ b/lib/tui/render/render.ml @@ -6,12 +6,10 @@ type 'a t = { layout : Pretty.Layout.t; } -let issue_char = "\u{f41b}" - let fmt_issue_state (state : Gh.Issue.state) = match state with - | Open -> Layout.(fmt Style.issue_open issue_char) - | Closed -> Layout.(fmt Style.issue_closed issue_char) + | Open -> Layout.(fmt Style.issue_open Pretty.Icon.issue_char) + | Closed -> Layout.(fmt Style.issue_closed Pretty.Icon.issue_char) let fmt_title (issue : Gh.Issue.t) = let open Layout in From 8dff863f1e01dbbabb8ff13769e13a1bcf515827 Mon Sep 17 00:00:00 2001 From: Heath Henley Date: Tue, 11 Feb 2025 14:09:28 -0500 Subject: [PATCH 3/5] Add docs about Icon module Co-authored-by: Dmitrii Kovanikov --- lib/pretty/pretty.mli | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/pretty/pretty.mli b/lib/pretty/pretty.mli index 6f65c72..e25fc0b 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 From 98b272d8722d213898fa2293e549c7a196600321 Mon Sep 17 00:00:00 2001 From: Heath Henley Date: Tue, 11 Feb 2025 14:10:02 -0500 Subject: [PATCH 4/5] Make icon an arg to sprintf Co-authored-by: Dmitrii Kovanikov --- lib/tui/widget/common.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tui/widget/common.ml b/lib/tui/widget/common.ml index 30879f9..a0a3d53 100644 --- a/lib/tui/widget/common.ml +++ b/lib/tui/widget/common.ml @@ -13,7 +13,7 @@ let fmt_error (error : Gh.Client.error) = ] | Bad_credentials { msg; doc_url; code } -> [ - str (Pretty.Icon.warning ^ Format.sprintf " [%d] %s" code msg); + str (Format.sprintf "%s [%d] %s" Pretty.Icon.warning code msg); str ""; str ("Documentation url: " ^ doc_url); ] From efd43ca3ff4acf5b6242b15ecf6e0acd2b3f5c0b Mon Sep 17 00:00:00 2001 From: Heath Henley Date: Tue, 11 Feb 2025 14:12:07 -0500 Subject: [PATCH 5/5] PR suggestions + dune fmt --- lib/pretty/pretty.mli | 5 +++-- lib/tui/widget/common.ml | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/pretty/pretty.mli b/lib/pretty/pretty.mli index e25fc0b..c961dd7 100644 --- a/lib/pretty/pretty.mli +++ b/lib/pretty/pretty.mli @@ -13,9 +13,10 @@ 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: +(** 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 *) + - https://www.nerdfonts.com/cheat-sheet *) module Icon = Icon (** Render a document into the final string diff --git a/lib/tui/widget/common.ml b/lib/tui/widget/common.ml index a0a3d53..51831db 100644 --- a/lib/tui/widget/common.ml +++ b/lib/tui/widget/common.ml @@ -20,8 +20,8 @@ let fmt_error (error : Gh.Client.error) = | Curl_error { code; msg } -> [ str - (Pretty.Icon.warning - ^ Format.sprintf " GitHub API returned error code: %d" code); + (Format.sprintf "%s GitHub API returned error code: %d" + Pretty.Icon.warning code); str ""; str msg; ]