-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.zig
More file actions
50 lines (42 loc) · 1.67 KB
/
input.zig
File metadata and controls
50 lines (42 loc) · 1.67 KB
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
48
49
50
const std = @import("std");
const fmt = std.fmt;
const umbra = @import("src/umbra.zig");
const TTY = umbra.TTY;
const escseq = umbra.escseq;
const events = umbra.events;
pub fn main() !void {
var tty = try TTY.init();
defer tty.deinit();
const w = tty.writer();
try escseq.Private.enableMouseInput(w);
defer escseq.Private.disableMouseInput(w) catch unreachable;
try escseq.Cursor.home(w);
{
var buffer: [16]u8 = undefined;
while (true) {
const input = buffer[0..try tty.getInput(&buffer)];
try w.print("raw: '{s}'\n", .{fmt.fmtSliceEscapeLower(input)});
switch (try events.Event.fromString(input)) {
.mouse => |mouse| {
try w.print("input:mouse: {any}\n", .{mouse});
},
.symbol => |symbol| {
switch (symbol.symbol) {
'q', 'Q' => break,
'0' => try escseq.Cursor.home(w),
'\r', '\n' => try w.print("input:symbol enter\n", .{}),
'\t' => try w.print("input:symbol tab\n", .{}),
'h' => try escseq.Cursor.back(w, 1),
'j' => try escseq.Cursor.down(w, 1),
'k' => try escseq.Cursor.up(w, 1),
'l' => try escseq.Cursor.forward(w, 1),
else => |sym| try w.print("input:symbol '{c}' ({d})\n", .{ sym, sym }),
}
},
.codes => |codes| {
try w.print("input:codes: '{c}'\n", .{fmt.fmtSliceEscapeLower(codes.codes)});
},
}
}
}
}