Use an empty stream on Windows to remove duplication
This commit is contained in:
parent
821565e4ef
commit
585793eb46
1 changed files with 32 additions and 46 deletions
|
@ -19,9 +19,12 @@ use crossterm::{
|
|||
execute, terminal,
|
||||
};
|
||||
#[cfg(not(windows))]
|
||||
use signal_hook::{consts::signal, low_level};
|
||||
#[cfg(not(windows))]
|
||||
use signal_hook_tokio::Signals;
|
||||
use {
|
||||
signal_hook::{consts::signal, low_level},
|
||||
signal_hook_tokio::Signals,
|
||||
};
|
||||
#[cfg(windows)]
|
||||
type Signals = futures_util::stream::Empty<()>;
|
||||
|
||||
pub struct Application {
|
||||
compositor: Compositor,
|
||||
|
@ -40,7 +43,6 @@ pub struct Application {
|
|||
#[allow(dead_code)]
|
||||
syn_loader: Arc<syntax::Loader>,
|
||||
|
||||
#[cfg(not(windows))]
|
||||
signals: Signals,
|
||||
jobs: Jobs,
|
||||
lsp_progress: LspProgressMap,
|
||||
|
@ -108,6 +110,8 @@ impl Application {
|
|||
|
||||
editor.set_theme(theme);
|
||||
|
||||
#[cfg(windows)]
|
||||
let signals = futures_util::stream::empty();
|
||||
#[cfg(not(windows))]
|
||||
let signals = Signals::new(&[signal::SIGTSTP, signal::SIGCONT])?;
|
||||
|
||||
|
@ -120,7 +124,6 @@ impl Application {
|
|||
theme_loader,
|
||||
syn_loader,
|
||||
|
||||
#[cfg(not(windows))]
|
||||
signals,
|
||||
jobs: Jobs::new(),
|
||||
lsp_progress: LspProgressMap::new(),
|
||||
|
@ -158,7 +161,6 @@ impl Application {
|
|||
|
||||
use futures_util::StreamExt;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
tokio::select! {
|
||||
biased;
|
||||
|
||||
|
@ -166,6 +168,35 @@ impl Application {
|
|||
self.handle_terminal_events(event)
|
||||
}
|
||||
Some(signal) = self.signals.next() => {
|
||||
self.handle_signals(signal).await;
|
||||
}
|
||||
Some((id, call)) = self.editor.language_servers.incoming.next() => {
|
||||
self.handle_language_server_message(call, id).await;
|
||||
// limit render calls for fast language server messages
|
||||
let last = self.editor.language_servers.incoming.is_empty();
|
||||
if last || last_render.elapsed() > deadline {
|
||||
self.render();
|
||||
last_render = Instant::now();
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
// no signal handling available on windows
|
||||
pub async fn handle_signals(&mut self, _signal: ()) {}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub async fn handle_signals(&mut self, signal: i32) {
|
||||
use helix_view::graphics::Rect;
|
||||
match signal {
|
||||
signal::SIGTSTP => {
|
||||
|
@ -184,51 +215,6 @@ impl Application {
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
Some((id, call)) = self.editor.language_servers.incoming.next() => {
|
||||
self.handle_language_server_message(call, id).await;
|
||||
// limit render calls for fast language server messages
|
||||
let last = self.editor.language_servers.incoming.is_empty();
|
||||
if last || last_render.elapsed() > deadline {
|
||||
self.render();
|
||||
last_render = Instant::now();
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
tokio::select! {
|
||||
biased;
|
||||
|
||||
event = reader.next() => {
|
||||
self.handle_terminal_events(event)
|
||||
}
|
||||
Some((id, call)) = self.editor.language_servers.incoming.next() => {
|
||||
self.handle_language_server_message(call, id).await;
|
||||
// limit render calls for fast language server messages
|
||||
let last = self.editor.language_servers.incoming.is_empty();
|
||||
if last || last_render.elapsed() > deadline {
|
||||
self.render();
|
||||
last_render = Instant::now();
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) {
|
||||
let mut cx = crate::compositor::Context {
|
||||
|
|
Loading…
Reference in a new issue