refactor: zigify imports and correct minor mistakes
This commit is contained in:
81
src/app.zig
81
src/app.zig
@@ -1,19 +1,4 @@
|
||||
//! Application type for TUI-applications
|
||||
const std = @import("std");
|
||||
const code_point = @import("code_point");
|
||||
const event = @import("event.zig");
|
||||
const input = @import("input.zig");
|
||||
const terminal = @import("terminal.zig");
|
||||
const queue = @import("queue.zig");
|
||||
|
||||
const mergeTaggedUnions = event.mergeTaggedUnions;
|
||||
const isTaggedUnion = event.isTaggedUnion;
|
||||
|
||||
const Mouse = input.Mouse;
|
||||
const Key = input.Key;
|
||||
const Point = @import("point.zig").Point;
|
||||
|
||||
const log = std.log.scoped(.app);
|
||||
|
||||
/// Create the App Type with the associated user events _E_ which describes
|
||||
/// an tagged union for all the user events that can be send through the
|
||||
@@ -39,18 +24,10 @@ pub fn App(comptime E: type) type {
|
||||
@compileError("Provided user event `E` for `App(comptime E: type)` is not of type `union(enum)`.");
|
||||
}
|
||||
return struct {
|
||||
pub const Event = mergeTaggedUnions(event.SystemEvent, E);
|
||||
pub const Container = @import("container.zig").Container(Event);
|
||||
const element = @import("element.zig");
|
||||
pub const Element = element.Element(Event);
|
||||
pub const Scrollable = element.Scrollable(Event);
|
||||
pub const Exec = element.Exec(Event, Queue);
|
||||
pub const Queue = queue.Queue(Event, 256);
|
||||
|
||||
queue: Queue,
|
||||
thread: ?std.Thread = null,
|
||||
quit_event: std.Thread.ResetEvent,
|
||||
termios: ?std.posix.termios = null,
|
||||
thread: ?Thread = null,
|
||||
quit_event: Thread.ResetEvent,
|
||||
termios: ?posix.termios = null,
|
||||
|
||||
pub const SignalHandler = struct {
|
||||
context: *anyopaque,
|
||||
@@ -69,9 +46,9 @@ pub fn App(comptime E: type) type {
|
||||
this.postEvent(.init);
|
||||
|
||||
this.quit_event.reset();
|
||||
this.thread = try std.Thread.spawn(.{}, @This().run, .{this});
|
||||
this.thread = try Thread.spawn(.{}, @This().run, .{this});
|
||||
|
||||
var termios: std.posix.termios = undefined;
|
||||
var termios: posix.termios = undefined;
|
||||
try terminal.enableRawMode(&termios);
|
||||
if (this.termios) |_| {} else this.termios = termios;
|
||||
|
||||
@@ -192,9 +169,9 @@ pub fn App(comptime E: type) type {
|
||||
// CSI number ~
|
||||
// CSI number ; modifier ~
|
||||
// CSI number ; modifier:event_type ; text_as_codepoint ~
|
||||
var field_iter = std.mem.splitScalar(u8, sequence[2 .. sequence.len - 1], ';');
|
||||
var field_iter = mem.splitScalar(u8, sequence[2 .. sequence.len - 1], ';');
|
||||
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 number = fmt.parseUnsigned(u16, number_buf, 10) catch break;
|
||||
|
||||
const key: Key = .{
|
||||
.cp = switch (number) {
|
||||
@@ -231,11 +208,11 @@ pub fn App(comptime E: type) type {
|
||||
std.debug.assert(sequence.len >= 4);
|
||||
if (sequence[2] != '<') break;
|
||||
|
||||
const delim1 = std.mem.indexOfScalarPos(u8, sequence, 3, ';') orelse break;
|
||||
const button_mask = std.fmt.parseUnsigned(u16, sequence[3..delim1], 10) catch break;
|
||||
const delim2 = std.mem.indexOfScalarPos(u8, sequence, delim1 + 1, ';') orelse break;
|
||||
const px = std.fmt.parseUnsigned(u16, sequence[delim1 + 1 .. delim2], 10) catch break;
|
||||
const py = std.fmt.parseUnsigned(u16, sequence[delim2 + 1 .. sequence.len - 1], 10) catch break;
|
||||
const delim1 = mem.indexOfScalarPos(u8, sequence, 3, ';') orelse break;
|
||||
const button_mask = fmt.parseUnsigned(u16, sequence[3..delim1], 10) catch break;
|
||||
const delim2 = mem.indexOfScalarPos(u8, sequence, delim1 + 1, ';') orelse break;
|
||||
const px = fmt.parseUnsigned(u16, sequence[delim1 + 1 .. delim2], 10) catch break;
|
||||
const py = fmt.parseUnsigned(u16, sequence[delim2 + 1 .. sequence.len - 1], 10) catch break;
|
||||
|
||||
const mouse_bits = packed struct {
|
||||
const motion: u8 = 0b00100000;
|
||||
@@ -280,9 +257,9 @@ pub fn App(comptime E: type) type {
|
||||
't' => {
|
||||
// XTWINOPS
|
||||
// Split first into fields delimited by ';'
|
||||
var iter = std.mem.splitScalar(u8, sequence[2 .. sequence.len - 1], ';');
|
||||
var iter = mem.splitScalar(u8, sequence[2 .. sequence.len - 1], ';');
|
||||
const ps = iter.first();
|
||||
if (std.mem.eql(u8, "48", ps)) {
|
||||
if (mem.eql(u8, "48", ps)) {
|
||||
// in band window resize
|
||||
// CSI 48 ; height ; width ; height_pix ; width_pix t
|
||||
const width_char = iter.next() orelse break;
|
||||
@@ -291,8 +268,8 @@ pub fn App(comptime E: type) type {
|
||||
_ = width_char;
|
||||
_ = height_char;
|
||||
// this.postEvent(.{ .size = .{
|
||||
// .x = std.fmt.parseUnsigned(u16, width_char, 10) catch break,
|
||||
// .y = std.fmt.parseUnsigned(u16, height_char, 10) catch break,
|
||||
// .x = fmt.parseUnsigned(u16, width_char, 10) catch break,
|
||||
// .y = fmt.parseUnsigned(u16, height_char, 10) catch break,
|
||||
// } });
|
||||
}
|
||||
},
|
||||
@@ -338,5 +315,31 @@ pub fn App(comptime E: type) type {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const element = @import("element.zig");
|
||||
pub const Event = mergeTaggedUnions(event.SystemEvent, E);
|
||||
pub const Container = @import("container.zig").Container(Event);
|
||||
pub const Element = element.Element(Event);
|
||||
pub const Scrollable = element.Scrollable(Event);
|
||||
pub const Exec = element.Exec(Event, Queue);
|
||||
pub const Queue = queue.Queue(Event, 256);
|
||||
};
|
||||
}
|
||||
|
||||
const log = std.log.scoped(.app);
|
||||
|
||||
const std = @import("std");
|
||||
const mem = std.mem;
|
||||
const fmt = std.fmt;
|
||||
const posix = std.posix;
|
||||
const Thread = std.Thread;
|
||||
const code_point = @import("code_point");
|
||||
const event = @import("event.zig");
|
||||
const input = @import("input.zig");
|
||||
const terminal = @import("terminal.zig");
|
||||
const queue = @import("queue.zig");
|
||||
const mergeTaggedUnions = event.mergeTaggedUnions;
|
||||
const isTaggedUnion = event.isTaggedUnion;
|
||||
const Mouse = input.Mouse;
|
||||
const Key = input.Key;
|
||||
const Point = @import("point.zig").Point;
|
||||
|
||||
Reference in New Issue
Block a user