1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-27 02:25:28 +03:00
wezterm/termwiz/examples/terminal_direct.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

28 lines
968 B
Rust

//! This example shows how to render `Change`s directly to
//! an instance of `Terminal`. When used in this way, the
//! library performas no optimization on the change stream.
//! Consider using the `Surface` struct to enable optimization;
//! the `buffered_terminal.rs` example demonstrates a simple
//! way to enable optimizations.
use termwiz::caps::Capabilities;
use termwiz::cell::AttributeChange;
use termwiz::color::AnsiColor;
use termwiz::surface::Change;
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.render(&[
Change::Attribute(AttributeChange::Foreground(AnsiColor::Maroon.into())),
Change::Text("Hello world\r\n".into()),
Change::Attribute(AttributeChange::Foreground(AnsiColor::Red.into())),
Change::Text("and in red here\r\n".into()),
])?;
Ok(())
}