Add Label component & make colors custom

This commit also makes Ly more resilient to (impossible) screen
resolutions.

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2026-02-08 17:40:50 +01:00
parent 7bbdebe58b
commit f22593f828
10 changed files with 737 additions and 154 deletions

View File

@@ -25,6 +25,8 @@ pub fn init(
user_list: *UserList,
width: usize,
text_in_center: bool,
fg: u32,
bg: u32,
) Session {
return .{
.label = EnvironmentLabel.init(
@@ -35,6 +37,8 @@ pub fn init(
user_list,
width,
text_in_center,
fg,
bg,
),
.user_list = user_list,
};
@@ -70,11 +74,20 @@ fn sessionChanged(env: Env, maybe_user_list: ?*UserList) void {
}
fn drawItem(label: *EnvironmentLabel, env: Env, x: usize, y: usize, width: usize) void {
if (width < 3) return;
const length = @min(env.environment.name.len, width - 3);
if (length == 0) return;
const x_offset = if (label.text_in_center) (width - length - 1) / 2 else 0;
const x_offset = if (label.text_in_center and width >= length) (width - length) / 2 else 0;
label.item_width = length + x_offset;
label.buffer.drawLabel(env.environment.name, x + x_offset, y);
label.cursor = length + x_offset;
TerminalBuffer.drawConfinedText(
env.environment.name,
x + x_offset,
y,
width,
label.fg,
label.bg,
);
}