Created
November 26, 2025 11:58
-
-
Save andihaki/ca21f6410246f6088030f88f92535492 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn handle_event(&mut self, event: &Event) -> bool { | |
| if let Event::Key(key) = event { | |
| if key.kind == KeyEventKind::Press { | |
| match key.code { | |
| KeyCode::Char('q') | KeyCode::Esc => return false, | |
| KeyCode::Enter => self.calculate_tax(), | |
| KeyCode::Backspace => { | |
| self.input.pop(); | |
| } | |
| KeyCode::Char(c) => { | |
| let is_digit = c.is_ascii_digit(); | |
| if is_digit && self.input.len() < 18 { | |
| self.input.push(c); | |
| } else if is_digit { | |
| self.tax_bracket_info = | |
| "Input diblokir: Maksimal 18 digit.".to_string(); | |
| } | |
| } | |
| _ => {} | |
| } | |
| } | |
| } | |
| true | |
| } |
Author
Author
versi claude ai
fn handle_event(&mut self, event: &Event) -> bool {
let Event::Key(key) = event else {
return true;
};
if key.kind != KeyEventKind::Press {
return true;
}
match key.code {
KeyCode::Char('q') | KeyCode::Esc => false,
KeyCode::Enter => {
self.calculate_tax();
true
}
KeyCode::Backspace => {
self.input.pop();
true
}
KeyCode::Char(c) if c.is_ascii_digit() => {
self.handle_digit_input(c);
true
}
_ => true,
}
}
fn handle_digit_input(&mut self, c: char) {
if self.input.len() < 18 {
self.input.push(c);
} else {
self.tax_bracket_info = "Input diblokir: Maksimal 18 digit.".to_string();
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
refactor option:
0:
1:
2:
3: