mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 13:52:55 +03:00
86e59293d3
This simplifies usage and the Terminal trait
46 lines
1.2 KiB
Rust
46 lines
1.2 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::screen::{Change, Screen};
|
|
use termwiz::terminal::{self, Terminal};
|
|
|
|
#[cfg(unix)]
|
|
fn get_terminal(caps: Capabilities) -> Result<impl Terminal, failure::Error> {
|
|
terminal::UnixTerminal::new(caps)
|
|
}
|
|
|
|
#[cfg(windows)]
|
|
fn get_terminal(caps: Capabilities) -> Result<impl Terminal, failure::Error> {
|
|
terminal::WindowsTerminal::new(caps)
|
|
}
|
|
|
|
fn main() -> Result<(), Error> {
|
|
let caps = Capabilities::new_from_env()?;
|
|
|
|
let mut terminal = get_terminal(caps)?;
|
|
terminal.set_raw_mode()?;
|
|
|
|
let size = terminal.get_screen_size()?;
|
|
let mut screen = Screen::new(size.cols as usize, size.rows as usize);
|
|
|
|
screen.add_change(Change::Attribute(AttributeChange::Foreground(
|
|
AnsiColor::Maroon.into(),
|
|
)));
|
|
screen.add_change("Hello world\r\n");
|
|
screen.add_change(Change::Attribute(AttributeChange::Foreground(
|
|
AnsiColor::Red.into(),
|
|
)));
|
|
screen.add_change("and in red here\r\n");
|
|
|
|
let (_seq, changes) = screen.get_changes(0);
|
|
terminal.render(&changes)?;
|
|
//println!("changes: {:?}", changes);
|
|
println!("size: {:?}", size);
|
|
|
|
Ok(())
|
|
}
|