Add terminal size debug info

This commit is contained in:
Dmitrii Kovanikov 2024-03-24 11:42:12 +00:00
parent d8a889e117
commit a5e6cf13f1
6 changed files with 34 additions and 10 deletions

View File

@ -16,13 +16,14 @@
(name github_tui)
(synopsis "A short synopsis")
(description "A longer description")
(depends
(depends
(ocaml (>= "5.1"))
dune
(ANSITerminal (>= "0.8.5"))
(cmdliner (>= "1.2.0"))
(ezcurl (>= "0.2.4"))
(minttea (>= "0.0.2"))
(terminal_size (>= "0.2.0"))
uuseg
)
(tags

View File

@ -15,6 +15,7 @@ depends: [
"cmdliner" {>= "1.2.0"}
"ezcurl" {>= "0.2.4"}
"minttea" {>= "0.0.2"}
"terminal_size" {>= "0.2.0"}
"uuseg"
"odoc" {with-doc}
]

View File

@ -2,4 +2,4 @@
(library
(name github_tui)
(libraries ANSITerminal cmdliner ezcurl minttea uuseg.string))
(libraries ANSITerminal cmdliner ezcurl minttea terminal_size uuseg.string))

View File

@ -1,10 +1,17 @@
let init ~repo ~path : Model.initial_data =
let tree = Fs.read_tree path in
match tree with
| Fs.File path ->
Printf.printf "Given path '%s' is not a directory!" path;
exit 1
| Fs.Dir (dirname, files) -> { repo; dirname; files }
let dirname, files =
match tree with
| Fs.File path ->
Printf.printf "Given path '%s' is not a directory!" path;
exit 1
| Fs.Dir (dirname, files) -> (dirname, files)
in
let terminal_rows = Option.value (Terminal_size.get_rows ()) ~default:120 in
let terminal_cols =
Option.value (Terminal_size.get_columns ()) ~default:140
in
{ repo; dirname; files; terminal_rows; terminal_cols }
let app = Minttea.app ~init:Init.init ~update:Update.update ~view:View.view ()

View File

@ -11,6 +11,8 @@ type tab =
| PullRequests
type t = {
terminal_rows : int;
terminal_cols : int;
repo : string;
current_tab : tab;
code_tab : code_tab;
@ -20,7 +22,15 @@ type initial_data = {
repo : string;
dirname : string;
files : Fs.tree array;
terminal_rows : int;
terminal_cols : int;
}
let initial_model { repo; dirname; files } =
{ repo; current_tab = Code; code_tab = { dirname; fs = Fs.zip_it files } }
let initial_model { repo; dirname; files; terminal_rows; terminal_cols } =
{
terminal_rows;
terminal_cols;
repo;
current_tab = Code;
code_tab = { dirname; fs = Fs.zip_it files };
}

View File

@ -2,6 +2,10 @@ let style_repo = ANSITerminal.[ Bold; blue ]
let style_selected = ANSITerminal.[ Bold; green ]
let style_directory = ANSITerminal.[ Bold; magenta ]
let debug_section (model: Model.t) =
let debug_info = Printf.sprintf "%dw x %dh" model.terminal_cols model.terminal_rows in
Pretty.str debug_info
let tabs_section cur_tab =
let open Pretty in
let sep = col [ str " "; str " "; str "" ] in
@ -29,10 +33,11 @@ let tab_content_section (model : Model.t) =
let to_doc (model : Model.t) =
let open Pretty in
let empty = str "" in
let debug = debug_section model in
let repo = fmt style_repo model.repo in
let tabs = tabs_section model.current_tab in
let content = tab_content_section model in
col [ repo; empty; tabs; content; empty ]
col [ row [repo; str " "; debug ]; empty; tabs; content; empty ]
let view (model : Model.t) = model |> to_doc |> Pretty.render