Merge pull request #232 from mitchellh/cursor-vis

renderer: hide cursor is state explicit asks for invisible cursor
This commit is contained in:
Mitchell Hashimoto
2023-08-06 09:59:47 -07:00
committed by GitHub
3 changed files with 14 additions and 2 deletions

View File

@ -531,11 +531,15 @@ pub fn render(
// Setup our cursor state // Setup our cursor state
if (self.focused) { if (self.focused) {
self.cursor_visible = visible: { self.cursor_visible = visible: {
// If the cursor is explicitly not visible in the state,
// then it is not visible.
if (!state.cursor.visible) break :visible false;
// If the cursor isn't a blinking style, then never blink. // If the cursor isn't a blinking style, then never blink.
if (!state.cursor.style.blinking()) break :visible true; if (!state.cursor.style.blinking()) break :visible true;
// Otherwise, adhere to our current state. // Otherwise, adhere to our current state.
break :visible self.cursor_visible and state.cursor.visible; break :visible self.cursor_visible;
}; };
self.cursor_style = renderer.CursorStyle.fromTerminal(state.cursor.style) orelse .box; self.cursor_style = renderer.CursorStyle.fromTerminal(state.cursor.style) orelse .box;
} else { } else {

View File

@ -731,11 +731,15 @@ pub fn render(
// Setup our cursor state // Setup our cursor state
if (self.focused) { if (self.focused) {
self.cursor_visible = visible: { self.cursor_visible = visible: {
// If the cursor is explicitly not visible in the state,
// then it is not visible.
if (!state.cursor.visible) break :visible false;
// If the cursor isn't a blinking style, then never blink. // If the cursor isn't a blinking style, then never blink.
if (!state.cursor.style.blinking()) break :visible true; if (!state.cursor.style.blinking()) break :visible true;
// Otherwise, adhere to our current state. // Otherwise, adhere to our current state.
break :visible self.cursor_visible and state.cursor.visible; break :visible self.cursor_visible;
}; };
self.cursor_style = renderer.CursorStyle.fromTerminal(state.cursor.style) orelse .box; self.cursor_style = renderer.CursorStyle.fromTerminal(state.cursor.style) orelse .box;
} else { } else {

View File

@ -1173,6 +1173,10 @@ const StreamHandler = struct {
} }
pub fn setMode(self: *StreamHandler, mode: terminal.Mode, enabled: bool) !void { pub fn setMode(self: *StreamHandler, mode: terminal.Mode, enabled: bool) !void {
// Note: this function doesn't need to grab the render state or
// terminal locks because it is only called from process() which
// grabs the lock.
switch (mode) { switch (mode) {
.cursor_keys => { .cursor_keys => {
self.terminal.modes.cursor_keys = enabled; self.terminal.modes.cursor_keys = enabled;