Don't redraw the view on exit

This commit is contained in:
Dmitrii Kovanikov 2024-06-24 18:57:36 +01:00
parent 063b01a111
commit 3e8b21dcec
3 changed files with 6 additions and 2 deletions

View File

@ -11,6 +11,7 @@ type tab =
| PullRequests
type t = {
exit : bool;
width : int;
height : int;
repo : string;
@ -31,6 +32,7 @@ let initial_model { repo; root_dir_path; files; width; height } =
width;
height;
repo;
exit = false;
current_tab = Code;
code_tab = { root_dir_path; fs = Fs.zip_it files };
}

View File

@ -28,7 +28,8 @@ let update event (model : Model.t) =
match event with
(* if we press `q` or the escape key, we exit *)
| Event.KeyDown ((Key "q" | Escape), _modifier) ->
(model, Command.(Seq [ Exit_alt_screen; Show_cursor; Quit ]))
( { model with exit = true },
Command.(Seq [ Exit_alt_screen; Show_cursor; Quit ]) )
(* if we press a digit, we switch to the corresponding tab *)
| Event.KeyDown (Key "1", _modifier) ->
({ model with current_tab = Model.Code }, Command.Noop)

View File

@ -42,4 +42,5 @@ let to_doc (model : Model.t) =
empty;
]
let view (model : Model.t) = model |> to_doc |> Pretty.render ~width:model.width
let view (model : Model.t) =
if model.exit then "" else model |> to_doc |> Pretty.render ~width:model.width