2020-11-12 14:12:51 +03:00
|
|
|
import term.ui as tui
|
|
|
|
|
|
|
|
struct App {
|
|
|
|
mut:
|
2022-09-15 07:59:31 +03:00
|
|
|
tui &tui.Context = unsafe { nil }
|
2020-11-12 14:12:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn event(e &tui.Event, x voidptr) {
|
2020-11-13 16:30:47 +03:00
|
|
|
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')
|
2022-11-15 16:53:13 +03:00
|
|
|
app.tui.write('${e}')
|
|
|
|
app.tui.write('\n\nRaw event bytes: "${e.utf8.bytes().hex()}" = ${e.utf8.bytes()}')
|
2021-02-21 17:07:49 +03:00
|
|
|
if !e.modifiers.is_empty() {
|
2022-11-15 16:53:13 +03:00
|
|
|
app.tui.write('\nModifiers: ${e.modifiers} = ')
|
2021-02-21 17:07:49 +03:00
|
|
|
if e.modifiers.has(.ctrl) {
|
2021-01-26 17:43:10 +03:00
|
|
|
app.tui.write('ctrl. ')
|
|
|
|
}
|
2021-02-21 17:07:49 +03:00
|
|
|
if e.modifiers.has(.shift) {
|
2021-01-26 17:43:10 +03:00
|
|
|
app.tui.write('shift ')
|
|
|
|
}
|
2021-02-21 17:07:49 +03:00
|
|
|
if e.modifiers.has(.alt) {
|
2021-01-26 17:43:10 +03:00
|
|
|
app.tui.write('alt. ')
|
|
|
|
}
|
2020-11-14 10:14:54 +03:00
|
|
|
}
|
2020-11-13 16:30:47 +03:00
|
|
|
app.tui.flush()
|
2020-11-12 14:12:51 +03:00
|
|
|
|
2021-01-26 17:43:10 +03:00
|
|
|
if e.typ == .key_down && e.code == .escape {
|
|
|
|
exit(0)
|
|
|
|
}
|
2020-11-12 14:12:51 +03:00
|
|
|
}
|
|
|
|
|
2021-02-04 18:34:49 +03:00
|
|
|
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')
|
2022-05-13 06:56:21 +03:00
|
|
|
app.tui.run()?
|
2021-02-04 18:34:49 +03:00
|
|
|
}
|