2019-05-27 08:52:07 +03:00
|
|
|
use failure::Fallible;
|
2019-05-27 22:42:19 +03:00
|
|
|
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<()> {
|
2019-05-27 08:52:07 +03:00
|
|
|
let mut editor = line_editor()?;
|
2019-05-27 07:10:37 +03:00
|
|
|
|
2019-05-27 22:42:19 +03:00
|
|
|
let mut host = Host {};
|
|
|
|
let line = editor.read_line(&mut host)?;
|
2019-05-27 20:29:22 +03:00
|
|
|
println!("read line: {:?}", line);
|
2019-05-27 07:10:37 +03:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|