remove explicit dirty manipulation from Renderable
This commit leaves mux domains broken for the moment, but also simplifes the implementation of the renderable interface.
This commit is contained in:
1 parent
ed97a56055
commit
400c8aa66d
12 files changed
+154
-211
No files matched your search
@@ -223,11 +223,8 @@ impl WindowCallbacks for TermWindow {
|
||||
// Reset the cursor blink phase
|
||||
self.prev_cursor.bump();
|
||||
|
||||
// Heavyweight way to force cursor update
|
||||
let mux = Mux::get().unwrap();
|
||||
if let Some(tab) = mux.get_active_tab_for_window(self.mux_window_id) {
|
||||
tab.renderer().make_all_lines_dirty();
|
||||
}
|
||||
// force cursor to be repainted
|
||||
self.window.as_ref().unwrap().invalidate();
|
||||
}
|
||||
|
||||
fn mouse_event(&mut self, event: &MouseEvent, context: &dyn WindowOps) {
|
||||
@@ -300,7 +297,6 @@ impl WindowCallbacks for TermWindow {
|
||||
.unwrap_or(dims.physical_top)
|
||||
.saturating_sub(amount.into());
|
||||
self.set_viewport(tab.tab_id(), Some(position), dims);
|
||||
render.make_all_lines_dirty();
|
||||
context.invalidate();
|
||||
return;
|
||||
}
|
||||
@@ -331,7 +327,6 @@ impl WindowCallbacks for TermWindow {
|
||||
&self.dimensions,
|
||||
);
|
||||
self.set_viewport(tab.tab_id(), Some(row), dims);
|
||||
render.make_all_lines_dirty();
|
||||
context.invalidate();
|
||||
return;
|
||||
}
|
||||
@@ -441,7 +436,6 @@ impl WindowCallbacks for TermWindow {
|
||||
self.recreate_texture_atlas(None)
|
||||
.expect("OutOfTextureSpace and failed to recreate atlas");
|
||||
}
|
||||
tab.renderer().make_all_lines_dirty();
|
||||
// Recursively initiate a new paint
|
||||
return self.paint(ctx);
|
||||
}
|
||||
@@ -475,7 +469,6 @@ impl WindowCallbacks for TermWindow {
|
||||
self.recreate_texture_atlas(None)
|
||||
.expect("OutOfTextureSpace and failed to recreate atlas");
|
||||
}
|
||||
tab.renderer().make_all_lines_dirty();
|
||||
// Recursively initiate a new paint
|
||||
return self.paint_opengl(frame);
|
||||
}
|
||||
@@ -581,60 +574,66 @@ impl TermWindow {
|
||||
|
||||
let cloned_window = window.clone();
|
||||
|
||||
let mut last_config_generation = config.generation();
|
||||
Connection::get()
|
||||
.unwrap()
|
||||
.schedule_timer(std::time::Duration::from_millis(35), {
|
||||
let mut last_blink_paint = Instant::now();
|
||||
let mut last_config_generation = config.generation();
|
||||
move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
cloned_window.apply(move |myself, _| {
|
||||
if let Some(myself) = myself.downcast_mut::<Self>() {
|
||||
let mux = Mux::get().unwrap();
|
||||
|
||||
if let Some(tab) = mux.get_active_tab_for_window(mux_window_id) {
|
||||
// If the config was reloaded, ask the window to apply
|
||||
// and render any changes
|
||||
let config = configuration();
|
||||
let current_generation = config.generation();
|
||||
if current_generation != last_config_generation {
|
||||
last_config_generation = current_generation;
|
||||
cloned_window.apply(|myself, _| {
|
||||
if let Some(myself) = myself.downcast_mut::<Self>() {
|
||||
if let Some(tab) = mux.get_active_tab_for_window(mux_window_id) {
|
||||
// If the config was reloaded, ask the window to apply
|
||||
// and render any changes
|
||||
let config = configuration();
|
||||
let current_generation = config.generation();
|
||||
if current_generation != last_config_generation {
|
||||
last_config_generation = current_generation;
|
||||
myself.config_was_reloaded();
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
let mut render = tab.renderer();
|
||||
let mut render = tab.renderer();
|
||||
|
||||
// If blinking is permitted, and the cursor shape is set
|
||||
// to a blinking variant, and it's been longer than the
|
||||
// blink rate interval, then invalid the lines in the terminal
|
||||
// so that we will re-evaluate the cursor visibility.
|
||||
// This is pretty heavyweight: it would be nice to only invalidate
|
||||
// the line on which the cursor resides, and then only if the cursor
|
||||
// is within the viewport.
|
||||
if config.cursor_blink_rate != 0 {
|
||||
let shape = config
|
||||
.default_cursor_style
|
||||
.effective_shape(render.get_cursor_position().shape);
|
||||
if shape.is_blinking() {
|
||||
let now = Instant::now();
|
||||
if now.duration_since(last_blink_paint)
|
||||
> Duration::from_millis(config.cursor_blink_rate)
|
||||
{
|
||||
render.make_all_lines_dirty();
|
||||
last_blink_paint = now;
|
||||
// If blinking is permitted, and the cursor shape is set
|
||||
// to a blinking variant, and it's been longer than the
|
||||
// blink rate interval, then invalid the lines in the terminal
|
||||
// so that we will re-evaluate the cursor visibility.
|
||||
// This is pretty heavyweight: it would be nice to only invalidate
|
||||
// the line on which the cursor resides, and then only if the cursor
|
||||
// is within the viewport.
|
||||
if config.cursor_blink_rate != 0 {
|
||||
let shape = config
|
||||
.default_cursor_style
|
||||
.effective_shape(render.get_cursor_position().shape);
|
||||
if shape.is_blinking() {
|
||||
let now = Instant::now();
|
||||
if now.duration_since(last_blink_paint)
|
||||
> Duration::from_millis(config.cursor_blink_rate)
|
||||
{
|
||||
myself.window.as_ref().unwrap().invalidate();
|
||||
last_blink_paint = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the model is dirty, arrange to re-paint
|
||||
let dims = render.get_dimensions();
|
||||
let viewport = myself
|
||||
.get_viewport(tab.tab_id())
|
||||
.unwrap_or(dims.physical_top);
|
||||
let visible_range =
|
||||
viewport..viewport + dims.viewport_rows as StableRowIndex;
|
||||
if !render.get_dirty_lines(visible_range).is_empty() {
|
||||
myself.window.as_ref().unwrap().invalidate();
|
||||
}
|
||||
} else {
|
||||
myself.window.as_ref().unwrap().close();
|
||||
}
|
||||
}
|
||||
|
||||
// If the model is dirty, arrange to re-paint
|
||||
if render.has_dirty_lines() {
|
||||
cloned_window.invalidate();
|
||||
}
|
||||
} else {
|
||||
cloned_window.close();
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -988,7 +987,6 @@ impl TermWindow {
|
||||
.unwrap_or(dims.physical_top)
|
||||
.saturating_add(amount * dims.viewport_rows as isize);
|
||||
self.set_viewport(tab.tab_id(), Some(position), dims);
|
||||
render.make_all_lines_dirty();
|
||||
if let Some(win) = self.window.as_ref() {
|
||||
win.invalidate();
|
||||
}
|
||||
@@ -1062,7 +1060,7 @@ impl TermWindow {
|
||||
let mut s = String::new();
|
||||
if let Some(sel) = self.selection.range.as_ref().map(|r| r.normalize()) {
|
||||
let mut last_was_wrapped = false;
|
||||
let renderer = tab.renderer();
|
||||
let mut renderer = tab.renderer();
|
||||
let (first_row, lines) = renderer.get_lines(sel.rows());
|
||||
for (idx, line) in lines.iter().enumerate() {
|
||||
let cols = sel.cols_for_row(first_row + idx as StableRowIndex);
|
||||
@@ -1341,31 +1339,27 @@ impl TermWindow {
|
||||
let (stable_top, lines) = term.get_lines(stable_range);
|
||||
|
||||
for (line_idx, line) in lines.iter().enumerate() {
|
||||
if line.is_dirty() {
|
||||
let stable_row = stable_top + line_idx as StableRowIndex;
|
||||
let stable_row = stable_top + line_idx as StableRowIndex;
|
||||
|
||||
let selrange = self
|
||||
.selection
|
||||
.range
|
||||
.map(|sel| sel.cols_for_row(stable_row))
|
||||
.unwrap_or(0..0);
|
||||
let selrange = self
|
||||
.selection
|
||||
.range
|
||||
.map(|sel| sel.cols_for_row(stable_row))
|
||||
.unwrap_or(0..0);
|
||||
|
||||
self.render_screen_line(
|
||||
ctx,
|
||||
line_idx + first_line_offset,
|
||||
stable_row,
|
||||
&line,
|
||||
selrange,
|
||||
&cursor,
|
||||
&*term,
|
||||
&palette,
|
||||
)?;
|
||||
}
|
||||
self.render_screen_line(
|
||||
ctx,
|
||||
line_idx + first_line_offset,
|
||||
stable_row,
|
||||
&line,
|
||||
selrange,
|
||||
&cursor,
|
||||
&*term,
|
||||
&palette,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
term.clean_dirty_lines();
|
||||
|
||||
// Fill any padding
|
||||
let config = configuration();
|
||||
let bg = rgbcolor_to_window_color(palette.background);
|
||||
@@ -1554,25 +1548,23 @@ impl TermWindow {
|
||||
}
|
||||
|
||||
for (line_idx, line) in lines.iter().enumerate() {
|
||||
if line.is_dirty() {
|
||||
let stable_row = stable_top + line_idx as StableRowIndex;
|
||||
let selrange = self
|
||||
.selection
|
||||
.range
|
||||
.map(|sel| sel.cols_for_row(stable_row))
|
||||
.unwrap_or(0..0);
|
||||
let stable_row = stable_top + line_idx as StableRowIndex;
|
||||
let selrange = self
|
||||
.selection
|
||||
.range
|
||||
.map(|sel| sel.cols_for_row(stable_row))
|
||||
.unwrap_or(0..0);
|
||||
|
||||
self.render_screen_line_opengl(
|
||||
line_idx + first_line_offset,
|
||||
stable_row,
|
||||
&line,
|
||||
selrange,
|
||||
&cursor,
|
||||
&*term,
|
||||
&palette,
|
||||
&mut quads,
|
||||
)?;
|
||||
}
|
||||
self.render_screen_line_opengl(
|
||||
line_idx + first_line_offset,
|
||||
stable_row,
|
||||
&line,
|
||||
selrange,
|
||||
&cursor,
|
||||
&*term,
|
||||
&palette,
|
||||
&mut quads,
|
||||
)?;
|
||||
}
|
||||
|
||||
let tex = gl_state.glyph_cache.borrow().atlas.texture();
|
||||
@@ -1642,8 +1634,6 @@ impl TermWindow {
|
||||
&draw_params,
|
||||
)?;
|
||||
|
||||
term.clean_dirty_lines();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -2329,7 +2319,6 @@ impl TermWindow {
|
||||
),
|
||||
dims,
|
||||
);
|
||||
render.make_all_lines_dirty();
|
||||
context.invalidate();
|
||||
}
|
||||
ScrollHit::Below => {
|
||||
@@ -2343,7 +2332,6 @@ impl TermWindow {
|
||||
),
|
||||
dims,
|
||||
);
|
||||
render.make_all_lines_dirty();
|
||||
context.invalidate();
|
||||
}
|
||||
ScrollHit::OnThumb(from_top) => {
|
||||
@@ -2383,7 +2371,7 @@ impl TermWindow {
|
||||
|
||||
fn double_click_left(&mut self, tab: &Rc<dyn Tab>, x: usize, row: StableRowIndex) {
|
||||
use termwiz::surface::line::DoubleClickRange;
|
||||
let renderer = tab.renderer();
|
||||
let mut renderer = tab.renderer();
|
||||
let (first, lines) = renderer.get_lines(row..row + 1);
|
||||
if first != row {
|
||||
return;
|
||||
@@ -2488,7 +2476,6 @@ impl TermWindow {
|
||||
}),
|
||||
) => {
|
||||
self.triple_click_left(&tab, x, stable_row);
|
||||
tab.renderer().make_all_lines_dirty();
|
||||
context.invalidate();
|
||||
}
|
||||
// Double click to select a word
|
||||
@@ -2501,7 +2488,6 @@ impl TermWindow {
|
||||
}),
|
||||
) => {
|
||||
self.double_click_left(&tab, x, stable_row);
|
||||
tab.renderer().make_all_lines_dirty();
|
||||
context.invalidate();
|
||||
}
|
||||
|
||||
@@ -2532,7 +2518,6 @@ impl TermWindow {
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.set_clipboard(self.selection_text(&tab));
|
||||
tab.renderer().make_all_lines_dirty();
|
||||
context.invalidate();
|
||||
}
|
||||
|
||||
@@ -2553,7 +2538,6 @@ impl TermWindow {
|
||||
Some(sel) => sel.extend(end),
|
||||
};
|
||||
self.selection.range = Some(sel);
|
||||
tab.renderer().make_all_lines_dirty();
|
||||
context.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
+32
-35
@@ -1,6 +1,5 @@
|
||||
use downcast_rs::{impl_downcast, Downcast};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::borrow::Cow;
|
||||
use std::ops::Range;
|
||||
use std::sync::Arc;
|
||||
use term::{Line, StableRowIndex, Terminal, TerminalState};
|
||||
@@ -40,12 +39,9 @@ pub trait Renderable: Downcast {
|
||||
/// the visible screen
|
||||
fn get_cursor_position(&self) -> StableCursorPosition;
|
||||
|
||||
/// 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, Cow<Line>, Range<usize>)>;
|
||||
/// Given a range of lines, return the subset of those lines that
|
||||
/// have their dirty flag set to true.
|
||||
fn get_dirty_lines(&self, lines: Range<StableRowIndex>) -> Vec<StableRowIndex>;
|
||||
|
||||
/// Returns a set of lines from the scrollback or visible portion of
|
||||
/// the display. The lines are indexed using StableRowIndex, which
|
||||
@@ -58,14 +54,11 @@ pub trait Renderable: Downcast {
|
||||
/// screen and the index would go off the bottom.
|
||||
/// Because of this, we also return the adjusted StableRowIndex for
|
||||
/// the first row in the range.
|
||||
fn get_lines(&self, lines: Range<StableRowIndex>) -> (StableRowIndex, Vec<Cow<Line>>);
|
||||
|
||||
fn has_dirty_lines(&self) -> bool;
|
||||
|
||||
fn make_all_lines_dirty(&mut self);
|
||||
|
||||
/// Clear the dirty flag for all dirty lines
|
||||
fn clean_dirty_lines(&mut self);
|
||||
///
|
||||
/// For each line, if it was dirty in the backing data, then the dirty
|
||||
/// flag will be cleared in the backing data. The returned line will
|
||||
/// have its dirty bit set appropriately.
|
||||
fn get_lines(&mut self, lines: Range<StableRowIndex>) -> (StableRowIndex, Vec<Line>);
|
||||
|
||||
/// Returns the currently highlighted hyperlink
|
||||
fn current_highlight(&self) -> Option<Arc<Hyperlink>>;
|
||||
@@ -86,36 +79,44 @@ impl Renderable for Terminal {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_dirty_lines(&self) -> Vec<(usize, Cow<Line>, Range<usize>)> {
|
||||
TerminalState::get_dirty_lines(self)
|
||||
.into_iter()
|
||||
.map(|(idx, line, range)| (idx, Cow::Borrowed(line), range))
|
||||
fn get_dirty_lines(&self, lines: Range<StableRowIndex>) -> Vec<StableRowIndex> {
|
||||
let screen = self.screen();
|
||||
let phys = screen.stable_range(&lines);
|
||||
screen
|
||||
.lines
|
||||
.iter()
|
||||
.enumerate()
|
||||
.skip(phys.start)
|
||||
.take(phys.end - phys.start)
|
||||
.filter_map(|(idx, line)| {
|
||||
if line.is_dirty() {
|
||||
Some(screen.phys_to_stable_row_index(idx))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn get_lines(&self, lines: Range<StableRowIndex>) -> (StableRowIndex, Vec<Cow<Line>>) {
|
||||
let screen = self.screen();
|
||||
fn get_lines(&mut self, lines: Range<StableRowIndex>) -> (StableRowIndex, Vec<Line>) {
|
||||
let screen = self.screen_mut();
|
||||
let phys_range = screen.stable_range(&lines);
|
||||
(
|
||||
screen.phys_to_stable_row_index(phys_range.start),
|
||||
screen
|
||||
.lines
|
||||
.iter()
|
||||
.iter_mut()
|
||||
.skip(phys_range.start)
|
||||
.take(phys_range.end - phys_range.start)
|
||||
.map(|line| Cow::Borrowed(line))
|
||||
.map(|line| {
|
||||
let cloned = line.clone();
|
||||
line.clear_dirty();
|
||||
cloned
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn clean_dirty_lines(&mut self) {
|
||||
TerminalState::clean_dirty_lines(self)
|
||||
}
|
||||
|
||||
fn make_all_lines_dirty(&mut self) {
|
||||
TerminalState::make_all_lines_dirty(self)
|
||||
}
|
||||
|
||||
fn current_highlight(&self) -> Option<Arc<Hyperlink>> {
|
||||
TerminalState::current_highlight(self)
|
||||
}
|
||||
@@ -130,8 +131,4 @@ impl Renderable for Terminal {
|
||||
scrollback_top: screen.phys_to_stable_row_index(0),
|
||||
}
|
||||
}
|
||||
|
||||
fn has_dirty_lines(&self) -> bool {
|
||||
TerminalState::has_dirty_lines(self)
|
||||
}
|
||||
}
|
||||
@@ -86,8 +86,6 @@ impl Window {
|
||||
let len = self.tabs.len();
|
||||
if len > 0 && self.active == idx && idx >= len {
|
||||
self.set_active(len - 1);
|
||||
} else if let Some(tab) = self.get_by_idx(self.active) {
|
||||
tab.renderer().make_all_lines_dirty();
|
||||
}
|
||||
true
|
||||
} else {
|
||||
@@ -107,10 +105,6 @@ impl Window {
|
||||
pub fn set_active(&mut self, idx: usize) {
|
||||
assert!(idx < self.tabs.len());
|
||||
self.active = idx;
|
||||
self.get_by_idx(idx)
|
||||
.unwrap()
|
||||
.renderer()
|
||||
.make_all_lines_dirty();
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &Rc<dyn Tab>> {
|
||||
|
||||
@@ -445,7 +445,6 @@ impl ClientSurfaceState {
|
||||
|
||||
if (dims.viewport_rows != surface_height) || (dims.cols != surface_width) {
|
||||
self.surface.resize(dims.cols, dims.viewport_rows);
|
||||
renderable.make_all_lines_dirty();
|
||||
}
|
||||
|
||||
let (x, y) = self.surface.cursor_position();
|
||||
@@ -461,13 +460,15 @@ impl ClientSurfaceState {
|
||||
}
|
||||
}
|
||||
|
||||
todo!();
|
||||
/*
|
||||
let mut changes = vec![];
|
||||
|
||||
for (line_idx, line, _selrange) in renderable.get_dirty_lines() {
|
||||
changes.append(&mut self.surface.diff_against_numbered_line(line_idx, &line));
|
||||
}
|
||||
|
||||
self.surface.add_changes(changes);
|
||||
*/
|
||||
}
|
||||
|
||||
let title = tab.get_title();
|
||||
@@ -795,12 +796,12 @@ impl<S: ReadAndWrite> ClientSession<S> {
|
||||
let tab = mux
|
||||
.get_tab(tab_id)
|
||||
.ok_or_else(|| anyhow!("no such tab {}", tab_id))?;
|
||||
let renderer = tab.renderer();
|
||||
let mut renderer = tab.renderer();
|
||||
let (first_row, lines) = renderer.get_lines(lines);
|
||||
Ok(Pdu::GetLinesResponse(GetLinesResponse {
|
||||
tab_id,
|
||||
first_row,
|
||||
lines: lines.into_iter().map(|line| line.into_owned()).collect(),
|
||||
lines,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
+11
-16
@@ -11,7 +11,6 @@ use filedescriptor::Pipe;
|
||||
use log::{error, info};
|
||||
use portable_pty::PtySize;
|
||||
use promise::{BrokenPromise, Future};
|
||||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
use std::cell::RefMut;
|
||||
use std::collections::VecDeque;
|
||||
@@ -21,7 +20,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
use term::color::ColorPalette;
|
||||
use term::selection::SelectionRange;
|
||||
use term::{
|
||||
Clipboard, KeyCode, KeyModifiers, Line, MouseButton, MouseEvent, MouseEventKind,
|
||||
StableRowIndex, TerminalHost,
|
||||
@@ -141,7 +139,6 @@ impl ClientTab {
|
||||
client: Arc::clone(client),
|
||||
remote_tab_id,
|
||||
};
|
||||
let selection_range = Arc::new(Mutex::new(None));
|
||||
let something_changed = Arc::new(AtomicBool::new(true));
|
||||
let highlight = Arc::new(Mutex::new(None));
|
||||
|
||||
@@ -163,7 +160,6 @@ impl ClientTab {
|
||||
surface: Surface::new(size.cols as usize, size.rows as usize),
|
||||
remote_sequence: 0,
|
||||
local_sequence: 0,
|
||||
selection_range,
|
||||
something_changed,
|
||||
highlight,
|
||||
}),
|
||||
@@ -327,7 +323,6 @@ struct RenderableInner {
|
||||
remote_sequence: SequenceNo,
|
||||
local_sequence: SequenceNo,
|
||||
poll_interval: Duration,
|
||||
selection_range: Arc<Mutex<Option<SelectionRange>>>,
|
||||
something_changed: Arc<AtomicBool>,
|
||||
highlight: Arc<Mutex<Option<Arc<Hyperlink>>>>,
|
||||
}
|
||||
@@ -397,7 +392,8 @@ impl Renderable for RenderableState {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_lines(&self, lines: Range<StableRowIndex>) -> (StableRowIndex, Vec<Cow<Line>>) {
|
||||
fn get_lines(&mut self, lines: Range<StableRowIndex>) -> (StableRowIndex, Vec<Line>) {
|
||||
// FIXME: mark clean
|
||||
let inner = self.inner.borrow_mut();
|
||||
(
|
||||
lines.start,
|
||||
@@ -407,11 +403,16 @@ impl Renderable for RenderableState {
|
||||
.into_iter()
|
||||
.skip(lines.start.try_into().unwrap())
|
||||
.take((lines.end - lines.start).try_into().unwrap())
|
||||
.map(|line| Cow::Owned(line.into_owned()))
|
||||
.map(|line| line.into_owned())
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn get_dirty_lines(&self, _lines: Range<StableRowIndex>) -> Vec<StableRowIndex> {
|
||||
todo!();
|
||||
}
|
||||
|
||||
/*
|
||||
fn get_dirty_lines(&self) -> Vec<(usize, Cow<Line>, Range<usize>)> {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
let seq = inner.surface.current_seqno();
|
||||
@@ -433,7 +434,9 @@ impl Renderable for RenderableState {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
fn has_dirty_lines(&self) -> bool {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
if let Err(err) = inner.poll() {
|
||||
@@ -451,15 +454,7 @@ impl Renderable for RenderableState {
|
||||
}
|
||||
inner.surface.has_changes(inner.local_sequence)
|
||||
}
|
||||
|
||||
fn make_all_lines_dirty(&mut self) {
|
||||
self.inner
|
||||
.borrow()
|
||||
.something_changed
|
||||
.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
fn clean_dirty_lines(&mut self) {}
|
||||
*/
|
||||
|
||||
fn current_highlight(&self) -> Option<Arc<Hyperlink>> {
|
||||
self.inner
|
||||
|
||||
+13
-41
@@ -15,7 +15,6 @@ use crossbeam_channel::{unbounded as channel, Receiver, Sender};
|
||||
use filedescriptor::Pipe;
|
||||
use portable_pty::*;
|
||||
use promise::{Future, Promise};
|
||||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
use std::cell::RefMut;
|
||||
use std::convert::TryInto;
|
||||
@@ -25,7 +24,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
use term::color::ColorPalette;
|
||||
use term::selection::SelectionRange;
|
||||
use term::{KeyCode, KeyModifiers, Line, MouseEvent, StableRowIndex, TerminalHost};
|
||||
use termwiz::hyperlink::Hyperlink;
|
||||
use termwiz::input::{InputEvent, KeyEvent};
|
||||
@@ -35,7 +33,6 @@ use termwiz::terminal::{ScreenSize, Terminal, TerminalWaker};
|
||||
|
||||
struct RenderableInner {
|
||||
surface: Surface,
|
||||
selection_range: Arc<Mutex<Option<SelectionRange>>>,
|
||||
something_changed: Arc<AtomicBool>,
|
||||
highlight: Arc<Mutex<Option<Arc<Hyperlink>>>>,
|
||||
local_sequence: SequenceNo,
|
||||
@@ -75,8 +72,12 @@ impl Renderable for RenderableState {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_lines(&self, lines: Range<StableRowIndex>) -> (StableRowIndex, Vec<Cow<Line>>) {
|
||||
fn get_lines(&mut self, lines: Range<StableRowIndex>) -> (StableRowIndex, Vec<Line>) {
|
||||
let inner = self.inner.borrow_mut();
|
||||
|
||||
// Reset the dirty bit
|
||||
inner.something_changed.store(false, Ordering::SeqCst);
|
||||
|
||||
(
|
||||
lines.start,
|
||||
inner
|
||||
@@ -85,34 +86,12 @@ impl Renderable for RenderableState {
|
||||
.into_iter()
|
||||
.skip(lines.start.try_into().unwrap())
|
||||
.take((lines.end - lines.start).try_into().unwrap())
|
||||
.map(|line| Cow::Owned(line.into_owned()))
|
||||
.map(|line| line.into_owned())
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn get_dirty_lines(&self) -> Vec<(usize, Cow<Line>, Range<usize>)> {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
let seq = inner.surface.current_seqno();
|
||||
inner.surface.flush_changes_older_than(seq);
|
||||
let selection = *inner.selection_range.lock().unwrap();
|
||||
inner.something_changed.store(false, Ordering::SeqCst);
|
||||
inner.local_sequence = seq;
|
||||
inner
|
||||
.surface
|
||||
.screen_lines()
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(idx, line)| {
|
||||
let r = match selection {
|
||||
None => 0..0,
|
||||
Some(sel) => sel.normalize().cols_for_row(idx as i32),
|
||||
};
|
||||
(idx, Cow::Owned(line.into_owned()), r)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn has_dirty_lines(&self) -> bool {
|
||||
fn get_dirty_lines(&self, lines: Range<StableRowIndex>) -> Vec<StableRowIndex> {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
|
||||
loop {
|
||||
@@ -129,21 +108,15 @@ impl Renderable for RenderableState {
|
||||
}
|
||||
}
|
||||
|
||||
if inner.something_changed.load(Ordering::SeqCst) {
|
||||
return true;
|
||||
if inner.something_changed.load(Ordering::SeqCst)
|
||||
|| inner.surface.has_changes(inner.local_sequence)
|
||||
{
|
||||
lines.into_iter().collect()
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
inner.surface.has_changes(inner.local_sequence)
|
||||
}
|
||||
|
||||
fn make_all_lines_dirty(&mut self) {
|
||||
self.inner
|
||||
.borrow()
|
||||
.something_changed
|
||||
.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
fn clean_dirty_lines(&mut self) {}
|
||||
|
||||
fn current_highlight(&self) -> Option<Arc<Hyperlink>> {
|
||||
self.inner
|
||||
.borrow()
|
||||
@@ -437,7 +410,6 @@ pub fn run<T: Send + 'static, F: Send + 'static + Fn(TermWizTerminal) -> anyhow:
|
||||
local_sequence: 0,
|
||||
dead: false,
|
||||
something_changed: Arc::new(AtomicBool::new(false)),
|
||||
selection_range: Arc::new(Mutex::new(None)),
|
||||
input_tx,
|
||||
render_rx,
|
||||
};
|
||||
|
||||
+1
-1
@@ -198,7 +198,7 @@ pub trait WindowOps {
|
||||
/// The `Any` that is passed in corresponds to the WindowCallbacks
|
||||
/// impl you passed to `new_window`, pre-converted to Any so that
|
||||
/// you can `downcast_ref` or `downcast_mut` it and operate on it.
|
||||
fn apply<R, F: Send + 'static + Fn(&mut dyn Any, &dyn WindowOps) -> anyhow::Result<R>>(
|
||||
fn apply<R, F: Send + 'static + FnMut(&mut dyn Any, &dyn WindowOps) -> anyhow::Result<R>>(
|
||||
&self,
|
||||
func: F,
|
||||
) -> promise::Future<R>
|
||||
|
||||
@@ -407,9 +407,9 @@ impl WindowOps for Window {
|
||||
})
|
||||
}
|
||||
|
||||
fn apply<R, F: Send + 'static + Fn(&mut dyn Any, &dyn WindowOps) -> anyhow::Result<R>>(
|
||||
fn apply<R, F: Send + 'static + FnMut(&mut dyn Any, &dyn WindowOps) -> anyhow::Result<R>>(
|
||||
&self,
|
||||
func: F,
|
||||
mut func: F,
|
||||
) -> promise::Future<R>
|
||||
where
|
||||
Self: Sized,
|
||||
|
||||
@@ -684,9 +684,9 @@ impl WindowOps for WaylandWindow {
|
||||
})
|
||||
}
|
||||
|
||||
fn apply<R, F: Send + 'static + Fn(&mut dyn Any, &dyn WindowOps) -> anyhow::Result<R>>(
|
||||
fn apply<R, F: Send + 'static + FnMut(&mut dyn Any, &dyn WindowOps) -> anyhow::Result<R>>(
|
||||
&self,
|
||||
func: F,
|
||||
mut func: F,
|
||||
) -> promise::Future<R>
|
||||
where
|
||||
Self: Sized,
|
||||
|
||||
@@ -368,9 +368,9 @@ impl WindowOps for Window {
|
||||
})
|
||||
}
|
||||
|
||||
fn apply<R, F: Send + 'static + Fn(&mut dyn Any, &dyn WindowOps) -> anyhow::Result<R>>(
|
||||
fn apply<R, F: Send + 'static + FnMut(&mut dyn Any, &dyn WindowOps) -> anyhow::Result<R>>(
|
||||
&self,
|
||||
func: F,
|
||||
mut func: F,
|
||||
) -> promise::Future<R>
|
||||
where
|
||||
Self: Sized,
|
||||
|
||||
@@ -850,9 +850,9 @@ impl WindowOps for XWindow {
|
||||
})
|
||||
}
|
||||
|
||||
fn apply<R, F: Send + 'static + Fn(&mut dyn Any, &dyn WindowOps) -> anyhow::Result<R>>(
|
||||
fn apply<R, F: Send + 'static + FnMut(&mut dyn Any, &dyn WindowOps) -> anyhow::Result<R>>(
|
||||
&self,
|
||||
func: F,
|
||||
mut func: F,
|
||||
) -> promise::Future<R>
|
||||
where
|
||||
Self: Sized,
|
||||
|
||||
@@ -226,7 +226,7 @@ impl WindowOps for Window {
|
||||
}
|
||||
}
|
||||
|
||||
fn apply<R, F: Send + 'static + Fn(&mut dyn Any, &dyn WindowOps) -> anyhow::Result<R>>(
|
||||
fn apply<R, F: Send + 'static + FnMut(&mut dyn Any, &dyn WindowOps) -> anyhow::Result<R>>(
|
||||
&self,
|
||||
func: F,
|
||||
) -> promise::Future<R>
|
||||
|
||||
Reference in new issue
Block a user