From ee705dcb3363aeb197f6125ab2f8285782333010 Mon Sep 17 00:00:00 2001 From: Skyler Hawthorne Date: Tue, 19 Apr 2022 01:21:31 -0400 Subject: use main application event loop Use the Application's main event loop to allow LSP, file writes, etc --- helix-term/src/application.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 44025ea0..15026bb6 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -1,4 +1,5 @@ use arc_swap::{access::Map, ArcSwap}; +use futures_util::Stream; use helix_core::{ config::{default_syntax_loader, user_syntax_loader}, pos_at_coords, syntax, Selection, @@ -27,7 +28,7 @@ use std::{ use anyhow::Error; use crossterm::{ - event::{DisableMouseCapture, EnableMouseCapture, Event, EventStream}, + event::{DisableMouseCapture, EnableMouseCapture, Event}, execute, terminal, tty::IsTty, }; @@ -68,7 +69,7 @@ fn setup_integration_logging() { message )) }) - .level(log::LevelFilter::Info) + .level(log::LevelFilter::Debug) .chain(std::io::stdout()) .apply(); } @@ -225,8 +226,10 @@ impl Application { } } - pub async fn event_loop(&mut self) { - let mut reader = EventStream::new(); + pub async fn event_loop(&mut self, input_stream: &mut S) + where + S: Stream> + Unpin, + { let mut last_render = Instant::now(); let deadline = Duration::from_secs(1) / 60; @@ -242,7 +245,7 @@ impl Application { tokio::select! { biased; - Some(event) = reader.next() => { + Some(event) = input_stream.next() => { self.handle_terminal_events(event) } Some(signal) = self.signals.next() => { @@ -749,7 +752,10 @@ impl Application { Ok(()) } - pub async fn run(&mut self) -> Result { + pub async fn run(&mut self, input_stream: &mut S) -> Result + where + S: Stream> + Unpin, + { self.claim_term().await?; // Exit the alternate screen and disable raw mode before panicking @@ -764,16 +770,20 @@ impl Application { hook(info); })); - self.event_loop().await; + self.event_loop(input_stream).await; + self.close().await?; + self.restore_term()?; + + Ok(self.editor.exit_code) + } + pub async fn close(&mut self) -> anyhow::Result<()> { self.jobs.finish().await; if self.editor.close_language_servers(None).await.is_err() { log::error!("Timed out waiting for language servers to shutdown"); }; - self.restore_term()?; - - Ok(self.editor.exit_code) + Ok(()) } } -- cgit v1.2.3-70-g09d2