refactor: add renderer abstraction layer

This commit is contained in:
CJ van den Berg 2024-04-25 22:45:02 +02:00
parent 9ff63fbed5
commit b15fa47f30
47 changed files with 1419 additions and 1023 deletions

View file

@ -1,7 +1,11 @@
const nc = @import("notcurses");
const tp = @import("thespian");
const root = @import("root");
const key = @import("renderer").input.key;
const mod = @import("renderer").input.modifier;
const event_type = @import("renderer").input.event_type;
const egc_ = @import("renderer").egc;
const tui = @import("../../tui.zig");
const command = @import("../../command.zig");
const EventHandler = @import("../../EventHandler.zig");
@ -10,8 +14,6 @@ const Allocator = @import("std").mem.Allocator;
const ArrayList = @import("std").ArrayList;
const json = @import("std").json;
const eql = @import("std").mem.eql;
const mod = nc.mod;
const key = nc.key;
const Self = @This();
const input_buffer_size = 1024;
@ -60,9 +62,9 @@ pub fn add_keybind() void {}
fn mapEvent(self: *Self, evtype: u32, keypress: u32, egc: u32, modifiers: u32) tp.result {
return switch (evtype) {
nc.event_type.PRESS => self.mapPress(keypress, egc, modifiers),
nc.event_type.REPEAT => self.mapPress(keypress, egc, modifiers),
nc.event_type.RELEASE => self.mapRelease(keypress, egc, modifiers),
event_type.PRESS => self.mapPress(keypress, egc, modifiers),
event_type.REPEAT => self.mapPress(keypress, egc, modifiers),
event_type.RELEASE => self.mapRelease(keypress, egc, modifiers),
else => {},
};
}
@ -248,7 +250,7 @@ fn insert_code_point(self: *Self, c: u32) tp.result {
if (self.input.items.len + 4 > input_buffer_size)
try self.flush_input();
var buf: [6]u8 = undefined;
const bytes = nc.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e);
const bytes = egc_.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e);
self.input.appendSlice(buf[0..bytes]) catch |e| return tp.exit_error(e);
}

View file

@ -1,8 +1,11 @@
const std = @import("std");
const nc = @import("notcurses");
const tp = @import("thespian");
const root = @import("root");
const key = @import("renderer").input.key;
const event_type = @import("renderer").input.event_type;
const mod = @import("renderer").input.modifier;
const tui = @import("../../tui.zig");
const command = @import("../../command.zig");
const EventHandler = @import("../../EventHandler.zig");
@ -41,8 +44,8 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
fn mapEvent(self: *Self, evtype: u32, keypress: u32, modifiers: u32) tp.result {
return switch (evtype) {
nc.event_type.PRESS => self.mapPress(keypress, modifiers),
nc.event_type.REPEAT => self.mapPress(keypress, modifiers),
event_type.PRESS => self.mapPress(keypress, modifiers),
event_type.REPEAT => self.mapPress(keypress, modifiers),
else => {},
};
}
@ -50,7 +53,7 @@ fn mapEvent(self: *Self, evtype: u32, keypress: u32, modifiers: u32) tp.result {
fn mapPress(self: *Self, keypress: u32, modifiers: u32) tp.result {
const keynormal = if ('a' <= keypress and keypress <= 'z') keypress - ('a' - 'A') else keypress;
return switch (modifiers) {
nc.mod.CTRL => switch (keynormal) {
mod.CTRL => switch (keynormal) {
'F' => self.sheeran(),
'J' => self.cmd("toggle_logview", .{}),
'Q' => self.cmd("quit", .{}),
@ -60,7 +63,7 @@ fn mapPress(self: *Self, keypress: u32, modifiers: u32) tp.result {
'/' => self.cmd("open_help", .{}),
else => {},
},
nc.mod.CTRL | nc.mod.SHIFT => switch (keynormal) {
mod.CTRL | mod.SHIFT => switch (keynormal) {
'Q' => self.cmd("quit_without_saving", .{}),
'R' => self.cmd("restart", .{}),
'F' => self.cmd("enter_find_in_files_mode", .{}),
@ -69,11 +72,11 @@ fn mapPress(self: *Self, keypress: u32, modifiers: u32) tp.result {
'/' => self.cmd("open_help", .{}),
else => {},
},
nc.mod.ALT => switch (keynormal) {
mod.ALT => switch (keynormal) {
'L' => self.cmd("toggle_logview", .{}),
'I' => self.cmd("toggle_inputview", .{}),
nc.key.LEFT => self.cmd("jump_back", .{}),
nc.key.RIGHT => self.cmd("jump_forward", .{}),
key.LEFT => self.cmd("jump_back", .{}),
key.RIGHT => self.cmd("jump_forward", .{}),
else => {},
},
0 => switch (keypress) {
@ -85,15 +88,15 @@ fn mapPress(self: *Self, keypress: u32, modifiers: u32) tp.result {
'c' => self.cmd("open_config", .{}),
'q' => self.cmd("quit", .{}),
nc.key.F01 => self.cmd("open_help", .{}),
nc.key.F06 => self.cmd("open_config", .{}),
nc.key.F09 => self.cmd("theme_prev", .{}),
nc.key.F10 => self.cmd("theme_next", .{}),
nc.key.F11 => self.cmd("toggle_logview", .{}),
nc.key.F12 => self.cmd("toggle_inputview", .{}),
nc.key.UP => self.cmd("home_menu_up", .{}),
nc.key.DOWN => self.cmd("home_menu_down", .{}),
nc.key.ENTER => self.cmd("home_menu_activate", .{}),
key.F01 => self.cmd("open_help", .{}),
key.F06 => self.cmd("open_config", .{}),
key.F09 => self.cmd("theme_prev", .{}),
key.F10 => self.cmd("theme_next", .{}),
key.F11 => self.cmd("toggle_logview", .{}),
key.F12 => self.cmd("toggle_inputview", .{}),
key.UP => self.cmd("home_menu_up", .{}),
key.DOWN => self.cmd("home_menu_down", .{}),
key.ENTER => self.cmd("home_menu_activate", .{}),
else => {},
},
else => {},

View file

@ -1,7 +1,11 @@
const nc = @import("notcurses");
const tp = @import("thespian");
const root = @import("root");
const key = @import("renderer").input.key;
const mod = @import("renderer").input.modifier;
const event_type = @import("renderer").input.event_type;
const egc_ = @import("renderer").egc;
const tui = @import("../../../tui.zig");
const command = @import("../../../command.zig");
const EventHandler = @import("../../../EventHandler.zig");
@ -10,8 +14,6 @@ const Allocator = @import("std").mem.Allocator;
const ArrayList = @import("std").ArrayList;
const json = @import("std").json;
const eql = @import("std").mem.eql;
const mod = nc.mod;
const key = nc.key;
const Self = @This();
const input_buffer_size = 1024;
@ -63,9 +65,9 @@ pub fn add_keybind() void {}
fn mapEvent(self: *Self, evtype: u32, keypress: u32, egc: u32, modifiers: u32) tp.result {
return switch (evtype) {
nc.event_type.PRESS => self.mapPress(keypress, egc, modifiers),
nc.event_type.REPEAT => self.mapPress(keypress, egc, modifiers),
nc.event_type.RELEASE => self.mapRelease(keypress, egc, modifiers),
event_type.PRESS => self.mapPress(keypress, egc, modifiers),
event_type.REPEAT => self.mapPress(keypress, egc, modifiers),
event_type.RELEASE => self.mapRelease(keypress, egc, modifiers),
else => {},
};
}
@ -249,7 +251,7 @@ fn insert_code_point(self: *Self, c: u32) tp.result {
if (self.input.items.len + 4 > input_buffer_size)
try self.flush_input();
var buf: [6]u8 = undefined;
const bytes = nc.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e);
const bytes = egc_.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e);
self.input.appendSlice(buf[0..bytes]) catch |e| return tp.exit_error(e);
}

View file

@ -1,7 +1,11 @@
const nc = @import("notcurses");
const tp = @import("thespian");
const root = @import("root");
const key = @import("renderer").input.key;
const mod = @import("renderer").input.modifier;
const event_type = @import("renderer").input.event_type;
const egc_ = @import("renderer").egc;
const tui = @import("../../../tui.zig");
const command = @import("../../../command.zig");
const EventHandler = @import("../../../EventHandler.zig");
@ -10,8 +14,6 @@ const Allocator = @import("std").mem.Allocator;
const ArrayList = @import("std").ArrayList;
const json = @import("std").json;
const eql = @import("std").mem.eql;
const mod = nc.mod;
const key = nc.key;
const Self = @This();
const input_buffer_size = 1024;
@ -64,9 +66,9 @@ pub fn add_keybind() void {}
fn mapEvent(self: *Self, evtype: u32, keypress: u32, egc: u32, modifiers: u32) tp.result {
return switch (evtype) {
nc.event_type.PRESS => self.mapPress(keypress, egc, modifiers),
nc.event_type.REPEAT => self.mapPress(keypress, egc, modifiers),
nc.event_type.RELEASE => self.mapRelease(keypress, egc, modifiers),
event_type.PRESS => self.mapPress(keypress, egc, modifiers),
event_type.REPEAT => self.mapPress(keypress, egc, modifiers),
event_type.RELEASE => self.mapRelease(keypress, egc, modifiers),
else => {},
};
}
@ -451,7 +453,7 @@ fn insert_code_point(self: *Self, c: u32) tp.result {
if (self.input.items.len + 4 > input_buffer_size)
try self.flush_input();
var buf: [6]u8 = undefined;
const bytes = nc.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e);
const bytes = egc_.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e);
self.input.appendSlice(buf[0..bytes]) catch |e| return tp.exit_error(e);
}

View file

@ -1,7 +1,11 @@
const nc = @import("notcurses");
const tp = @import("thespian");
const root = @import("root");
const key = @import("renderer").input.key;
const mod = @import("renderer").input.modifier;
const event_type = @import("renderer").input.event_type;
const egc_ = @import("renderer").egc;
const tui = @import("../../../tui.zig");
const command = @import("../../../command.zig");
const EventHandler = @import("../../../EventHandler.zig");
@ -10,8 +14,6 @@ const Allocator = @import("std").mem.Allocator;
const ArrayList = @import("std").ArrayList;
const json = @import("std").json;
const eql = @import("std").mem.eql;
const mod = nc.mod;
const key = nc.key;
const Self = @This();
const input_buffer_size = 1024;
@ -64,9 +66,9 @@ pub fn add_keybind() void {}
fn mapEvent(self: *Self, evtype: u32, keypress: u32, egc: u32, modifiers: u32) tp.result {
return switch (evtype) {
nc.event_type.PRESS => self.mapPress(keypress, egc, modifiers),
nc.event_type.REPEAT => self.mapPress(keypress, egc, modifiers),
nc.event_type.RELEASE => self.mapRelease(keypress, egc, modifiers),
event_type.PRESS => self.mapPress(keypress, egc, modifiers),
event_type.REPEAT => self.mapPress(keypress, egc, modifiers),
event_type.RELEASE => self.mapRelease(keypress, egc, modifiers),
else => {},
};
}
@ -409,7 +411,7 @@ fn insert_code_point(self: *Self, c: u32) tp.result {
if (self.input.items.len + 4 > input_buffer_size)
try self.flush_input();
var buf: [6]u8 = undefined;
const bytes = nc.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e);
const bytes = egc_.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e);
self.input.appendSlice(buf[0..bytes]) catch |e| return tp.exit_error(e);
}

View file

@ -1,6 +1,10 @@
const nc = @import("notcurses");
const tp = @import("thespian");
const key = @import("renderer").input.key;
const mod = @import("renderer").input.modifier;
const event_type = @import("renderer").input.event_type;
const egc_ = @import("renderer").egc;
const tui = @import("../../tui.zig");
const mainview = @import("../../mainview.zig");
const command = @import("../../command.zig");
@ -10,8 +14,6 @@ const ed = @import("../../editor.zig");
const Allocator = @import("std").mem.Allocator;
const json = @import("std").json;
const eql = @import("std").mem.eql;
const mod = nc.mod;
const key = nc.key;
const Self = @This();
@ -83,9 +85,9 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
fn mapEvent(self: *Self, evtype: u32, keypress: u32, egc: u32, modifiers: u32) tp.result {
switch (evtype) {
nc.event_type.PRESS => try self.mapPress(keypress, egc, modifiers),
nc.event_type.REPEAT => try self.mapPress(keypress, egc, modifiers),
nc.event_type.RELEASE => try self.mapRelease(keypress, egc, modifiers),
event_type.PRESS => try self.mapPress(keypress, egc, modifiers),
event_type.REPEAT => try self.mapPress(keypress, egc, modifiers),
event_type.RELEASE => try self.mapRelease(keypress, egc, modifiers),
else => {},
}
}
@ -159,7 +161,7 @@ fn mapRelease(self: *Self, keypress: u32, _: u32, _: u32) tp.result {
fn insert_code_point(self: *Self, c: u32) tp.result {
if (self.input.len + 16 > self.buf.len)
try self.flush_input();
const bytes = nc.ucs32_to_utf8(&[_]u32{c}, self.buf[self.input.len..]) catch |e| return tp.exit_error(e);
const bytes = egc_.ucs32_to_utf8(&[_]u32{c}, self.buf[self.input.len..]) catch |e| return tp.exit_error(e);
self.input = self.buf[0 .. self.input.len + bytes];
}

View file

@ -1,6 +1,10 @@
const nc = @import("notcurses");
const tp = @import("thespian");
const key = @import("renderer").input.key;
const mod = @import("renderer").input.modifier;
const event_type = @import("renderer").input.event_type;
const egc_ = @import("renderer").egc;
const tui = @import("../../tui.zig");
const mainview = @import("../../mainview.zig");
const command = @import("../../command.zig");
@ -10,8 +14,6 @@ const ed = @import("../../editor.zig");
const Allocator = @import("std").mem.Allocator;
const json = @import("std").json;
const eql = @import("std").mem.eql;
const mod = nc.mod;
const key = nc.key;
const Self = @This();
@ -82,9 +84,9 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
fn mapEvent(self: *Self, evtype: u32, keypress: u32, egc: u32, modifiers: u32) tp.result {
switch (evtype) {
nc.event_type.PRESS => try self.mapPress(keypress, egc, modifiers),
nc.event_type.REPEAT => try self.mapPress(keypress, egc, modifiers),
nc.event_type.RELEASE => try self.mapRelease(keypress, egc, modifiers),
event_type.PRESS => try self.mapPress(keypress, egc, modifiers),
event_type.REPEAT => try self.mapPress(keypress, egc, modifiers),
event_type.RELEASE => try self.mapRelease(keypress, egc, modifiers),
else => {},
}
}
@ -156,7 +158,7 @@ fn mapRelease(self: *Self, keypress: u32, _: u32, _: u32) tp.result {
fn insert_code_point(self: *Self, c: u32) tp.result {
if (self.input.len + 16 > self.buf.len)
try self.flush_input();
const bytes = nc.ucs32_to_utf8(&[_]u32{c}, self.buf[self.input.len..]) catch |e| return tp.exit_error(e);
const bytes = egc_.ucs32_to_utf8(&[_]u32{c}, self.buf[self.input.len..]) catch |e| return tp.exit_error(e);
self.input = self.buf[0 .. self.input.len + bytes];
}

View file

@ -1,6 +1,9 @@
const nc = @import("notcurses");
const tp = @import("thespian");
const key = @import("renderer").input.key;
const mod = @import("renderer").input.modifier;
const event_type = @import("renderer").input.event_type;
const tui = @import("../../tui.zig");
const mainview = @import("../../mainview.zig");
const command = @import("../../command.zig");
@ -10,8 +13,6 @@ const Allocator = @import("std").mem.Allocator;
const json = @import("std").json;
const eql = @import("std").mem.eql;
const fmt = @import("std").fmt;
const mod = nc.mod;
const key = nc.key;
const Self = @This();
@ -64,8 +65,8 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
fn mapEvent(self: *Self, evtype: u32, keypress: u32, modifiers: u32) tp.result {
switch (evtype) {
nc.event_type.PRESS => try self.mapPress(keypress, modifiers),
nc.event_type.REPEAT => try self.mapPress(keypress, modifiers),
event_type.PRESS => try self.mapPress(keypress, modifiers),
event_type.REPEAT => try self.mapPress(keypress, modifiers),
else => {},
}
}

View file

@ -1,6 +1,10 @@
const nc = @import("notcurses");
const tp = @import("thespian");
const key = @import("renderer").input.key;
const mod = @import("renderer").input.modifier;
const event_type = @import("renderer").input.event_type;
const egc_ = @import("renderer").egc;
const tui = @import("../../tui.zig");
const mainview = @import("../../mainview.zig");
const command = @import("../../command.zig");
@ -10,8 +14,6 @@ const Allocator = @import("std").mem.Allocator;
const json = @import("std").json;
const eql = @import("std").mem.eql;
const fmt = @import("std").fmt;
const mod = nc.mod;
const key = nc.key;
const Self = @This();
@ -76,7 +78,7 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
fn mapEvent(self: *Self, evtype: u32, keypress: u32, egc: u32, modifiers: u32) tp.result {
switch (evtype) {
nc.event_type.PRESS => try self.mapPress(keypress, egc, modifiers),
event_type.PRESS => try self.mapPress(keypress, egc, modifiers),
else => {},
}
}
@ -112,7 +114,7 @@ fn execute_operation(self: *Self, c: u32) void {
},
};
var buf: [6]u8 = undefined;
const bytes = nc.ucs32_to_utf8(&[_]u32{c}, &buf) catch return;
const bytes = egc_.ucs32_to_utf8(&[_]u32{c}, &buf) catch return;
command.executeName(cmd, command.fmt(.{buf[0..bytes]})) catch {};
command.executeName("exit_mini_mode", .{}) catch {};
}

View file

@ -1,7 +1,11 @@
const std = @import("std");
const nc = @import("notcurses");
const tp = @import("thespian");
const key = @import("renderer").input.key;
const mod = @import("renderer").input.modifier;
const event_type = @import("renderer").input.event_type;
const egc_ = @import("renderer").egc;
const tui = @import("../../tui.zig");
const mainview = @import("../../mainview.zig");
const command = @import("../../command.zig");
@ -68,9 +72,9 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
fn mapEvent(self: *Self, evtype: u32, keypress: u32, egc: u32, modifiers: u32) tp.result {
switch (evtype) {
nc.event_type.PRESS => try self.mapPress(keypress, egc, modifiers),
nc.event_type.REPEAT => try self.mapPress(keypress, egc, modifiers),
nc.event_type.RELEASE => try self.mapRelease(keypress, egc, modifiers),
event_type.PRESS => try self.mapPress(keypress, egc, modifiers),
event_type.REPEAT => try self.mapPress(keypress, egc, modifiers),
event_type.RELEASE => try self.mapRelease(keypress, egc, modifiers),
else => {},
}
}
@ -78,7 +82,7 @@ fn mapEvent(self: *Self, evtype: u32, keypress: u32, egc: u32, modifiers: u32) t
fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
const keynormal = if ('a' <= keypress and keypress <= 'z') keypress - ('a' - 'A') else keypress;
return switch (modifiers) {
nc.mod.CTRL => switch (keynormal) {
mod.CTRL => switch (keynormal) {
'Q' => self.cmd("quit", .{}),
'V' => self.cmd("system_paste", .{}),
'U' => self.file_path.clearRetainingCapacity(),
@ -86,30 +90,30 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
'C' => self.cancel(),
'L' => self.cmd("scroll_view_center", .{}),
'I' => self.insert_bytes("\t"),
nc.key.SPACE => self.cancel(),
nc.key.BACKSPACE => self.file_path.clearRetainingCapacity(),
key.SPACE => self.cancel(),
key.BACKSPACE => self.file_path.clearRetainingCapacity(),
else => {},
},
nc.mod.ALT => switch (keynormal) {
mod.ALT => switch (keynormal) {
'V' => self.cmd("system_paste", .{}),
else => {},
},
nc.mod.ALT | nc.mod.SHIFT => switch (keynormal) {
mod.ALT | mod.SHIFT => switch (keynormal) {
'V' => self.cmd("system_paste", .{}),
else => {},
},
nc.mod.SHIFT => switch (keypress) {
else => if (!nc.key.synthesized_p(keypress))
mod.SHIFT => switch (keypress) {
else => if (!key.synthesized_p(keypress))
self.insert_code_point(egc)
else {},
},
0 => switch (keypress) {
nc.key.ESC => self.cancel(),
nc.key.ENTER => self.navigate(),
nc.key.BACKSPACE => if (self.file_path.items.len > 0) {
key.ESC => self.cancel(),
key.ENTER => self.navigate(),
key.BACKSPACE => if (self.file_path.items.len > 0) {
self.file_path.shrinkRetainingCapacity(self.file_path.items.len - 1);
},
else => if (!nc.key.synthesized_p(keypress))
else => if (!key.synthesized_p(keypress))
self.insert_code_point(egc)
else {},
},
@ -121,7 +125,7 @@ fn mapRelease(_: *Self, _: u32, _: u32, _: u32) tp.result {}
fn insert_code_point(self: *Self, c: u32) tp.result {
var buf: [32]u8 = undefined;
const bytes = nc.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e);
const bytes = egc_.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e);
self.file_path.appendSlice(buf[0..bytes]) catch |e| return tp.exit_error(e);
}

View file

@ -1,9 +1,15 @@
const std = @import("std");
const nc = @import("notcurses");
const tp = @import("thespian");
const log = @import("log");
const cbor = @import("cbor");
const Plane = @import("renderer").Plane;
const planeutils = @import("renderer").planeutils;
const key = @import("renderer").input.key;
const mod = @import("renderer").input.modifier;
const event_type = @import("renderer").input.event_type;
const egc_ = @import("renderer").egc;
const tui = @import("../../tui.zig");
const command = @import("../../command.zig");
const EventHandler = @import("../../EventHandler.zig");
@ -66,7 +72,7 @@ pub fn deinit(self: *Self) void {
fn on_render_menu(_: *Self, button: *Button.State(*Menu.State(*Self)), theme: *const Widget.Theme, selected: bool) bool {
const style_base = if (button.active) theme.editor_cursor else if (button.hover or selected) theme.editor_selection else theme.editor_widget;
try tui.set_base_style_alpha(button.plane, " ", style_base, nc.ALPHA_OPAQUE, nc.ALPHA_OPAQUE);
button.plane.set_base_style(" ", style_base);
button.plane.erase();
button.plane.home();
var file_path: []const u8 = undefined;
@ -89,11 +95,11 @@ fn on_render_menu(_: *Self, button: *Button.State(*Menu.State(*Self)), theme: *c
return false;
}
fn render_cell(plane: nc.Plane, y: usize, x: usize, style: Widget.Theme.Style) !void {
fn render_cell(plane: Plane, y: usize, x: usize, style: Widget.Theme.Style) !void {
plane.cursor_move_yx(@intCast(y), @intCast(x)) catch return;
var cell = plane.cell_init();
_ = plane.at_cursor_cell(&cell) catch return;
tui.set_cell_style(&cell, style);
cell.set_style(style);
_ = plane.putc(&cell) catch {};
}
@ -203,9 +209,9 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
fn mapEvent(self: *Self, evtype: u32, keypress: u32, egc: u32, modifiers: u32) tp.result {
return switch (evtype) {
nc.event_type.PRESS => self.mapPress(keypress, egc, modifiers),
nc.event_type.REPEAT => self.mapPress(keypress, egc, modifiers),
nc.event_type.RELEASE => self.mapRelease(keypress, modifiers),
event_type.PRESS => self.mapPress(keypress, egc, modifiers),
event_type.REPEAT => self.mapPress(keypress, egc, modifiers),
event_type.RELEASE => self.mapRelease(keypress, modifiers),
else => {},
};
}
@ -213,7 +219,7 @@ fn mapEvent(self: *Self, evtype: u32, keypress: u32, egc: u32, modifiers: u32) t
fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
const keynormal = if ('a' <= keypress and keypress <= 'z') keypress - ('a' - 'A') else keypress;
return switch (modifiers) {
nc.mod.CTRL => switch (keynormal) {
mod.CTRL => switch (keynormal) {
'J' => self.cmd("toggle_logview", .{}),
'Q' => self.cmd("quit", .{}),
'W' => self.cmd("close_file", .{}),
@ -223,14 +229,14 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
'V' => self.cmd("system_paste", .{}),
'C' => self.cmd("exit_overlay_mode", .{}),
'G' => self.cmd("exit_overlay_mode", .{}),
nc.key.ESC => self.cmd("exit_overlay_mode", .{}),
nc.key.UP => self.cmd("open_recent_menu_up", .{}),
nc.key.DOWN => self.cmd("open_recent_menu_down", .{}),
nc.key.ENTER => self.cmd("open_recent_menu_activate", .{}),
nc.key.BACKSPACE => self.delete_word(),
key.ESC => self.cmd("exit_overlay_mode", .{}),
key.UP => self.cmd("open_recent_menu_up", .{}),
key.DOWN => self.cmd("open_recent_menu_down", .{}),
key.ENTER => self.cmd("open_recent_menu_activate", .{}),
key.BACKSPACE => self.delete_word(),
else => {},
},
nc.mod.CTRL | nc.mod.SHIFT => switch (keynormal) {
mod.CTRL | mod.SHIFT => switch (keynormal) {
'Q' => self.cmd("quit_without_saving", .{}),
'W' => self.cmd("close_file_without_saving", .{}),
'R' => self.cmd("restart", .{}),
@ -239,27 +245,27 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
'E' => self.cmd("open_recent_menu_up", .{}),
else => {},
},
nc.mod.ALT => switch (keynormal) {
mod.ALT => switch (keynormal) {
'L' => self.cmd("toggle_logview", .{}),
'I' => self.cmd("toggle_inputview", .{}),
else => {},
},
nc.mod.SHIFT => switch (keypress) {
else => if (!nc.key.synthesized_p(keypress))
mod.SHIFT => switch (keypress) {
else => if (!key.synthesized_p(keypress))
self.insert_code_point(egc)
else {},
},
0 => switch (keypress) {
nc.key.F09 => self.cmd("theme_prev", .{}),
nc.key.F10 => self.cmd("theme_next", .{}),
nc.key.F11 => self.cmd("toggle_logview", .{}),
nc.key.F12 => self.cmd("toggle_inputview", .{}),
nc.key.ESC => self.cmd("exit_overlay_mode", .{}),
nc.key.UP => self.cmd("open_recent_menu_up", .{}),
nc.key.DOWN => self.cmd("open_recent_menu_down", .{}),
nc.key.ENTER => self.cmd("open_recent_menu_activate", .{}),
nc.key.BACKSPACE => self.delete_code_point(),
else => if (!nc.key.synthesized_p(keypress))
key.F09 => self.cmd("theme_prev", .{}),
key.F10 => self.cmd("theme_next", .{}),
key.F11 => self.cmd("toggle_logview", .{}),
key.F12 => self.cmd("toggle_inputview", .{}),
key.ESC => self.cmd("exit_overlay_mode", .{}),
key.UP => self.cmd("open_recent_menu_up", .{}),
key.DOWN => self.cmd("open_recent_menu_down", .{}),
key.ENTER => self.cmd("open_recent_menu_activate", .{}),
key.BACKSPACE => self.delete_code_point(),
else => if (!key.synthesized_p(keypress))
self.insert_code_point(egc)
else {},
},
@ -269,7 +275,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) tp.result {
fn mapRelease(self: *Self, keypress: u32, _: u32) tp.result {
return switch (keypress) {
nc.key.LCTRL, nc.key.RCTRL => if (self.menu.selected orelse 0 > 0) return self.cmd("open_recent_menu_activate", .{}),
key.LCTRL, key.RCTRL => if (self.menu.selected orelse 0 > 0) return self.cmd("open_recent_menu_activate", .{}),
else => {},
};
}
@ -307,7 +313,7 @@ fn delete_code_point(self: *Self) tp.result {
fn insert_code_point(self: *Self, c: u32) tp.result {
var buf: [6]u8 = undefined;
const bytes = nc.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e);
const bytes = egc_.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e);
self.inputbox.text.appendSlice(buf[0..bytes]) catch |e| return tp.exit_error(e);
self.inputbox.cursor = self.inputbox.text.items.len;
return self.start_query();