1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-24 16:08:34 +03:00
wezterm/termwiz/examples/line_editor.rs

34 lines
1016 B
Rust
Raw Normal View History

use failure::Fallible;
use termwiz::cell::AttributeChange;
use termwiz::color::{AnsiColor, ColorAttribute, RgbColor};
use termwiz::lineedit::{line_editor, LineEditorHost, OutputElement};
struct Host {}
impl LineEditorHost for Host {
// Render the prompt with a darkslateblue background color if
// the terminal supports true color, otherwise render it with
// a navy blue ansi color.
fn render_prompt(&self, prompt: &str) -> Vec<OutputElement> {
vec![
OutputElement::Attribute(AttributeChange::Background(
ColorAttribute::TrueColorWithPaletteFallback(
RgbColor::from_named("darkslateblue").unwrap(),
AnsiColor::Navy.into(),
),
)),
OutputElement::Text(prompt.to_owned()),
]
}
}
2019-05-27 07:10:37 +03:00
fn main() -> Fallible<()> {
let mut editor = line_editor()?;
2019-05-27 07:10:37 +03:00
let mut host = Host {};
let line = editor.read_line(&mut host)?;
println!("read line: {:?}", line);
2019-05-27 07:10:37 +03:00
Ok(())
}