Skip to content

Commit 8c27d55

Browse files
oli-obkchris-laplante
authored andcommitted
Track draw target height
1 parent a1d1367 commit 8c27d55

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/in_memory.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl InMemoryTerm {
2626

2727
pub fn reset(&self) {
2828
let mut state = self.state.lock().unwrap();
29-
*state = InMemoryTermState::new(state.parser.screen().size().0, state.width);
29+
*state = InMemoryTermState::new(state.height, state.width);
3030
}
3131

3232
pub fn contents(&self) -> String {
@@ -99,6 +99,10 @@ impl TermLike for InMemoryTerm {
9999
self.state.lock().unwrap().width
100100
}
101101

102+
fn height(&self) -> u16 {
103+
self.state.lock().unwrap().height
104+
}
105+
102106
fn move_cursor_up(&self, n: usize) -> std::io::Result<()> {
103107
match n {
104108
0 => Ok(()),
@@ -158,13 +162,15 @@ impl TermLike for InMemoryTerm {
158162

159163
struct InMemoryTermState {
160164
width: u16,
165+
height: u16,
161166
parser: vt100::Parser,
162167
}
163168

164169
impl InMemoryTermState {
165170
pub(crate) fn new(rows: u16, cols: u16) -> InMemoryTermState {
166171
InMemoryTermState {
167172
width: cols,
173+
height: rows,
168174
parser: Parser::new(rows, cols, 0),
169175
}
170176
}

src/term_like.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ use console::Term;
1111
pub trait TermLike: Debug + Send + Sync {
1212
/// Return the terminal width
1313
fn width(&self) -> u16;
14+
/// Return the terminal height
15+
fn height(&self) -> u16 {
16+
// FIXME: remove this default impl in the next major version bump
17+
20 // sensible default
18+
}
1419

1520
/// Move the cursor up by `n` lines
1621
fn move_cursor_up(&self, n: usize) -> io::Result<()>;
1722
/// Move the cursor down by `n` lines
1823
fn move_cursor_down(&self, n: usize) -> io::Result<()>;
19-
/// Move the cursor right by `n` lines
24+
/// Move the cursor right by `n` chars
2025
fn move_cursor_right(&self, n: usize) -> io::Result<()>;
21-
/// Move the cursor left by `n` lines
26+
/// Move the cursor left by `n` chars
2227
fn move_cursor_left(&self, n: usize) -> io::Result<()>;
2328

2429
/// Write a string and add a newline.
@@ -36,6 +41,10 @@ impl TermLike for Term {
3641
self.size().1
3742
}
3843

44+
fn height(&self) -> u16 {
45+
self.size().0
46+
}
47+
3948
fn move_cursor_up(&self, n: usize) -> io::Result<()> {
4049
self.move_cursor_up(n)
4150
}

0 commit comments

Comments
 (0)