mirror of
https://github.com/fairyglade/ly.git
synced 2026-03-21 22:43:38 +00:00
Show UI errors in info line again
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
@@ -10,11 +10,20 @@ const ErrorHandler = packed struct {
|
||||
const SharedError = @This();
|
||||
|
||||
data: []align(std.heap.page_size_min) u8,
|
||||
write_error_event_fn: ?*const fn (anyerror, *anyopaque) anyerror!void,
|
||||
ctx: ?*anyopaque,
|
||||
|
||||
pub fn init() !SharedError {
|
||||
pub fn init(
|
||||
write_error_event_fn: ?*const fn (anyerror, *anyopaque) anyerror!void,
|
||||
ctx: ?*anyopaque,
|
||||
) !SharedError {
|
||||
const data = try std.posix.mmap(null, @sizeOf(ErrorHandler), std.posix.PROT.READ | std.posix.PROT.WRITE, .{ .TYPE = .SHARED, .ANONYMOUS = true }, -1, 0);
|
||||
|
||||
return .{ .data = data };
|
||||
return .{
|
||||
.data = data,
|
||||
.write_error_event_fn = write_error_event_fn,
|
||||
.ctx = ctx,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *SharedError) void {
|
||||
@@ -25,6 +34,10 @@ pub fn writeError(self: SharedError, err: anyerror) void {
|
||||
var buf_stream = std.io.fixedBufferStream(self.data);
|
||||
const writer = buf_stream.writer();
|
||||
writer.writeStruct(ErrorHandler{ .has_error = true, .err_int = @intFromError(err) }) catch {};
|
||||
|
||||
if (self.write_error_event_fn) |write_error_event_fn| {
|
||||
@call(.auto, write_error_event_fn, .{ err, self.ctx.? }) catch {};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn readError(self: SharedError) ?anyerror {
|
||||
|
||||
Reference in New Issue
Block a user