Minor prompt fixes

pull/2/head
Mark 2023-08-04 12:24:58 -07:00
parent 88e272fd6f
commit 9a391480b9
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 30 additions and 1 deletions

View File

@ -36,6 +36,33 @@ impl PromptBuffer {
}; };
} }
// Same as write_primpt, but pretends there is no cursor
pub fn write_prompt_nocursor(&mut self, stdout: &mut RawTerminal<std::io::Stdout>) -> Result<(), std::io::Error> {
// Draw prettyprinted expression
let (_, s) = substitute_cursor(&self.get_contents(), self.buffer.chars().count());
write!(
stdout, "\r{}{}==>{}{} {}",
style::Bold,
color::Fg(color::Blue),
color::Fg(color::Reset),
style::Reset,
s
)?;
// If this string is shorter, clear the remaining old one.
if s.chars().count() < self.last_print_len {
write!(
stdout, "{}{}",
" ".repeat(self.last_print_len - s.chars().count()),
termion::cursor::Left((self.last_print_len - s.chars().count()) as u16)
)?;
}
self.last_print_len = s.chars().count();
stdout.flush()?;
return Ok(());
}
pub fn write_prompt(&mut self, stdout: &mut RawTerminal<std::io::Stdout>) -> Result<(), std::io::Error> { pub fn write_prompt(&mut self, stdout: &mut RawTerminal<std::io::Stdout>) -> Result<(), std::io::Error> {
let l = self.buffer.chars().count(); let l = self.buffer.chars().count();
@ -82,7 +109,9 @@ impl PromptBuffer {
pub fn get_contents(&self) -> &String {&self.buffer} pub fn get_contents(&self) -> &String {&self.buffer}
pub fn enter(&mut self) -> String { pub fn enter(&mut self) -> String {
let s = String::from(self.buffer.trim()); // Don't trim input string so that linelocations are correct
//let s = String::from(self.buffer.trim());
let s = self.buffer.clone();
self.buffer.clear(); self.buffer.clear();
self.hist_cursor = 0; self.hist_cursor = 0;
self.cursor = 0; self.cursor = 0;