repline: change error formatting
This commit is contained in:
parent
088cd4d1e4
commit
eebabf02fb
@ -112,6 +112,17 @@ impl<'a> Editor<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_err<W: Write>(&self, w: &mut W, err: impl Display) -> ReplResult<()> {
|
||||
queue!(
|
||||
w,
|
||||
SavePosition,
|
||||
Clear(ClearType::UntilNewLine),
|
||||
Print(err),
|
||||
RestorePosition
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Prints the characters after the cursor on the current line.
|
||||
pub fn print_tail<W: Write>(&self, w: &mut W) -> ReplResult<()> {
|
||||
let Self { tail, .. } = self;
|
||||
|
@ -49,7 +49,7 @@ where F: FnMut(&str) -> Result<Response, Box<dyn Error>> {
|
||||
Ok(Response::Deny) => rl.deny(),
|
||||
Ok(Response::Break) => break,
|
||||
Ok(Response::Continue) => continue,
|
||||
Err(e) => print!("\x1b[40G\x1b[A\x1bJ\x1b[91m{e}\x1b[0m\x1b[B"),
|
||||
Err(e) => rl.print_inline(format_args!("\x1b[40G\x1b[91m{e}\x1b[0m"))?,
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -111,6 +111,15 @@ impl<'a, R: Read> Repline<'a, R> {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Prints a message without moving the cursor
|
||||
pub fn print_inline(&mut self, value: impl std::fmt::Display) -> ReplResult<()> {
|
||||
let mut stdout = stdout().lock();
|
||||
self.print_err(&mut stdout, value)
|
||||
}
|
||||
/// Prints a message (ideally an error) without moving the cursor
|
||||
fn print_err<W: Write>(&mut self, w: &mut W, value: impl std::fmt::Display) -> ReplResult<()> {
|
||||
self.ed.print_err(w, value)
|
||||
}
|
||||
/// Handle ANSI Escape
|
||||
fn escape<W: Write>(&mut self, w: &mut W) -> ReplResult<()> {
|
||||
match self.input.next().ok_or(Error::EndOfInput)?? {
|
||||
|
Loading…
x
Reference in New Issue
Block a user