mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 13:52:55 +03:00
fix rendering of the cursor position in the line editor
This commit is contained in:
parent
6289c08a4e
commit
d397976acf
11
src/ssh.rs
11
src/ssh.rs
@ -44,13 +44,18 @@ fn password_prompt(
|
||||
|
||||
// Rewrite the input so that we can obscure the password
|
||||
// characters when output to the terminal widget
|
||||
fn highlight_line(&self, line: &str, _cursor_position: usize) -> Vec<OutputElement> {
|
||||
fn highlight_line(
|
||||
&self,
|
||||
line: &str,
|
||||
cursor_position: usize,
|
||||
) -> (Vec<OutputElement>, usize) {
|
||||
let placeholder = "🔑";
|
||||
let grapheme_count = unicode_column_width(line);
|
||||
let mut output = vec![];
|
||||
for _ in 0..grapheme_count {
|
||||
output.push(OutputElement::Text("🔑".to_string()));
|
||||
output.push(OutputElement::Text(placeholder.to_string()));
|
||||
}
|
||||
output
|
||||
(output, unicode_column_width(placeholder) * cursor_position)
|
||||
}
|
||||
}
|
||||
match termwiztermtab::run(60, 10, move |mut term| {
|
||||
|
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
authors = ["Wez Furlong"]
|
||||
name = "termwiz"
|
||||
version = "0.4.0"
|
||||
version = "0.5.0"
|
||||
edition = "2018"
|
||||
repository = "https://github.com/wez/wezterm"
|
||||
description = "Terminal Wizardry for Unix and Windows"
|
||||
|
@ -57,8 +57,9 @@ pub trait LineEditorHost {
|
||||
/// The `OutputElement` type allows returning graphic attribute changes
|
||||
/// as well as textual output.
|
||||
/// The default implementation returns the line as-is with no coloring.
|
||||
fn highlight_line(&self, line: &str, _cursor_position: usize) -> Vec<OutputElement> {
|
||||
vec![OutputElement::Text(line.to_owned())]
|
||||
fn highlight_line(&self, line: &str, cursor_position: usize) -> (Vec<OutputElement>, usize) {
|
||||
let cursor_x_pos = crate::cell::unicode_column_width(&line[0..cursor_position]);
|
||||
(vec![OutputElement::Text(line.to_owned())], cursor_x_pos)
|
||||
}
|
||||
|
||||
/// Returns the history implementation
|
||||
|
@ -163,16 +163,12 @@ impl<T: Terminal> LineEditor<T> {
|
||||
}
|
||||
changes.push(Change::AllAttributes(Default::default()));
|
||||
|
||||
let mut grapheme_count = 0;
|
||||
for ele in host.highlight_line(&self.line, self.cursor) {
|
||||
if let OutputElement::Text(ref t) = ele {
|
||||
grapheme_count += unicode_column_width(t);
|
||||
}
|
||||
let (elements, cursor_x_pos) = host.highlight_line(&self.line, self.cursor);
|
||||
for ele in elements {
|
||||
changes.push(ele.into());
|
||||
}
|
||||
|
||||
changes.push(Change::CursorPosition {
|
||||
x: Position::Absolute(prompt_width + grapheme_count),
|
||||
x: Position::Absolute(prompt_width + cursor_x_pos),
|
||||
y: Position::NoChange,
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user