pub struct TermBuffer { /* private fields */ }
Expand description
Represents a range of lines in a terminal and the cursor position. This is suitable when you don’t want to use an “alternate screen”, but rather retain previous terminal output, such as shell prompts/responses.
New frames are rendered by replacing the lines. All operations work on a relative coordinate system where (0, 0) is the top-left corner of the lines TermBuffer controls.
Further, we never check the actual cursor position, but rather move the cursor relative to its current position. The meaning of (0, 0) is actually the cursor position when TermBuffer first renders.
Implementations§
Source§impl TermBuffer
impl TermBuffer
pub fn new() -> Self
Sourcepub fn push_line(&mut self, row: impl Into<String>)
pub fn push_line(&mut self, row: impl Into<String>)
Add a row to the desired output
Examples found in repository?
37pub fn main() {
38 let mut state = State(0, Direction::Grow);
39 let mut buf = TermBuffer::default();
40
41 loop {
42 let count = state.update();
43 // let count = MAX;
44
45 for i in 0..count {
46 let line = format!("|{}\\", "*".repeat(i));
47 buf.push_line(line);
48 }
49 buf.push_line(format!(" {}", "‾".repeat(count - 1)));
50
51 buf.render_frame();
52 buf.flush();
53 // x
54 std::thread::sleep(std::time::Duration::from_millis(15));
55 }
56}
pub fn lines(&self) -> u16
Sourcepub fn set_next_cursor(&mut self, cursor: (u16, u16))
pub fn set_next_cursor(&mut self, cursor: (u16, u16))
Positions the cursor where (0, 0) is the first character printed by this program
Sourcepub fn forget(&mut self) -> usize
pub fn forget(&mut self) -> usize
This causes us to skip past the currently displayed buffer area and forget about it, resulting in future renders to happen below it. If this is called, and then the TermBuffer is dropped, the default behavior of clearing the area will be a no-op.
Sourcepub fn render_frame(&mut self)
pub fn render_frame(&mut self)
Perform the necessary update to the terminal. This may choose a more optimized update than a full frame.
Examples found in repository?
37pub fn main() {
38 let mut state = State(0, Direction::Grow);
39 let mut buf = TermBuffer::default();
40
41 loop {
42 let count = state.update();
43 // let count = MAX;
44
45 for i in 0..count {
46 let line = format!("|{}\\", "*".repeat(i));
47 buf.push_line(line);
48 }
49 buf.push_line(format!(" {}", "‾".repeat(count - 1)));
50
51 buf.render_frame();
52 buf.flush();
53 // x
54 std::thread::sleep(std::time::Duration::from_millis(15));
55 }
56}
pub fn render_one_line(&mut self, line_index: usize)
Sourcepub fn render_full(&mut self)
pub fn render_full(&mut self)
Renders a complete frame to the terminal
Sourcepub fn flush(&mut self)
pub fn flush(&mut self)
Examples found in repository?
37pub fn main() {
38 let mut state = State(0, Direction::Grow);
39 let mut buf = TermBuffer::default();
40
41 loop {
42 let count = state.update();
43 // let count = MAX;
44
45 for i in 0..count {
46 let line = format!("|{}\\", "*".repeat(i));
47 buf.push_line(line);
48 }
49 buf.push_line(format!(" {}", "‾".repeat(count - 1)));
50
51 buf.render_frame();
52 buf.flush();
53 // x
54 std::thread::sleep(std::time::Duration::from_millis(15));
55 }
56}