Add mobile ergonomic acceptance tasks
This commit is contained in:
+36
-3
@@ -153,9 +153,16 @@ pub const Client = struct {
|
||||
|
||||
pub fn handleInput(self: *Client, raw: []const u8) !void {
|
||||
if (self.quit) return Error.ClientQuit;
|
||||
const action = try self.leader.handleEvent(input.normalize(raw));
|
||||
defer action.deinit(self.allocator);
|
||||
try self.applyLeaderAction(action);
|
||||
const event = input.normalize(raw);
|
||||
if (self.leader.capturesInput() or isLeaderTrigger(event)) {
|
||||
const action = try self.leader.handleEvent(event);
|
||||
defer action.deinit(self.allocator);
|
||||
try self.applyLeaderAction(action);
|
||||
return;
|
||||
}
|
||||
|
||||
_ = try self.leader.handleEvent(event);
|
||||
try self.applyNormalInput(event);
|
||||
}
|
||||
|
||||
pub fn saved(self: *const Client) ![]const u8 {
|
||||
@@ -167,10 +174,36 @@ pub const Client = struct {
|
||||
if (std.mem.eql(u8, key_name, "enter")) return self.handleInput("\r");
|
||||
if (std.mem.eql(u8, key_name, "backspace")) return self.handleInput("\x7f");
|
||||
if (std.mem.eql(u8, key_name, "escape")) return self.handleInput("\x1b");
|
||||
if (std.mem.eql(u8, key_name, "left")) return self.handleInput("\x1b[D");
|
||||
if (std.mem.eql(u8, key_name, "right")) return self.handleInput("\x1b[C");
|
||||
if (key_name.len == 1) return self.handleInput(key_name);
|
||||
return Error.UnknownTraceEvent;
|
||||
}
|
||||
|
||||
fn isLeaderTrigger(event: input.Event) bool {
|
||||
return switch (event) {
|
||||
.key => |key| key == .space,
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
fn applyNormalInput(self: *Client, event: input.Event) !void {
|
||||
switch (event) {
|
||||
.text => |text| {
|
||||
const line = try std.fmt.allocPrint(self.allocator, "insert {s}", .{text});
|
||||
defer self.allocator.free(line);
|
||||
try self.applyProtocolCommand(line);
|
||||
},
|
||||
.key => |key| switch (key) {
|
||||
.backspace => try self.applyProtocol("command delete_backward"),
|
||||
.arrow_left => try self.applyProtocol("command move_left"),
|
||||
.arrow_right => try self.applyProtocol("command move_right"),
|
||||
else => {},
|
||||
},
|
||||
.unknown => {},
|
||||
}
|
||||
}
|
||||
|
||||
fn applyLeaderAction(self: *Client, action: leader_mod.Action) !void {
|
||||
switch (action) {
|
||||
.none => {},
|
||||
|
||||
Reference in New Issue
Block a user