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

Helix leaves terminal in a bad state when killed #6754

Closed
ccmtaylor opened this issue Apr 14, 2023 · 5 comments · Fixed by #7236
Closed

Helix leaves terminal in a bad state when killed #6754

ccmtaylor opened this issue Apr 14, 2023 · 5 comments · Fixed by #7236
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug

Comments

@ccmtaylor
Copy link

ccmtaylor commented Apr 14, 2023

Summary

After killing helix because it was stuck (I inadvertently caused a global search in my entire home directory), the editor left the terminal (iTerm 2 on macOS) in a bad state: entering normal characters work, but control keys (e.g. C-a, C-e) echo escape codes instead of moving the shell cursor.

Possibly related to #2250, however mouse movement doesn't spam the terminal for me.

Reproduction Steps

reproduction recording:

I tried this:

  1. hx
  2. killall hx (either in a separate terminal, or within helix with :sh)
  3. try to enter control characters in the terminal

I expected this to happen:

I expected the terminal to work normally after exiting Helix.

Instead, this happened:

the terminal echoes control characters. Trying to reset the terminal using reset, or starting and exiting Helix cleanly, does not return things to normal.

Helix log

~/.cache/helix/helix.log
2023-04-14T14:09:58.690 helix_view::clipboard [DEBUG] Using pbcopy+pbpaste to interact with the system clipboard
2023-04-14T14:09:58.693 helix_tui::backend::crossterm [DEBUG] The keyboard enhancement protocol is supported in this terminal (checked in 2.146462ms)
2023-04-14T14:09:58.694 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:09:59.092 helix_term::application [DEBUG] received editor event: IdleTimer
2023-04-14T14:09:59.766 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:00.168 helix_term::application [DEBUG] received editor event: IdleTimer
2023-04-14T14:10:01.103 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:01.303 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:01.519 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:01.629 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:01.823 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:01.926 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:02.064 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:02.231 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:02.732 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:02.823 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:05.958 helix_view::editor [ERROR] editor error: no such command: 'killall'
2023-04-14T14:10:05.959 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:07.799 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:08.201 helix_term::application [DEBUG] received editor event: IdleTimer
2023-04-14T14:10:08.375 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:08.479 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:08.624 globset [DEBUG] built glob set; 0 literals, 14 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
2023-04-14T14:10:08.625 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:09.872 globset [DEBUG] built glob set; 0 literals, 14 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
2023-04-14T14:10:09.873 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:10.063 globset [DEBUG] built glob set; 0 literals, 14 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
2023-04-14T14:10:10.065 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:10.298 globset [DEBUG] built glob set; 0 literals, 14 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
2023-04-14T14:10:10.299 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:10.416 globset [DEBUG] built glob set; 0 literals, 14 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
2023-04-14T14:10:10.417 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:10.616 globset [DEBUG] built glob set; 0 literals, 14 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
2023-04-14T14:10:10.618 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:10.696 globset [DEBUG] built glob set; 0 literals, 14 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
2023-04-14T14:10:10.698 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:10.829 globset [DEBUG] built glob set; 0 literals, 14 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
2023-04-14T14:10:10.829 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:10.979 globset [DEBUG] built glob set; 0 literals, 14 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
2023-04-14T14:10:10.980 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:11.187 globset [DEBUG] built glob set; 0 literals, 14 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
2023-04-14T14:10:11.188 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:11.296 globset [DEBUG] built glob set; 0 literals, 14 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
2023-04-14T14:10:11.297 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2023-04-14T14:10:11.984 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0

Platform

macOS

Terminal Emulator

iTerm 2 (Build 3.4.19)

Helix Version

helix 23.03 (3cf0372)

@ccmtaylor ccmtaylor added the C-bug Category: This is a bug label Apr 14, 2023
@the-mikedavis
Copy link
Member

When Helix is killed we don't restore the terminal (exit raw mode, disable mouse capture, etc.). We can't do anything about this for hard kills (kill -9) but we could add a handler for sigterm that restores the terminal and exits gracefully. Kakoune and Vim both do this.

@the-mikedavis the-mikedavis added the A-helix-term Area: Helix term improvements label Apr 14, 2023
@sbromberger
Copy link
Contributor

Does using the reset command at the command prompt fix things? This isn't a solution, but it might be a workaround until Helix can restore the terminal.

@ccmtaylor
Copy link
Author

@sbromberger no, reset does not restore the terminal behaviour. I don't actually know any way to get things into a good state apart from closing the window.

@the-mikedavis I think that sounds like a good approach 👍

@tommyscholly
Copy link
Contributor

tommyscholly commented May 3, 2023

Is the solution to this not just adding SIGTERM to the application handle_signals (and to the signals passed into the application)

If so, I can make that PR quickly.

@the-mikedavis
Copy link
Member

Yep, we need to add SIGTERM to the list of signals we handle:

let signals = Signals::new([signal::SIGTSTP, signal::SIGCONT, signal::SIGUSR1])

Then add a block in handle_signals that restores the terminal and breaks the event loop so that we exit gracefully.

We could handle SIGINT the same way (that's what Kakoune does: https://github.com/mawww/kakoune/blob/a4918f934ceb8c36ab398c0c973174ac17fc8600/src/main.cc#L764-L765).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants