Skip to content

Commit a3a9213

Browse files
[#50] Move all the icons into Pretty.Icon (#51)
* Move all the icons into Pretty.Icon * Forgot to move issue_char * Add docs about Icon module * Make icon an arg to sprintf * PR suggestions + dune fmt --------- Co-authored-by: Dmitrii Kovanikov <kovanikov@gmail.com>
1 parent deb91b8 commit a3a9213

8 files changed

Lines changed: 39 additions & 28 deletions

File tree

lib/pretty/icon.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let closed_char = "\u{ebda}"
2+
let open_char = "\u{ea64}"
3+
let merged_char = "\u{e725}"
4+
let arrow_left_char = "\u{f0a8}"
5+
let pwd_char = "\u{e5fd}"
6+
let dir_char = "\u{f4d4}"
7+
let empty_dir_char = "\u{f413}"
8+
let file_char = "\u{f4a5}"
9+
let bin_char = "\u{eae8}"
10+
let warning = "\u{26A0}"
11+
let issue_char = "\u{f41b}"

lib/pretty/pretty.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Doc = Doc
22
module Layout = Layout
33
module Style = Style
4+
module Icon = Icon
45

56
let render ~width ~height doc =
67
doc |> Doc.render ~width ~height |> Layout.to_lines |> Extra.String.unlines

lib/pretty/pretty.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ module Doc = Doc
1313
{!Layout.t} is the output of {!Doc.render} with all the sizes calculated. *)
1414
module Layout = Layout
1515

16+
(** Icons and symbols used for identifying different parts. Symbols from Hack
17+
Nerd Font Mono are used when it's available. Symbols list:
18+
19+
- https://www.nerdfonts.com/cheat-sheet *)
20+
module Icon = Icon
21+
1622
(** Render a document into the final string
1723
1824
All notes from {!Doc.render} apply. *)

lib/tui/render/render.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ type 'a t = {
66
layout : Pretty.Layout.t;
77
}
88

9-
let issue_char = "\u{f41b}"
10-
119
let fmt_issue_state (state : Gh.Issue.state) =
1210
match state with
13-
| Open -> Layout.(fmt Style.issue_open issue_char)
14-
| Closed -> Layout.(fmt Style.issue_closed issue_char)
11+
| Open -> Layout.(fmt Style.issue_open Pretty.Icon.issue_char)
12+
| Closed -> Layout.(fmt Style.issue_closed Pretty.Icon.issue_char)
1513

1614
let fmt_title (issue : Gh.Issue.t) =
1715
let open Layout in

lib/tui/widget/code.ml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@ let scroll ~lines ~span ~offset =
77
| None -> Pretty.Doc.str " "
88
| Some scroll -> scroll |> Scroll.to_sections |> Scroll.render
99

10-
let pwd_char = "\u{e5fd}"
11-
let dir_char = "\u{f4d4}"
12-
let empty_dir_char = "\u{f413}"
13-
let file_char = "\u{f4a5}"
14-
let bin_char = "\u{eae8}"
15-
1610
let parents_path parents =
1711
List.fold_left (fun acc cur -> Filename.concat acc cur) "" (List.rev parents)
1812

1913
let pwd root_dir_path (fs : Fs.zipper) =
2014
let parents = Fs.zipper_parents fs in
2115
let pwd_path = parents_path parents in
2216
let root_dir_name = Filename.basename root_dir_path in
23-
let full_path = pwd_char ^ " " ^ Filename.concat root_dir_name pwd_path in
17+
let full_path =
18+
Pretty.Icon.pwd_char ^ " " ^ Filename.concat root_dir_name pwd_path
19+
in
2420
Pretty.Doc.(fmt Style.directory full_path)
2521

2622
let file_contents_to_doc ~(file_contents : Fs.Filec.t) =
@@ -56,12 +52,12 @@ let fmt_file ~max_name_len (tree : Fs.tree) =
5652
match tree with
5753
| File (name, _, file_type) -> (
5854
match Lazy.force file_type with
59-
| Fs.Filec.Text -> file_char ^ " " ^ pad name
60-
| Fs.Filec.Binary -> bin_char ^ " " ^ pad name)
55+
| Fs.Filec.Text -> Pretty.Icon.file_char ^ " " ^ pad name
56+
| Fs.Filec.Binary -> Pretty.Icon.bin_char ^ " " ^ pad name)
6157
| Dir (name, (lazy children)) -> (
6258
match children with
63-
| [||] -> empty_dir_char ^ " " ^ pad name
64-
| _ -> dir_char ^ " " ^ pad name)
59+
| [||] -> Pretty.Icon.empty_dir_char ^ " " ^ pad name
60+
| _ -> Pretty.Icon.dir_char ^ " " ^ pad name)
6561

6662
let current_level_to_doc (cursor : Fs.dir_cursor) ~has_next ~is_file_chosen =
6763
let open Pretty.Doc in

lib/tui/widget/common.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@ let fmt_error (error : Gh.Client.error) =
44
| No_github_token ->
55
[
66
str
7-
"\u{26A0} GITHUB_TOKEN not found. Make sure it's configured in your \
8-
environment.";
7+
(Pretty.Icon.warning
8+
^ " GITHUB_TOKEN not found. Make sure it's configured in your \
9+
environment.");
910
str "";
1011
str "If you don't have a token, visit the following page to create one:";
1112
str " • https://github.com/settings/tokens";
1213
]
1314
| Bad_credentials { msg; doc_url; code } ->
1415
[
15-
str (Format.sprintf "\u{26A0} [%d] %s" code msg);
16+
str (Format.sprintf "%s [%d] %s" Pretty.Icon.warning code msg);
1617
str "";
1718
str ("Documentation url: " ^ doc_url);
1819
]
1920
| Curl_error { code; msg } ->
2021
[
21-
str (Format.sprintf "\u{26A0} GitHub API returned error code %d: " code);
22+
str
23+
(Format.sprintf "%s GitHub API returned error code: %d"
24+
Pretty.Icon.warning code);
2225
str "";
2326
str msg;
2427
]

lib/tui/widget/generic.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ let of_lines lines = { is_selected = false; item_type = Lines lines }
2222
* 1: Unicode box character (right)
2323
*)
2424
let item_padding = 4
25-
let arrow_left_char = "\u{f0a8}"
2625

2726
(* Calculate the number of lines it takes to render [n] issues.
2827
@@ -66,7 +65,8 @@ let vlist_border ~scroll_start ~selected items =
6665
| hd :: tl ->
6766
let first_line =
6867
Doc.(
69-
horizontal [ fmt_selected_line hd; str " "; str arrow_left_char ])
68+
horizontal
69+
[ fmt_selected_line hd; str " "; str Pretty.Icon.arrow_left_char ])
7070
in
7171
let other_lines = List.map fmt_selected_line tl in
7272
first_line :: other_lines

lib/tui/widget/pr.ml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
module Style = Pretty.Style
22

3-
let closed_char = "\u{ebda}"
4-
let open_char = "\u{ea64}"
5-
let merged_char = "\u{e725}"
6-
73
let section (tab : Model.Pr.t) =
84
let open Pretty.Doc in
95
let docs =
106
match tab.error with
117
| None ->
128
let fmt_state = function
139
| None -> str ""
14-
| Some Gh.Pr.Merged -> fmt Style.pr_merged merged_char
15-
| Some Gh.Pr.Open -> fmt Style.pr_open open_char
16-
| Some Gh.Pr.Closed -> fmt Style.pr_closed closed_char
10+
| Some Gh.Pr.Merged -> fmt Style.pr_merged Pretty.Icon.merged_char
11+
| Some Gh.Pr.Open -> fmt Style.pr_open Pretty.Icon.open_char
12+
| Some Gh.Pr.Closed -> fmt Style.pr_closed Pretty.Icon.closed_char
1713
in
1814
let fmt_pr (pr : Gh.Pr.t) =
1915
Pretty.Doc.(

0 commit comments

Comments
 (0)