Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/pretty/icon.ml
Original file line number Diff line number Diff line change
@@ -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}"
1 change: 1 addition & 0 deletions lib/pretty/pretty.ml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions lib/pretty/pretty.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)
Expand Down
6 changes: 2 additions & 4 deletions lib/tui/render/render.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 7 additions & 11 deletions lib/tui/widget/code.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@ 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)

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) =
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions lib/tui/widget/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
]
4 changes: 2 additions & 2 deletions lib/tui/widget/generic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions lib/tui/widget/pr.ml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
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 =
match tab.error with
| 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.(
Expand Down