Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminal not restored properly after exiting alt screen #55

Closed
hedyhli opened this issue Jun 6, 2024 · 1 comment
Closed

Terminal not restored properly after exiting alt screen #55

hedyhli opened this issue Jun 6, 2024 · 1 comment

Comments

@hedyhli
Copy link

hedyhli commented Jun 6, 2024

Ideally, a TUI that makes use of an alt screen should restore the screen state and cursor after exiting. This is the expected behaviour of TUI apps that uses an alt screen.

Expected:

prompt $ echo hi
hi
prompt $ ./main.exe  # enters alt screen
prompt $ |           # cursor here after TUI finishes

Actual:
When the TUI exits, the terminal outputs and prompts of the previous one or two commands are gone, including the ./main.exe line that runs the TUI itself.

Demo

open Minttea

type model = { quitting : bool }

let init _ = Command.Enter_alt_screen
let initial_model = { quitting = false }

let update event model =
  match event with
  | Event.KeyDown (Key "q" | Escape) ->
      ({ quitting = true }, Command.Quit)
  | _ -> (model, Command.Noop)

let view model =
  if model.quitting then ""
  else
    "in alt screen"

let () = Minttea.app ~init ~update ~view () |> Minttea.start ~initial_model

demo

Workaround

open Minttea

type model = { quitting : bool; in_alt : bool }

let ref = Riot.Ref.make ()
let init _ = Command.Set_timer (ref, 0.1)
let initial_model = { quitting = false; in_alt = false }

let update event model =
  match event with
  | Event.KeyDown (Key "q" | Escape) ->
      ({ model with quitting = true }, Command.Quit)
  (* Entering alt screen after initialization fixes the issue. *)
  | Event.Timer _ref -> ({model with in_alt = true}, Command.Enter_alt_screen)
  | _ -> (model, Command.Noop)

let view model =
  if not model.in_alt then " "  (* empty string does not work *)
  else if model.quitting then ""
  else
    "in alt screen"

let () = Minttea.app ~init ~update ~view () |> Minttea.start ~initial_model

demo

Unfortunately, I didn't find a way to remove the newline produced before entering alt screen, and the extra newline after exiting.

@hedyhli hedyhli changed the title Terminal restored properly after exiting alt screen Terminal not restored properly after exiting alt screen Jun 6, 2024
@hedyhli
Copy link
Author

hedyhli commented Jun 6, 2024

Welp, it looks like it's a duplicate #6

Perhaps it's included in 0.0.3 which isn't yet on opam (#54)?

@hedyhli hedyhli closed this as not planned Won't fix, can't repro, duplicate, stale Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant