bump to zig 0.14.dev
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m33s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m33s
This commit is contained in:
@@ -17,7 +17,7 @@ jobs:
|
|||||||
- name: Setup zig installation
|
- name: Setup zig installation
|
||||||
uses: mlugg/setup-zig@v1
|
uses: mlugg/setup-zig@v1
|
||||||
with:
|
with:
|
||||||
version: 0.13.0
|
version: master
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: zig build --release=fast
|
run: zig build --release=fast
|
||||||
- name: Release build artifacts
|
- name: Release build artifacts
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ jobs:
|
|||||||
- name: Setup zig installation
|
- name: Setup zig installation
|
||||||
uses: mlugg/setup-zig@v1
|
uses: mlugg/setup-zig@v1
|
||||||
with:
|
with:
|
||||||
version: 0.13.0
|
version: master
|
||||||
- name: Lint check
|
- name: Lint check
|
||||||
run: zig fmt --check .
|
run: zig fmt --check .
|
||||||
- name: Spell checking
|
- name: Spell checking
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
`zterm` is a terminal user interface library to implement terminal (fullscreen or inline) applications.
|
`zterm` is a terminal user interface library to implement terminal (fullscreen or inline) applications.
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> Currently version `0.13.0` is officially supported. Builds using the master version might not work.
|
> Only builds using the master version might will work.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,8 @@
|
|||||||
.hash = "122055beff332830a391e9895c044d33b15ea21063779557024b46169fb1984c6e40",
|
.hash = "122055beff332830a391e9895c044d33b15ea21063779557024b46169fb1984c6e40",
|
||||||
},
|
},
|
||||||
.interface = .{
|
.interface = .{
|
||||||
.url = "git+https://github.com/nilslice/zig-interface#c6ca205de75969fdcf04542f48d813d529196594",
|
.url = "git+https://github.com/yves-biener/zig-interface#ef47e045df19e09250fff45c0702d014fb3d3c37",
|
||||||
.hash = "1220401627a97a7b429acd084bd3447fe5838122d71bbca57061906a2c3baf1c2e98",
|
.hash = "1220a442e8d9b813572bab7a55eef504c83b628f0b17fd283e776dbc1d1a3d98e842",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ pub fn App(comptime E: type, comptime R: fn (comptime bool) type, comptime fulls
|
|||||||
.mask = std.posix.empty_sigset,
|
.mask = std.posix.empty_sigset,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
};
|
};
|
||||||
std.posix.sigaction(std.posix.SIG.WINCH, &winch_act, null) catch @panic("could not attach signal WINCH");
|
std.posix.sigaction(std.posix.SIG.WINCH, &winch_act, null);
|
||||||
|
|
||||||
try registerWinch(.{
|
try registerWinch(.{
|
||||||
.context = this,
|
.context = this,
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ pub fn mergeTaggedUnions(comptime A: type, comptime B: type) type {
|
|||||||
if (!isTaggedUnion(A) or !isTaggedUnion(B)) {
|
if (!isTaggedUnion(A) or !isTaggedUnion(B)) {
|
||||||
@compileError("Both types for merging tagged unions need to be of type `union(enum)`.");
|
@compileError("Both types for merging tagged unions need to be of type `union(enum)`.");
|
||||||
}
|
}
|
||||||
const a_fields = @typeInfo(A).Union.fields;
|
const a_fields = @typeInfo(A).@"union".fields;
|
||||||
const a_fields_tag = @typeInfo(A).Union.tag_type.?;
|
const a_fields_tag = @typeInfo(A).@"union".tag_type.?;
|
||||||
const a_enum_fields = @typeInfo(a_fields_tag).Enum.fields;
|
const a_enum_fields = @typeInfo(a_fields_tag).@"enum".fields;
|
||||||
const b_fields = @typeInfo(B).Union.fields;
|
const b_fields = @typeInfo(B).@"union".fields;
|
||||||
const b_fields_tag = @typeInfo(B).Union.tag_type.?;
|
const b_fields_tag = @typeInfo(B).@"union".tag_type.?;
|
||||||
const b_enum_fields = @typeInfo(b_fields_tag).Enum.fields;
|
const b_enum_fields = @typeInfo(b_fields_tag).@"enum".fields;
|
||||||
var fields: [a_fields.len + b_fields.len]std.builtin.Type.UnionField = undefined;
|
var fields: [a_fields.len + b_fields.len]std.builtin.Type.UnionField = undefined;
|
||||||
var enum_fields: [a_fields.len + b_fields.len]std.builtin.Type.EnumField = undefined;
|
var enum_fields: [a_fields.len + b_fields.len]std.builtin.Type.EnumField = undefined;
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
@@ -49,19 +49,19 @@ pub fn mergeTaggedUnions(comptime A: type, comptime B: type) type {
|
|||||||
|
|
||||||
const log2_i = @bitSizeOf(@TypeOf(i)) - @clz(i);
|
const log2_i = @bitSizeOf(@TypeOf(i)) - @clz(i);
|
||||||
|
|
||||||
const EventType = @Type(.{ .Int = .{
|
const EventType = @Type(.{ .int = .{
|
||||||
.signedness = .unsigned,
|
.signedness = .unsigned,
|
||||||
.bits = log2_i,
|
.bits = log2_i,
|
||||||
} });
|
} });
|
||||||
|
|
||||||
const Event = @Type(.{ .Enum = .{
|
const Event = @Type(.{ .@"enum" = .{
|
||||||
.tag_type = EventType,
|
.tag_type = EventType,
|
||||||
.fields = enum_fields[0..],
|
.fields = enum_fields[0..],
|
||||||
.decls = &.{},
|
.decls = &.{},
|
||||||
.is_exhaustive = true,
|
.is_exhaustive = true,
|
||||||
} });
|
} });
|
||||||
|
|
||||||
return @Type(.{ .Union = .{
|
return @Type(.{ .@"union" = .{
|
||||||
.layout = .auto,
|
.layout = .auto,
|
||||||
.tag_type = Event,
|
.tag_type = Event,
|
||||||
.fields = fields[0..],
|
.fields = fields[0..],
|
||||||
@@ -72,7 +72,7 @@ pub fn mergeTaggedUnions(comptime A: type, comptime B: type) type {
|
|||||||
// Determine at `comptime` whether the provided type `E` is an `union(enum)`.
|
// Determine at `comptime` whether the provided type `E` is an `union(enum)`.
|
||||||
pub fn isTaggedUnion(comptime E: type) bool {
|
pub fn isTaggedUnion(comptime E: type) bool {
|
||||||
switch (@typeInfo(E)) {
|
switch (@typeInfo(E)) {
|
||||||
.Union => |u| {
|
.@"union" => |u| {
|
||||||
if (u.tag_type) |_| {} else {
|
if (u.tag_type) |_| {} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
if (!isTaggedUnion(Element)) {
|
if (!isTaggedUnion(Element)) {
|
||||||
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[0].name, "layout")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[0].name, "layout")) {
|
||||||
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[1].name, "widget")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[1].name, "widget")) {
|
||||||
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
||||||
}
|
}
|
||||||
const Events = std.ArrayList(Event);
|
const Events = std.ArrayList(Event);
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
if (!isTaggedUnion(Element)) {
|
if (!isTaggedUnion(Element)) {
|
||||||
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[0].name, "layout")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[0].name, "layout")) {
|
||||||
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[1].name, "widget")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[1].name, "widget")) {
|
||||||
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
||||||
}
|
}
|
||||||
const Container = struct {
|
const Container = struct {
|
||||||
@@ -31,8 +31,8 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
container_size: u8, // 0 - 100 %
|
container_size: u8, // 0 - 100 %
|
||||||
};
|
};
|
||||||
const Containers = std.ArrayList(Container);
|
const Containers = std.ArrayList(Container);
|
||||||
const LayoutType = @typeInfo(Element).Union.fields[0].type;
|
const LayoutType = @typeInfo(Element).@"union".fields[0].type;
|
||||||
const WidgetType = @typeInfo(Element).Union.fields[1].type;
|
const WidgetType = @typeInfo(Element).@"union".fields[1].type;
|
||||||
const Events = std.ArrayList(Event);
|
const Events = std.ArrayList(Event);
|
||||||
return struct {
|
return struct {
|
||||||
// TODO: current focused `Element`?
|
// TODO: current focused `Element`?
|
||||||
@@ -44,20 +44,20 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
pub fn init(allocator: std.mem.Allocator, children: anytype) *@This() {
|
pub fn init(allocator: std.mem.Allocator, children: anytype) *@This() {
|
||||||
const ArgsType = @TypeOf(children);
|
const ArgsType = @TypeOf(children);
|
||||||
const args_type_info = @typeInfo(ArgsType);
|
const args_type_info = @typeInfo(ArgsType);
|
||||||
if (args_type_info != .Struct) {
|
if (args_type_info != .@"struct") {
|
||||||
@compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
|
@compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
|
||||||
}
|
}
|
||||||
comptime var total_size = 0;
|
comptime var total_size = 0;
|
||||||
const fields_info = args_type_info.Struct.fields;
|
const fields_info = args_type_info.@"struct".fields;
|
||||||
var containers = Containers.initCapacity(allocator, fields_info.len) catch @panic("OOM");
|
var containers = Containers.initCapacity(allocator, fields_info.len) catch @panic("OOM");
|
||||||
inline for (comptime fields_info) |field| {
|
inline for (comptime fields_info) |field| {
|
||||||
const child = @field(children, field.name);
|
const child = @field(children, field.name);
|
||||||
const ChildType = @TypeOf(child);
|
const ChildType = @TypeOf(child);
|
||||||
const child_type_info = @typeInfo(ChildType);
|
const child_type_info = @typeInfo(ChildType);
|
||||||
if (child_type_info != .Struct) {
|
if (child_type_info != .@"struct") {
|
||||||
@compileError("expected tuple or struct as child type, found " ++ @typeName(ChildType));
|
@compileError("expected tuple or struct as child type, found " ++ @typeName(ChildType));
|
||||||
}
|
}
|
||||||
const child_fields = child_type_info.Struct.fields;
|
const child_fields = child_type_info.@"struct".fields;
|
||||||
if (child_fields.len != 2) {
|
if (child_fields.len != 2) {
|
||||||
@compileError("expected nested tuple or struct to have exactly 2 fields, but found " ++ child_fields.len);
|
@compileError("expected nested tuple or struct to have exactly 2 fields, but found " ++ child_fields.len);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,15 +18,15 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
if (!isTaggedUnion(Element)) {
|
if (!isTaggedUnion(Element)) {
|
||||||
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[0].name, "layout")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[0].name, "layout")) {
|
||||||
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[1].name, "widget")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[1].name, "widget")) {
|
||||||
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
||||||
}
|
}
|
||||||
const Elements = std.ArrayList(Element);
|
const Elements = std.ArrayList(Element);
|
||||||
const LayoutType = @typeInfo(Element).Union.fields[0].type;
|
const LayoutType = @typeInfo(Element).@"union".fields[0].type;
|
||||||
const WidgetType = @typeInfo(Element).Union.fields[1].type;
|
const WidgetType = @typeInfo(Element).@"union".fields[1].type;
|
||||||
const Events = std.ArrayList(Event);
|
const Events = std.ArrayList(Event);
|
||||||
return struct {
|
return struct {
|
||||||
// TODO: current focused `Element`?
|
// TODO: current focused `Element`?
|
||||||
@@ -38,10 +38,10 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
pub fn init(allocator: std.mem.Allocator, children: anytype) *@This() {
|
pub fn init(allocator: std.mem.Allocator, children: anytype) *@This() {
|
||||||
const ArgsType = @TypeOf(children);
|
const ArgsType = @TypeOf(children);
|
||||||
const args_type_info = @typeInfo(ArgsType);
|
const args_type_info = @typeInfo(ArgsType);
|
||||||
if (args_type_info != .Struct) {
|
if (args_type_info != .@"struct") {
|
||||||
@compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
|
@compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
|
||||||
}
|
}
|
||||||
const fields_info = args_type_info.Struct.fields;
|
const fields_info = args_type_info.@"struct".fields;
|
||||||
var elements = Elements.initCapacity(allocator, fields_info.len) catch @panic("OOM");
|
var elements = Elements.initCapacity(allocator, fields_info.len) catch @panic("OOM");
|
||||||
inline for (comptime fields_info) |field| {
|
inline for (comptime fields_info) |field| {
|
||||||
const child = @field(children, field.name);
|
const child = @field(children, field.name);
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
if (!isTaggedUnion(Element)) {
|
if (!isTaggedUnion(Element)) {
|
||||||
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[0].name, "layout")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[0].name, "layout")) {
|
||||||
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[1].name, "widget")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[1].name, "widget")) {
|
||||||
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
||||||
}
|
}
|
||||||
const Events = std.ArrayList(Event);
|
const Events = std.ArrayList(Event);
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
if (!isTaggedUnion(Element)) {
|
if (!isTaggedUnion(Element)) {
|
||||||
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[0].name, "layout")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[0].name, "layout")) {
|
||||||
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[1].name, "widget")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[1].name, "widget")) {
|
||||||
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
||||||
}
|
}
|
||||||
const Events = std.ArrayList(Event);
|
const Events = std.ArrayList(Event);
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
if (!isTaggedUnion(Element)) {
|
if (!isTaggedUnion(Element)) {
|
||||||
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[0].name, "layout")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[0].name, "layout")) {
|
||||||
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[1].name, "widget")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[1].name, "widget")) {
|
||||||
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
||||||
}
|
}
|
||||||
const Container = struct {
|
const Container = struct {
|
||||||
@@ -31,8 +31,8 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
container_size: u8, // 0 - 100 %
|
container_size: u8, // 0 - 100 %
|
||||||
};
|
};
|
||||||
const Containers = std.ArrayList(Container);
|
const Containers = std.ArrayList(Container);
|
||||||
const LayoutType = @typeInfo(Element).Union.fields[0].type;
|
const LayoutType = @typeInfo(Element).@"union".fields[0].type;
|
||||||
const WidgetType = @typeInfo(Element).Union.fields[1].type;
|
const WidgetType = @typeInfo(Element).@"union".fields[1].type;
|
||||||
const Events = std.ArrayList(Event);
|
const Events = std.ArrayList(Event);
|
||||||
return struct {
|
return struct {
|
||||||
// TODO: current focused `Element`?
|
// TODO: current focused `Element`?
|
||||||
@@ -44,20 +44,20 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
pub fn init(allocator: std.mem.Allocator, children: anytype) *@This() {
|
pub fn init(allocator: std.mem.Allocator, children: anytype) *@This() {
|
||||||
const ArgsType = @TypeOf(children);
|
const ArgsType = @TypeOf(children);
|
||||||
const args_type_info = @typeInfo(ArgsType);
|
const args_type_info = @typeInfo(ArgsType);
|
||||||
if (args_type_info != .Struct) {
|
if (args_type_info != .@"struct") {
|
||||||
@compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
|
@compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
|
||||||
}
|
}
|
||||||
comptime var total_size = 0;
|
comptime var total_size = 0;
|
||||||
const fields_info = args_type_info.Struct.fields;
|
const fields_info = args_type_info.@"struct".fields;
|
||||||
var containers = Containers.initCapacity(allocator, fields_info.len) catch @panic("OOM");
|
var containers = Containers.initCapacity(allocator, fields_info.len) catch @panic("OOM");
|
||||||
inline for (comptime fields_info) |field| {
|
inline for (comptime fields_info) |field| {
|
||||||
const child = @field(children, field.name);
|
const child = @field(children, field.name);
|
||||||
const ChildType = @TypeOf(child);
|
const ChildType = @TypeOf(child);
|
||||||
const child_type_info = @typeInfo(ChildType);
|
const child_type_info = @typeInfo(ChildType);
|
||||||
if (child_type_info != .Struct) {
|
if (child_type_info != .@"struct") {
|
||||||
@compileError("expected tuple or struct as child type, found " ++ @typeName(ChildType));
|
@compileError("expected tuple or struct as child type, found " ++ @typeName(ChildType));
|
||||||
}
|
}
|
||||||
const child_fields = child_type_info.Struct.fields;
|
const child_fields = child_type_info.@"struct".fields;
|
||||||
if (child_fields.len != 2) {
|
if (child_fields.len != 2) {
|
||||||
@compileError("expected nested tuple or struct to have exactly 2 fields, but found " ++ child_fields.len);
|
@compileError("expected nested tuple or struct to have exactly 2 fields, but found " ++ child_fields.len);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,15 +18,15 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
if (!isTaggedUnion(Element)) {
|
if (!isTaggedUnion(Element)) {
|
||||||
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[0].name, "layout")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[0].name, "layout")) {
|
||||||
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
||||||
}
|
}
|
||||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[1].name, "widget")) {
|
if (!std.mem.eql(u8, @typeInfo(Element).@"union".fields[1].name, "widget")) {
|
||||||
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
||||||
}
|
}
|
||||||
const Elements = std.ArrayList(Element);
|
const Elements = std.ArrayList(Element);
|
||||||
const LayoutType = @typeInfo(Element).Union.fields[0].type;
|
const LayoutType = @typeInfo(Element).@"union".fields[0].type;
|
||||||
const WidgetType = @typeInfo(Element).Union.fields[1].type;
|
const WidgetType = @typeInfo(Element).@"union".fields[1].type;
|
||||||
const Events = std.ArrayList(Event);
|
const Events = std.ArrayList(Event);
|
||||||
return struct {
|
return struct {
|
||||||
// TODO: current focused `Element`?
|
// TODO: current focused `Element`?
|
||||||
@@ -38,10 +38,10 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
|||||||
pub fn init(allocator: std.mem.Allocator, children: anytype) *@This() {
|
pub fn init(allocator: std.mem.Allocator, children: anytype) *@This() {
|
||||||
const ArgsType = @TypeOf(children);
|
const ArgsType = @TypeOf(children);
|
||||||
const args_type_info = @typeInfo(ArgsType);
|
const args_type_info = @typeInfo(ArgsType);
|
||||||
if (args_type_info != .Struct) {
|
if (args_type_info != .@"struct") {
|
||||||
@compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
|
@compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
|
||||||
}
|
}
|
||||||
const fields_info = args_type_info.Struct.fields;
|
const fields_info = args_type_info.@"struct".fields;
|
||||||
var elements = Elements.initCapacity(allocator, fields_info.len) catch @panic("OOM");
|
var elements = Elements.initCapacity(allocator, fields_info.len) catch @panic("OOM");
|
||||||
inline for (comptime fields_info) |field| {
|
inline for (comptime fields_info) |field| {
|
||||||
const child = @field(children, field.name);
|
const child = @field(children, field.name);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub const ReportMode = enum {
|
|||||||
pub fn getTerminalSize() Size {
|
pub fn getTerminalSize() Size {
|
||||||
var ws: std.posix.winsize = undefined;
|
var ws: std.posix.winsize = undefined;
|
||||||
_ = std.posix.system.ioctl(std.posix.STDIN_FILENO, std.posix.T.IOCGWINSZ, @intFromPtr(&ws));
|
_ = std.posix.system.ioctl(std.posix.STDIN_FILENO, std.posix.T.IOCGWINSZ, @intFromPtr(&ws));
|
||||||
return .{ .cols = ws.ws_col, .rows = ws.ws_row };
|
return .{ .cols = ws.col, .rows = ws.row };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn saveScreen() !void {
|
pub fn saveScreen() !void {
|
||||||
|
|||||||
Reference in New Issue
Block a user