Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zig: update for 0.14.0 #114

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/configure-pages@v2
- uses: mlugg/setup-zig@v1
with:
version: 0.13.0
version: 0.14.0-dev.2456+a68119f8f
- run: zig build docs
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ jobs:
- uses: actions/checkout@v3
- uses: mlugg/setup-zig@v1
with:
version: 0.13.0
version: 0.14.0-dev.2456+a68119f8f
- run: zig build test
check-fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: mlugg/setup-zig@v1
with:
version: 0.13.0
version: 0.14.0-dev.2456+a68119f8f
- run: zig fmt --check .
8 changes: 4 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
.minimum_zig_version = "0.13.0",
.dependencies = .{
.zigimg = .{
.url = "git+https://github.com/zigimg/zigimg#3a667bdb3d7f0955a5a51c8468eac83210c1439e",
.hash = "1220dd654ef941fc76fd96f9ec6adadf83f69b9887a0d3f4ee5ac0a1a3e11be35cf5",
.url = "git+https://github.com/zigimg/zigimg#1496bdd39bc35a795e8514c493114e2ab82f8cf3",
.hash = "1220a5e36ab5e2be076f8765d165f3368a4c9f326dc77ac61c1e90bbce312fc37a39",
},
.zg = .{
.url = "https://codeberg.org/atman/zg/archive/v0.13.2.tar.gz",
.hash = "122055beff332830a391e9895c044d33b15ea21063779557024b46169fb1984c6e40",
.url = "git+https://codeberg.org/utkarshmalik/zg#7ca90b6f8796cd6615ddc61e12cd292ea26662ce",
.hash = "1220f3e29bc40856bfc06e0ee133f814b0011c76de987d8a6a458c2f34d82708899a",
},
},
.paths = .{
Expand Down
14 changes: 12 additions & 2 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,20 @@ pub fn init(alloc: std.mem.Allocator, opts: Vaxis.Options) !Vaxis {
return Vaxis.init(alloc, opts);
}

pub const Panic = struct {
pub const call = panic_handler;
pub const sentinelMismatch = std.debug.FormattedPanic.sentinelMismatch;
pub const unwrapError = std.debug.FormattedPanic.unwrapError;
pub const outOfBounds = std.debug.FormattedPanic.outOfBounds;
pub const startGreaterThanEnd = std.debug.FormattedPanic.startGreaterThanEnd;
pub const inactiveUnionField = std.debug.FormattedPanic.inactiveUnionField;
pub const messages = std.debug.FormattedPanic.messages;
};

/// Resets terminal state on a panic, then calls the default zig panic handler
pub fn panic_handler(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn {
pub fn panic_handler(msg: []const u8, _: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn {
recover();
std.builtin.default_panic(msg, error_return_trace, ret_addr);
std.debug.defaultPanic(msg, ret_addr);
}

/// Resets the terminal state using the global tty instance. Use this only to recover during a panic
Expand Down
20 changes: 10 additions & 10 deletions src/tty.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub const PosixTty = struct {
},
.flags = 0,
};
try posix.sigaction(posix.SIG.WINCH, &act, null);
posix.sigaction(posix.SIG.WINCH, &act, null);
handler_installed = true;

const self: PosixTty = .{
Expand Down Expand Up @@ -97,7 +97,7 @@ pub const PosixTty = struct {
},
.flags = 0,
};
posix.sigaction(posix.SIG.WINCH, &act, null) catch {};
posix.sigaction(posix.SIG.WINCH, &act, null);
}

/// Write bytes to the tty
Expand Down Expand Up @@ -187,19 +187,19 @@ pub const PosixTty = struct {
/// Get the window size from the kernel
pub fn getWinsize(fd: posix.fd_t) !Winsize {
var winsize = posix.winsize{
.ws_row = 0,
.ws_col = 0,
.ws_xpixel = 0,
.ws_ypixel = 0,
.row = 0,
.col = 0,
.xpixel = 0,
.ypixel = 0,
};

const err = posix.system.ioctl(fd, posix.T.IOCGWINSZ, @intFromPtr(&winsize));
if (posix.errno(err) == .SUCCESS)
return Winsize{
.rows = winsize.ws_row,
.cols = winsize.ws_col,
.x_pixel = winsize.ws_xpixel,
.y_pixel = winsize.ws_ypixel,
.rows = winsize.row,
.cols = winsize.col,
.x_pixel = winsize.xpixel,
.y_pixel = winsize.ypixel,
};
return error.IoctlError;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vxfw/FlexColumn.zig
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn draw(self: *const FlexColumn, ctx: vxfw.DrawContext) Allocator.Error!vxfw
second_pass_height += surf.size.height;
}

const size = .{ .width = max_width, .height = second_pass_height };
const size: vxfw.Size = .{ .width = max_width, .height = second_pass_height };
return .{
.size = size,
.widget = self.widget(),
Expand Down
2 changes: 1 addition & 1 deletion src/vxfw/FlexRow.zig
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn draw(self: *const FlexRow, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Su
max_height = @max(max_height, surf.size.height);
second_pass_width += surf.size.width;
}
const size = .{ .width = second_pass_width, .height = max_height };
const size: vxfw.Size = .{ .width = second_pass_width, .height = max_height };
return .{
.size = size,
.widget = self.widget(),
Expand Down
2 changes: 1 addition & 1 deletion src/vxfw/Padding.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn draw(self: *const Padding, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Su
.origin = .{ .row = pad.top, .col = pad.left },
};

const size = .{
const size: vxfw.Size = .{
.width = child_surface.size.width + (pad.right + pad.left),
.height = child_surface.size.height + (pad.top + pad.bottom),
};
Expand Down
12 changes: 6 additions & 6 deletions src/widgets/Table.zig
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ pub fn drawTable(
const DataListT = @TypeOf(data_list);
const data_ti = @typeInfo(DataListT);
switch (data_ti) {
.Pointer => |ptr| {
.pointer => |ptr| {
if (ptr.size != .Slice) return error.UnsupportedTableDataType;
break :getData data_list;
},
.Struct => {
.@"struct" => {
const di_fields = meta.fields(DataListT);
const al_fields = meta.fields(std.ArrayList([]const u8));
const mal_fields = meta.fields(std.MultiArrayList(struct { a: u8 = 0, b: u32 = 0 }));
Expand Down Expand Up @@ -168,7 +168,7 @@ pub fn drawTable(
const mal_slice = data_list.slice();
const DataT = dataType: {
const fn_info = @typeInfo(@TypeOf(@field(@TypeOf(mal_slice), "get")));
break :dataType fn_info.Fn.return_type orelse @panic("No Child Type");
break :dataType fn_info.@"fn".return_type orelse @panic("No Child Type");
};
var data_out_list = std.ArrayList(DataT).init(_alloc);
for (0..mal_slice.len) |idx| try data_out_list.append(mal_slice.get(idx));
Expand Down Expand Up @@ -340,10 +340,10 @@ pub fn drawTable(
},
else => nonStr: {
switch (@typeInfo(ItemT)) {
.Enum => break :nonStr @tagName(item),
.Optional => {
.@"enum" => break :nonStr @tagName(item),
.optional => {
const opt_item = item orelse break :nonStr "-";
switch (@typeInfo(ItemT).Optional.child) {
switch (@typeInfo(ItemT).optional.child) {
[]const u8 => break :nonStr opt_item,
[][]const u8, []const []const u8 => {
break :nonStr if (alloc) |_alloc| try fmt.allocPrint(_alloc, "{s}", .{opt_item}) else fmt.comptimePrint("[unsupported ({s})]", .{@typeName(DataT)});
Expand Down
13 changes: 8 additions & 5 deletions src/widgets/View.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub fn window(self: *View) Window {
return .{
.x_off = 0,
.y_off = 0,
.parent_x_off = 0,
.parent_y_off = 0,
.width = self.screen.width,
.height = self.screen.height,
.screen = &self.screen,
Expand All @@ -69,11 +71,12 @@ pub fn draw(self: *View, win: Window, opts: DrawOptions) void {
const width = @min(win.width, self.screen.width - opts.x_off);
const height = @min(win.height, self.screen.height - opts.y_off);

for (0..height) |row| {
const src_start = opts.x_off + ((row + opts.y_off) * self.screen.width);
const src_end = src_start + width;
const dst_start = win.x_off + ((row + win.y_off) * win.screen.width);
const dst_end = dst_start + width;
for (0..height) |_row| {
const row: i17 = @intCast(_row);
const src_start: usize = @intCast(opts.x_off + ((row + opts.y_off) * self.screen.width));
const src_end: usize = @intCast(src_start + width);
const dst_start: usize = @intCast(win.x_off + ((row + win.y_off) * win.screen.width));
const dst_end: usize = @intCast(dst_start + width);
@memcpy(win.screen.buf[dst_start..dst_end], self.screen.buf[src_start..src_end]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/terminal/Command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn spawn(self: *Command, allocator: std.mem.Allocator) !void {
},
.flags = 0,
};
try posix.sigaction(posix.SIG.CHLD, &act, null);
posix.sigaction(posix.SIG.CHLD, &act, null);
}

return;
Expand Down
8 changes: 4 additions & 4 deletions src/widgets/terminal/Pty.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ pub fn deinit(self: Pty) void {
/// sets the size of the pty
pub fn setSize(self: Pty, ws: Winsize) !void {
const _ws: posix.winsize = .{
.ws_row = @truncate(ws.rows),
.ws_col = @truncate(ws.cols),
.ws_xpixel = @truncate(ws.x_pixel),
.ws_ypixel = @truncate(ws.y_pixel),
.row = @truncate(ws.rows),
.col = @truncate(ws.cols),
.xpixel = @truncate(ws.x_pixel),
.ypixel = @truncate(ws.y_pixel),
};
if (posix.system.ioctl(self.pty, posix.T.IOCSWINSZ, @intFromPtr(&_ws)) != 0)
return error.SetWinsizeError;
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/terminal/Terminal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn spawn(self: *Terminal) !void {
try self.working_directory.appendSlice(pwd);
} else {
const pwd = std.fs.cwd();
var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var buffer: [std.fs.max_path_bytes]u8 = undefined;
const out_path = try std.os.getFdPath(pwd.fd, &buffer);
try self.working_directory.appendSlice(out_path);
}
Expand Down
Loading