mirror of https://github.com/fairyglade/ly.git
Center the environment name.
This commit is contained in:
parent
c87d5b4e7a
commit
8794b0a540
|
@ -188,6 +188,9 @@ sleep_cmd = null
|
||||||
# Specifies the key used for sleep (F1-F12)
|
# Specifies the key used for sleep (F1-F12)
|
||||||
sleep_key = F3
|
sleep_key = F3
|
||||||
|
|
||||||
|
# Center the session name.
|
||||||
|
text_in_center = false
|
||||||
|
|
||||||
# TTY in use
|
# TTY in use
|
||||||
tty = $DEFAULT_TTY
|
tty = $DEFAULT_TTY
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ shutdown_cmd: []const u8 = "/sbin/shutdown -a now",
|
||||||
shutdown_key: []const u8 = "F1",
|
shutdown_key: []const u8 = "F1",
|
||||||
sleep_cmd: ?[]const u8 = null,
|
sleep_cmd: ?[]const u8 = null,
|
||||||
sleep_key: []const u8 = "F3",
|
sleep_key: []const u8 = "F3",
|
||||||
|
text_in_center: bool = false,
|
||||||
tty: u8 = build_options.tty,
|
tty: u8 = build_options.tty,
|
||||||
vi_default_mode: ViMode = .normal,
|
vi_default_mode: ViMode = .normal,
|
||||||
vi_mode: bool = false,
|
vi_mode: bool = false,
|
||||||
|
|
|
@ -283,8 +283,8 @@ pub fn main() !void {
|
||||||
buffer.drawBoxCenter(!config.hide_borders, config.blank_box);
|
buffer.drawBoxCenter(!config.hide_borders, config.blank_box);
|
||||||
|
|
||||||
const coordinates = buffer.calculateComponentCoordinates();
|
const coordinates = buffer.calculateComponentCoordinates();
|
||||||
info_line.label.position(coordinates.start_x, coordinates.y, coordinates.full_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);
|
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);
|
login.position(coordinates.x, coordinates.y + 4, coordinates.visible_length);
|
||||||
password.position(coordinates.x, coordinates.y + 6, coordinates.visible_length);
|
password.position(coordinates.x, coordinates.y + 6, coordinates.visible_length);
|
||||||
|
|
||||||
|
@ -405,8 +405,8 @@ pub fn main() !void {
|
||||||
|
|
||||||
if (resolution_changed) {
|
if (resolution_changed) {
|
||||||
const coordinates = buffer.calculateComponentCoordinates();
|
const coordinates = buffer.calculateComponentCoordinates();
|
||||||
info_line.label.position(coordinates.start_x, coordinates.y, coordinates.full_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);
|
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);
|
login.position(coordinates.x, coordinates.y + 4, coordinates.visible_length);
|
||||||
password.position(coordinates.x, coordinates.y + 6, coordinates.visible_length);
|
password.position(coordinates.x, coordinates.y + 6, coordinates.visible_length);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
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);
|
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);
|
TerminalBuffer.drawColorLabel(message.text, x, label.y, message.fg, message.bg);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -133,7 +133,10 @@ fn drawItem(label: *EnvironmentLabel, environment: Environment, x: usize, y: usi
|
||||||
const length = @min(environment.name.len, label.visible_length - 3);
|
const length = @min(environment.name.len, label.visible_length - 3);
|
||||||
if (length == 0) return false;
|
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.specifier, x, y);
|
||||||
label.buffer.drawLabel(environment.name, label.x + 2, label.y);
|
label.buffer.drawLabel(environment.name, nx, label.y);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ pub fn CyclableLabel(comptime ItemType: type) type {
|
||||||
x: usize,
|
x: usize,
|
||||||
y: usize,
|
y: usize,
|
||||||
first_char_x: usize,
|
first_char_x: usize,
|
||||||
|
text_in_center: bool,
|
||||||
draw_item_fn: DrawItemFn,
|
draw_item_fn: DrawItemFn,
|
||||||
|
|
||||||
pub fn init(allocator: Allocator, buffer: *TerminalBuffer, draw_item_fn: DrawItemFn) Self {
|
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,
|
.x = 0,
|
||||||
.y = 0,
|
.y = 0,
|
||||||
.first_char_x = 0,
|
.first_char_x = 0,
|
||||||
|
.text_in_center = false,
|
||||||
.draw_item_fn = draw_item_fn,
|
.draw_item_fn = draw_item_fn,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -41,11 +43,14 @@ pub fn CyclableLabel(comptime ItemType: type) type {
|
||||||
self.list.deinit();
|
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.x = x;
|
||||||
self.y = y;
|
self.y = y;
|
||||||
self.visible_length = visible_length;
|
self.visible_length = visible_length;
|
||||||
self.first_char_x = x + 2;
|
self.first_char_x = x + 2;
|
||||||
|
if (text_in_center) |value| {
|
||||||
|
self.text_in_center = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addItem(self: *Self, item: ItemType) !void {
|
pub fn addItem(self: *Self, item: ItemType) !void {
|
||||||
|
|
Loading…
Reference in New Issue