MCPcopy Create free account
hub / github.com/cherryramatisdev/regexer / on_event

Method on_event

cli/src/tui/tui.rs:22–64  ·  view source on GitHub ↗
(&mut self, event: Event, _nodes: &mut Nodes<'_>)

Source from the content-addressed store, hash-verified

20 type State = RootState;
21
22 fn on_event(&mut self, event: Event, _nodes: &mut Nodes<'_>) {
23 if let Event::KeyPress(code, ..) = event {
24 match code {
25 KeyCode::Left if *self.state.cursor_pos > 0 => *self.state.cursor_pos -= 1,
26 KeyCode::Right => {
27 if self.state.input.is_empty() {
28 return;
29 }
30
31 if *self.state.cursor_pos <= self.state.input.chars().count() - 1 {
32 *self.state.cursor_pos += 1;
33 }
34 }
35 KeyCode::Char(c) => {
36 if *self.state.cursor_pos == self.state.input.chars().count() {
37 *self.state.cursor_pos += 1;
38 self.state.input.push(c);
39 } else {
40 self.state.input.insert(*self.state.cursor_pos, c);
41 *self.state.cursor_pos += 1;
42 }
43 }
44 KeyCode::Backspace => {
45 if *self.state.cursor_pos == 0 {
46 return;
47 }
48
49 if *self.state.cursor_pos == self.state.input.chars().count() {
50 *self.state.cursor_pos -= 1;
51 self.state.input.pop();
52 } else {
53 self.state.input.remove(*self.state.cursor_pos);
54 *self.state.cursor_pos -= 1;
55 }
56 }
57 KeyCode::Enter => {
58 let regex = parse(self.state.input.to_string());
59 *self.state.output = regex;
60 }
61 _ => {}
62 }
63 }
64 }
65
66 fn state(&self) -> &dyn State {
67 &self.state

Callers

nothing calls this directly

Calls 1

parseFunction · 0.50

Tested by

no test coverage detected