refactor: move input types to new module and use directly use libvaxis types

This commit is contained in:
CJ van den Berg 2024-11-15 21:01:50 +01:00
parent e08c2aa3ba
commit 18f321bf41
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
36 changed files with 1224 additions and 1363 deletions

View file

@ -4,11 +4,8 @@ const cbor = @import("cbor");
const log = @import("log");
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 input = @import("input");
const keybind = @import("keybind");
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
const project_manager = @import("project_manager");
const command = @import("command");
const EventHandler = @import("EventHandler");
@ -310,7 +307,7 @@ pub fn Create(options: type) type {
return error.InvalidArgument;
self.complete_trigger_count = 0;
var buf: [32]u8 = undefined;
const bytes = try ucs32_to_utf8(&[_]u32{egc}, &buf);
const bytes = try input.ucs32_to_utf8(&[_]u32{egc}, &buf);
try self.file_path.appendSlice(buf[0..bytes]);
self.update_mini_mode_text();
}

View file

@ -1,10 +1,7 @@
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 input = @import("input");
const keybind = @import("keybind");
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
const command = @import("command");
const EventHandler = @import("EventHandler");
@ -82,7 +79,7 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
fn insert_code_point(self: *Self, c: u32) !void {
var buf: [16]u8 = undefined;
const bytes = ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e, @errorReturnTrace());
const bytes = input.ucs32_to_utf8(&[_]u32{c}, &buf) catch |e| return tp.exit_error(e, @errorReturnTrace());
try self.input.appendSlice(buf[0..bytes]);
}

View file

@ -1,10 +1,7 @@
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 input = @import("input");
const keybind = @import("keybind");
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
const command = @import("command");
const EventHandler = @import("EventHandler");
@ -75,7 +72,7 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
fn insert_code_point(self: *Self, c: u32) !void {
if (self.input.len + 16 > self.buf.len)
try self.flush_input();
const bytes = try ucs32_to_utf8(&[_]u32{c}, self.buf[self.input.len..]);
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, self.buf[self.input.len..]);
self.input = self.buf[0 .. self.input.len + bytes];
}

View file

@ -1,9 +1,6 @@
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 ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
const input = @import("input");
const keybind = @import("keybind");
const command = @import("command");
const EventHandler = @import("EventHandler");
@ -89,7 +86,7 @@ fn execute_operation(self: *Self, c: u32) void {
},
};
var buf: [6]u8 = undefined;
const bytes = ucs32_to_utf8(&[_]u32{c}, &buf) catch return;
const bytes = input.ucs32_to_utf8(&[_]u32{c}, &buf) catch return;
command.executeName(cmd, command.fmt(.{buf[0..bytes]})) catch {};
command.executeName("exit_mini_mode", .{}) catch {};
}
@ -104,7 +101,7 @@ const cmds = struct {
if (!try ctx.args.match(.{tp.extract(&code_point)}))
return error.InvalidArgument;
var buf: [6]u8 = undefined;
const bytes = ucs32_to_utf8(&[_]u32{code_point}, &buf) catch return error.InvalidArgument;
const bytes = input.ucs32_to_utf8(&[_]u32{code_point}, &buf) catch return error.InvalidArgument;
const cmd = switch (self.direction) {
.left => switch (self.operation) {
.move => "move_to_char_left",

View file

@ -5,11 +5,8 @@ const cbor = @import("cbor");
const root = @import("root");
const Plane = @import("renderer").Plane;
const key = @import("renderer").input.key;
const mod = @import("renderer").input.modifier;
const event_type = @import("renderer").input.event_type;
const input = @import("input");
const keybind = @import("keybind");
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
const project_manager = @import("project_manager");
const command = @import("command");
const EventHandler = @import("EventHandler");
@ -243,7 +240,7 @@ fn delete_code_point(self: *Self) !void {
fn insert_code_point(self: *Self, c: u32) !void {
var buf: [6]u8 = undefined;
const bytes = try ucs32_to_utf8(&[_]u32{c}, &buf);
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, &buf);
try self.inputbox.text.appendSlice(buf[0..bytes]);
self.inputbox.cursor = self.inputbox.text.items.len;
return self.start_query();

View file

@ -5,11 +5,8 @@ const cbor = @import("cbor");
const fuzzig = @import("fuzzig");
const Plane = @import("renderer").Plane;
const key = @import("renderer").input.key;
const mod = @import("renderer").input.modifier;
const event_type = @import("renderer").input.event_type;
const input = @import("input");
const keybind = @import("keybind");
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
const command = @import("command");
const EventHandler = @import("EventHandler");
@ -315,7 +312,7 @@ pub fn Create(options: type) type {
fn insert_code_point(self: *Self, c: u32) !void {
var buf: [6]u8 = undefined;
const bytes = try ucs32_to_utf8(&[_]u32{c}, &buf);
const bytes = try input.ucs32_to_utf8(&[_]u32{c}, &buf);
try self.inputbox.text.appendSlice(buf[0..bytes]);
self.inputbox.cursor = self.inputbox.text.items.len;
self.view_pos = 0;