1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-25 14:22:37 +03:00
wezterm/examples/hello.rs
Wez Furlong e7486d331a ensure that we can copy screens even if they are blank
We were optimizing away setting the cells if only the background
attributes were different between the src and dest
2018-07-22 10:41:34 -07:00

41 lines
1.1 KiB
Rust

extern crate failure;
extern crate termwiz;
use failure::Error;
use termwiz::caps::Capabilities;
use termwiz::cell::AttributeChange;
use termwiz::color::AnsiColor;
use termwiz::surface::{Change, Position, Surface};
use termwiz::terminal::buffered::BufferedTerminal;
use termwiz::terminal::{new_terminal, Terminal};
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)?;
let mut block = Surface::new(5, 5);
block.add_change(Change::ClearScreen(AnsiColor::Blue.into()));
buf.draw_from_screen(&block, 10, 10);
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.add_change(Change::CursorPosition {
x: Position::Absolute(0),
y: Position::Absolute(20),
});
buf.flush()?;
Ok(())
}