diff --git a/lib/pretty/icon.ml b/lib/pretty/icon.ml new file mode 100644 index 0000000..1467968 --- /dev/null +++ b/lib/pretty/icon.ml @@ -0,0 +1,11 @@ +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}" 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..c961dd7 100644 --- a/lib/pretty/pretty.mli +++ b/lib/pretty/pretty.mli @@ -13,6 +13,12 @@ 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 All notes from {!Doc.render} apply. *) 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 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..51831db 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 (Format.sprintf "%s [%d] %s" Pretty.Icon.warning 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 + (Format.sprintf "%s GitHub API returned error code: %d" + Pretty.Icon.warning 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.(