Compare commits

...

2 commits

Author SHA1 Message Date
3e8faabd9d
feat: add clock widget digit style parameter
May be ascii, digital, subscript or superscript
2025-03-25 21:05:47 +01:00
f6847001db
refactor: remove obsolete lsp_request_timeout config parameter 2025-03-25 20:56:28 +01:00
4 changed files with 18 additions and 9 deletions

View file

@ -41,8 +41,7 @@ pub fn send_request(
var cb = std.ArrayList(u8).init(self.allocator);
defer cb.deinit();
try cbor.writeValue(cb.writer(), m);
const request_timeout: u64 = @intCast(std.time.ns_per_s * tp.env.get().num("lsp-request-timeout"));
return RequestContext(@TypeOf(ctx)).send(allocator, self.pid.ref(), ctx, request_timeout, tp.message.fmt(.{ "REQ", method, cb.items }));
return RequestContext(@TypeOf(ctx)).send(allocator, self.pid.ref(), ctx, tp.message.fmt(.{ "REQ", method, cb.items }));
}
pub fn send_notification(self: Self, method: []const u8, m: anytype) (OutOfMemoryError || SendError)!void {
@ -72,8 +71,7 @@ fn RequestContext(T: type) type {
const Self = @This();
const ReceiverT = tp.Receiver(*@This());
fn send(a: std.mem.Allocator, to: tp.pid_ref, ctx: T, timeout_ns: u64, request: tp.message) (OutOfMemoryError || SpawnError)!void {
_ = timeout_ns;
fn send(a: std.mem.Allocator, to: tp.pid_ref, ctx: T, request: tp.message) (OutOfMemoryError || SpawnError)!void {
const self = try a.create(@This());
self.* = .{
.receiver = undefined,

View file

@ -25,8 +25,6 @@ bottom_bar: []const u8 = "mode file log selection diagnostics keybind linenumber
show_scrollbars: bool = true,
show_fileicons: bool = true,
lsp_request_timeout: usize = 10,
include_files: []const u8 = "",
pub const DigitStyle = enum {

View file

@ -9,16 +9,22 @@ const Plane = @import("renderer").Plane;
const Widget = @import("../Widget.zig");
const MessageFilter = @import("../MessageFilter.zig");
const tui = @import("../tui.zig");
const fonts = @import("../fonts.zig");
const DigitStyle = fonts.DigitStyle;
allocator: std.mem.Allocator,
plane: Plane,
tick_timer: ?tp.Cancellable = null,
on_event: ?EventHandler,
tz: zeit.timezone.TimeZone,
style: ?DigitStyle,
const Self = @This();
pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler, _: ?[]const u8) @import("widget.zig").CreateError!Widget {
pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler, arg: ?[]const u8) @import("widget.zig").CreateError!Widget {
const style: ?DigitStyle = if (arg) |style| std.meta.stringToEnum(DigitStyle, style) orelse null else null;
var env = std.process.getEnvMap(allocator) catch |e| {
std.log.err("clock: std.process.getEnvMap failed with {any}", .{e});
return error.WidgetInitFailed;
@ -33,6 +39,7 @@ pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Event
std.log.err("clock: zeit.local failed with {any}", .{e});
return error.WidgetInitFailed;
},
.style = style,
};
try tui.message_filters().add(MessageFilter.bind(self, receive_tick));
self.update_tick_timer(.init);
@ -74,7 +81,14 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool {
const now = zeit.instant(.{ .timezone = &self.tz }) catch return false;
const dt = now.time();
_ = self.plane.print("{d:0>2}:{d:0>2}", .{ dt.hour, dt.minute }) catch {};
var buf: [64]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buf);
const writer = fbs.writer();
std.fmt.format(writer, "{d:0>2}:{d:0>2}", .{ dt.hour, dt.minute }) catch {};
const value_str = fbs.getWritten();
for (value_str, 0..) |_, i| _ = self.plane.putstr(fonts.get_digit_ascii(value_str[i .. i + 1], self.style orelse .ascii)) catch {};
return false;
}

View file

@ -114,7 +114,6 @@ fn init(allocator: Allocator) InitError!*Self {
if (frame_rate != 0)
conf.frame_rate = frame_rate;
tp.env.get().num_set("frame-rate", @intCast(conf.frame_rate));
tp.env.get().num_set("lsp-request-timeout", @intCast(conf.lsp_request_timeout));
const frame_time = std.time.us_per_s / conf.frame_rate;
const frame_clock = try tp.metronome.init(frame_time);