aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/examples/term.ui/event_viewer.v
blob: f9c443fd87a49fd1c30ce0abc3e82d759e8e0dc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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() ?
}