don't blink the cursor while typing

This commit is contained in:
Mitchell Hashimoto
2022-04-23 10:22:27 -07:00
parent bbaa28fce1
commit 825a90e7cc
2 changed files with 20 additions and 2 deletions

View File

@ -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 {

View File

@ -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 its inactive.
/// Rule of thumb: if a handle of type uv_foo_t has a uv_foo_start()
/// function, then its 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(