Skip to content

Commit

Permalink
Merge pull request #4 from anotherlusitano/Support-utf8-messages
Browse files Browse the repository at this point in the history
Support utf8 messages
  • Loading branch information
anotherlusitano authored Jul 12, 2024
2 parents 27a4a3f + 58f8feb commit 7f867c5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down

0 comments on commit 7f867c5

Please sign in to comment.