refactor: clean-up flow logo rendering
This commit is contained in:
parent
b831d99d1c
commit
08e06bc8dd
7 changed files with 35 additions and 13 deletions
|
@ -17,7 +17,6 @@ pub var max_diff_lines: usize = 50000;
|
|||
pub var max_syntax_lines: usize = 50000;
|
||||
|
||||
pub const application_name = "flow";
|
||||
pub const application_logo = " ";
|
||||
|
||||
pub const std_options = .{
|
||||
// .log_level = if (builtin.mode == .Debug) .debug else .warn,
|
||||
|
|
|
@ -31,7 +31,7 @@ pub fn create(a: Allocator) !tui.Mode {
|
|||
};
|
||||
return .{
|
||||
.handler = EventHandler.to_owned(self),
|
||||
.name = root.application_logo ++ root.application_name,
|
||||
.name = root.application_name,
|
||||
.description = "default",
|
||||
.keybind_hints = &hints,
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@ pub fn create(a: std.mem.Allocator) !tui.Mode {
|
|||
};
|
||||
return .{
|
||||
.handler = EventHandler.to_owned(self),
|
||||
.name = root.application_logo ++ root.application_name,
|
||||
.name = root.application_name,
|
||||
.description = "home",
|
||||
.keybind_hints = &hints,
|
||||
};
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const tp = @import("thespian");
|
||||
const root = @import("root");
|
||||
|
||||
const key = @import("renderer").input.key;
|
||||
const mod = @import("renderer").input.modifier;
|
||||
|
@ -33,7 +32,7 @@ pub fn create(a: Allocator) !tui.Mode {
|
|||
try self.commands.init(self);
|
||||
return .{
|
||||
.handler = EventHandler.to_owned(self),
|
||||
.name = root.application_logo ++ "INSERT",
|
||||
.name = "INSERT",
|
||||
.description = "vim",
|
||||
.line_numbers = if (tui.current().config.vim_insert_gutter_line_numbers_relative) .relative else .absolute,
|
||||
};
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const tp = @import("thespian");
|
||||
const root = @import("root");
|
||||
|
||||
const key = @import("renderer").input.key;
|
||||
const mod = @import("renderer").input.modifier;
|
||||
|
@ -34,7 +33,7 @@ pub fn create(a: Allocator) !tui.Mode {
|
|||
try self.commands.init(self);
|
||||
return .{
|
||||
.handler = EventHandler.to_owned(self),
|
||||
.name = root.application_logo ++ "NORMAL",
|
||||
.name = "NORMAL",
|
||||
.description = "vim",
|
||||
.line_numbers = if (tui.current().config.vim_normal_gutter_line_numbers_relative) .relative else .absolute,
|
||||
.keybind_hints = &hints,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const tp = @import("thespian");
|
||||
const root = @import("root");
|
||||
|
||||
const key = @import("renderer").input.key;
|
||||
const mod = @import("renderer").input.modifier;
|
||||
|
@ -34,7 +33,7 @@ pub fn create(a: Allocator) !tui.Mode {
|
|||
try self.commands.init(self);
|
||||
return .{
|
||||
.handler = EventHandler.to_owned(self),
|
||||
.name = root.application_logo ++ "VISUAL",
|
||||
.name = "VISUAL",
|
||||
.description = "vim",
|
||||
.line_numbers = if (tui.current().config.vim_visual_gutter_line_numbers_relative) .relative else .absolute,
|
||||
.keybind_hints = &hints,
|
||||
|
|
|
@ -28,8 +28,10 @@ pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler)
|
|||
pub fn layout(_: *void, btn: *Button.State(void)) Widget.Layout {
|
||||
const name = tui.get_mode();
|
||||
const width = btn.plane.egc_chunk_width(name, 0);
|
||||
const padding: usize = if (is_mini_mode()) 3 else 2;
|
||||
return .{ .static = width + padding };
|
||||
const logo = btn.plane.egc_chunk_width(left ++ symbol ++ right, 0);
|
||||
const padding: usize = 2;
|
||||
const minimode_sep: usize = if (is_mini_mode()) 1 else 0;
|
||||
return .{ .static = logo + width + padding + minimode_sep };
|
||||
}
|
||||
|
||||
fn is_mini_mode() bool {
|
||||
|
@ -41,12 +43,16 @@ fn is_overlay_mode() bool {
|
|||
}
|
||||
|
||||
pub fn render(_: *void, self: *Button.State(void), theme: *const Widget.Theme) bool {
|
||||
self.plane.set_base_style(" ", if (self.active) theme.editor_cursor else if (self.hover) theme.editor_selection else theme.statusbar_hover);
|
||||
const base_style = if (self.active) theme.editor_cursor else if (self.hover) theme.editor_selection else theme.statusbar_hover;
|
||||
self.plane.set_base_style(" ", base_style);
|
||||
self.plane.on_styles(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 false) catch {};
|
||||
render_logo(self, theme, base_style);
|
||||
self.plane.set_base_style(" ", base_style);
|
||||
self.plane.on_styles(style.bold);
|
||||
_ = self.plane.putstr(std.fmt.bufPrintZ(&buf, "{s} ", .{tui.get_mode()}) catch return false) catch {};
|
||||
if (is_mini_mode())
|
||||
render_separator(self, theme);
|
||||
return false;
|
||||
|
@ -58,6 +64,26 @@ fn render_separator(self: *Button.State(void), theme: *const Widget.Theme) void
|
|||
_ = self.plane.putstr("") catch {};
|
||||
}
|
||||
|
||||
const left = " ";
|
||||
const symbol = "";
|
||||
const right = " ";
|
||||
|
||||
fn render_logo(self: *Button.State(void), theme: *const Widget.Theme, base_style: Widget.Theme.Style) void {
|
||||
// const style_symbol: Widget.Theme.Style = if (tui.find_scope_style(theme, "number")) |sty| .{ .fg = sty.style.fg, .bg = base_style.bg, .fs = base_style.fs } else base_style;
|
||||
const style_symbol = if (self.active) theme.editor_cursor else if (self.hover) theme.editor_selection else theme.statusbar_hover;
|
||||
const style_braces: Widget.Theme.Style = if (tui.find_scope_style(theme, "punctuation")) |sty| .{ .fg = sty.style.fg, .bg = base_style.bg, .fs = base_style.fs } else base_style;
|
||||
if (left.len > 0) {
|
||||
self.plane.set_style(style_braces);
|
||||
_ = self.plane.putstr(" " ++ left) catch {};
|
||||
}
|
||||
self.plane.set_style(style_symbol);
|
||||
_ = self.plane.putstr(symbol) catch {};
|
||||
if (right.len > 0) {
|
||||
self.plane.set_style(style_braces);
|
||||
_ = self.plane.putstr(right) catch {};
|
||||
}
|
||||
}
|
||||
|
||||
fn on_click(_: *void, _: *Button.State(void)) void {
|
||||
if (is_mini_mode()) {
|
||||
command.executeName("exit_mini_mode", .{}) catch {};
|
||||
|
|
Loading…
Add table
Reference in a new issue