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
16 changes: 13 additions & 3 deletions lib/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/pretty/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
(libraries
ansifmt
shell
str
;; Internal dependencies
extra))
54 changes: 43 additions & 11 deletions lib/pretty/icon.ml
Original file line number Diff line number Diff line change
@@ -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";
}
23 changes: 23 additions & 0 deletions lib/pretty/icon.mli
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion lib/pretty/pretty.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ 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

Expand Down
8 changes: 5 additions & 3 deletions lib/tui/init/init.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
1 change: 1 addition & 0 deletions lib/tui/init/init.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/tui/model/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
;; Internal dependencies
fs
gh
pretty
render))
4 changes: 2 additions & 2 deletions lib/tui/model/issue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/tui/model/issue.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions lib/tui/model/model.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -33,16 +34,20 @@ 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;
owner;
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;
}
18 changes: 9 additions & 9 deletions lib/tui/render/render.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/tui/render/render.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions lib/tui/view.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading