2020-11-12 12:12:51 +01:00
|
|
|
import term.ui as tui
|
|
|
|
|
|
|
|
struct App {
|
|
|
|
mut:
|
|
|
|
tui &tui.Context = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
fn event(e &tui.Event, x voidptr) {
|
2020-11-13 14:30:47 +01: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')
|
|
|
|
app.tui.write('$e')
|
|
|
|
app.tui.write('\n\nRaw event bytes: "${e.utf8.bytes().hex()}" = ${e.utf8.bytes()}')
|
2020-11-14 08:14:54 +01:00
|
|
|
if e.modifiers != 0 {
|
|
|
|
app.tui.write('\nModifiers: $e.modifiers = ')
|
|
|
|
if e.modifiers & tui.ctrl != 0 { app.tui.write('ctrl. ') }
|
|
|
|
if e.modifiers & tui.shift != 0 { app.tui.write('shift ') }
|
|
|
|
if e.modifiers & tui.alt != 0 { app.tui.write('alt. ') }
|
|
|
|
}
|
2020-11-13 14:30:47 +01:00
|
|
|
app.tui.flush()
|
2020-11-12 12:12:51 +01:00
|
|
|
|
|
|
|
if e.typ == .key_down && e.code == .escape { exit(0) }
|
|
|
|
}
|
|
|
|
|
|
|
|
mut app := &App{}
|
|
|
|
app.tui = tui.init(
|
|
|
|
user_data: app,
|
|
|
|
event_fn: event
|
|
|
|
|
2020-11-13 14:30:47 +01:00
|
|
|
window_title: 'V term.ui event viewer'
|
2020-11-12 12:12:51 +01:00
|
|
|
hide_cursor: true
|
|
|
|
capture_events: true
|
|
|
|
frame_rate: 60
|
|
|
|
)
|
|
|
|
|
2020-11-14 08:14:54 +01:00
|
|
|
println('V term.ui event viewer (press `esc` to exit)\n\n')
|
2020-11-12 12:12:51 +01:00
|
|
|
app.tui.run()
|