aboutsummaryrefslogtreecommitdiff
path: root/src/term.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-06-07 21:15:53 -0700
committerJoe Wilm <joe@jwilm.com>2016-06-07 21:15:53 -0700
commit6c82fa9d7b39a6ae70f1e233c9123b9d32c30623 (patch)
tree1a4ec091f5deb6391bc2d81262e49795377fcbb8 /src/term.rs
parent781c67f0a06d7be9b3625afac57325c4dbcc3c9b (diff)
downloadr-alacritty-6c82fa9d7b39a6ae70f1e233c9123b9d32c30623.tar.gz
r-alacritty-6c82fa9d7b39a6ae70f1e233c9123b9d32c30623.tar.bz2
r-alacritty-6c82fa9d7b39a6ae70f1e233c9123b9d32c30623.zip
Only draw when terminal state has changed
This is achieved by setting a `dirty` flag when the terminal receives an event that causes visible state to change. The implementation is pretty much crap because most methods know about the flag. Figure out something better later.
Diffstat (limited to 'src/term.rs')
-rw-r--r--src/term.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/term.rs b/src/term.rs
index c254f6b9..1845d9e3 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -93,6 +93,9 @@ pub struct Term {
/// Cell attributes
attr: grid::CellFlags,
+
+ /// Whether state has changed and needs to be updated.
+ dirty: bool,
}
impl Term {
@@ -115,9 +118,18 @@ impl Term {
tty: tty,
tabs: tabs,
attr: CellFlags::empty(),
+ dirty: false,
}
}
+ pub fn dirty(&self) -> bool {
+ self.dirty
+ }
+
+ pub fn clear_dirty(&mut self) {
+ self.dirty = false;
+ }
+
pub fn grid(&self) -> &Grid {
&self.grid
}
@@ -153,6 +165,7 @@ impl Term {
/// Set character in current cursor position
fn set_char(&mut self, c: char) {
+ self.dirty = true;
if self.cursor.x == self.grid.num_cols() as u16 {
self.cursor.y += 1;
self.cursor.x = 0;
@@ -187,14 +200,17 @@ impl ansi::Handler for Term {
fn goto(&mut self, x: i64, y: i64) {
println!("goto: x={}, y={}", x, y);
+ self.dirty = true;
self.cursor.goto(x as u16, y as u16);
}
fn goto_row(&mut self, y: i64) {
+ self.dirty = true;
println!("goto_row: {}", y);
let x = self.cursor_x();
self.cursor.goto(x, y as u16);
}
fn goto_col(&mut self, x: i64) {
+ self.dirty = true;
println!("goto_col: {}", x);
let y = self.cursor_y();
self.cursor.goto(x as u16, y);
@@ -203,21 +219,25 @@ impl ansi::Handler for Term {
fn insert_blank(&mut self, num: i64) { println!("insert_blank: {}", num); }
fn move_up(&mut self, rows: i64) {
+ self.dirty = true;
println!("move_up: {}", rows);
self.cursor.advance(-rows, 0);
}
fn move_down(&mut self, rows: i64) {
+ self.dirty = true;
println!("move_down: {}", rows);
self.cursor.advance(rows, 0);
}
fn move_forward(&mut self, cols: i64) {
+ self.dirty = true;
println!("move_forward: {}", cols);
self.cursor.advance(0, cols);
}
fn move_backward(&mut self, spaces: i64) {
+ self.dirty = true;
println!("move_backward: {}", spaces);
self.cursor.advance(0, -spaces);
}
@@ -226,6 +246,7 @@ impl ansi::Handler for Term {
fn move_down_and_cr(&mut self, rows: i64) { println!("move_down_and_cr: {}", rows); }
fn move_up_and_cr(&mut self, rows: i64) { println!("move_up_and_cr: {}", rows); }
fn put_tab(&mut self, mut count: i64) {
+ self.dirty = true;
println!("put_tab: {}", count);
let mut x = self.cursor_x();
@@ -245,6 +266,8 @@ impl ansi::Handler for Term {
/// Backspace `count` characters
#[inline]
fn backspace(&mut self, count: i64) {
+ println!("backspace");
+ self.dirty = true;
self.cursor.x -= 1;
self.set_char(' ');
}
@@ -252,12 +275,15 @@ impl ansi::Handler for Term {
/// Carriage return
#[inline]
fn carriage_return(&mut self) {
+ println!("carriage_return");
+ self.dirty = true;
self.cursor.x = 0;
}
/// Linefeed
#[inline]
fn linefeed(&mut self) {
+ self.dirty = true;
println!("linefeed");
// TODO handle scroll? not clear what parts of this the pty handle
if self.cursor_y() + 1 == self.grid.num_rows() as u16 {
@@ -284,6 +310,7 @@ impl ansi::Handler for Term {
fn save_cursor_position(&mut self) { println!("save_cursor_position"); }
fn restore_cursor_position(&mut self) { println!("restore_cursor_position"); }
fn clear_line(&mut self, mode: ansi::LineClearMode) {
+ self.dirty = true;
println!("clear_line: {:?}", mode);
match mode {
ansi::LineClearMode::Right => {
@@ -298,6 +325,7 @@ impl ansi::Handler for Term {
}
}
fn clear_screen(&mut self, mode: ansi::ClearMode) {
+ self.dirty = true;
println!("clear_screen: {:?}", mode);
match mode {
ansi::ClearMode::Below => {
@@ -321,6 +349,7 @@ impl ansi::Handler for Term {
fn clear_tabs(&mut self, mode: ansi::TabulationClearMode) { println!("clear_tabs: {:?}", mode); }
fn reset_state(&mut self) { println!("reset_state"); }
fn reverse_index(&mut self) {
+ self.dirty = true;
println!("reverse_index");
// if cursor is at the top
if self.cursor.y == 0 {