diff --git a/src/mux/mod.rs b/src/mux/mod.rs index 9710f8661..815d9a5cf 100644 --- a/src/mux/mod.rs +++ b/src/mux/mod.rs @@ -9,6 +9,8 @@ use std::thread; use term::TerminalHost; use termwiz::hyperlink::Hyperlink; +pub mod renderable; + #[derive(Default)] pub struct Mux { tabs: RefCell>>, diff --git a/src/mux/renderable.rs b/src/mux/renderable.rs new file mode 100644 index 000000000..5a2b32212 --- /dev/null +++ b/src/mux/renderable.rs @@ -0,0 +1,53 @@ +use std::ops::Range; +use std::rc::Rc; +use term::{CursorPosition, Line, Terminal, TerminalState}; +use termwiz::hyperlink::Hyperlink; + +/// Renderable allows passing something that isn't an actual term::Terminal +/// instance into the renderer, which opens up remoting of the terminal +/// surfaces via a multiplexer. +pub trait Renderable { + /// Returns the 0-based cursor position relative to the top left of + /// the visible screen + fn get_cursor_position(&self) -> CursorPosition; + + /// Returns the set of visible lines that are dirty. + /// The return value is a Vec<(line_idx, line, selrange)>, where + /// line_idx is relative to the top of the viewport. + /// The selrange value is the column range representing the selected + /// columns on this line. + fn get_dirty_lines(&self) -> Vec<(usize, &Line, Range)>; + + /// Clear the dirty flag for all dirty lines + fn clean_dirty_lines(&mut self); + + /// Returns the currently highlighted hyperlink + fn current_highlight(&self) -> Option>; + + /// Returns physical, non-scrollback (rows, cols) for the + /// terminal screen + fn physical_dimensions(&self) -> (usize, usize); +} + +impl Renderable for Terminal { + fn get_cursor_position(&self) -> CursorPosition { + self.cursor_pos() + } + + fn get_dirty_lines(&self) -> Vec<(usize, &Line, Range)> { + TerminalState::get_dirty_lines(self) + } + + fn clean_dirty_lines(&mut self) { + TerminalState::clean_dirty_lines(self) + } + + fn current_highlight(&self) -> Option> { + TerminalState::current_highlight(self) + } + + fn physical_dimensions(&self) -> (usize, usize) { + let screen = self.screen(); + (screen.physical_cols, screen.physical_rows) + } +} diff --git a/src/opengl/render.rs b/src/opengl/render.rs index deaf162c2..df548d5cd 100644 --- a/src/opengl/render.rs +++ b/src/opengl/render.rs @@ -3,6 +3,7 @@ use super::textureatlas::{Atlas, Sprite, SpriteSlice, TEX_SIZE}; use crate::config::TextStyle; use crate::font::{FontConfiguration, GlyphInfo}; +use crate::mux::renderable::Renderable; use euclid; use failure::{err_msg, Error}; use glium::backend::Facade; @@ -749,9 +750,9 @@ impl Renderer { line: &Line, selection: Range, cursor: &CursorPosition, - terminal: &term::Terminal, + terminal: &Renderable, ) -> Result<(), Error> { - let num_cols = terminal.screen().physical_cols; + let (num_cols, _num_rows) = terminal.physical_dimensions(); let mut vb = self.glyph_vertex_buffer.borrow_mut(); let mut vertices = { let per_line = num_cols * VERTICES_PER_CELL;