From 652cdda8338bee55eeff58066cd20e68bb0b5a44 Mon Sep 17 00:00:00 2001 From: Skyler Hawthorne Date: Wed, 27 Apr 2022 00:07:59 -0400 Subject: [PATCH] use test terminal backend for integration tests --- helix-term/src/application.rs | 20 +++++++------------- helix-term/src/commands.rs | 8 ++++---- helix-term/src/compositor.rs | 20 +++++++++++++++++++- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 65cf4b2e7..886b531be 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -216,21 +216,15 @@ impl Application { } fn render(&mut self) { - #[cfg(feature = "integration")] - return; - - #[allow(unreachable_code)] - { - let compositor = &mut self.compositor; + let compositor = &mut self.compositor; - let mut cx = crate::compositor::Context { - editor: &mut self.editor, - jobs: &mut self.jobs, - scroll: None, - }; + let mut cx = crate::compositor::Context { + editor: &mut self.editor, + jobs: &mut self.jobs, + scroll: None, + }; - compositor.render(&mut cx); - } + compositor.render(&mut cx); } pub async fn event_loop(&mut self, input_stream: &mut S) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 85dbfd562..4dfa6ec8c 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2100,10 +2100,10 @@ fn insert_mode(cx: &mut Context) { doc.text().to_string() ); - let selection = doc.selection(view.id).clone().transform(|range| { - let new_range = Range::new(range.to(), range.from()); - new_range - }); + let selection = doc + .selection(view.id) + .clone() + .transform(|range| Range::new(range.to(), range.from())); doc.set_selection(view.id, selection); } diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs index 1d4212135..61a3bfaf1 100644 --- a/helix-term/src/compositor.rs +++ b/helix-term/src/compositor.rs @@ -5,6 +5,9 @@ use helix_core::Position; use helix_view::graphics::{CursorKind, Rect}; use crossterm::event::Event; + +#[cfg(feature = "integration")] +use tui::backend::TestBackend; use tui::buffer::Buffer as Surface; pub type Callback = Box; @@ -64,10 +67,20 @@ pub trait Component: Any + AnyComponent { } use anyhow::Context as AnyhowContext; +use tui::backend::Backend; + +#[cfg(not(feature = "integration"))] +use tui::backend::CrosstermBackend; + +#[cfg(not(feature = "integration"))] use std::io::stdout; -use tui::backend::{Backend, CrosstermBackend}; + +#[cfg(not(feature = "integration"))] type Terminal = tui::terminal::Terminal>; +#[cfg(feature = "integration")] +type Terminal = tui::terminal::Terminal; + pub struct Compositor { layers: Vec>, terminal: Terminal, @@ -77,7 +90,12 @@ pub struct Compositor { impl Compositor { pub fn new() -> anyhow::Result { + #[cfg(not(feature = "integration"))] let backend = CrosstermBackend::new(stdout()); + + #[cfg(feature = "integration")] + let backend = TestBackend::new(120, 150); + let terminal = Terminal::new(backend).context("build terminal")?; Ok(Self { layers: Vec::new(),