Skip to content

Commit

Permalink
Stop using byte length to compute sizes from strings (to properly dis…
Browse files Browse the repository at this point in the history
…play non-ASCII characters).
  • Loading branch information
apognu committed Oct 15, 2023
1 parent d99a7a9 commit a111f1c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/ui/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box<dyn
f.render_widget(
command_value,
Rect::new(
1 + chunks[0].x + fl!("new_command").len() as u16,
1 + chunks[0].x + fl!("new_command").chars().count() as u16,
chunks[0].y,
get_input_width(greeter, width, &Some(fl!("new_command"))),
1,
Expand All @@ -51,5 +51,5 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box<dyn
let new_command = greeter.new_command.clone();
let offset = get_cursor_offset(greeter, new_command.chars().count());

Ok((2 + cursor.x + fl!("new_command").len() as u16 + offset as u16, cursor.y + 1))
Ok((2 + cursor.x + fl!("new_command").chars().count() as u16 + offset as u16, cursor.y + 1))
}
4 changes: 2 additions & 2 deletions src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box<dyn
f.render_widget(
username_value,
Rect::new(
1 + chunks[USERNAME_INDEX].x + fl!("username").len() as u16,
1 + chunks[USERNAME_INDEX].x + fl!("username").chars().count() as u16,
chunks[USERNAME_INDEX].y,
get_input_width(greeter, width, &Some(fl!("username"))),
1,
Expand Down Expand Up @@ -128,7 +128,7 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box<dyn
let username_length = greeter.username.chars().count();
let offset = get_cursor_offset(greeter, username_length);

Ok((2 + cursor.x + fl!("username").len() as u16 + offset as u16, USERNAME_INDEX as u16 + cursor.y))
Ok((2 + cursor.x + fl!("username").chars().count() as u16 + offset as u16, USERNAME_INDEX as u16 + cursor.y))
}

Mode::Password => {
Expand Down

0 comments on commit a111f1c

Please sign in to comment.