Renderable: replace a 2-tuple with an expanded struct
This cleans up the API a little as part of refs: https://github.com/wez/wezterm/issues/106
This commit is contained in:
1 parent
318267c88b
commit
56c170240f
5 files changed
+56
-30
No files matched your search
@@ -595,7 +595,9 @@ impl TermWindow {
|
||||
tab: &Rc<dyn Tab>,
|
||||
mux_window_id: MuxWindowId,
|
||||
) -> anyhow::Result<()> {
|
||||
let (physical_rows, physical_cols) = tab.renderer().physical_dimensions();
|
||||
let dims = tab.renderer().get_dimensions();
|
||||
let physical_rows = dims.viewport_rows;
|
||||
let physical_cols = dims.cols;
|
||||
|
||||
let render_metrics = RenderMetrics::new(fontconfig);
|
||||
|
||||
@@ -1387,7 +1389,8 @@ impl TermWindow {
|
||||
let config = configuration();
|
||||
let bg = rgbcolor_to_window_color(palette.background);
|
||||
// Fill any padding below the last row
|
||||
let (num_rows, _num_cols) = term.physical_dimensions();
|
||||
let dims = term.get_dimensions();
|
||||
let num_rows = dims.viewport_rows;
|
||||
let pixel_height_of_cells = config.window_padding.top as usize
|
||||
+ (num_rows + first_line_offset) * self.render_metrics.cell_size.height as usize;
|
||||
ctx.clear_rect(
|
||||
@@ -1653,7 +1656,8 @@ impl TermWindow {
|
||||
) -> anyhow::Result<()> {
|
||||
let gl_state = self.render_state.opengl();
|
||||
|
||||
let (_num_rows, num_cols) = terminal.physical_dimensions();
|
||||
let dims = terminal.get_dimensions();
|
||||
let num_cols = dims.cols;
|
||||
|
||||
let current_highlight = terminal.current_highlight();
|
||||
let cursor_border_color = rgbcolor_to_window_color(palette.cursor_border);
|
||||
@@ -1908,7 +1912,8 @@ impl TermWindow {
|
||||
let padding_left = config.window_padding.left as isize;
|
||||
let padding_top = config.window_padding.top as isize;
|
||||
|
||||
let (_num_rows, num_cols) = terminal.physical_dimensions();
|
||||
let dims = terminal.get_dimensions();
|
||||
let num_cols = dims.cols;
|
||||
let current_highlight = terminal.current_highlight();
|
||||
let cursor_border_color = rgbcolor_to_window_color(palette.cursor_border);
|
||||
|
||||
|
||||
+18
-5
@@ -5,6 +5,16 @@ use std::sync::Arc;
|
||||
use term::{CursorPosition, Line, Terminal, TerminalState, VisibleRowIndex};
|
||||
use termwiz::hyperlink::Hyperlink;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct RenderableDimensions {
|
||||
/// The viewport width
|
||||
pub cols: usize,
|
||||
/// How many rows fit in the viewport
|
||||
pub viewport_rows: usize,
|
||||
/// The total number of lines in the scrollback, including the viewport
|
||||
pub scrollback_rows: usize,
|
||||
}
|
||||
|
||||
/// 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.
|
||||
@@ -30,9 +40,8 @@ pub trait Renderable: Downcast {
|
||||
/// Returns the currently highlighted hyperlink
|
||||
fn current_highlight(&self) -> Option<Arc<Hyperlink>>;
|
||||
|
||||
/// Returns physical, non-scrollback (rows, cols) for the
|
||||
/// terminal screen
|
||||
fn physical_dimensions(&self) -> (usize, usize);
|
||||
/// Returns render related dimensions
|
||||
fn get_dimensions(&self) -> RenderableDimensions;
|
||||
|
||||
/// Returns the potentially scrolled viewport offset, and the
|
||||
/// size of the scrollback. This information is intended to be
|
||||
@@ -66,9 +75,13 @@ impl Renderable for Terminal {
|
||||
TerminalState::current_highlight(self)
|
||||
}
|
||||
|
||||
fn physical_dimensions(&self) -> (usize, usize) {
|
||||
fn get_dimensions(&self) -> RenderableDimensions {
|
||||
let screen = self.screen();
|
||||
(screen.physical_rows, screen.physical_cols)
|
||||
RenderableDimensions {
|
||||
cols: screen.physical_cols,
|
||||
viewport_rows: screen.physical_rows,
|
||||
scrollback_rows: screen.lines.len(),
|
||||
}
|
||||
}
|
||||
|
||||
fn has_dirty_lines(&self) -> bool {
|
||||
|
||||
@@ -388,10 +388,10 @@ fn maybe_push_tab_changes(
|
||||
) -> anyhow::Result<()> {
|
||||
let tab_id = tab.tab_id();
|
||||
let mut surfaces = surfaces.lock().unwrap();
|
||||
let (rows, cols) = tab.renderer().physical_dimensions();
|
||||
let dims = tab.renderer().get_dimensions();
|
||||
let surface = surfaces
|
||||
.entry(tab_id)
|
||||
.or_insert_with(|| ClientSurfaceState::new(cols, rows));
|
||||
.or_insert_with(|| ClientSurfaceState::new(dims.cols, dims.viewport_rows));
|
||||
surface.update_surface_from_screen(&tab);
|
||||
|
||||
let (new_seq, changes) = surface.get_and_flush_changes(surface.last_seq);
|
||||
@@ -437,11 +437,11 @@ impl ClientSurfaceState {
|
||||
|
||||
{
|
||||
let mut renderable = tab.renderer();
|
||||
let (rows, cols) = renderable.physical_dimensions();
|
||||
let dims = renderable.get_dimensions();
|
||||
let (surface_width, surface_height) = self.surface.dimensions();
|
||||
|
||||
if (rows != surface_height) || (cols != surface_width) {
|
||||
self.surface.resize(cols, rows);
|
||||
if (dims.viewport_rows != surface_height) || (dims.cols != surface_width) {
|
||||
self.surface.resize(dims.cols, dims.viewport_rows);
|
||||
renderable.make_all_lines_dirty();
|
||||
}
|
||||
|
||||
@@ -450,7 +450,7 @@ impl ClientSurfaceState {
|
||||
if (x != cursor.x) || (y as i64 != cursor.y) {
|
||||
// Update the cursor, but if we're scrolled back
|
||||
// and it is our of range, skip the update.
|
||||
if cursor.y < rows as i64 {
|
||||
if cursor.y < dims.viewport_rows as i64 {
|
||||
self.surface.add_change(Change::CursorPosition {
|
||||
x: Position::Absolute(cursor.x),
|
||||
y: Position::Absolute(cursor.y as usize),
|
||||
@@ -654,14 +654,14 @@ impl<S: ReadAndWrite> ClientSession<S> {
|
||||
for window_id in mux.iter_windows().into_iter() {
|
||||
let window = mux.get_window(window_id).unwrap();
|
||||
for tab in window.iter() {
|
||||
let (rows, cols) = tab.renderer().physical_dimensions();
|
||||
let dims = tab.renderer().get_dimensions();
|
||||
tabs.push(WindowAndTabEntry {
|
||||
window_id,
|
||||
tab_id: tab.tab_id(),
|
||||
title: tab.get_title(),
|
||||
size: PtySize {
|
||||
cols: cols as u16,
|
||||
rows: rows as u16,
|
||||
cols: dims.cols as u16,
|
||||
rows: dims.viewport_rows as u16,
|
||||
pixel_height: 0,
|
||||
pixel_width: 0,
|
||||
},
|
||||
|
||||
+10
-6
@@ -1,7 +1,7 @@
|
||||
use crate::config::configuration;
|
||||
use crate::frontend::executor;
|
||||
use crate::mux::domain::DomainId;
|
||||
use crate::mux::renderable::Renderable;
|
||||
use crate::mux::renderable::{Renderable, RenderableDimensions};
|
||||
use crate::mux::tab::{alloc_tab_id, Tab, TabId};
|
||||
use crate::server::client::Client;
|
||||
use crate::server::codec::*;
|
||||
@@ -470,16 +470,20 @@ impl Renderable for RenderableState {
|
||||
.cloned()
|
||||
}
|
||||
|
||||
fn physical_dimensions(&self) -> (usize, usize) {
|
||||
let (cols, rows) = self.inner.borrow().surface.dimensions();
|
||||
(rows, cols)
|
||||
fn get_dimensions(&self) -> RenderableDimensions {
|
||||
let (cols, viewport_rows) = self.inner.borrow().surface.dimensions();
|
||||
RenderableDimensions {
|
||||
viewport_rows,
|
||||
cols,
|
||||
scrollback_rows: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_scrollbar_info(&self) -> (VisibleRowIndex, usize) {
|
||||
// Dummy scrollback information for now, until we
|
||||
// plumb this into the protocol
|
||||
let (_cols, rows) = self.physical_dimensions();
|
||||
(0, rows)
|
||||
let dims = self.get_dimensions();
|
||||
(0, dims.viewport_rows)
|
||||
}
|
||||
fn set_viewport_position(&mut self, _: VisibleRowIndex) {}
|
||||
}
|
||||
|
||||
+10
-6
@@ -6,7 +6,7 @@
|
||||
use crate::font::FontConfiguration;
|
||||
use crate::frontend::{executor, front_end};
|
||||
use crate::mux::domain::{alloc_domain_id, Domain, DomainId, DomainState};
|
||||
use crate::mux::renderable::Renderable;
|
||||
use crate::mux::renderable::{Renderable, RenderableDimensions};
|
||||
use crate::mux::tab::{alloc_tab_id, Tab, TabId};
|
||||
use crate::mux::window::WindowId;
|
||||
use crate::mux::Mux;
|
||||
@@ -140,14 +140,18 @@ impl Renderable for RenderableState {
|
||||
.cloned()
|
||||
}
|
||||
|
||||
fn physical_dimensions(&self) -> (usize, usize) {
|
||||
let (cols, rows) = self.inner.borrow().surface.dimensions();
|
||||
(rows, cols)
|
||||
fn get_dimensions(&self) -> RenderableDimensions {
|
||||
let (cols, viewport_rows) = self.inner.borrow().surface.dimensions();
|
||||
RenderableDimensions {
|
||||
viewport_rows,
|
||||
cols,
|
||||
scrollback_rows: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_scrollbar_info(&self) -> (VisibleRowIndex, usize) {
|
||||
let (_cols, rows) = self.physical_dimensions();
|
||||
(0, rows)
|
||||
let dims = self.get_dimensions();
|
||||
(0, dims.viewport_rows)
|
||||
}
|
||||
fn set_viewport_position(&mut self, _: VisibleRowIndex) {}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user