feat: custom keybindings

This commit is contained in:
LordMZTE 2022-10-15 11:19:47 +02:00
parent cb510b2d6b
commit be618fa15c
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
5 changed files with 565 additions and 92 deletions

9
plugin.kdl Normal file
View file

@ -0,0 +1,9 @@
layout {
pane size=1 borderless=true {
plugin location="zellij:tab-bar"
}
pane
pane size=1 borderless=true {
plugin location="zellij:compact-status"
}
}

View file

@ -1,22 +0,0 @@
---
template:
direction: Horizontal
parts:
- direction: Vertical
borderless: true
split_size:
Fixed: 1
run:
plugin:
location: "zellij:tab-bar"
- direction: Vertical
body: true
- direction: Vertical
borderless: true
split_size:
Fixed: 1
run:
plugin:
location: "file:zig-out/share/zellij/plugins/compact-status.wasm"
tabs:
- direction: Vertical

509
src/Keymap.zig Normal file
View file

@ -0,0 +1,509 @@
const std = @import("std");
const zz = @import("zellzig");
const at = @import("ansi-term");
const sets = @import("settings.zig");
const Key = zz.types.Key;
const Keybind = zz.types.Keybind;
const Action = zz.types.Action;
normal: Normal = .{},
pane: Pane = .{},
tab: Tab = .{},
resize: Resize = .{},
move: Move = .{},
search: Search = .{},
session: Session = .{},
const Self = @This();
pub fn populate(self: *Self, bind_sets: []zz.types.KeybindSet) void {
for (bind_sets) |set| {
switch (set.@"0") {
.Normal => self.normal.populate(set.@"1"),
.Pane => self.pane.populate(set.@"1"),
.Tab => self.tab.populate(set.@"1"),
.Resize => self.resize.populate(set.@"1"),
.Move => self.move.populate(set.@"1"),
.Search, .Scroll => self.search.populate(set.@"1"),
else => {},
}
}
}
fn findKey(kbs: []Keybind, action: Action) ?Key {
for (kbs) |kb| {
for (kb.@"1") |ac| {
if (std.meta.eql(ac, action)) {
return kb.@"0";
}
}
}
return null;
}
fn drawKey(
pl: anytype,
pal: zz.types.Palette,
comptime fmt: []const u8,
key: ?Key,
) !void {
if (key) |k| {
var buf: [512]u8 = undefined;
const fmt_k = FmtKey{ .k = k };
try pl.draw(.{
.text = try std.fmt.bufPrint(&buf, fmt, .{fmt_k}),
.style = fmt_k.style(pal),
});
}
}
/// gets the inner key, for example takes returns the key inside of .{ .Alt = ... }
fn innerCharOrArrow(key: Key) ?zz.types.CharOrArrow {
return switch (key) {
.Alt => |k| k,
.Ctrl => |c| .{ .Char = c },
.Char => |c| .{ .Char = c },
.Left => .{ .Direction = .Left },
.Right => .{ .Direction = .Right },
.Up => .{ .Direction = .Up },
.Down => .{ .Direction = .Down },
else => null,
};
}
fn arrowKeys(left_: ?Key, right_: ?Key, up_: ?Key, down_: ?Key) bool {
var left = if (left_) |k| innerCharOrArrow(k) else null;
var right = if (right_) |k| innerCharOrArrow(k) else null;
var up = if (up_) |k| innerCharOrArrow(k) else null;
var down = if (down_) |k| innerCharOrArrow(k) else null;
if (!std.meta.eql(
left,
.{ .Direction = .Left },
) and !std.meta.eql(
left,
.{ .Char = .{ .c = 'h' } },
)) return false;
if (!std.meta.eql(
right,
.{ .Direction = .Right },
) and !std.meta.eql(
right,
.{ .Char = .{ .c = 'l' } },
)) return false;
if (!std.meta.eql(
up,
.{ .Direction = .Up },
) and !std.meta.eql(
up,
.{ .Char = .{ .c = 'k' } },
)) return false;
if (!std.meta.eql(
down,
.{ .Direction = .Down },
) and !std.meta.eql(
down,
.{ .Char = .{ .c = 'j' } },
)) return false;
return true;
}
fn altArrowKeys(left: ?Key, right: ?Key, up: ?Key, down: ?Key) bool {
if (!std.meta.eql(
left,
.{ .Alt = .{ .Direction = .Left } },
) and !std.meta.eql(
left,
.{ .Alt = .{ .Char = .{ .c = 'h' } } },
)) return false;
if (!std.meta.eql(
right,
.{ .Alt = .{ .Direction = .Right } },
) and !std.meta.eql(
right,
.{ .Alt = .{ .Char = .{ .c = 'l' } } },
)) return false;
if (!std.meta.eql(
up,
.{ .Alt = .{ .Direction = .Up } },
) and !std.meta.eql(
up,
.{ .Alt = .{ .Char = .{ .c = 'k' } } },
)) return false;
if (!std.meta.eql(
down,
.{ .Alt = .{ .Direction = .Down } },
) and !std.meta.eql(
down,
.{ .Alt = .{ .Char = .{ .c = 'j' } } },
)) return false;
return true;
}
const FmtKey = struct {
k: Key,
pub fn format(
self: FmtKey,
comptime _: []const u8,
_: std.fmt.FormatOptions,
w: anytype,
) !void {
switch (self.k) {
.PageUp, .PageDown => try w.writeAll(" "),
.Left => try w.writeAll(directionChar(.Left)),
.Right => try w.writeAll(directionChar(.Right)),
.Up => try w.writeAll(directionChar(.Up)),
.Down => try w.writeAll(directionChar(.Down)),
.Home => try w.writeAll(""),
.End => try w.writeAll(""),
.Backspace => try w.writeAll(""),
.Delete => try w.writeAll("del"),
.Insert => try w.writeAll("ins"),
.F => |n| try w.print("F{d}", .{n}),
.Char => |c| try w.writeByte(c.c),
.Alt => |c| switch (c) {
.Char => |char| try w.print("<M-{c}>", .{char.c}),
.Direction => |dir| try w.print("<M-{s}>", .{directionChar(dir)}),
},
.Ctrl => |c| try w.print("<C-{c}>", .{c.c}),
.BackTab => try w.writeAll("backtab"),
.Null => try w.writeAll("null"),
.Esc => try w.writeAll("esc"),
}
}
pub fn style(self: FmtKey, pal: zz.types.Palette) at.Style {
return switch (self.k) {
.Alt => sets.altStyle(pal),
.Ctrl => sets.ctrlStyle(pal),
else => sets.singleStyle(pal),
};
}
fn directionChar(dir: zz.types.Direction) []const u8 {
return switch (dir) {
.Left => "",
.Right => "",
.Up => "",
.Down => "",
};
}
};
pub const Normal = struct {
lock_mode: ?Key = null,
pane_mode: ?Key = null,
tab_mode: ?Key = null,
resize_mode: ?Key = null,
move_mode: ?Key = null,
search_mode: ?Key = null,
session_mode: ?Key = null,
quit: ?Key = null,
focus_left: ?Key = null,
focus_right: ?Key = null,
focus_up: ?Key = null,
focus_down: ?Key = null,
new: ?Key = null,
increase_size: ?Key = null,
decrease_size: ?Key = null,
pub fn populate(self: *Normal, kbs: []Keybind) void {
self.lock_mode = findKey(kbs, .{ .SwitchToMode = .Locked });
self.pane_mode = findKey(kbs, .{ .SwitchToMode = .Pane });
self.tab_mode = findKey(kbs, .{ .SwitchToMode = .Tab });
self.resize_mode = findKey(kbs, .{ .SwitchToMode = .Resize });
self.move_mode = findKey(kbs, .{ .SwitchToMode = .Move });
self.search_mode = findKey(kbs, .{ .SwitchToMode = .Search }) orelse
findKey(kbs, .{ .SwitchToMode = .Scroll });
self.session_mode = findKey(kbs, .{ .SwitchToMode = .Session });
self.quit = findKey(kbs, .Quit);
self.focus_left = findKey(kbs, .{ .MoveFocusOrTab = .Left });
self.focus_right = findKey(kbs, .{ .MoveFocusOrTab = .Right });
self.focus_up = findKey(kbs, .{ .MoveFocus = .Up });
self.focus_down = findKey(kbs, .{ .MoveFocus = .Down });
self.new = findKey(kbs, .{ .NewPane = null });
self.increase_size = findKey(kbs, .{ .Resize = .Increase });
self.decrease_size = findKey(kbs, .{ .Resize = .Decrease });
}
pub fn draw(self: *Normal, pl: anytype, pal: zz.types.Palette) !void {
try drawKey(pl, pal, "{} |  ", self.lock_mode);
try drawKey(pl, pal, "{} |  ", self.pane_mode);
try drawKey(pl, pal, "{} | ﴵ ", self.tab_mode);
try drawKey(pl, pal, "{} | ﭕ ", self.resize_mode);
try drawKey(pl, pal, "{} |  ", self.move_mode);
try drawKey(pl, pal, "{} |  ", self.search_mode);
try drawKey(pl, pal, "{} |  ", self.session_mode);
try drawKey(pl, pal, "{} |  ", self.quit);
if (altArrowKeys(
self.focus_left,
self.focus_right,
self.focus_up,
self.focus_down,
)) {
try pl.draw(.{ .text = "<M->", .style = sets.altStyle(pal) });
} else {
try drawKey(pl, pal, "{} |  ", self.focus_left);
try drawKey(pl, pal, "{} |  ", self.focus_right);
try drawKey(pl, pal, "{} |  ", self.focus_up);
try drawKey(pl, pal, "{} |  ", self.focus_down);
}
try drawKey(pl, pal, "{} |  ", self.new);
if (std.meta.eql(self.increase_size, .{ .Alt = .{ .Char = .{ .c = '+' } } }) and
std.meta.eql(self.decrease_size, .{ .Alt = .{ .Char = .{ .c = '-' } } }))
{
try pl.draw(.{ .text = "<M-+/-> | ﭔ ", .style = sets.altStyle(pal) });
} else {
try drawKey(pl, pal, "{} | +ﭔ ", self.increase_size);
try drawKey(pl, pal, "{} | -ﭔ ", self.decrease_size);
}
}
};
pub const Pane = struct {
focus_left: ?Key = null,
focus_right: ?Key = null,
focus_up: ?Key = null,
focus_down: ?Key = null,
next: ?Key = null,
new: ?Key = null,
split_down: ?Key = null,
split_right: ?Key = null,
close: ?Key = null,
fullscreen: ?Key = null,
frame: ?Key = null,
rename: ?Key = null,
floating: ?Key = null,
embed: ?Key = null,
pub fn populate(self: *Pane, kbs: []Keybind) void {
self.focus_left = findKey(kbs, .{ .MoveFocus = .Left });
self.focus_right = findKey(kbs, .{ .MoveFocus = .Right });
self.focus_up = findKey(kbs, .{ .MoveFocus = .Up });
self.focus_down = findKey(kbs, .{ .MoveFocus = .Down });
self.next = findKey(kbs, .SwitchFocus);
self.new = findKey(kbs, .{ .NewPane = null });
self.split_down = findKey(kbs, .{ .NewPane = .Down });
self.split_right = findKey(kbs, .{ .NewPane = .Right });
self.close = findKey(kbs, .CloseFocus);
self.fullscreen = findKey(kbs, .ToggleFocusFullscreen);
self.frame = findKey(kbs, .TogglePaneFrames);
self.rename = findKey(kbs, .{ .SwitchToMode = .RenamePane });
self.floating = findKey(kbs, .ToggleFloatingPanes);
self.embed = findKey(kbs, .TogglePaneEmbedOrFloating);
}
pub fn draw(self: *Pane, pl: anytype, pal: zz.types.Palette) !void {
if (arrowKeys(self.focus_left, self.focus_right, self.focus_up, self.focus_down)) {
try pl.draw(.{ .text = "", .style = sets.singleStyle(pal) });
} else {
try drawKey(pl, pal, "{} |  ", self.focus_left);
try drawKey(pl, pal, "{} |  ", self.focus_right);
try drawKey(pl, pal, "{} |  ", self.focus_up);
try drawKey(pl, pal, "{} |  ", self.focus_down);
}
try drawKey(pl, pal, "{} | 怜", self.next);
try drawKey(pl, pal, "{} |  ", self.new);
try drawKey(pl, pal, "{} |   ", self.split_down);
try drawKey(pl, pal, "{} |   ", self.split_right);
try drawKey(pl, pal, "{} |  ", self.close);
try drawKey(pl, pal, "{} |  ", self.fullscreen);
try drawKey(pl, pal, "{} |  ", self.frame);
try drawKey(pl, pal, "{} | 凜", self.rename);
try drawKey(pl, pal, "{} |  ", self.floating);
try drawKey(pl, pal, "{} |  ", self.embed);
}
};
pub const Tab = struct {
focus_left: ?Key = null,
focus_right: ?Key = null,
toggle_tab: ?Key = null,
new: ?Key = null,
close: ?Key = null,
rename: ?Key = null,
sync: ?Key = null,
pub fn populate(self: *Tab, kbs: []Keybind) void {
self.focus_left = findKey(kbs, .GoToPreviousTab);
self.focus_right = findKey(kbs, .GoToNextTab);
self.toggle_tab = findKey(kbs, .ToggleTab);
self.new = findKey(kbs, .{ .NewTab = .{ null, null } });
self.close = findKey(kbs, .Quit);
self.rename = findKey(kbs, .{ .SwitchToMode = .RenameTab });
self.sync = findKey(kbs, .ToggleActiveSyncTab);
}
pub fn draw(self: *Tab, pl: anytype, pal: zz.types.Palette) !void {
if (arrowKeys(self.focus_left, self.focus_right, .Up, .Down)) {
try pl.draw(.{ .text = "", .style = sets.singleStyle(pal) });
} else {
try drawKey(pl, pal, "{} |  ", self.focus_left);
try drawKey(pl, pal, "{} |  ", self.focus_right);
}
if (std.meta.eql(self.toggle_tab, .{ .Char = .{ .c = '\t' } })) {
try pl.draw(.{ .text = "", .style = sets.singleStyle(pal) });
} else {
try drawKey(pl, pal, "{} | ⇋ ", self.toggle_tab);
}
try drawKey(pl, pal, "{} |  ", self.new);
try drawKey(pl, pal, "{} |  ", self.close);
try drawKey(pl, pal, "{} | 凜", self.rename);
}
};
pub const Resize = struct {
resize_left: ?Key = null,
resize_right: ?Key = null,
resize_up: ?Key = null,
resize_down: ?Key = null,
increase: ?Key = null,
decrease: ?Key = null,
pub fn populate(self: *Resize, kbs: []Keybind) void {
self.resize_left = findKey(kbs, .{ .Resize = .Left });
self.resize_right = findKey(kbs, .{ .Resize = .Right });
self.resize_up = findKey(kbs, .{ .Resize = .Up });
self.resize_down = findKey(kbs, .{ .Resize = .Down });
self.increase = findKey(kbs, .{ .Resize = .Increase });
self.decrease = findKey(kbs, .{ .Resize = .Decrease });
}
pub fn draw(self: *Resize, pl: anytype, pal: zz.types.Palette) !void {
if (arrowKeys(
self.resize_left,
self.resize_right,
self.resize_up,
self.resize_down,
)) {
try pl.draw(.{ .text = "", .style = sets.singleStyle(pal) });
} else {
try drawKey(pl, pal, "{} |  ", self.resize_left);
try drawKey(pl, pal, "{} |  ", self.resize_right);
try drawKey(pl, pal, "{} |  ", self.resize_up);
try drawKey(pl, pal, "{} |  ", self.resize_down);
}
if (std.meta.eql(self.increase, .{ .Char = .{ .c = '+' } }) and
std.meta.eql(self.decrease, .{ .Char = .{ .c = '-' } }))
{
try pl.draw(.{ .text = "+-", .style = sets.singleStyle(pal) });
} else {
try drawKey(pl, pal, "{} | + ", self.increase);
try drawKey(pl, pal, "{} | - ", self.decrease);
}
}
};
pub const Move = struct {
move_left: ?Key = null,
move_right: ?Key = null,
move_up: ?Key = null,
move_down: ?Key = null,
move: ?Key = null,
pub fn populate(self: *Move, kbs: []Keybind) void {
self.move_left = findKey(kbs, .{ .MovePane = .Left });
self.move_right = findKey(kbs, .{ .MovePane = .Right });
self.move_up = findKey(kbs, .{ .MovePane = .Up });
self.move_down = findKey(kbs, .{ .MovePane = .Down });
self.move = findKey(kbs, .{ .MovePane = null });
}
pub fn draw(self: *Move, pl: anytype, pal: zz.types.Palette) !void {
if (arrowKeys(
self.move_left,
self.move_right,
self.move_up,
self.move_down,
)) {
try pl.draw(.{ .text = "", .style = sets.singleStyle(pal) });
} else {
try drawKey(pl, pal, "{} |  ", self.move_left);
try drawKey(pl, pal, "{} |  ", self.move_right);
try drawKey(pl, pal, "{} |  ", self.move_up);
try drawKey(pl, pal, "{} |  ", self.move_down);
}
if (std.meta.eql(self.move, .{ .Char = .{ .c = '\t' } })) {
try pl.draw(.{ .text = "", .style = sets.singleStyle(pal) });
} else {
try drawKey(pl, pal, "{} | ⇋ ", self.move);
}
}
};
pub const Search = struct {
scroll_up: ?Key = null,
scroll_down: ?Key = null,
page_up: ?Key = null,
page_down: ?Key = null,
half_page_up: ?Key = null,
half_page_down: ?Key = null,
edit: ?Key = null,
search: ?Key = null,
pub fn populate(self: *Search, kbs: []Keybind) void {
self.scroll_up = findKey(kbs, .ScrollUp);
self.scroll_down = findKey(kbs, .ScrollDown);
self.page_up = findKey(kbs, .PageScrollUp);
self.page_down = findKey(kbs, .PageScrollDown);
self.half_page_up = findKey(kbs, .HalfPageScrollUp);
self.half_page_down = findKey(kbs, .HalfPageScrollDown);
self.edit = findKey(kbs, .EditScrollback);
self.search = findKey(kbs, .{ .SwitchToMode = .EnterSearch });
}
pub fn draw(self: *Search, pl: anytype, pal: zz.types.Palette) !void {
if (arrowKeys(.Left, .Right, self.scroll_up, self.scroll_down)) {
try pl.draw(.{ .text = "", .style = sets.singleStyle(pal) });
} else {
try drawKey(pl, pal, "{} |  ", self.scroll_up);
try drawKey(pl, pal, "{} |  ", self.scroll_down);
}
if (std.meta.eql(self.page_up, .PageUp) and
std.meta.eql(self.page_down, .PageDown))
{
try pl.draw(.{ .text = "  ", .style = sets.singleStyle(pal) });
} else {
try drawKey(pl, pal, "{} |   ", self.page_up);
try drawKey(pl, pal, "{} |   ", self.page_up);
}
try drawKey(pl, pal, "{} | ﯕ  ", self.half_page_up);
try drawKey(pl, pal, "{} | ﯕ  ", self.half_page_down);
try drawKey(pl, pal, "{} |  ", self.edit);
try drawKey(pl, pal, "{} |  ", self.search);
}
};
pub const Session = struct {
detach: ?Key = null,
pub fn populate(self: *Search, kbs: []Keybind) void {
self.detach = findKey(kbs, .Detach);
}
pub fn draw(self: *Session, pl: anytype, pal: zz.types.Palette) !void {
try drawKey(pl, pal, "{} |  ", self.detach);
}
};

View file

@ -1,6 +1,7 @@
const std = @import("std");
const zz = @import("zellzig");
const at = @import("ansi-term");
const Keymap = @import("Keymap.zig");
const powerline = @import("powerline.zig");
const sets = @import("settings.zig");
const util = @import("util.zig");
@ -12,31 +13,37 @@ comptime {
zz.createPlugin(@This());
}
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
// this is fine, as we should always get a mode event before rendering
var mi: zz.types.ModeInfo = undefined;
var mode: zz.types.InputMode = undefined;
var pal: zz.types.Palette = undefined;
var keymap: Keymap = .{};
pub fn init() void {
zz.allocator = gpa.allocator();
zz.api.setSelectable(false);
zz.api.subscribe(&[_]zz.types.EventType{.ModeUpdate}) catch
@panic("unable to subscribe to events");
}
pub fn update(ev: zz.Event) void {
switch (ev) {
.ModeUpdate => |info| mi = info,
var event_heap: [1024 * 128]u8 = undefined;
var event_fba = std.heap.FixedBufferAllocator.init(&event_heap);
pub fn update() void {
defer event_fba.end_index = 0;
var ev = zz.getEvent(event_fba.allocator()) catch |e| {
std.log.err("Failed to deserialize event: {}", .{e});
return;
};
switch (ev.data) {
.ModeUpdate => |info| {
mode = info.mode;
pal = info.style.colors;
keymap.populate(info.keybinds);
},
else => {},
}
}
fn tryRender(cols: usize) !void {
const pal = mi.style.colors;
const ctrl_style = sets.ctrlStyle(pal);
const alt_style = sets.altStyle(pal);
const single_style = sets.singleStyle(pal);
const writer = std.io.getStdOut().writer();
var pl = powerline.Powerline(@TypeOf(writer)).init(
writer,
@ -44,7 +51,7 @@ fn tryRender(cols: usize) !void {
col(pal.bg),
);
switch (mi.mode) {
switch (mode) {
.Locked => {
try pl.draw(.{
.text = "<C-g>  ",
@ -66,17 +73,7 @@ fn tryRender(cols: usize) !void {
}),
});
try pl.draw(.{ .text = "<C-g> |  ", .style = ctrl_style });
try pl.draw(.{ .text = "<C-p> |  ", .style = ctrl_style });
try pl.draw(.{ .text = "<C-t> | ﴵ ", .style = ctrl_style });
try pl.draw(.{ .text = "<C-n> | ﭕ ", .style = ctrl_style });
try pl.draw(.{ .text = "<C-h> |  ", .style = ctrl_style });
try pl.draw(.{ .text = "<C-s> |  ", .style = ctrl_style });
try pl.draw(.{ .text = "<C-o> |  ", .style = ctrl_style });
try pl.draw(.{ .text = "<C-q> |  ", .style = ctrl_style });
try pl.draw(.{ .text = "<M- >", .style = alt_style });
try pl.draw(.{ .text = "<M-n> |  ", .style = alt_style });
try pl.draw(.{ .text = "<M-+/-> | ﭔ ", .style = alt_style });
try keymap.normal.draw(&pl, pal);
},
.Pane => {
@ -89,18 +86,7 @@ fn tryRender(cols: usize) !void {
}),
});
try pl.draw(.{ .text = "", .style = single_style });
try pl.draw(.{ .text = "p | 怜", .style = single_style });
try pl.draw(.{ .text = "n |  ", .style = single_style });
try pl.draw(.{ .text = "d |   ", .style = single_style });
try pl.draw(.{ .text = "r |   ", .style = single_style });
try pl.draw(.{ .text = "x |  ", .style = single_style });
try pl.draw(.{ .text = "f |  ", .style = single_style });
try pl.draw(.{ .text = "z |  ", .style = single_style });
try pl.draw(.{ .text = "c | 凜 ", .style = single_style });
try pl.draw(.{ .text = "w |  ", .style = single_style });
try pl.draw(.{ .text = "e |  ", .style = single_style });
try pl.draw(.{ .text = " |  ", .style = single_style });
try keymap.pane.draw(&pl, pal);
},
.Tab => {
@ -113,14 +99,7 @@ fn tryRender(cols: usize) !void {
}),
});
try pl.draw(.{ .text = "", .style = single_style });
try pl.draw(.{ .text = "", .style = single_style });
try pl.draw(.{ .text = "", .style = single_style });
try pl.draw(.{ .text = "n |  ", .style = single_style });
try pl.draw(.{ .text = "x |  ", .style = single_style });
try pl.draw(.{ .text = "r | 凜 ", .style = single_style });
try pl.draw(.{ .text = "s | מּ ", .style = single_style });
try pl.draw(.{ .text = " |  ", .style = single_style });
try keymap.tab.draw(&pl, pal);
},
.Resize => {
@ -133,9 +112,7 @@ fn tryRender(cols: usize) !void {
}),
});
try pl.draw(.{ .text = "", .style = single_style });
try pl.draw(.{ .text = "+-", .style = single_style });
try pl.draw(.{ .text = " |  ", .style = single_style });
try keymap.resize.draw(&pl, pal);
},
.Move => {
@ -144,18 +121,16 @@ fn tryRender(cols: usize) !void {
.style = sty(.{
.font = .{ .bold = true },
.fg = pal.black,
.bg = pal.gray,
.bg = pal.cyan,
}),
});
try pl.draw(.{ .text = "", .style = single_style });
try pl.draw(.{ .text = "⇋/n | ⇋", .style = single_style });
try pl.draw(.{ .text = " |  ", .style = single_style });
try keymap.move.draw(&pl, pal);
},
.Scroll => {
.Scroll, .Search => {
try pl.draw(.{
.text = "Scroll",
.text = "Search",
.style = sty(.{
.font = .{ .bold = true },
.fg = pal.black,
@ -163,11 +138,7 @@ fn tryRender(cols: usize) !void {
}),
});
try pl.draw(.{ .text = "", .style = single_style });
try pl.draw(.{ .text = " ", .style = single_style });
try pl.draw(.{ .text = "u/d | ﯕ ", .style = single_style });
try pl.draw(.{ .text = "e | ", .style = single_style });
try pl.draw(.{ .text = " |  ", .style = single_style });
try keymap.search.draw(&pl, pal);
},
.Session => {
@ -180,8 +151,7 @@ fn tryRender(cols: usize) !void {
}),
});
try pl.draw(.{ .text = "d |  ", .style = single_style });
try pl.draw(.{ .text = " |  ", .style = single_style });
try keymap.session.draw(&pl, pal);
},
.RenameTab => {
@ -228,7 +198,14 @@ fn tryRender(cols: usize) !void {
});
},
else => {
// TODO
try pl.draw(.{
.text = @tagName(mode),
.style = sty(.{
.font = .{ .bold = true },
.fg = pal.black,
.bg = pal.blue,
}),
});
},
}

View file

@ -25,7 +25,7 @@ pub fn Powerline(comptime Writer: type) type {
pub fn draw(self: *Self, segment: Segment) !void {
// +2 for worst-case separator width
self.*.current_len += segment.text.len + 2;
self.current_len += segment.text.len + 2;
if (self.current_len > self.max_len)
return;
@ -34,12 +34,12 @@ pub fn Powerline(comptime Writer: type) type {
if (self.last_style) |ls| {
try self.setStyle(.{
.foreground = ls.background,
.background = self.*.background,
.background = self.background,
});
try self.writeSeparator();
try self.setStyle(.{
.foreground = self.*.background,
.foreground = self.background,
.background = segment.style.background,
});
try self.writeSeparator();
@ -50,24 +50,24 @@ pub fn Powerline(comptime Writer: type) type {
try self.writer.writeAll(" ");
}
try self.*.writer.writeAll(segment.text);
try self.writer.writeAll(segment.text);
}
pub fn finish(self: *Self) !void {
try self.setStyle(.{
.foreground = (self.*.last_style orelse at.Style{}).background,
.foreground = (self.last_style orelse at.Style{}).background,
});
try self.*.writeSeparator();
try self.writeSeparator();
}
fn setStyle(self: *Self, style: at.Style) !void {
try at.updateStyle(self.*.writer, style, self.*.last_style);
self.*.last_style = style;
try at.updateStyle(self.writer, style, self.last_style);
self.last_style = style;
}
fn writeSeparator(self: *Self) !void {
try self.*.writer.writeAll(separator);
try self.writer.writeAll(separator);
}
};
}