| 1 | import term.ui as tui |
| 2 | |
| 3 | struct App { |
| 4 | mut: |
| 5 | tui &tui.Context = unsafe { nil } |
| 6 | } |
| 7 | |
| 8 | fn (mut app App) show_header() { |
| 9 | app.tui.clear() |
| 10 | app.tui.set_cursor_position(0, 0) |
| 11 | app.tui.write('V term.input event viewer (press `esc` to exit)\n\n') |
| 12 | app.tui.flush() |
| 13 | } |
| 14 | |
| 15 | fn event(e &tui.Event, mut app App) { |
| 16 | app.show_header() |
| 17 | app.tui.write('${e}') |
| 18 | app.tui.write('\n\nRaw event bytes: "${e.utf8.bytes().hex()}" = ${e.utf8.bytes()}') |
| 19 | if !e.modifiers.is_empty() { |
| 20 | app.tui.write('\nModifiers: ${e.modifiers} = ') |
| 21 | if e.modifiers.has(.ctrl) { |
| 22 | app.tui.write('ctrl. ') |
| 23 | } |
| 24 | if e.modifiers.has(.shift) { |
| 25 | app.tui.write('shift ') |
| 26 | } |
| 27 | if e.modifiers.has(.alt) { |
| 28 | app.tui.write('alt. ') |
| 29 | } |
| 30 | } |
| 31 | app.tui.flush() |
| 32 | if e.typ == .key_down && e.code == .escape { |
| 33 | println('\nGood bye.') |
| 34 | exit(0) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | type EventFn = fn (&tui.Event, voidptr) |
| 39 | |
| 40 | fn main() { |
| 41 | mut app := &App{} |
| 42 | app.tui = tui.init( |
| 43 | user_data: app |
| 44 | event_fn: EventFn(event) |
| 45 | window_title: 'V term.ui event viewer' |
| 46 | hide_cursor: true |
| 47 | capture_events: true |
| 48 | frame_rate: 60 |
| 49 | use_alternate_buffer: false |
| 50 | ) |
| 51 | app.show_header() |
| 52 | app.tui.run()! |
| 53 | } |
| 54 | |