diff --git a/src/Window.zig b/src/Window.zig index 13a0fadc8..89b231882 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -107,7 +107,7 @@ pub fn create(alloc: Allocator, loop: libuv.Loop) !*Window { errdefer timer.deinit(alloc); errdefer timer.close(null); timer.setData(self); - try timer.start(cursorTimerCallback, 800, 800); + try timer.start(cursorTimerCallback, 600, 600); self.* = .{ .alloc = alloc, @@ -196,6 +196,13 @@ fn charCallback(window: glfw.Window, codepoint: u21) void { // Append this character to the terminal win.terminal.appendChar(win.alloc, @intCast(u8, codepoint)) catch unreachable; + // Whenever a character is typed, we ensure the cursor is visible + // and we restart the cursor timer. + win.grid.cursor_visible = true; + if (win.cursor_timer.isActive() catch false) { + _ = win.cursor_timer.again() catch null; + } + // Update the cells for drawing win.grid.updateCells(win.terminal) catch unreachable; } @@ -222,7 +229,7 @@ fn focusCallback(window: glfw.Window, focused: bool) void { const win = window.getUserPointer(Window) orelse return; if (focused) { win.wakeup = true; - win.cursor_timer.start(cursorTimerCallback, 0, 800) catch unreachable; + win.cursor_timer.start(cursorTimerCallback, 0, win.cursor_timer.getRepeat()) catch unreachable; win.grid.cursor_style = .box; win.grid.cursor_visible = false; } else { diff --git a/src/libuv/handle.zig b/src/libuv/handle.zig index ea23e62b0..eaa08a4fc 100644 --- a/src/libuv/handle.zig +++ b/src/libuv/handle.zig @@ -1,6 +1,7 @@ const c = @import("c.zig"); const Loop = @import("Loop.zig"); +const errors = @import("error.zig"); /// Returns a struct that has all the shared handle functions for the /// given handle type T. The type T must have a field named "handle". @@ -50,6 +51,16 @@ pub fn Handle(comptime T: type) type { return .{ .loop = c.uv_handle_get_loop(handle) }; } + /// Returns non-zero if the handle is active, zero if it’s inactive. + /// Rule of thumb: if a handle of type uv_foo_t has a uv_foo_start() + /// function, then it’s active from the moment that function is called. + /// Likewise, uv_foo_stop() deactivates the handle again. + pub fn isActive(self: T) !bool { + const res = c.uv_is_active(@ptrCast(*c.uv_handle_t, self.handle)); + try errors.convertError(res); + return res > 0; + } + /// Sets handle->data to data. pub fn setData(self: T, pointer: ?*anyopaque) void { c.uv_handle_set_data(