From 2af3aa55afa7316d8b3515329e12dfa533bd9db5 Mon Sep 17 00:00:00 2001 From: Ivan Duran Date: Sun, 3 Nov 2024 14:55:23 +0300 Subject: [PATCH] Add adjust-cursor-height metric --- src/config/Config.zig | 4 +++- src/font/SharedGridSet.zig | 3 +++ src/font/face/Metrics.zig | 9 +++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index a674046e1..83f1171bc 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -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 diff --git a/src/font/SharedGridSet.zig b/src/font/SharedGridSet.zig index c3067fa6d..a12e39243 100644 --- a/src/font/SharedGridSet.zig +++ b/src/font/SharedGridSet.zig @@ -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; }; diff --git a/src/font/face/Metrics.zig b/src/font/face/Metrics.zig index a1eb50bdd..2d1e28cf9 100644 --- a/src/font/face/Metrics.zig +++ b/src/font/face/Metrics.zig @@ -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