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,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 => {},