Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support utf8 messages #4

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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