summaryrefslogtreecommitdiff
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.rs55
1 files changed, 6 insertions, 49 deletions
diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs
index 1452d31f..bbcd2181 100644
--- a/helix-term/src/compositor.rs
+++ b/helix-term/src/compositor.rs
@@ -75,56 +75,28 @@ pub trait Component: Any + AnyComponent {
}
}
-use anyhow::Context as AnyhowContext;
-
-#[cfg(not(feature = "integration"))]
-use tui::backend::CrosstermBackend;
-
-#[cfg(not(feature = "integration"))]
-use std::io::stdout;
-
-#[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>>,
- pub terminal: Terminal,
area: Rect,
pub(crate) last_picker: Option<Box<dyn Component>>,
}
impl Compositor {
- pub fn new() -> anyhow::Result<Self> {
- #[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")?;
- let area = terminal.size().expect("couldn't get terminal size");
- Ok(Self {
+ pub fn new(area: Rect) -> Self {
+ Self {
layers: Vec::new(),
area,
- terminal,
last_picker: None,
- })
+ }
}
pub fn size(&self) -> Rect {
self.area
}
- pub fn resize(&mut self, width: u16, height: u16) {
- self.terminal
- .resize(Rect::new(0, 0, width, height))
- .expect("Unable to resize terminal");
-
- self.area = self.terminal.size().expect("couldn't get terminal size");
+ pub fn resize(&mut self, area: Rect) {
+ self.area = area;
}
pub fn push(&mut self, mut layer: Box<dyn Component>) {
@@ -192,25 +164,10 @@ impl Compositor {
consumed
}
- pub fn render(&mut self, cx: &mut Context) {
- self.terminal
- .autoresize()
- .expect("Unable to determine terminal size");
-
- // TODO: need to recalculate view tree if necessary
-
- let surface = self.terminal.current_buffer_mut();
-
- let area = *surface.area();
-
+ pub fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
for layer in &mut self.layers {
layer.render(area, surface, cx);
}
-
- let (pos, kind) = self.cursor(area, cx.editor);
- let pos = pos.map(|pos| (pos.col as u16, pos.row as u16));
-
- self.terminal.draw(pos, kind).unwrap();
}
pub fn cursor(&self, area: Rect, editor: &Editor) -> (Option<Position>, CursorKind) {