From 3d477da29ecada3198a42cb5060ec0d15774d662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ribeiro?= Date: Sat, 13 Jul 2024 00:14:31 +0100 Subject: [PATCH 1/2] Add support to utf8 messages Its just the messages, the app still crashes when the user insert some non-ascii char --- src/input.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/input.rs b/src/input.rs index 726c723..09434ff 100644 --- a/src/input.rs +++ b/src/input.rs @@ -63,13 +63,13 @@ impl<'a> Input<'a> { while !quit { while poll(Duration::ZERO).unwrap() { let space = 1; - let message_len = (self.message.len() + space) as u16; + let message_len = (self.message.chars().count() + space) as u16; let cursor_pos = crossterm::cursor::position().unwrap().0; match read().unwrap() { Event::Key(event) => match event.code { KeyCode::Enter => { - if answer.trim().len() as u16 >= self.minimum_chars { + if answer.trim().chars().count() as u16 >= self.minimum_chars { stdout.queue(ResetColor).unwrap(); stdout.queue(Clear(ClearType::All)).unwrap(); stdout.queue(cursor::MoveTo(0, 0)).unwrap(); @@ -87,7 +87,7 @@ impl<'a> Input<'a> { } } KeyCode::Right => { - let whole_text = message_len + answer.len() as u16; + let whole_text = message_len + answer.chars().count() as u16; let cursor_in_end_of_text = cursor_pos == whole_text; if !cursor_in_end_of_text { @@ -146,7 +146,7 @@ impl<'a> Input<'a> { fn insert_char(&self, ch: char, answer: &mut String) { let space = 1; - let message_len = (self.message.len() + space) as u16; + let message_len = (self.message.chars().count() + space) as u16; let cursor_pos = crossterm::cursor::position().unwrap().0; @@ -157,7 +157,7 @@ impl<'a> Input<'a> { fn delete_char(&self, user_input: &mut String) { let space = 1; - let message_len = self.message.len() + space; + let message_len = self.message.chars().count() + space; let cursor_pos = crossterm::cursor::position().unwrap().0 as usize; From 58f8feb36e2ddc7f7296a62902fda9cdbd28e419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ribeiro?= Date: Sat, 13 Jul 2024 00:15:24 +0100 Subject: [PATCH 2/2] Bump version 0.2.3 --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d9be02..d86b9ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -119,7 +119,7 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "selthi" -version = "0.2.2" +version = "0.2.3" dependencies = [ "crossterm", "ueberzug", diff --git a/Cargo.toml b/Cargo.toml index f94f46f..d7e7801 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "selthi" -version = "0.2.2" +version = "0.2.3" edition = "2021" author = "João Ribeiro" repository = "https://github.com/anotherlusitano/selthi" diff --git a/README.md b/README.md index c01814c..f588f7c 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ cargo add selthi \* If you want to support images, add the feature `with_images` ``` -selthi = { version = "0.2.2", features = ["with_images"] } +selthi = { version = "0.2.3", features = ["with_images"] } ``` ## Prompts