renderer: render lock for password input

This commit is contained in:
Mitchell Hashimoto
2024-09-18 11:08:32 -07:00
parent 39627e3221
commit 5c469a0b44
4 changed files with 113 additions and 42 deletions

View File

@ -55,6 +55,11 @@ const NullPty = struct {
_ = self;
}
pub fn getMode(self: Pty) error{GetModeFailed}!Mode {
_ = self;
return .{};
}
pub fn setSize(self: *Pty, size: winsize) !void {
_ = self;
_ = size;

View File

@ -947,7 +947,10 @@ pub fn updateFrame(
errdefer screen_copy.deinit();
// Whether to draw our cursor or not.
const cursor_style = renderer.cursorStyle(
const cursor_style = if (state.terminal.flags.password_input)
.lock
else
renderer.cursorStyle(
state,
self.focused,
cursor_blink_visible,
@ -2652,14 +2655,21 @@ fn addCursor(
break :alpha @intFromFloat(@ceil(alpha));
};
const render = switch (cursor_style) {
.block,
.block_hollow,
.bar,
.underline,
=> render: {
const sprite: font.Sprite = switch (cursor_style) {
.block => .cursor_rect,
.block_hollow => .cursor_hollow_rect,
.bar => .cursor_bar,
.underline => .underline,
.lock => unreachable,
};
const render = self.font_grid.renderGlyph(
break :render self.font_grid.renderGlyph(
self.alloc,
font.sprite_index,
@intFromEnum(sprite),
@ -2671,6 +2681,27 @@ fn addCursor(
log.warn("error rendering cursor glyph err={}", .{err});
return;
};
},
.lock => self.font_grid.renderCodepoint(
self.alloc,
0xF023, // lock symbol
.regular,
.text,
.{
.cell_width = if (wide) 2 else 1,
.grid_metrics = self.grid_metrics,
},
) catch |err| {
log.warn("error rendering cursor glyph err={}", .{err});
return;
} orelse {
// This should never happen because we embed nerd
// fonts so we just log and return instead of fallback.
log.warn("failed to find lock symbol for cursor codepoint=0xF023", .{});
return;
},
};
self.cells.setCursor(.{
.mode = .cursor,

View File

@ -767,7 +767,10 @@ pub fn updateFrame(
errdefer screen_copy.deinit();
// Whether to draw our cursor or not.
const cursor_style = renderer.cursorStyle(
const cursor_style = if (state.terminal.flags.password_input)
.lock
else
renderer.cursorStyle(
state,
self.focused,
cursor_blink_visible,
@ -1537,14 +1540,21 @@ fn addCursor(
break :alpha @intFromFloat(@ceil(alpha));
};
const render = switch (cursor_style) {
.block,
.block_hollow,
.bar,
.underline,
=> render: {
const sprite: font.Sprite = switch (cursor_style) {
.block => .cursor_rect,
.block_hollow => .cursor_hollow_rect,
.bar => .cursor_bar,
.underline => .underline,
.lock => unreachable,
};
const render = self.font_grid.renderGlyph(
break :render self.font_grid.renderGlyph(
self.alloc,
font.sprite_index,
@intFromEnum(sprite),
@ -1556,6 +1566,27 @@ fn addCursor(
log.warn("error rendering cursor glyph err={}", .{err});
return null;
};
},
.lock => self.font_grid.renderCodepoint(
self.alloc,
0xF023, // lock symbol
.regular,
.text,
.{
.cell_width = if (wide) 2 else 1,
.grid_metrics = self.grid_metrics,
},
) catch |err| {
log.warn("error rendering cursor glyph err={}", .{err});
return null;
} orelse {
// This should never happen because we embed nerd
// fonts so we just log and return instead of fallback.
log.warn("failed to find lock symbol for cursor codepoint=0xF023", .{});
return null;
},
};
try self.cells.append(self.alloc, .{
.mode = .fg,

View File

@ -6,11 +6,15 @@ const State = @import("State.zig");
/// This is a superset of terminal cursor styles since the renderer supports
/// some additional cursor states such as the hollow block.
pub const Style = enum {
// Typical cursor input styles
block,
block_hollow,
bar,
underline,
// Special cursor styles
lock,
/// Create a cursor style from the terminal style request.
pub fn fromTerminal(term: terminal.CursorStyle) ?Style {
return switch (term) {