aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/compositor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/compositor.rs')
-rw-r--r--helix-term/src/compositor.rs26
1 files changed, 22 insertions, 4 deletions
diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs
index e3cec643..61a3bfaf 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<dyn FnOnce(&mut Compositor, &mut Context)>;
@@ -63,11 +66,21 @@ pub trait Component: Any + AnyComponent {
}
}
-use anyhow::Error;
+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<CrosstermBackend<std::io::Stdout>>;
+#[cfg(feature = "integration")]
+type Terminal = tui::terminal::Terminal<TestBackend>;
+
pub struct Compositor {
layers: Vec<Box<dyn Component>>,
terminal: Terminal,
@@ -76,9 +89,14 @@ pub struct Compositor {
}
impl Compositor {
- pub fn new() -> Result<Self, Error> {
+ pub fn new() -> anyhow::Result<Self> {
+ #[cfg(not(feature = "integration"))]
let backend = CrosstermBackend::new(stdout());
- let terminal = Terminal::new(backend)?;
+
+ #[cfg(feature = "integration")]
+ let backend = TestBackend::new(120, 150);
+
+ let terminal = Terminal::new(backend).context("build terminal")?;
Ok(Self {
layers: Vec::new(),
terminal,