diff --git a/res/config.ini b/res/config.ini index 596ef36..1d28cb8 100644 --- a/res/config.ini +++ b/res/config.ini @@ -188,6 +188,9 @@ sleep_cmd = null # Specifies the key used for sleep (F1-F12) sleep_key = F3 +# Center the session name. +text_in_center = false + # TTY in use tty = $DEFAULT_TTY diff --git a/src/config/Config.zig b/src/config/Config.zig index 2d3cd07..38c8b4c 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -50,6 +50,7 @@ shutdown_cmd: []const u8 = "/sbin/shutdown -a now", shutdown_key: []const u8 = "F1", sleep_cmd: ?[]const u8 = null, sleep_key: []const u8 = "F3", +text_in_center: bool = false, tty: u8 = build_options.tty, vi_default_mode: ViMode = .normal, vi_mode: bool = false, diff --git a/src/main.zig b/src/main.zig index b9cf38a..00dde46 100644 --- a/src/main.zig +++ b/src/main.zig @@ -283,8 +283,8 @@ pub fn main() !void { buffer.drawBoxCenter(!config.hide_borders, config.blank_box); const coordinates = buffer.calculateComponentCoordinates(); - info_line.label.position(coordinates.start_x, coordinates.y, coordinates.full_visible_length); - session.label.position(coordinates.x, coordinates.y + 2, coordinates.visible_length); + info_line.label.position(coordinates.start_x, coordinates.y, coordinates.full_visible_length, null); + session.label.position(coordinates.x, coordinates.y + 2, coordinates.visible_length, config.text_in_center); login.position(coordinates.x, coordinates.y + 4, coordinates.visible_length); password.position(coordinates.x, coordinates.y + 6, coordinates.visible_length); @@ -405,8 +405,8 @@ pub fn main() !void { if (resolution_changed) { const coordinates = buffer.calculateComponentCoordinates(); - info_line.label.position(coordinates.start_x, coordinates.y, coordinates.full_visible_length); - session.label.position(coordinates.x, coordinates.y + 2, coordinates.visible_length); + info_line.label.position(coordinates.start_x, coordinates.y, coordinates.full_visible_length, null); + session.label.position(coordinates.x, coordinates.y + 2, coordinates.visible_length, config.text_in_center); login.position(coordinates.x, coordinates.y + 4, coordinates.visible_length); password.position(coordinates.x, coordinates.y + 6, coordinates.visible_length); diff --git a/src/tui/components/InfoLine.zig b/src/tui/components/InfoLine.zig index d4ef7a4..a43b083 100644 --- a/src/tui/components/InfoLine.zig +++ b/src/tui/components/InfoLine.zig @@ -54,7 +54,7 @@ fn drawItem(label: *MessageLabel, message: Message, _: usize, _: usize) bool { if (message.width == 0 or label.buffer.box_width <= message.width) return false; const x = label.buffer.box_x + ((label.buffer.box_width - message.width) / 2); - label.first_char_x = x; + label.first_char_x = x + message.width; TerminalBuffer.drawColorLabel(message.text, x, label.y, message.fg, message.bg); return true; diff --git a/src/tui/components/Session.zig b/src/tui/components/Session.zig index fbc2620..2cc081a 100644 --- a/src/tui/components/Session.zig +++ b/src/tui/components/Session.zig @@ -133,7 +133,10 @@ fn drawItem(label: *EnvironmentLabel, environment: Environment, x: usize, y: usi const length = @min(environment.name.len, label.visible_length - 3); if (length == 0) return false; + const nx = if (label.text_in_center) (label.x + (label.visible_length - environment.name.len) / 2) else (label.x + 2); + label.first_char_x = nx + environment.name.len; + label.buffer.drawLabel(environment.specifier, x, y); - label.buffer.drawLabel(environment.name, label.x + 2, label.y); + label.buffer.drawLabel(environment.name, nx, label.y); return true; } diff --git a/src/tui/components/generic.zig b/src/tui/components/generic.zig index 215a876..126916b 100644 --- a/src/tui/components/generic.zig +++ b/src/tui/components/generic.zig @@ -21,6 +21,7 @@ pub fn CyclableLabel(comptime ItemType: type) type { x: usize, y: usize, first_char_x: usize, + text_in_center: bool, draw_item_fn: DrawItemFn, pub fn init(allocator: Allocator, buffer: *TerminalBuffer, draw_item_fn: DrawItemFn) Self { @@ -33,6 +34,7 @@ pub fn CyclableLabel(comptime ItemType: type) type { .x = 0, .y = 0, .first_char_x = 0, + .text_in_center = false, .draw_item_fn = draw_item_fn, }; } @@ -41,11 +43,14 @@ pub fn CyclableLabel(comptime ItemType: type) type { self.list.deinit(); } - pub fn position(self: *Self, x: usize, y: usize, visible_length: usize) void { + pub fn position(self: *Self, x: usize, y: usize, visible_length: usize, text_in_center: ?bool) void { self.x = x; self.y = y; self.visible_length = visible_length; self.first_char_x = x + 2; + if (text_in_center) |value| { + self.text_in_center = value; + } } pub fn addItem(self: *Self, item: ItemType) !void {