chor: bumb zig version to 0.16.0-dev
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 1m41s
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 1m41s
This commit is contained in:
@@ -57,18 +57,20 @@ const Spinner = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const InputField = struct {
|
const InputField = struct {
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
input: std.ArrayList(u21),
|
input: std.ArrayList(u21),
|
||||||
queue: *App.Queue,
|
queue: *App.Queue,
|
||||||
|
|
||||||
pub fn init(allocator: std.mem.Allocator, queue: *App.Queue) @This() {
|
pub fn init(allocator: std.mem.Allocator, queue: *App.Queue) @This() {
|
||||||
return .{
|
return .{
|
||||||
.input = .init(allocator),
|
.allocator = allocator,
|
||||||
|
.input = std.ArrayList(u21).initCapacity(allocator, 8) catch unreachable,
|
||||||
.queue = queue,
|
.queue = queue,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(this: @This()) void {
|
pub fn deinit(this: *@This()) void {
|
||||||
this.input.deinit();
|
this.input.deinit(this.allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn element(this: *@This()) App.Element {
|
pub fn element(this: *@This()) App.Element {
|
||||||
@@ -85,10 +87,10 @@ const InputField = struct {
|
|||||||
const this: *@This() = @ptrCast(@alignCast(ctx));
|
const this: *@This() = @ptrCast(@alignCast(ctx));
|
||||||
switch (event) {
|
switch (event) {
|
||||||
.key => |key| {
|
.key => |key| {
|
||||||
if (key.isAscii()) try this.input.append(key.cp);
|
if (key.isAscii()) try this.input.append(this.allocator, key.cp);
|
||||||
|
|
||||||
if (key.eql(.{ .cp = zterm.input.Enter }) or key.eql(.{ .cp = zterm.input.KpEnter }))
|
if (key.eql(.{ .cp = zterm.input.Enter }) or key.eql(.{ .cp = zterm.input.KpEnter }))
|
||||||
this.queue.push(.{ .accept = try this.input.toOwnedSlice() });
|
this.queue.push(.{ .accept = try this.input.toOwnedSlice(this.allocator) });
|
||||||
|
|
||||||
if (key.eql(.{ .cp = zterm.input.Backspace }))
|
if (key.eql(.{ .cp = zterm.input.Backspace }))
|
||||||
_ = this.input.pop();
|
_ = this.input.pop();
|
||||||
|
|||||||
@@ -622,17 +622,17 @@ pub fn Container(comptime Event: type) type {
|
|||||||
.size = .{},
|
.size = .{},
|
||||||
.properties = properties,
|
.properties = properties,
|
||||||
.element = element,
|
.element = element,
|
||||||
.elements = std.ArrayList(@This()).init(allocator),
|
.elements = try std.ArrayList(@This()).initCapacity(allocator, 2),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(this: *const @This()) void {
|
pub fn deinit(this: *@This()) void {
|
||||||
for (this.elements.items) |*element| element.deinit();
|
for (this.elements.items) |*element| element.deinit();
|
||||||
this.elements.deinit();
|
this.elements.deinit(this.allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append(this: *@This(), element: @This()) !void {
|
pub fn append(this: *@This(), element: @This()) !void {
|
||||||
try this.elements.append(element);
|
try this.elements.append(this.allocator, element);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reposition(this: *@This(), origin: Point) void {
|
pub fn reposition(this: *@This(), origin: Point) void {
|
||||||
|
|||||||
@@ -361,6 +361,9 @@ pub fn Scrollable(Event: type) type {
|
|||||||
};
|
};
|
||||||
} // Scrollable(Event: type)
|
} // Scrollable(Event: type)
|
||||||
|
|
||||||
|
// TODO features
|
||||||
|
// - clear input (with and without retaining of capacity) through an public api
|
||||||
|
// - make handle / content functions public
|
||||||
pub fn Input(Event: type, Queue: type) fn (meta.FieldEnum(Event)) type {
|
pub fn Input(Event: type, Queue: type) fn (meta.FieldEnum(Event)) type {
|
||||||
// NOTE the struct is necessary, as otherwise I cannot point to the function I want to return
|
// NOTE the struct is necessary, as otherwise I cannot point to the function I want to return
|
||||||
const input_struct = struct {
|
const input_struct = struct {
|
||||||
@@ -386,6 +389,7 @@ pub fn Input(Event: type, Queue: type) fn (meta.FieldEnum(Event)) type {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
return struct {
|
return struct {
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
/// Offset from the end describing the current position of the cursor.
|
/// Offset from the end describing the current position of the cursor.
|
||||||
cursor_offset: usize = 0,
|
cursor_offset: usize = 0,
|
||||||
/// Configuration for the InputField.
|
/// Configuration for the InputField.
|
||||||
@@ -406,14 +410,15 @@ pub fn Input(Event: type, Queue: type) fn (meta.FieldEnum(Event)) type {
|
|||||||
|
|
||||||
pub fn init(allocator: std.mem.Allocator, queue: *Queue, configuration: Configuration) @This() {
|
pub fn init(allocator: std.mem.Allocator, queue: *Queue, configuration: Configuration) @This() {
|
||||||
return .{
|
return .{
|
||||||
|
.allocator = allocator,
|
||||||
.configuration = configuration,
|
.configuration = configuration,
|
||||||
.input = .init(allocator),
|
.input = std.ArrayList(u21).initCapacity(allocator, 8) catch unreachable,
|
||||||
.queue = queue,
|
.queue = queue,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(this: @This()) void {
|
pub fn deinit(this: *@This()) void {
|
||||||
this.input.deinit();
|
this.input.deinit(this.allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn element(this: *@This()) Element(Event) {
|
pub fn element(this: *@This()) Element(Event) {
|
||||||
@@ -497,7 +502,7 @@ pub fn Input(Event: type, Queue: type) fn (meta.FieldEnum(Event)) type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// usual input keys
|
// usual input keys
|
||||||
if (key.isAscii()) try this.input.insert(this.input.items.len - this.cursor_offset, key.cp);
|
if (key.isAscii()) try this.input.insert(this.allocator, this.input.items.len - this.cursor_offset, key.cp);
|
||||||
|
|
||||||
if (key.eql(.{ .cp = input.Backspace })) {
|
if (key.eql(.{ .cp = input.Backspace })) {
|
||||||
if (this.cursor_offset < this.input.items.len) {
|
if (this.cursor_offset < this.input.items.len) {
|
||||||
@@ -518,9 +523,9 @@ pub fn Input(Event: type, Queue: type) fn (meta.FieldEnum(Event)) type {
|
|||||||
switch (event_type) {
|
switch (event_type) {
|
||||||
.ascii => {
|
.ascii => {
|
||||||
// NOTE convert unicode characters to ascii characters; if non ascii characters are found this is will fail!
|
// NOTE convert unicode characters to ascii characters; if non ascii characters are found this is will fail!
|
||||||
var slice = try this.input.allocator.alloc(u8, this.input.items.len);
|
var slice = try this.allocator.alloc(u8, this.input.items.len);
|
||||||
for (0.., this.input.items) |i, c| slice[i] = @intCast(c);
|
for (0.., this.input.items) |i, c| slice[i] = @intCast(c);
|
||||||
this.input.clearAndFree();
|
this.input.clearAndFree(this.allocator);
|
||||||
this.queue.push(@unionInit(
|
this.queue.push(@unionInit(
|
||||||
Event,
|
Event,
|
||||||
@tagName(accept_event),
|
@tagName(accept_event),
|
||||||
@@ -530,7 +535,7 @@ pub fn Input(Event: type, Queue: type) fn (meta.FieldEnum(Event)) type {
|
|||||||
.utf8 => this.queue.push(@unionInit(
|
.utf8 => this.queue.push(@unionInit(
|
||||||
Event,
|
Event,
|
||||||
@tagName(accept_event),
|
@tagName(accept_event),
|
||||||
try this.input.toOwnedSlice(),
|
try this.input.toOwnedSlice(this.allocator),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
this.cursor_offset = 0;
|
this.cursor_offset = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user