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

[feat] Graceful shutdown #56

Open
chshersh opened this issue Jun 24, 2024 · 0 comments
Open

[feat] Graceful shutdown #56

chshersh opened this issue Jun 24, 2024 · 0 comments

Comments

@chshersh
Copy link

When starting a Mint Tea app, I enter the alt screen and hide the cursor like this:

let init _model = Command.(Seq [ Hide_cursor; Enter_alt_screen ])

When exiting, I restore their behaviour:

  (* if we press `q` or the escape key, we exit *)
  | Event.KeyDown ((Key "q" | Escape), _modifier) ->
      ( { model with exit = true },
        Command.(Seq [ Exit_alt_screen; Show_cursor; Quit ]) )

However, if exit with Ctrl+C, then I'm still stuck in an alt screen with a hidden cursor.

I tried to exit gracefully myself by installing a signal handler like this:

let graceful_shutdown _sigint =
  Tty.Escape_seq.exit_alt_screen_seq ();
  Tty.Escape_seq.show_cursor_seq ();
  exit 0

let set_sigint_handler () =
  Sys.(set_signal sigint (Signal_handle graceful_shutdown))

let main () =
  set_sigint_handler ();

This handles the signal but for some reason breaks my terminal completely (can't type anything, can't run anything).

I assume that Mint Tea wants to do some other clean up that I'm missing, so it would be really nice if this clean up functionality was exposed or if Mint Tea provided a way to configure graceful shutdown handlers.

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