Skip to content

Commit

Permalink
Refactor terminal size warning
Browse files Browse the repository at this point in the history
  • Loading branch information
thezbm committed Jan 30, 2025
1 parent deb9fdc commit bb22708
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/tui/tui.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ type terminal = {
}

let min_height, min_width = (40, 140)
let size_warning = ref true

let get_terminal_dimensions () =
let get_terminal_dimensions ignore_size_warning =
match (Terminal_size.get_rows (), Terminal_size.get_columns ()) with
| Some height, Some width ->
if !size_warning && (height < min_height || width < min_width) then (
if (not ignore_size_warning) && (height < min_height || width < min_width)
then (
Printf.printf
{|⚠️ Terminal size is too small! GitHub TUI works better on bigger terminals.
Expected size: %3d width x %3d height
Expand All @@ -62,16 +62,15 @@ let get_terminal_dimensions () =
Printf.printf "⚠️ Not able to get the terminal size.\n";
exit 1

let init ~owner_repo ~local_path : Model.initial_data =
let init ~owner_repo ~local_path ~ignore_size_warning : 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 () in
let { height; width } = get_terminal_dimensions ignore_size_warning in
{ owner; repo; root_dir_path; files; width; height }

let start ~owner_repo ~local_path ~log_file ~ignore_size_warning =
size_warning := not ignore_size_warning;
let initial_data = init ~owner_repo ~local_path in
let initial_data = init ~owner_repo ~local_path ~ignore_size_warning in
let init = Model.initial_model initial_data in
let app = Tea.make ~init ~update:Update.update ~view:View.view in
Tea.run ?path:log_file app

0 comments on commit bb22708

Please sign in to comment.