doc: correct TODO, NOTE and FIX comment statements
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 48s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 48s
This commit is contained in:
@@ -26,7 +26,7 @@ const QuitText = struct {
|
|||||||
cells[anchor + idx].style.bg = .black;
|
cells[anchor + idx].style.bg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ const QuitText = struct {
|
|||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
errdefer |err| log.err("Application Error: {any}", .{err});
|
errdefer |err| log.err("Application Error: {any}", .{err});
|
||||||
|
|
||||||
// TODO: maybe create own allocator as some sort of arena allocator to have consistent memory usage
|
// TODO maybe create own allocator as some sort of arena allocator to have consistent memory usage
|
||||||
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
|
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
|
||||||
defer if (gpa.deinit() == .leak) log.err("memory leak", .{});
|
defer if (gpa.deinit() == .leak) log.err("memory leak", .{});
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ pub fn main() !void {
|
|||||||
|
|
||||||
var quit_text: QuitText = .{};
|
var quit_text: QuitText = .{};
|
||||||
|
|
||||||
// TODO: what should the demo application do?
|
// TODO what should the demo application do?
|
||||||
// - some sort of chat? -> write messages and have them displayed in a scrollable array at the right hand side?
|
// - some sort of chat? -> write messages and have them displayed in a scrollable array at the right hand side?
|
||||||
// - on the left some buttons?
|
// - on the left some buttons?
|
||||||
var box = try App.Container.init(allocator, .{
|
var box = try App.Container.init(allocator, .{
|
||||||
@@ -127,12 +127,12 @@ pub fn main() !void {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// NOTE: errors could be displayed in another container in case one was received, etc. to provide the user with feedback
|
// NOTE errors could be displayed in another container in case one was received, etc. to provide the user with feedback
|
||||||
.err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }),
|
.err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: returned errors should be propagated back to the application
|
// NOTE returned errors should be propagated back to the application
|
||||||
container.handle(event) catch |err| app.postEvent(.{
|
container.handle(event) catch |err| app.postEvent(.{
|
||||||
.err = .{
|
.err = .{
|
||||||
.err = err,
|
.err = err,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const QuitText = struct {
|
|||||||
cells[anchor + idx].style.bg = .black;
|
cells[anchor + idx].style.bg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ const Clickable = struct {
|
|||||||
cells[anchor + idx].style.emphasis = &.{.bold};
|
cells[anchor + idx].style.emphasis = &.{.bold};
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const QuitText = struct {
|
|||||||
cells[anchor + idx].style.bg = .black;
|
cells[anchor + idx].style.bg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ const InputField = struct {
|
|||||||
cells[anchor + idx].style.fg = .black;
|
cells[anchor + idx].style.fg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const QuitText = struct {
|
|||||||
cells[anchor + idx].style.bg = .black;
|
cells[anchor + idx].style.bg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ const HelloWorldText = packed struct {
|
|||||||
_ = ctx;
|
_ = ctx;
|
||||||
std.debug.assert(cells.len == @as(usize, size.cols) * @as(usize, size.rows));
|
std.debug.assert(cells.len == @as(usize, size.cols) * @as(usize, size.rows));
|
||||||
|
|
||||||
// NOTE: error should only be returned here in case an in-recoverable exception has occurred
|
// NOTE error should only be returned here in case an in-recoverable exception has occurred
|
||||||
const row = size.rows / 2;
|
const row = size.rows / 2;
|
||||||
const col = size.cols / 2 -| (text.len / 2);
|
const col = size.cols / 2 -| (text.len / 2);
|
||||||
const anchor = (row * size.cols) + col;
|
const anchor = (row * size.cols) + col;
|
||||||
@@ -61,7 +61,7 @@ const HelloWorldText = packed struct {
|
|||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
errdefer |err| log.err("Application Error: {any}", .{err});
|
errdefer |err| log.err("Application Error: {any}", .{err});
|
||||||
|
|
||||||
// TODO: maybe create own allocator as some sort of arena allocator to have consistent memory usage
|
// TODO maybe create own allocator as some sort of arena allocator to have consistent memory usage
|
||||||
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
|
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
|
||||||
defer {
|
defer {
|
||||||
const deinit_status = gpa.deinit();
|
const deinit_status = gpa.deinit();
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const QuitText = struct {
|
|||||||
cells[anchor + idx].style.bg = .black;
|
cells[anchor + idx].style.bg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ const InfoText = struct {
|
|||||||
cells[anchor + idx].style.bg = .black;
|
cells[anchor + idx].style.bg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ const ErrorNotification = struct {
|
|||||||
cells[anchor + idx].style.bg = .black;
|
cells[anchor + idx].style.bg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const QuitText = struct {
|
|||||||
cells[anchor + idx].style.bg = .black;
|
cells[anchor + idx].style.bg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,12 +89,12 @@ pub fn main() !void {
|
|||||||
.quit => break,
|
.quit => break,
|
||||||
.resize => |size| try renderer.resize(size),
|
.resize => |size| try renderer.resize(size),
|
||||||
.key => |key| if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) app.quit(),
|
.key => |key| if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) app.quit(),
|
||||||
// NOTE: errors could be displayed in another container in case one was received, etc. to provide the user with feedback
|
// NOTE errors could be displayed in another container in case one was received, etc. to provide the user with feedback
|
||||||
.err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }),
|
.err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: returned errors should be propagated back to the application
|
// NOTE returned errors should be propagated back to the application
|
||||||
container.handle(event) catch |err| app.postEvent(.{
|
container.handle(event) catch |err| app.postEvent(.{
|
||||||
.err = .{
|
.err = .{
|
||||||
.err = err,
|
.err = err,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const QuitText = struct {
|
|||||||
cells[anchor + idx].style.bg = .black;
|
cells[anchor + idx].style.bg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,12 +81,12 @@ pub fn main() !void {
|
|||||||
.quit => break,
|
.quit => break,
|
||||||
.resize => |size| try renderer.resize(size),
|
.resize => |size| try renderer.resize(size),
|
||||||
.key => |key| if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) app.quit(),
|
.key => |key| if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) app.quit(),
|
||||||
// NOTE: errors could be displayed in another container in case one was received, etc. to provide the user with feedback
|
// NOTE errors could be displayed in another container in case one was received, etc. to provide the user with feedback
|
||||||
.err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }),
|
.err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: returned errors should be propagated back to the application
|
// NOTE returned errors should be propagated back to the application
|
||||||
container.handle(event) catch |err| app.postEvent(.{
|
container.handle(event) catch |err| app.postEvent(.{
|
||||||
.err = .{
|
.err = .{
|
||||||
.err = err,
|
.err = err,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const QuitText = struct {
|
|||||||
cells[anchor + idx].style.bg = .black;
|
cells[anchor + idx].style.bg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,12 +93,12 @@ pub fn main() !void {
|
|||||||
.quit => break,
|
.quit => break,
|
||||||
.resize => |size| try renderer.resize(size),
|
.resize => |size| try renderer.resize(size),
|
||||||
.key => |key| if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) app.quit(),
|
.key => |key| if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) app.quit(),
|
||||||
// NOTE: errors could be displayed in another container in case one was received, etc. to provide the user with feedback
|
// NOTE errors could be displayed in another container in case one was received, etc. to provide the user with feedback
|
||||||
.err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }),
|
.err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: returned errors should be propagated back to the application
|
// NOTE returned errors should be propagated back to the application
|
||||||
container.handle(event) catch |err| app.postEvent(.{
|
container.handle(event) catch |err| app.postEvent(.{
|
||||||
.err = .{
|
.err = .{
|
||||||
.err = err,
|
.err = err,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const QuitText = struct {
|
|||||||
cells[anchor + idx].style.bg = .black;
|
cells[anchor + idx].style.bg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,12 +80,12 @@ pub fn main() !void {
|
|||||||
.quit => break,
|
.quit => break,
|
||||||
.resize => |size| try renderer.resize(size),
|
.resize => |size| try renderer.resize(size),
|
||||||
.key => |key| if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) app.quit(),
|
.key => |key| if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) app.quit(),
|
||||||
// NOTE: errors could be displayed in another container in case one was received, etc. to provide the user with feedback
|
// NOTE errors could be displayed in another container in case one was received, etc. to provide the user with feedback
|
||||||
.err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }),
|
.err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: returned errors should be propagated back to the application
|
// NOTE returned errors should be propagated back to the application
|
||||||
container.handle(event) catch |err| app.postEvent(.{
|
container.handle(event) catch |err| app.postEvent(.{
|
||||||
.err = .{
|
.err = .{
|
||||||
.err = err,
|
.err = err,
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const QuitText = struct {
|
|||||||
cells[anchor + idx].style.bg = .black;
|
cells[anchor + idx].style.bg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const QuitText = struct {
|
|||||||
cells[anchor + idx].style.bg = .black;
|
cells[anchor + idx].style.bg = .black;
|
||||||
cells[anchor + idx].cp = cp;
|
cells[anchor + idx].cp = cp;
|
||||||
|
|
||||||
// NOTE: do not write over the contents of this `Container`'s `Size`
|
// NOTE do not write over the contents of this `Container`'s `Size`
|
||||||
if (anchor + idx == cells.len - 1) break;
|
if (anchor + idx == cells.len - 1) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/app.zig
12
src/app.zig
@@ -174,11 +174,11 @@ pub fn App(comptime E: type) type {
|
|||||||
// thread to read user inputs
|
// thread to read user inputs
|
||||||
var buf: [256]u8 = undefined;
|
var buf: [256]u8 = undefined;
|
||||||
while (true) {
|
while (true) {
|
||||||
// FIX: I still think that there is a race condition (I'm just waiting 'long' enough)
|
// FIX I still think that there is a race condition (I'm just waiting 'long' enough)
|
||||||
this.quit_event.timedWait(20 * std.time.ns_per_ms) catch {
|
this.quit_event.timedWait(20 * std.time.ns_per_ms) catch {
|
||||||
// FIX: in case the queue is full -> the next user input should panic and quit the application? because something seems to clock up the event queue
|
// FIX in case the queue is full -> the next user input should panic and quit the application? because something seems to clock up the event queue
|
||||||
const read_bytes = try terminal.read(buf[0..]);
|
const read_bytes = try terminal.read(buf[0..]);
|
||||||
// TODO: `break` should not terminate the reading of the user inputs, but instead only the received faulty input!
|
// TODO `break` should not terminate the reading of the user inputs, but instead only the received faulty input!
|
||||||
// escape key presses
|
// escape key presses
|
||||||
if (buf[0] == 0x1b and read_bytes > 1) {
|
if (buf[0] == 0x1b and read_bytes > 1) {
|
||||||
switch (buf[1]) {
|
switch (buf[1]) {
|
||||||
@@ -273,7 +273,7 @@ pub fn App(comptime E: type) type {
|
|||||||
};
|
};
|
||||||
this.postEvent(.{ .key = key });
|
this.postEvent(.{ .key = key });
|
||||||
},
|
},
|
||||||
// TODO: focus usage? should this even be in the default event system?
|
// TODO focus usage? should this even be in the default event system?
|
||||||
'I' => this.postEvent(.{ .focus = true }),
|
'I' => this.postEvent(.{ .focus = true }),
|
||||||
'O' => this.postEvent(.{ .focus = false }),
|
'O' => this.postEvent(.{ .focus = false }),
|
||||||
'M', 'm' => {
|
'M', 'm' => {
|
||||||
@@ -337,7 +337,7 @@ pub fn App(comptime E: type) type {
|
|||||||
const height_char = iter.next() orelse break;
|
const height_char = iter.next() orelse break;
|
||||||
const width_char = iter.next() orelse break;
|
const width_char = iter.next() orelse break;
|
||||||
|
|
||||||
// TODO: only post the event if the size has changed?
|
// TODO only post the event if the size has changed?
|
||||||
// because there might be too many resize events (which force a re-draw of the entire screen)
|
// because there might be too many resize events (which force a re-draw of the entire screen)
|
||||||
const size: Size = .{
|
const size: Size = .{
|
||||||
.rows = std.fmt.parseUnsigned(u16, height_char, 10) catch break,
|
.rows = std.fmt.parseUnsigned(u16, height_char, 10) catch break,
|
||||||
@@ -361,7 +361,7 @@ pub fn App(comptime E: type) type {
|
|||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// TODO: parse corresponding codes
|
// TODO parse corresponding codes
|
||||||
// 0x5B => parseCsi(input, &self.buf), // CSI see https://github.com/rockorager/libvaxis/blob/main/src/Parser.zig
|
// 0x5B => parseCsi(input, &self.buf), // CSI see https://github.com/rockorager/libvaxis/blob/main/src/Parser.zig
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const Style = @import("style.zig");
|
|||||||
pub const Cell = @This();
|
pub const Cell = @This();
|
||||||
|
|
||||||
style: Style = .{ .emphasis = &.{} },
|
style: Style = .{ .emphasis = &.{} },
|
||||||
// TODO: embrace `zg` dependency more due to utf-8 encoding
|
// TODO embrace `zg` dependency more due to utf-8 encoding
|
||||||
cp: u21 = ' ',
|
cp: u21 = ' ',
|
||||||
|
|
||||||
pub fn eql(this: Cell, other: Cell) bool {
|
pub fn eql(this: Cell, other: Cell) bool {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ pub const Color = enum(u8) {
|
|||||||
magenta,
|
magenta,
|
||||||
cyan,
|
cyan,
|
||||||
white,
|
white,
|
||||||
// TODO: add further colors as described in https://gist.github.com/ConnerWill/d4b6c776b509add763e17f9f113fd25b # Color / Graphics Mode - 256 Colors
|
// TODO add further colors as described in https://gist.github.com/ConnerWill/d4b6c776b509add763e17f9f113fd25b # Color / Graphics Mode - 256 Colors
|
||||||
|
|
||||||
pub inline fn write(this: Color, writer: anytype, comptime coloring: enum { fg, bg, ul }) !void {
|
pub inline fn write(this: Color, writer: anytype, comptime coloring: enum { fg, bg, ul }) !void {
|
||||||
if (this == .default) {
|
if (this == .default) {
|
||||||
|
|||||||
@@ -149,11 +149,11 @@ pub const Border = packed struct {
|
|||||||
/// Rectangle configuration struct
|
/// Rectangle configuration struct
|
||||||
pub const Rectangle = packed struct {
|
pub const Rectangle = packed struct {
|
||||||
/// `Color` to use to fill the `Rectangle` with
|
/// `Color` to use to fill the `Rectangle` with
|
||||||
/// NOTE: used as background color when rendering! such that it renders the
|
/// NOTE used as background color when rendering! such that it renders the
|
||||||
/// children accordingly without removing the coloring of the `Rectangle`
|
/// children accordingly without removing the coloring of the `Rectangle`
|
||||||
fill: Color = .default,
|
fill: Color = .default,
|
||||||
|
|
||||||
// NOTE: caller owns `Cells` slice and ensures that `cells.len == size.cols * size.rows`
|
// NOTE caller owns `Cells` slice and ensures that `cells.len == size.cols * size.rows`
|
||||||
pub fn contents(this: @This(), cells: []Cell, size: Size) void {
|
pub fn contents(this: @This(), cells: []Cell, size: Size) void {
|
||||||
std.debug.assert(cells.len == @as(usize, size.cols) * @as(usize, size.rows));
|
std.debug.assert(cells.len == @as(usize, size.cols) * @as(usize, size.rows));
|
||||||
|
|
||||||
@@ -700,7 +700,7 @@ pub fn Container(comptime Event: type) type {
|
|||||||
var element_size: Size = undefined;
|
var element_size: Size = undefined;
|
||||||
switch (layout.direction) {
|
switch (layout.direction) {
|
||||||
.horizontal => {
|
.horizontal => {
|
||||||
// TODO: this should not always be the max size property!
|
// TODO this should not always be the max size property!
|
||||||
var cols = blk: {
|
var cols = blk: {
|
||||||
if (element.properties.fixed_size.cols > 0) break :blk element.properties.fixed_size.cols;
|
if (element.properties.fixed_size.cols > 0) break :blk element.properties.fixed_size.cols;
|
||||||
break :blk element_cols;
|
break :blk element_cols;
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ pub const bg_rgb_legacy = "\x1b[48;2;{d};{d};{d}m";
|
|||||||
pub const ul_rgb_legacy = "\x1b[58;2;{d};{d};{d}m";
|
pub const ul_rgb_legacy = "\x1b[58;2;{d};{d};{d}m";
|
||||||
|
|
||||||
// Underlines
|
// Underlines
|
||||||
pub const ul_off = "\x1b[24m"; // NOTE: this could be \x1b[4:0m but is not as widely supported
|
pub const ul_off = "\x1b[24m"; // NOTE this could be \x1b[4:0m but is not as widely supported
|
||||||
pub const ul_single = "\x1b[4m";
|
pub const ul_single = "\x1b[4m";
|
||||||
pub const ul_double = "\x1b[4:2m";
|
pub const ul_double = "\x1b[4:2m";
|
||||||
pub const ul_curly = "\x1b[4:3m";
|
pub const ul_curly = "\x1b[4:3m";
|
||||||
|
|||||||
@@ -92,12 +92,12 @@ pub fn Scrollable(Event: type) type {
|
|||||||
switch (event) {
|
switch (event) {
|
||||||
.resize => |size| {
|
.resize => |size| {
|
||||||
this.size = size;
|
this.size = size;
|
||||||
// TODO: scrollbar space - depending on configuration and only if necessary?
|
// TODO scrollbar space - depending on configuration and only if necessary?
|
||||||
this.container_size = size.max(this.min_size);
|
this.container_size = size.max(this.min_size);
|
||||||
this.container_size.anchor = size.anchor;
|
this.container_size.anchor = size.anchor;
|
||||||
try this.container.handle(.{ .resize = this.container_size });
|
try this.container.handle(.{ .resize = this.container_size });
|
||||||
},
|
},
|
||||||
// TODO: other means to scroll except with the mouse? (i.e. Ctrl-u/d, k/j, etc.?)
|
// TODO other means to scroll except with the mouse? (i.e. Ctrl-u/d, k/j, etc.?)
|
||||||
.mouse => |mouse| switch (mouse.button) {
|
.mouse => |mouse| switch (mouse.button) {
|
||||||
Mouse.Button.wheel_up => if (this.container_size.rows > this.size.rows) {
|
Mouse.Button.wheel_up => if (this.container_size.rows > this.size.rows) {
|
||||||
this.anchor.row -|= 1;
|
this.anchor.row -|= 1;
|
||||||
@@ -164,7 +164,7 @@ pub fn Scrollable(Event: type) type {
|
|||||||
for (this.container.elements.items) |child| try render_container(child, container_cells, container_size);
|
for (this.container.elements.items) |child| try render_container(child, container_cells, container_size);
|
||||||
|
|
||||||
const anchor = (@as(usize, this.anchor.row) * @as(usize, container_size.cols)) + @as(usize, this.anchor.col);
|
const anchor = (@as(usize, this.anchor.row) * @as(usize, container_size.cols)) + @as(usize, this.anchor.col);
|
||||||
// TODO: render scrollbar according to configuration!
|
// TODO render scrollbar according to configuration!
|
||||||
for (0..size.rows) |row| {
|
for (0..size.rows) |row| {
|
||||||
for (0..size.cols) |col| {
|
for (0..size.cols) |col| {
|
||||||
cells[(row * size.cols) + col] = container_cells[anchor + (row * container_size.cols) + col];
|
cells[(row * size.cols) + col] = container_cells[anchor + (row * container_size.cols) + col];
|
||||||
@@ -175,8 +175,8 @@ pub fn Scrollable(Event: type) type {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: nested scrollable `Container`s?'
|
// TODO nested scrollable `Container`s?'
|
||||||
// TODO: reaction only for when the event is actually pushed to the corresponding `Container` rendered container
|
// TODO reaction only for when the event is actually pushed to the corresponding `Container` rendered container
|
||||||
|
|
||||||
test "scrollable vertical" {
|
test "scrollable vertical" {
|
||||||
const event = @import("event.zig");
|
const event = @import("event.zig");
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const Size = @import("size.zig").Size;
|
|||||||
/// System events available to every `zterm.App`
|
/// System events available to every `zterm.App`
|
||||||
pub const SystemEvent = union(enum) {
|
pub const SystemEvent = union(enum) {
|
||||||
/// Initialize event, which is send once at the beginning of the event loop and before the first render loop
|
/// Initialize event, which is send once at the beginning of the event loop and before the first render loop
|
||||||
/// TODO: not sure if this is necessary or if there is an actual usecase for this - for now it will remain
|
/// TODO not sure if this is necessary or if there is an actual usecase for this - for now it will remain
|
||||||
init,
|
init,
|
||||||
/// Quit event to signify the end of the event loop (rendering should stop afterwards)
|
/// Quit event to signify the end of the event loop (rendering should stop afterwards)
|
||||||
quit,
|
quit,
|
||||||
@@ -28,7 +28,7 @@ pub const SystemEvent = union(enum) {
|
|||||||
/// Mouse input event
|
/// Mouse input event
|
||||||
mouse: Mouse,
|
mouse: Mouse,
|
||||||
/// Focus event for mouse interaction
|
/// Focus event for mouse interaction
|
||||||
/// TODO: this should instead be a union with a `Size` to derive which container / element the focus meant for
|
/// TODO this should instead be a union with a `Size` to derive which container / element the focus meant for
|
||||||
focus: bool,
|
focus: bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ pub const Buffered = struct {
|
|||||||
|
|
||||||
/// Write *virtual screen* to alternate screen (should be called once and last during each render loop iteration in the main loop).
|
/// Write *virtual screen* to alternate screen (should be called once and last during each render loop iteration in the main loop).
|
||||||
pub fn flush(this: *@This()) !void {
|
pub fn flush(this: *@This()) !void {
|
||||||
// TODO: measure timings of rendered frames?
|
// TODO measure timings of rendered frames?
|
||||||
const writer = terminal.writer();
|
const writer = terminal.writer();
|
||||||
const s = this.screen;
|
const s = this.screen;
|
||||||
const vs = this.virtual_screen;
|
const vs = this.virtual_screen;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ pub fn value(this: Style, writer: anytype, cp: u21) !void {
|
|||||||
try std.fmt.format(writer, ";", .{});
|
try std.fmt.format(writer, ";", .{});
|
||||||
try this.bg.write(writer, .bg);
|
try this.bg.write(writer, .bg);
|
||||||
// underline
|
// underline
|
||||||
// FIX: assert that if the underline property is set that the ul style and the attribute for underlining is available
|
// FIX assert that if the underline property is set that the ul style and the attribute for underlining is available
|
||||||
try std.fmt.format(writer, ";", .{});
|
try std.fmt.format(writer, ";", .{});
|
||||||
try this.ul.write(writer, .ul);
|
try this.ul.write(writer, .ul);
|
||||||
// append styles (aka attributes like bold, italic, strikethrough, etc.)
|
// append styles (aka attributes like bold, italic, strikethrough, etc.)
|
||||||
@@ -67,6 +67,6 @@ pub fn value(this: Style, writer: anytype, cp: u21) !void {
|
|||||||
try std.fmt.format(writer, "\x1b[0m", .{});
|
try std.fmt.format(writer, "\x1b[0m", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement helper functions for terminal capabilities:
|
// TODO implement helper functions for terminal capabilities:
|
||||||
// - links / url display (osc 8)
|
// - links / url display (osc 8)
|
||||||
// - show / hide cursor?
|
// - show / hide cursor?
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const DisplayWidth = @import("DisplayWidth");
|
|||||||
const Position = @import("size.zig").Position;
|
const Position = @import("size.zig").Position;
|
||||||
const Size = @import("size.zig").Size;
|
const Size = @import("size.zig").Size;
|
||||||
|
|
||||||
// TODO: how would I describe the expected screens?
|
// TODO how would I describe the expected screens?
|
||||||
// - including styling?
|
// - including styling?
|
||||||
// - compare generated strings instead? -> how would this be generated for the user?
|
// - compare generated strings instead? -> how would this be generated for the user?
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user