ref(input): move mouse.zig and key.zig into public input.zig namespace
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m41s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m41s
This commit is contained in:
122
src/app.zig
122
src/app.zig
@@ -1,14 +1,15 @@
|
||||
//! Application type for TUI-applications
|
||||
const std = @import("std");
|
||||
const terminal = @import("terminal.zig");
|
||||
const code_point = @import("code_point");
|
||||
const event = @import("event.zig");
|
||||
const input = @import("input.zig");
|
||||
const terminal = @import("terminal.zig");
|
||||
|
||||
const mergeTaggedUnions = event.mergeTaggedUnions;
|
||||
const isTaggedUnion = event.isTaggedUnion;
|
||||
|
||||
const key = @import("key.zig");
|
||||
const Mouse = @import("mouse.zig").Mouse;
|
||||
const Key = key.Key;
|
||||
const Mouse = input.Mouse;
|
||||
const Key = input.Key;
|
||||
const Size = @import("size.zig").Size;
|
||||
const Queue = @import("queue.zig").Queue;
|
||||
|
||||
@@ -182,21 +183,21 @@ pub fn App(comptime E: type) type {
|
||||
0x4F => { // ss3
|
||||
if (read_bytes < 3) continue;
|
||||
|
||||
const k: Key = switch (buf[2]) {
|
||||
'A' => .{ .cp = key.Up },
|
||||
'B' => .{ .cp = key.Down },
|
||||
'C' => .{ .cp = key.Right },
|
||||
'D' => .{ .cp = key.Left },
|
||||
'E' => .{ .cp = key.KpBegin },
|
||||
'F' => .{ .cp = key.End },
|
||||
'H' => .{ .cp = key.Home },
|
||||
'P' => .{ .cp = key.F1 },
|
||||
'Q' => .{ .cp = key.F2 },
|
||||
'R' => .{ .cp = key.F3 },
|
||||
'S' => .{ .cp = key.F4 },
|
||||
const key: Key = switch (buf[2]) {
|
||||
'A' => .{ .cp = input.Up },
|
||||
'B' => .{ .cp = input.Down },
|
||||
'C' => .{ .cp = input.Right },
|
||||
'D' => .{ .cp = input.Left },
|
||||
'E' => .{ .cp = input.KpBegin },
|
||||
'F' => .{ .cp = input.End },
|
||||
'H' => .{ .cp = input.Home },
|
||||
'P' => .{ .cp = input.F1 },
|
||||
'Q' => .{ .cp = input.F2 },
|
||||
'R' => .{ .cp = input.F3 },
|
||||
'S' => .{ .cp = input.F4 },
|
||||
else => continue,
|
||||
};
|
||||
this.postEvent(.{ .key = k });
|
||||
this.postEvent(.{ .key = key });
|
||||
},
|
||||
0x5B => { // csi
|
||||
if (read_bytes < 3) continue;
|
||||
@@ -215,23 +216,23 @@ pub fn App(comptime E: type) type {
|
||||
// Legacy keys
|
||||
// CSI {ABCDEFHPQS}
|
||||
// CSI 1 ; modifier:event_type {ABCDEFHPQS}
|
||||
const k: Key = .{
|
||||
const key: Key = .{
|
||||
.cp = switch (final) {
|
||||
'A' => key.Up,
|
||||
'B' => key.Down,
|
||||
'C' => key.Right,
|
||||
'D' => key.Left,
|
||||
'E' => key.KpBegin,
|
||||
'F' => key.End,
|
||||
'H' => key.Home,
|
||||
'P' => key.F1,
|
||||
'Q' => key.F2,
|
||||
'R' => key.F3,
|
||||
'S' => key.F4,
|
||||
'A' => input.Up,
|
||||
'B' => input.Down,
|
||||
'C' => input.Right,
|
||||
'D' => input.Left,
|
||||
'E' => input.KpBegin,
|
||||
'F' => input.End,
|
||||
'H' => input.Home,
|
||||
'P' => input.F1,
|
||||
'Q' => input.F2,
|
||||
'R' => input.F3,
|
||||
'S' => input.F4,
|
||||
else => unreachable, // switch case prevents in this case form ever happening
|
||||
},
|
||||
};
|
||||
this.postEvent(.{ .key = k });
|
||||
this.postEvent(.{ .key = key });
|
||||
},
|
||||
'~' => {
|
||||
// Legacy keys
|
||||
@@ -242,34 +243,35 @@ pub fn App(comptime E: type) type {
|
||||
const number_buf = field_iter.next() orelse unreachable; // always will have one field
|
||||
const number = std.fmt.parseUnsigned(u16, number_buf, 10) catch break;
|
||||
|
||||
const k: Key = .{
|
||||
const key: Key = .{
|
||||
.cp = switch (number) {
|
||||
2 => key.Insert,
|
||||
3 => key.Delete,
|
||||
5 => key.PageUp,
|
||||
6 => key.PageDown,
|
||||
7 => key.Home,
|
||||
8 => key.End,
|
||||
11 => key.F1,
|
||||
12 => key.F2,
|
||||
13 => key.F3,
|
||||
14 => key.F4,
|
||||
15 => key.F5,
|
||||
17 => key.F6,
|
||||
18 => key.F7,
|
||||
19 => key.F8,
|
||||
20 => key.F9,
|
||||
21 => key.F10,
|
||||
23 => key.F11,
|
||||
24 => key.F12,
|
||||
2 => input.Insert,
|
||||
3 => input.Delete,
|
||||
5 => input.PageUp,
|
||||
6 => input.PageDown,
|
||||
7 => input.Home,
|
||||
8 => input.End,
|
||||
11 => input.F1,
|
||||
12 => input.F2,
|
||||
13 => input.F3,
|
||||
14 => input.F4,
|
||||
15 => input.F5,
|
||||
17 => input.F6,
|
||||
18 => input.F7,
|
||||
19 => input.F8,
|
||||
20 => input.F9,
|
||||
21 => input.F10,
|
||||
23 => input.F11,
|
||||
24 => input.F12,
|
||||
// 200 => return .{ .event = .paste_start, .n = sequence.len },
|
||||
// 201 => return .{ .event = .paste_end, .n = sequence.len },
|
||||
57427 => key.KpBegin,
|
||||
57427 => input.KpBegin,
|
||||
else => unreachable,
|
||||
},
|
||||
};
|
||||
this.postEvent(.{ .key = k });
|
||||
this.postEvent(.{ .key = key });
|
||||
},
|
||||
// TODO: focus usage? should this even be in the default event system?
|
||||
'I' => this.postEvent(.{ .focus = true }),
|
||||
'O' => this.postEvent(.{ .focus = false }),
|
||||
'M', 'm' => {
|
||||
@@ -296,7 +298,7 @@ pub fn App(comptime E: type) type {
|
||||
// const alt = button_mask & mouse_bits.alt > 0;
|
||||
// const ctrl = button_mask & mouse_bits.ctrl > 0;
|
||||
|
||||
const mouse = Mouse{
|
||||
const mouse: Mouse = .{
|
||||
.button = button,
|
||||
.col = px -| 1,
|
||||
.row = py -| 1,
|
||||
@@ -363,24 +365,24 @@ pub fn App(comptime E: type) type {
|
||||
}
|
||||
} else {
|
||||
const b = buf[0];
|
||||
const k: Key = switch (b) {
|
||||
const key: Key = switch (b) {
|
||||
0x00 => .{ .cp = '@', .mod = .{ .ctrl = true } },
|
||||
0x08 => .{ .cp = key.Backspace },
|
||||
0x09 => .{ .cp = key.Tab },
|
||||
0x0a, 0x0d => .{ .cp = key.Enter },
|
||||
0x08 => .{ .cp = input.Backspace },
|
||||
0x09 => .{ .cp = input.Tab },
|
||||
0x0a, 0x0d => .{ .cp = input.Enter },
|
||||
0x01...0x07, 0x0b...0x0c, 0x0e...0x1a => .{ .cp = b + 0x60, .mod = .{ .ctrl = true } },
|
||||
0x1b => escape: {
|
||||
std.debug.assert(read_bytes == 1);
|
||||
break :escape .{ .cp = key.Escape };
|
||||
break :escape .{ .cp = input.Escape };
|
||||
},
|
||||
0x7f => .{ .cp = key.Backspace },
|
||||
0x7f => .{ .cp = input.Backspace },
|
||||
else => {
|
||||
var iter = terminal.code_point.Iterator{ .bytes = buf[0..read_bytes] };
|
||||
var iter = code_point.Iterator{ .bytes = buf[0..read_bytes] };
|
||||
while (iter.next()) |cp| this.postEvent(.{ .key = .{ .cp = cp.code } });
|
||||
continue;
|
||||
},
|
||||
};
|
||||
this.postEvent(.{ .key = k });
|
||||
this.postEvent(.{ .key = key });
|
||||
}
|
||||
continue;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user