1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::app::{App, AppResult, LINE};
use crate::app::{PARAGRAPH, VECTOR};
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
if key_event.kind == KeyEventKind::Press {
match key_event.code {
KeyCode::Esc | KeyCode::Char('q') => {
app.quit();
}
KeyCode::Char('c') | KeyCode::Char('C') => {
if key_event.modifiers == KeyModifiers::CONTROL {
app.quit();
}
}
KeyCode::Char('s') => {
if app.tts.is_speaking()? {
app.tts.stop()?;
}
app.pause = false;
}
KeyCode::Char(' ') => {
app.pause = !app.pause;
}
KeyCode::Char('t') => {
app.pdf_mode = !app.pdf_mode;
}
KeyCode::Up | KeyCode::Char('k') => unsafe {
LINE = LINE.saturating_sub(app.jump_length);
},
KeyCode::Down | KeyCode::Char('j') => unsafe {
LINE = LINE.saturating_add(app.jump_length);
},
KeyCode::Left | KeyCode::Char('h') => unsafe {
PARAGRAPH = PARAGRAPH.saturating_sub(1);
},
KeyCode::Right | KeyCode::Char('l') => unsafe {
if !VECTOR.is_empty() && PARAGRAPH < VECTOR.len() - 1 {
PARAGRAPH += 1;
}
},
KeyCode::Char(char) if char.is_ascii_digit() => match char {
'0' => unsafe {
if app.history.len() == 10 {
PARAGRAPH = 0;
LINE = 0;
app.selected = 9;
// app.tts.speak(&app.history[app.selected], true).unwrap();
// COPY = app.history[app.selected].clone();
}
},
_ => unsafe {
if app.history.len() >= char as usize - 0x30 {
PARAGRAPH = 0;
LINE = 0;
app.selected = char as usize - 0x31;
// app.tts.speak(&app.history[app.selected], true).unwrap();
// COPY = app.history[app.selected].clone();
}
},
},
_ => {}
}
}
Ok(())
}