refactor: move digit styles to fonts.zig
This commit is contained in:
parent
8964a361a7
commit
4ae59d848a
3 changed files with 23 additions and 19 deletions
|
@ -5,7 +5,7 @@ theme: []const u8 = "default",
|
||||||
input_mode: []const u8 = "flow",
|
input_mode: []const u8 = "flow",
|
||||||
gutter_line_numbers: bool = true,
|
gutter_line_numbers: bool = true,
|
||||||
gutter_line_numbers_relative: bool = false,
|
gutter_line_numbers_relative: bool = false,
|
||||||
gutter_line_numbers_style: LineNumberStyle = .ascii,
|
gutter_line_numbers_style: DigitStyle = .ascii,
|
||||||
gutter_symbols: bool = true,
|
gutter_symbols: bool = true,
|
||||||
enable_terminal_cursor: bool = true,
|
enable_terminal_cursor: bool = true,
|
||||||
enable_terminal_color_scheme: bool = builtin.os.tag != .windows,
|
enable_terminal_color_scheme: bool = builtin.os.tag != .windows,
|
||||||
|
@ -27,7 +27,7 @@ lsp_request_timeout: usize = 10,
|
||||||
|
|
||||||
include_files: []const u8 = "",
|
include_files: []const u8 = "",
|
||||||
|
|
||||||
pub const LineNumberStyle = enum {
|
pub const DigitStyle = enum {
|
||||||
ascii,
|
ascii,
|
||||||
digital,
|
digital,
|
||||||
subscript,
|
subscript,
|
||||||
|
|
|
@ -17,7 +17,7 @@ const Widget = @import("Widget.zig");
|
||||||
const MessageFilter = @import("MessageFilter.zig");
|
const MessageFilter = @import("MessageFilter.zig");
|
||||||
const tui = @import("tui.zig");
|
const tui = @import("tui.zig");
|
||||||
const ed = @import("editor.zig");
|
const ed = @import("editor.zig");
|
||||||
const LineNumberStyle = @import("config").LineNumberStyle;
|
const DigitStyle = @import("config").DigitStyle;
|
||||||
|
|
||||||
allocator: Allocator,
|
allocator: Allocator,
|
||||||
plane: Plane,
|
plane: Plane,
|
||||||
|
@ -29,7 +29,7 @@ row: u32 = 1,
|
||||||
line: usize = 0,
|
line: usize = 0,
|
||||||
linenum: bool,
|
linenum: bool,
|
||||||
relative: bool,
|
relative: bool,
|
||||||
render_style: LineNumberStyle,
|
render_style: DigitStyle,
|
||||||
highlight: bool,
|
highlight: bool,
|
||||||
symbols: bool,
|
symbols: bool,
|
||||||
width: usize = 4,
|
width: usize = 4,
|
||||||
|
@ -424,7 +424,7 @@ fn int_width(n_: usize) usize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_digits(self: *Self, n_: anytype, style_: LineNumberStyle) !void {
|
fn print_digits(self: *Self, n_: anytype, style_: DigitStyle) !void {
|
||||||
var n = n_;
|
var n = n_;
|
||||||
var buf: [12][]const u8 = undefined;
|
var buf: [12][]const u8 = undefined;
|
||||||
var digits: std.ArrayListUnmanaged([]const u8) = .initBuffer(&buf);
|
var digits: std.ArrayListUnmanaged([]const u8) = .initBuffer(&buf);
|
||||||
|
@ -438,20 +438,8 @@ fn print_digits(self: *Self, n_: anytype, style_: LineNumberStyle) !void {
|
||||||
for (digits.items) |digit| _ = try self.plane.putstr(digit);
|
for (digits.items) |digit| _ = try self.plane.putstr(digit);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_digit(plane: *Plane, n: anytype, style_: LineNumberStyle) !void {
|
pub fn print_digit(plane: *Plane, n: anytype, style_: DigitStyle) !void {
|
||||||
_ = try plane.putstr(get_digit(n, style_));
|
_ = try plane.putstr(get_digit(n, style_));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_digit(n: anytype, style_: LineNumberStyle) []const u8 {
|
const get_digit = @import("fonts.zig").get_digit;
|
||||||
return switch (style_) {
|
|
||||||
.ascii => digits_ascii[n],
|
|
||||||
.digital => digits_digtl[n],
|
|
||||||
.subscript => digits_subsc[n],
|
|
||||||
.superscript => digits_super[n],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const digits_ascii: [10][]const u8 = .{ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
|
||||||
const digits_digtl: [10][]const u8 = .{ "🯰", "🯱", "🯲", "🯳", "🯴", "🯵", "🯶", "🯷", "🯸", "🯹" };
|
|
||||||
const digits_subsc: [10][]const u8 = .{ "₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉" };
|
|
||||||
const digits_super: [10][]const u8 = .{ "⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹" };
|
|
||||||
|
|
|
@ -230,3 +230,19 @@ pub const font_test_text: []const u8 =
|
||||||
\\ "Cascadia Code NF" => https://github.com/microsoft/cascadia-code/releases/download/v2407.24/CascadiaCode-2407.24.zip
|
\\ "Cascadia Code NF" => https://github.com/microsoft/cascadia-code/releases/download/v2407.24/CascadiaCode-2407.24.zip
|
||||||
\\
|
\\
|
||||||
;
|
;
|
||||||
|
|
||||||
|
pub const DigitStyle = @import("config").DigitStyle;
|
||||||
|
|
||||||
|
pub fn get_digit(n: anytype, style_: DigitStyle) []const u8 {
|
||||||
|
return switch (style_) {
|
||||||
|
.ascii => digits_ascii[n],
|
||||||
|
.digital => digits_digtl[n],
|
||||||
|
.subscript => digits_subsc[n],
|
||||||
|
.superscript => digits_super[n],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const digits_ascii: [10][]const u8 = .{ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||||
|
const digits_digtl: [10][]const u8 = .{ "🯰", "🯱", "🯲", "🯳", "🯴", "🯵", "🯶", "🯷", "🯸", "🯹" };
|
||||||
|
const digits_subsc: [10][]const u8 = .{ "₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉" };
|
||||||
|
const digits_super: [10][]const u8 = .{ "⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹" };
|
||||||
|
|
Loading…
Add table
Reference in a new issue