feat: use icons in mini mode labels

This commit is contained in:
CJ van den Berg 2024-03-03 22:00:08 +01:00
parent 9ba773c4a4
commit cf22ba38e7
7 changed files with 21 additions and 28 deletions

View file

@ -1149,7 +1149,7 @@ fn egc_len(egcs: []const u8, colcount: *c_int, abs_col: usize) usize {
}; };
} }
fn egc_chunk_width(chunk_: []const u8, abs_col_: usize) usize { pub fn egc_chunk_width(chunk_: []const u8, abs_col_: usize) usize {
var abs_col = abs_col_; var abs_col = abs_col_;
var chunk = chunk_; var chunk = chunk_;
var colcount: usize = 0; var colcount: usize = 0;

View file

@ -54,7 +54,7 @@ pub fn handler(self: *Self) EventHandler {
} }
pub fn name(_: *Self) []const u8 { pub fn name(_: *Self) []const u8 {
return "find"; return "󱎸 find";
} }
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -53,7 +53,7 @@ pub fn handler(self: *Self) EventHandler {
} }
pub fn name(_: *Self) []const u8 { pub fn name(_: *Self) []const u8 {
return "find in files"; return "󰥨 find";
} }
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -41,7 +41,7 @@ pub fn handler(self: *Self) EventHandler {
} }
pub fn name(_: *Self) []const u8 { pub fn name(_: *Self) []const u8 {
return "goto"; return "goto";
} }
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -54,12 +54,12 @@ pub fn handler(self: *Self) EventHandler {
pub fn name(self: *Self) []const u8 { pub fn name(self: *Self) []const u8 {
return switch (self.operation) { return switch (self.operation) {
.move => switch (self.direction) { .move => switch (self.direction) {
.left => "move left to char", .left => "move",
.right => "move right to char", .right => "move",
}, },
.select => switch (self.direction) { .select => switch (self.direction) {
.left => "select left to char", .left => "󰒅 ↶ select",
.right => "select right to char", .right => "󰒅 ↷ select",
}, },
}; };
} }

View file

@ -44,7 +44,7 @@ pub fn handler(self: *Self) EventHandler {
} }
pub fn name(_: *Self) []const u8 { pub fn name(_: *Self) []const u8 {
return "open file"; return "open";
} }
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {

View file

@ -4,6 +4,7 @@ const nc = @import("notcurses");
const tp = @import("thespian"); const tp = @import("thespian");
const tracy = @import("tracy"); const tracy = @import("tracy");
const root = @import("root"); const root = @import("root");
const Buffer = @import("Buffer");
const Widget = @import("../Widget.zig"); const Widget = @import("../Widget.zig");
const command = @import("../command.zig"); const command = @import("../command.zig");
@ -37,7 +38,10 @@ pub fn deinit(self: *Self, a: Allocator) void {
} }
pub fn layout(_: *Self) Widget.Layout { pub fn layout(_: *Self) Widget.Layout {
return .{ .static = if (is_mini_mode()) tui.get_mode().len + 5 else tui.get_mode().len - 1 }; const name = tui.get_mode();
const width = Buffer.egc_chunk_width(name, 0);
const padding: usize = if (is_mini_mode()) 3 else 2;
return .{ .static = width + padding };
} }
fn is_mini_mode() bool { fn is_mini_mode() bool {
@ -45,30 +49,19 @@ fn is_mini_mode() bool {
} }
pub fn render(self: *Self, theme: *const Widget.Theme) bool { pub fn render(self: *Self, theme: *const Widget.Theme) bool {
if (is_mini_mode())
self.render_mode(theme)
else
self.render_logo(theme);
return false;
}
fn render_mode(self: *Self, theme: *const Widget.Theme) void {
tui.set_base_style(&self.plane, " ", theme.statusbar_hover); tui.set_base_style(&self.plane, " ", theme.statusbar_hover);
self.plane.on_styles(nc.style.bold); self.plane.on_styles(nc.style.bold);
self.plane.erase(); self.plane.erase();
self.plane.home(); self.plane.home();
var buf: [31:0]u8 = undefined; var buf: [31:0]u8 = undefined;
_ = self.plane.putstr(std.fmt.bufPrintZ(&buf, " {s} ", .{tui.get_mode()}) catch return) catch {}; _ = self.plane.putstr(std.fmt.bufPrintZ(&buf, " {s} ", .{tui.get_mode()}) catch return false) catch {};
if (is_mini_mode())
self.render_separator(theme);
return false;
}
fn render_separator(self: *Self, theme: *const Widget.Theme) void {
if (theme.statusbar_hover.bg) |bg| self.plane.set_fg_rgb(bg) catch {}; if (theme.statusbar_hover.bg) |bg| self.plane.set_fg_rgb(bg) catch {};
if (theme.statusbar.bg) |bg| self.plane.set_bg_rgb(bg) catch {}; if (theme.statusbar.bg) |bg| self.plane.set_bg_rgb(bg) catch {};
_ = self.plane.putstr("") catch {}; _ = self.plane.putstr("") catch {};
} }
fn render_logo(self: *Self, theme: *const Widget.Theme) void {
tui.set_base_style(&self.plane, " ", theme.statusbar_hover);
self.plane.on_styles(nc.style.bold);
self.plane.erase();
self.plane.home();
var buf: [31:0]u8 = undefined;
_ = self.plane.putstr(std.fmt.bufPrintZ(&buf, " {s} ", .{tui.get_mode()}) catch return) catch {};
}