Skip to content

Commit

Permalink
fix: respect ign for tstp, fix helix-editor#3321
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderBrevig committed Aug 3, 2022
1 parent c5f8a83 commit 6a62ea8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ signal-hook = "0.3"
tokio-stream = "0.1"
futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
arc-swap = { version = "1.5.1" }
libc = "0.2"

# Logging
fern = "0.6"
Expand Down
16 changes: 14 additions & 2 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type Signals = futures_util::stream::Empty<()>;

const LSP_DEADLINE: Duration = Duration::from_millis(16);

pub static mut ENABLE_SIGTSTP: bool = true;

pub struct Application {
compositor: Compositor,
pub editor: Editor,
Expand Down Expand Up @@ -205,9 +207,19 @@ impl Application {

#[cfg(windows)]
let signals = futures_util::stream::empty();

let mut app_signals = vec![signal::SIGTSTP, signal::SIGCONT];
unsafe {
// If SIGTSTP is SIG_IGN, then do not listen for it
let tstp = libc::signal(signal_hook::consts::SIGTSTP, /*SIG_IGN*/ 1);
if tstp != /*SIG_ERR*/ 0 {
log::debug!("Disabling SIGTSTP, C-z will not suspend Helix");
ENABLE_SIGTSTP = false;
app_signals.remove(0);
}
}
#[cfg(not(windows))]
let signals =
Signals::new(&[signal::SIGTSTP, signal::SIGCONT]).context("build signal handler")?;
let signals = Signals::new(app_signals).context("build signal handler")?;

let app = Self {
compositor,
Expand Down
8 changes: 6 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4647,8 +4647,12 @@ fn shell_prompt(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBeha
}

fn suspend(_cx: &mut Context) {
#[cfg(not(windows))]
signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP).unwrap();
unsafe {
if crate::application::ENABLE_SIGTSTP {
#[cfg(not(windows))]
signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP).unwrap();
}
}
}

fn add_newline_above(cx: &mut Context) {
Expand Down

0 comments on commit 6a62ea8

Please sign in to comment.