diff options
author | Indrajith K L | 2022-12-03 17:00:20 +0530 |
---|---|---|
committer | Indrajith K L | 2022-12-03 17:00:20 +0530 |
commit | f5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch) | |
tree | 2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/old/examples/term.ui/event_viewer.v | |
download | cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2 cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip |
Diffstat (limited to 'v_windows/v/old/examples/term.ui/event_viewer.v')
-rw-r--r-- | v_windows/v/old/examples/term.ui/event_viewer.v | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/v_windows/v/old/examples/term.ui/event_viewer.v b/v_windows/v/old/examples/term.ui/event_viewer.v new file mode 100644 index 0000000..f9c443f --- /dev/null +++ b/v_windows/v/old/examples/term.ui/event_viewer.v @@ -0,0 +1,47 @@ +import term.ui as tui + +struct App { +mut: + tui &tui.Context = 0 +} + +fn event(e &tui.Event, x voidptr) { + mut app := &App(x) + app.tui.clear() + app.tui.set_cursor_position(0, 0) + app.tui.write('V term.input event viewer (press `esc` to exit)\n\n') + app.tui.write('$e') + app.tui.write('\n\nRaw event bytes: "$e.utf8.bytes().hex()" = $e.utf8.bytes()') + if !e.modifiers.is_empty() { + app.tui.write('\nModifiers: $e.modifiers = ') + if e.modifiers.has(.ctrl) { + app.tui.write('ctrl. ') + } + if e.modifiers.has(.shift) { + app.tui.write('shift ') + } + if e.modifiers.has(.alt) { + app.tui.write('alt. ') + } + } + app.tui.flush() + + if e.typ == .key_down && e.code == .escape { + exit(0) + } +} + +fn main() { + mut app := &App{} + app.tui = tui.init( + user_data: app + event_fn: event + window_title: 'V term.ui event viewer' + hide_cursor: true + capture_events: true + frame_rate: 60 + use_alternate_buffer: false + ) + println('V term.ui event viewer (press `esc` to exit)\n\n') + app.tui.run() ? +} |