1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-01 09:13:10 +03:00
wezterm/termwiz/examples/buffered_terminal.rs
Wez Furlong 5d360ae365 termwiz: Remove anyhow::Result from public API
It's been replaced with an opaque termwiz error type instead.

This is a bit of a more conservative approach than that in (refs: #407)
and has less of an impact on the surrounding code, which appeals to
me from a maintenance perspective.

refs: #406
refs: #407
2021-01-08 00:32:30 -08:00

34 lines
1.0 KiB
Rust

//! 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(())
}