From e2fae7ab2bfcee7e7612135776349327f772ec4a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 30 Aug 2023 08:12:38 -0700 Subject: [PATCH] surface should default to default cursor, blinking should check selected --- src/Surface.zig | 2 +- src/renderer/Metal.zig | 12 +++++++++--- src/renderer/OpenGL.zig | 12 +++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 85aa6c78b..9299aa111 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -415,7 +415,7 @@ pub fn init( .renderer_state = .{ .mutex = mutex, .cursor = .{ - .style = .blinking_block, + .style = .default, .visible = true, }, .terminal = &self.io.terminal, diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 129473439..055d5e617 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -475,6 +475,14 @@ pub fn render( return; } + // If the terminal state isn't requesting any particular style, + // then use the configured style. + const selected_cursor_style = style: { + if (state.cursor.style != .default) break :style state.cursor.style; + if (self.config.cursor_style != .default) break :style self.config.cursor_style; + break :style .blinking_block; + }; + self.cursor_visible = visible: { // If the cursor is explicitly not visible in the state, // then it is not visible. @@ -484,7 +492,7 @@ pub fn render( if (state.preedit != null) break :visible true; // If the cursor isn't a blinking style, then never blink. - if (!state.cursor.style.blinking()) break :visible true; + if (!selected_cursor_style.blinking()) break :visible true; // Otherwise, adhere to our current state. break :visible self.cursor_visible; @@ -499,8 +507,6 @@ pub fn render( // If we aren't focused, we use a hollow box if (!self.focused) break :cursor_style .box_hollow; - const selected_cursor_style = if (state.cursor.style == .default) self.config.cursor_style else state.cursor.style; - break :cursor_style renderer.CursorStyle.fromTerminal(selected_cursor_style) orelse .box; }; } diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 99b957a56..291fc4727 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -717,6 +717,14 @@ pub fn render( return; } + // If the terminal state isn't requesting any particular style, + // then use the configured style. + const selected_cursor_style = style: { + if (state.cursor.style != .default) break :style state.cursor.style; + if (self.config.cursor_style != .default) break :style self.config.cursor_style; + break :style .blinking_block; + }; + self.cursor_visible = visible: { // If the cursor is explicitly not visible in the state, // then it is not visible. @@ -726,7 +734,7 @@ pub fn render( if (state.preedit != null) break :visible true; // If the cursor isn't a blinking style, then never blink. - if (!state.cursor.style.blinking()) break :visible true; + if (!selected_cursor_style.blinking()) break :visible true; // Otherwise, adhere to our current state. break :visible self.cursor_visible; @@ -741,8 +749,6 @@ pub fn render( // If we aren't focused, we use a hollow box if (!self.focused) break :cursor_style .box_hollow; - const selected_cursor_style = if (state.cursor.style == .default) self.config.cursor_style else state.cursor.style; - break :cursor_style renderer.CursorStyle.fromTerminal(selected_cursor_style) orelse .box; }; }