Commit c5b37717 authored by stratact's avatar stratact

Account for the width of the prompt's last line if any.

parent 51f2f7e3
......@@ -673,7 +673,7 @@ impl<'a, W: Write> Editor<'a, W> {
}
let terminal_width = terminal_width()?;
let prompt_width = util::width(&self.prompt);
let prompt_width = util::last_prompt_line_width(&self.prompt);
let buf = cur_buf!(self);
let buf_width = buf.width();
......@@ -742,7 +742,7 @@ impl<'a, W: Write> Editor<'a, W> {
});
self.output_buf.extend_from_slice(prompt.as_bytes());
} else {
self.output_buf.extend_from_slice(handle_prompt(&self.prompt).as_bytes());
self.output_buf.extend_from_slice(util::handle_prompt(&self.prompt).as_bytes());
}
// If we have an autosuggestion, we make the autosuggestion the buffer we print out.
......@@ -855,17 +855,6 @@ fn terminal_width() -> io::Result<usize> {
}
}
/// prints prompt info lines and
/// returns the last prompt line.
fn handle_prompt(full_prompt: &str) -> &str {
if let Some(index) = full_prompt.rfind('\n') {
let (_, prompt) = full_prompt.split_at(index + 1);
prompt
} else {
full_prompt
}
}
#[cfg(test)]
mod tests {
use super::*;
......
use std::borrow::Cow;
use unicode_width::*;
pub fn width<S: AsRef<str>>(s: S) -> usize {
remove_codes(s.as_ref()).width()
pub fn last_prompt_line_width<S: AsRef<str>>(s: S) -> usize {
let last_prompt_line_width = handle_prompt(s.as_ref());
remove_codes(last_prompt_line_width).width()
}
pub fn find_longest_common_prefix<T: Clone + Eq>(among: &[Vec<T>]) -> Option<Vec<T>> {
......@@ -80,4 +81,14 @@ pub fn remove_codes(input: &str) -> Cow<str> {
} else {
Cow::Borrowed(input)
}
}
\ No newline at end of file
}
/// Returns the last prompt line.
pub fn handle_prompt(full_prompt: &str) -> &str {
if let Some(index) = full_prompt.rfind('\n') {
let (_, prompt) = full_prompt.split_at(index + 1);
prompt
} else {
full_prompt
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment