mirror of https://github.com/helix-editor/helix
Use an empty stream on Windows to remove duplication
parent
821565e4ef
commit
585793eb46
|
@ -19,9 +19,12 @@ use crossterm::{
|
||||||
execute, terminal,
|
execute, terminal,
|
||||||
};
|
};
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
use signal_hook::{consts::signal, low_level};
|
use {
|
||||||
#[cfg(not(windows))]
|
signal_hook::{consts::signal, low_level},
|
||||||
use signal_hook_tokio::Signals;
|
signal_hook_tokio::Signals,
|
||||||
|
};
|
||||||
|
#[cfg(windows)]
|
||||||
|
type Signals = futures_util::stream::Empty<()>;
|
||||||
|
|
||||||
pub struct Application {
|
pub struct Application {
|
||||||
compositor: Compositor,
|
compositor: Compositor,
|
||||||
|
@ -40,7 +43,6 @@ pub struct Application {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
syn_loader: Arc<syntax::Loader>,
|
syn_loader: Arc<syntax::Loader>,
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
signals: Signals,
|
signals: Signals,
|
||||||
jobs: Jobs,
|
jobs: Jobs,
|
||||||
lsp_progress: LspProgressMap,
|
lsp_progress: LspProgressMap,
|
||||||
|
@ -108,6 +110,8 @@ impl Application {
|
||||||
|
|
||||||
editor.set_theme(theme);
|
editor.set_theme(theme);
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
let signals = futures_util::stream::empty();
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
let signals = Signals::new(&[signal::SIGTSTP, signal::SIGCONT])?;
|
let signals = Signals::new(&[signal::SIGTSTP, signal::SIGCONT])?;
|
||||||
|
|
||||||
|
@ -120,7 +124,6 @@ impl Application {
|
||||||
theme_loader,
|
theme_loader,
|
||||||
syn_loader,
|
syn_loader,
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
signals,
|
signals,
|
||||||
jobs: Jobs::new(),
|
jobs: Jobs::new(),
|
||||||
lsp_progress: LspProgressMap::new(),
|
lsp_progress: LspProgressMap::new(),
|
||||||
|
@ -158,7 +161,6 @@ impl Application {
|
||||||
|
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
biased;
|
biased;
|
||||||
|
|
||||||
|
@ -166,23 +168,7 @@ impl Application {
|
||||||
self.handle_terminal_events(event)
|
self.handle_terminal_events(event)
|
||||||
}
|
}
|
||||||
Some(signal) = self.signals.next() => {
|
Some(signal) = self.signals.next() => {
|
||||||
use helix_view::graphics::Rect;
|
self.handle_signals(signal).await;
|
||||||
match signal {
|
|
||||||
signal::SIGTSTP => {
|
|
||||||
self.compositor.save_cursor();
|
|
||||||
self.restore_term().unwrap();
|
|
||||||
low_level::emulate_default_handler(signal::SIGTSTP).unwrap();
|
|
||||||
}
|
|
||||||
signal::SIGCONT => {
|
|
||||||
self.claim_term().await.unwrap();
|
|
||||||
// redraw the terminal
|
|
||||||
let Rect { width, height, .. } = self.compositor.size();
|
|
||||||
self.compositor.resize(width, height);
|
|
||||||
self.compositor.load_cursor();
|
|
||||||
self.render();
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Some((id, call)) = self.editor.language_servers.incoming.next() => {
|
Some((id, call)) = self.editor.language_servers.incoming.next() => {
|
||||||
self.handle_language_server_message(call, id).await;
|
self.handle_language_server_message(call, id).await;
|
||||||
|
@ -202,31 +188,31 @@ impl Application {
|
||||||
self.render();
|
self.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(windows)]
|
}
|
||||||
tokio::select! {
|
}
|
||||||
biased;
|
|
||||||
|
|
||||||
event = reader.next() => {
|
#[cfg(windows)]
|
||||||
self.handle_terminal_events(event)
|
// no signal handling available on windows
|
||||||
}
|
pub async fn handle_signals(&mut self, _signal: ()) {}
|
||||||
Some((id, call)) = self.editor.language_servers.incoming.next() => {
|
|
||||||
self.handle_language_server_message(call, id).await;
|
#[cfg(not(windows))]
|
||||||
// limit render calls for fast language server messages
|
pub async fn handle_signals(&mut self, signal: i32) {
|
||||||
let last = self.editor.language_servers.incoming.is_empty();
|
use helix_view::graphics::Rect;
|
||||||
if last || last_render.elapsed() > deadline {
|
match signal {
|
||||||
self.render();
|
signal::SIGTSTP => {
|
||||||
last_render = Instant::now();
|
self.compositor.save_cursor();
|
||||||
}
|
self.restore_term().unwrap();
|
||||||
}
|
low_level::emulate_default_handler(signal::SIGTSTP).unwrap();
|
||||||
Some(callback) = self.jobs.futures.next() => {
|
|
||||||
self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback);
|
|
||||||
self.render();
|
|
||||||
}
|
|
||||||
Some(callback) = self.jobs.wait_futures.next() => {
|
|
||||||
self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback);
|
|
||||||
self.render();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
signal::SIGCONT => {
|
||||||
|
self.claim_term().await.unwrap();
|
||||||
|
// redraw the terminal
|
||||||
|
let Rect { width, height, .. } = self.compositor.size();
|
||||||
|
self.compositor.resize(width, height);
|
||||||
|
self.compositor.load_cursor();
|
||||||
|
self.render();
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue