Add adjust-cursor-height metric

This commit is contained in:
Ivan Duran
2024-11-03 14:55:23 +03:00
parent d47df211b0
commit 2af3aa55af
3 changed files with 13 additions and 3 deletions

View File

@ -247,7 +247,8 @@ const c = @cImport({
///
/// * The font will be centered vertically in the cell.
///
/// * The cursor will remain the same size as the font.
/// * The cursor will remain the same size as the font, unless adjusted with
/// `adjust-cursor-height`.
///
/// * Powerline glyphs will be adjusted along with the cell height so
/// that things like status lines continue to look aligned.
@ -259,6 +260,7 @@ const c = @cImport({
@"adjust-strikethrough-position": ?MetricModifier = null,
@"adjust-strikethrough-thickness": ?MetricModifier = null,
@"adjust-cursor-thickness": ?MetricModifier = null,
@"adjust-cursor-height": ?MetricModifier = null,
/// The method to use for calculating the cell width of a grapheme cluster.
/// The default value is `unicode` which uses the Unicode standard to determine

View File

@ -427,6 +427,7 @@ pub const DerivedConfig = struct {
@"adjust-strikethrough-position": ?Metrics.Modifier,
@"adjust-strikethrough-thickness": ?Metrics.Modifier,
@"adjust-cursor-thickness": ?Metrics.Modifier,
@"adjust-cursor-height": ?Metrics.Modifier,
/// Initialize a DerivedConfig. The config should be either a
/// config.Config or another DerivedConfig to clone from.
@ -461,6 +462,7 @@ pub const DerivedConfig = struct {
.@"adjust-strikethrough-position" = config.@"adjust-strikethrough-position",
.@"adjust-strikethrough-thickness" = config.@"adjust-strikethrough-thickness",
.@"adjust-cursor-thickness" = config.@"adjust-cursor-thickness",
.@"adjust-cursor-height" = config.@"adjust-cursor-height",
// This must be last so the arena contains all our allocations
// from above since Zig does assignment in order.
@ -598,6 +600,7 @@ pub const Key = struct {
if (config.@"adjust-strikethrough-position") |m| try set.put(alloc, .strikethrough_position, m);
if (config.@"adjust-strikethrough-thickness") |m| try set.put(alloc, .strikethrough_thickness, m);
if (config.@"adjust-cursor-thickness") |m| try set.put(alloc, .cursor_thickness, m);
if (config.@"adjust-cursor-height") |m| try set.put(alloc, .cursor_height, m);
break :set set;
};

View File

@ -25,6 +25,9 @@ strikethrough_thickness: u32,
/// because it is not determined by fonts but rather by user configuration.
cursor_thickness: u32 = 1,
/// cursor height as a percentage of cell_height
cursor_height: u32 = 100,
/// Original cell width and height. These are used to render the cursor
/// in the original cell size after modification.
original_cell_width: ?u32 = null,
@ -32,6 +35,9 @@ original_cell_height: ?u32 = null,
/// Apply a set of modifiers.
pub fn apply(self: *Metrics, mods: ModifierSet) void {
if (mods.get(.cursor_height)) |mod| {
self.cursor_height = mod.apply(self.cursor_height);
}
var it = mods.iterator();
while (it.next()) |entry| {
switch (entry.key_ptr.*) {
@ -45,10 +51,9 @@ pub fn apply(self: *Metrics, mods: ModifierSet) void {
const new = @max(entry.value_ptr.apply(original), 1);
if (new == original) continue;
// Preserve the original cell width and height if not set.
if (self.original_cell_width == null) {
self.original_cell_width = self.cell_width;
self.original_cell_height = self.cell_height;
self.original_cell_height = self.cell_height * self.cursor_height / 100;
}
// Set the new value