introduce a Renderable trait
This commit is contained in:
1 parent
a833cf29b4
commit
3ceb71026e
3 files changed
+58
-2
No files matched your search
@@ -9,6 +9,8 @@ use std::thread;
|
||||
use term::TerminalHost;
|
||||
use termwiz::hyperlink::Hyperlink;
|
||||
|
||||
pub mod renderable;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Mux {
|
||||
tabs: RefCell<HashMap<TabId, Rc<Tab>>>,
|
||||
|
||||
@@ -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<usize>)>;
|
||||
|
||||
/// Clear the dirty flag for all dirty lines
|
||||
fn clean_dirty_lines(&mut self);
|
||||
|
||||
/// Returns the currently highlighted hyperlink
|
||||
fn current_highlight(&self) -> Option<Rc<Hyperlink>>;
|
||||
|
||||
/// 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<usize>)> {
|
||||
TerminalState::get_dirty_lines(self)
|
||||
}
|
||||
|
||||
fn clean_dirty_lines(&mut self) {
|
||||
TerminalState::clean_dirty_lines(self)
|
||||
}
|
||||
|
||||
fn current_highlight(&self) -> Option<Rc<Hyperlink>> {
|
||||
TerminalState::current_highlight(self)
|
||||
}
|
||||
|
||||
fn physical_dimensions(&self) -> (usize, usize) {
|
||||
let screen = self.screen();
|
||||
(screen.physical_cols, screen.physical_rows)
|
||||
}
|
||||
}
|
||||
@@ -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<usize>,
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user