File: buffered_terminal.rs

package info (click to toggle)
rust-termwiz 0.22.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,036 kB
  • sloc: sh: 10,450; makefile: 18
file content (33 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//! This example shows how to use `BufferedTerminal` to queue
//! up changes and then flush them.  `BufferedTerminal` enables
//! optimizing the output sequence to update the screen, which is
//! important on links with poor connectivity.
use termwiz::caps::Capabilities;
use termwiz::cell::AttributeChange;
use termwiz::color::AnsiColor;
use termwiz::surface::Change;
use termwiz::terminal::buffered::BufferedTerminal;
use termwiz::terminal::{new_terminal, Terminal};
use termwiz::Error;

fn main() -> Result<(), Error> {
    let caps = Capabilities::new_from_env()?;

    let mut terminal = new_terminal(caps)?;
    terminal.set_raw_mode()?;

    let mut buf = BufferedTerminal::new(terminal)?;

    buf.add_change(Change::Attribute(AttributeChange::Foreground(
        AnsiColor::Maroon.into(),
    )));
    buf.add_change("Hello world\r\n");
    buf.add_change(Change::Attribute(AttributeChange::Foreground(
        AnsiColor::Red.into(),
    )));
    buf.add_change("and in red here\r\n");

    buf.flush()?;

    Ok(())
}