8 Commits

Author SHA1 Message Date
AnErrupTion
afb1dc62a0 Fix merge conflict issues
Signed-off-by: AnErrupTion <anerruption@disroot.org>
2026-05-11 21:15:18 +02:00
AnErrupTion
efa56ae770 Use $EXECUTABLE_NAME in kmscon service
Signed-off-by: AnErrupTion <anerruption@disroot.org>
2026-05-11 21:11:07 +02:00
AnErrupTion
2a41391764 Fix labels_max_length calculation (closes #984)
Signed-off-by: AnErrupTion <anerruption@disroot.org>
2026-05-11 21:10:59 +02:00
AnErrupTion
e0f915d440 Improve keyboard handling (closes #982)
Signed-off-by: AnErrupTion <anerruption@disroot.org>
2026-05-11 21:10:52 +02:00
Titanium Brain
692ca9f7b5 Resolve merge conflict
Signed-off-by: AnErrupTion <anerruption@disroot.org>
2026-05-11 21:10:44 +02:00
AnErrupTion
f6c44d5e57 Fix building without X11
Signed-off-by: AnErrupTion <anerruption@disroot.org>
2026-05-11 21:10:11 +02:00
AnErrupTion
1080583233 Fix log file race condition
Signed-off-by: AnErrupTion <anerruption@disroot.org>
2026-05-11 21:10:02 +02:00
AnErrupTion
cd426bb3df Start Ly v1.4.1 development cycle
Signed-off-by: AnErrupTion <anerruption@disroot.org>
2026-05-11 21:09:46 +02:00
10 changed files with 109 additions and 274 deletions

View File

@@ -23,7 +23,7 @@ comptime {
}
}
const ly_version = std.SemanticVersion{ .major = 1, .minor = 5, .patch = 0 };
const ly_version = std.SemanticVersion{ .major = 1, .minor = 4, .patch = 1 };
var dest_directory: []const u8 = undefined;
var config_directory: []const u8 = undefined;

View File

@@ -1,6 +1,6 @@
.{
.name = .ly,
.version = "1.5.0",
.version = "1.4.1",
.fingerprint = 0xa148ffcc5dc2cb59,
.minimum_zig_version = "0.16.0",
.dependencies = .{

View File

@@ -1,6 +1,6 @@
.{
.name = .ly_core,
.version = "1.1.0",
.version = "1.0.1",
.fingerprint = 0xddda7afda795472,
.minimum_zig_version = "0.16.0",
.dependencies = .{

View File

@@ -3,85 +3,50 @@ const interop = @import("interop.zig");
const LogFile = @This();
maybe_path: ?[]const u8,
path: []const u8,
could_open_log_file: bool = undefined,
maybe_file: ?std.Io.File = null,
file: std.Io.File = undefined,
buffer: []u8,
maybe_file_writer: ?std.Io.File.Writer = null,
pub fn init(io: std.Io, path: ?[]const u8, buffer: []u8) !LogFile {
var log_file = LogFile{
.maybe_path = path,
.buffer = buffer,
};
if (path) |p| {
log_file.could_open_log_file = try openLogFile(io, p, &log_file);
} else {
std.posix.system.openlog("ly", 0, 0);
log_file.could_open_log_file = true;
}
file_writer: std.Io.File.Writer = undefined,
pub fn init(io: std.Io, path: []const u8, buffer: []u8) !LogFile {
var log_file = LogFile{ .path = path, .buffer = buffer };
log_file.could_open_log_file = try openLogFile(io, path, &log_file);
return log_file;
}
pub fn reinit(self: *LogFile, io: std.Io) !void {
if (self.maybe_path) |path| {
self.could_open_log_file = try openLogFile(io, path, self);
} else {
std.posix.system.openlog("ly", 0, 0);
self.could_open_log_file = true;
}
self.could_open_log_file = try openLogFile(io, self.path, self);
}
pub fn deinit(self: *LogFile, io: std.Io) void {
if (self.maybe_file) |file| {
file.close(io);
} else {
std.posix.system.closelog();
}
self.file.close(io);
}
pub fn info(self: *LogFile, io: std.Io, category: []const u8, comptime message: []const u8, args: anytype) !void {
if (self.maybe_file_writer) |*writer| {
var buffer: [128:0]u8 = undefined;
const time = interop.timeAsString(io, &buffer, "%Y-%m-%d %H:%M:%S");
try writer.interface.print("{s} [info/{s}] ", .{ time, category });
try writer.interface.print(message, args);
try writer.interface.writeByte('\n');
try writer.interface.flush();
} else {
var buffer: [1024]u8 = undefined;
const slice = try std.fmt.bufPrint(&buffer, message, args);
const msg = try std.fmt.bufPrintZ(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice });
std.posix.system.syslog(std.posix.LOG.INFO, msg.ptr);
}
try self.file_writer.interface.print("{s} [info/{s}] ", .{ time, category });
try self.file_writer.interface.print(message, args);
try self.file_writer.interface.writeByte('\n');
try self.file_writer.interface.flush();
}
pub fn err(self: *LogFile, io: std.Io, category: []const u8, comptime message: []const u8, args: anytype) !void {
if (self.maybe_file_writer) |*writer| {
var buffer: [128:0]u8 = undefined;
const time = interop.timeAsString(io, &buffer, "%Y-%m-%d %H:%M:%S");
try writer.interface.print("{s} [err/{s}] ", .{ time, category });
try writer.interface.print(message, args);
try writer.interface.writeByte('\n');
try writer.interface.flush();
} else {
var buffer: [1024]u8 = undefined;
const slice = try std.fmt.bufPrint(&buffer, message, args);
const msg = try std.fmt.bufPrintZ(buffer[slice.len..], "[info/{s}] {s}", .{ category, slice });
std.posix.system.syslog(std.posix.LOG.ERR, msg.ptr);
}
try self.file_writer.interface.print("{s} [err/{s}] ", .{ time, category });
try self.file_writer.interface.print(message, args);
try self.file_writer.interface.writeByte('\n');
try self.file_writer.interface.flush();
}
fn openLogFile(io: std.Io, path: []const u8, log_file: *LogFile) !bool {
var could_open_log_file = true;
open_log_file: {
log_file.maybe_file = std.Io.Dir.cwd().openFile(io, path, .{ .mode = .write_only }) catch std.Io.Dir.cwd().createFile(io, path, .{ .permissions = .fromMode(0o666) }) catch {
log_file.file = std.Io.Dir.cwd().openFile(io, path, .{ .mode = .write_only }) catch std.Io.Dir.cwd().createFile(io, path, .{ .permissions = .fromMode(0o666) }) catch {
// If we could neither open an existing log file nor create a new
// one, abort.
could_open_log_file = false;
@@ -90,17 +55,17 @@ fn openLogFile(io: std.Io, path: []const u8, log_file: *LogFile) !bool {
}
if (!could_open_log_file) {
log_file.maybe_file = try std.Io.Dir.openFileAbsolute(io, "/dev/null", .{ .mode = .write_only });
log_file.file = try std.Io.Dir.openFileAbsolute(io, "/dev/null", .{ .mode = .write_only });
}
var log_file_writer = log_file.maybe_file.?.writer(io, log_file.buffer);
var log_file_writer = log_file.file.writer(io, log_file.buffer);
// Seek to the end of the log file
if (could_open_log_file) {
const stat = try log_file.maybe_file.?.stat(io);
const stat = try log_file.file.stat(io);
try log_file_writer.seekTo(stat.size);
}
log_file.maybe_file_writer = log_file_writer;
log_file.file_writer = log_file_writer;
return could_open_log_file;
}

View File

@@ -1,6 +1,6 @@
.{
.name = .ly_ui,
.version = "1.1.0",
.version = "1.0.1",
.fingerprint = 0x8d11bf85a74ec803,
.minimum_zig_version = "0.16.0",
.dependencies = .{

View File

@@ -226,12 +226,6 @@ You can, of course, still select the init system of your choice when using this
You can find all the configuration in `/etc/ly/config.ini`. The file is fully commented, and includes the default values.
You may also check the validity of your configuration file (i.e. if there are any errors in it) with the following command:
```
$ ly --validate-config /etc/ly/config.ini
```
## Controls
Use the Up/Down arrow keys to change the current field, and the Left/Right arrow keys to scroll through the different fields (whether it be the info line, the desktop environment, or the username). The info line is where messages and errors are displayed.

View File

@@ -97,14 +97,6 @@ blank_box = true
# Border foreground color id
border_fg = 0x00FFFFFF
# Relative horizontal position from the end of the screen
# default: 0.5
box_position_h = 0.5
# Relative vertical position from the bottom of the screen
# default: 0.4
box_position_v = 0.4
# Title to show at the top of the main box
# If set to null, none will be shown
box_title = null
@@ -299,7 +291,6 @@ login_defs_path = /etc/login.defs
logout_cmd = null
# General log file path
# If null, syslog will be used instead
ly_log = /var/log/ly.log
# Main box horizontal margin

View File

@@ -19,7 +19,7 @@ const LogFile = ly_core.LogFile;
const enums = @import("../enums.zig");
const DurOffsetAlignment = enums.DurOffsetAlignment;
fn readDecompressFile(allocator: Allocator, io: std.Io, file_path: []const u8) ![]u8 {
fn read_decompress_file(allocator: Allocator, io: std.Io, file_path: []const u8) ![]u8 {
const file_buffer = std.Io.Dir.cwd().openFile(io, file_path, .{}) catch {
return error.FileNotFound;
};
@@ -62,7 +62,7 @@ const Frame = struct {
};
// https://github.com/cmang/durdraw/blob/0.29.0/durformat.md
const DurFormatRaw = struct {
const DurFormat = struct {
allocator: Allocator,
formatVersion: ?i64 = null,
colorFormat: ?[]const u8 = null,
@@ -72,48 +72,38 @@ const DurFormatRaw = struct {
lines: ?i64 = null,
frames: std.ArrayList(Frame) = undefined,
// Validate data and return a valid DurFormat
// Consumes `self`, making it unusable after
pub fn validate(self: *DurFormatRaw) !DurFormat {
pub fn valid(self: *DurFormat) bool {
if (self.formatVersion != null and
self.colorFormat != null and
self.encoding != null and
self.framerate != null and
self.columns != null and
self.lines != null and
self.frames.items.len >= 1)
{
// v8 may have breaking changes like changing the colormap xy direction
// (https://github.com/cmang/durdraw/issues/24)
const format_version = self.formatVersion orelse return error.MissingFieldVersion;
if (format_version != 7) return error.UnsupportedVersion;
if (self.formatVersion.? != 7) return false;
const color_format_str = self.colorFormat orelse return error.MissingFieldColorFormat;
// Code currently only supports 16 and 256 color format only
const color_format: DurColorFormat =
if (eql(u8, color_format_str, "16")) .@"16" else if (eql(u8, color_format_str, "256")) .@"256" else return error.UnsupportedColorFormat;
if (!(eql(u8, "16", self.colorFormat.?) or eql(u8, "256", self.colorFormat.?)))
return false;
const encoding_str = self.encoding orelse return error.MissingFieldEncoding;
// Code currently supports only utf-8 encoding
const encoding: DurEncoding = if (eql(u8, encoding_str, "utf-8")) .utf_8 else return error.UnsupportedEncoding;
if (self.framerate == null) return error.MissingFieldFramerate;
if (self.framerate.? <= 0) return error.InvalidFramerate;
const framerate: f64 = self.framerate.?;
if (!eql(u8, self.encoding.?, "utf-8")) return false;
// Sanity check on file
if (self.columns == null or self.lines == null) return error.MissingDimensions;
const columns = std.math.cast(u32, self.columns.?) orelse return error.InvalidColumnCount;
const lines = std.math.cast(u32, self.lines.?) orelse return error.InvalidLineCount;
if (self.columns.? <= 0) return false;
if (self.lines.? <= 0) return false;
if (self.framerate.? < 0) return false;
if (self.frames.items.len == 0) return error.NoFrames;
const frames = self.frames;
return .{
.allocator = self.allocator,
.formatVersion = format_version,
.colorFormat = color_format,
.encoding = encoding,
.framerate = framerate,
.columns = columns,
.lines = lines,
.frames = frames,
};
return true;
}
fn parseFromJson(self: *DurFormatRaw, allocator: Allocator, dur_json_root: Json.Value) !void {
return false;
}
fn parse_dur_from_json(self: *DurFormat, allocator: Allocator, dur_json_root: Json.Value) !void {
var dur_movie = if (dur_json_root.object.get("DurMovie")) |dm| dm.object else return error.NotValidFile;
// Depending on the version, a dur file can have different json object names (ie: columns vs sizeX)
@@ -160,44 +150,28 @@ const DurFormatRaw = struct {
}
}
pub fn createFromFile(self: *DurFormatRaw, allocator: Allocator, io: std.Io, file_path: []const u8) !void {
const file_decompressed = try readDecompressFile(allocator, io, file_path);
pub fn create_from_file(self: *DurFormat, allocator: Allocator, io: std.Io, file_path: []const u8) !void {
const file_decompressed = try read_decompress_file(allocator, io, file_path);
defer allocator.free(file_decompressed);
const parsed = try Json.parseFromSlice(Json.Value, allocator, file_decompressed, .{});
defer parsed.deinit();
try parseFromJson(self, allocator, parsed.value);
try parse_dur_from_json(self, allocator, parsed.value);
if (!self.valid()) {
return error.NotValidFile;
}
}
pub fn init(allocator: Allocator) DurFormatRaw {
pub fn init(allocator: Allocator) DurFormat {
return .{ .allocator = allocator };
}
pub fn deinit(self: *DurFormatRaw) void {
pub fn deinit(self: *DurFormat) void {
if (self.colorFormat) |str| self.allocator.free(str);
if (self.encoding) |str| self.allocator.free(str);
}
};
const DurColorFormat = enum {
@"16",
@"256",
};
const DurEncoding = enum { utf_8 };
const DurFormat = struct {
allocator: Allocator,
formatVersion: i64,
colorFormat: DurColorFormat,
encoding: DurEncoding,
framerate: f64,
columns: u32,
lines: u32,
frames: std.ArrayList(Frame),
pub fn deinit(self: *DurFormat) void {
for (self.frames.items) |frame| {
frame.deinit(self.allocator);
}
@@ -266,7 +240,7 @@ const durcolor_table_to_color16 = [17]u32{
15, // 16 bright white
};
fn sixCubeToChannel(sixcube: u32) u32 {
fn sixcube_to_channel(sixcube: u32) u32 {
// Although the range top for the extended range is 0xFF, 6 is not divisible into 0xFF,
// so we use 0xF0 instead with a scaler
const equal_divisions = 0xF0 / 6;
@@ -277,7 +251,7 @@ fn sixCubeToChannel(sixcube: u32) u32 {
return if (sixcube > 0) (sixcube * equal_divisions) + scaler else 0;
}
fn convert256ToRgb(color_256: u32) u32 {
fn convert_256_to_rgb(color_256: u32) u32 {
var rgb_color: u32 = 0;
// 0 - 15 is the standard color range, map to array table
@@ -293,9 +267,9 @@ fn convert256ToRgb(color_256: u32) u32 {
// divide by 1 gets the height of the cube (divide 1 for clarity for what we are doing)
// each channel can be 6 levels of brightness hence remander operation of 6
// finally bitshift to correct rgb channel (16 for red, 8 for green, 0 for blue)
rgb_color |= sixCubeToChannel(((color_256 - 16) / 36) % 6) << 16;
rgb_color |= sixCubeToChannel(((color_256 - 16) / 6) % 6) << 8;
rgb_color |= sixCubeToChannel(((color_256 - 16) / 1) % 6);
rgb_color |= sixcube_to_channel(((color_256 - 16) / 36) % 6) << 16;
rgb_color |= sixcube_to_channel(((color_256 - 16) / 6) % 6) << 8;
rgb_color |= sixcube_to_channel(((color_256 - 16) / 1) % 6);
}
// 232 - 255 is the grayscale range
else {
@@ -353,12 +327,12 @@ fn center(v: i64) i64 {
return @intCast(@divTrunc(v, 2) + @mod(v, 2));
}
fn calculateStartPos(terminal_buffer: *TerminalBuffer, dur_movie: *DurFormat, offset_alignment: DurOffsetAlignment, offset: IVec2) IVec2 {
fn calc_start_position(terminal_buffer: *TerminalBuffer, dur_movie: *DurFormat, offset_alignment: DurOffsetAlignment, offset: IVec2) IVec2 {
const buf_width: i64 = @intCast(terminal_buffer.width);
const buf_height: i64 = @intCast(terminal_buffer.height);
const movie_width: i64 = @intCast(dur_movie.columns);
const movie_height: i64 = @intCast(dur_movie.lines);
const movie_width: i64 = @intCast(dur_movie.columns.?);
const movie_height: i64 = @intCast(dur_movie.lines.?);
const start_pos: IVec2 = switch (offset_alignment) {
DurOffsetAlignment.center => .{ center(buf_width) - center(movie_width), center(buf_height) - center(movie_height) },
@@ -389,10 +363,9 @@ pub fn init(
timeout_sec: u12,
frame_delay: u16,
) !DurFile {
var dur_movie_raw: DurFormatRaw = .init(allocator);
defer dur_movie_raw.deinit();
var dur_movie: DurFormat = .init(allocator);
dur_movie_raw.createFromFile(allocator, io, file_path) catch |err| switch (err) {
dur_movie.create_from_file(allocator, io, file_path) catch |err| switch (err) {
error.FileNotFound => {
try log_file.err(io, "tui", "dur_file was not found at: {s}", .{file_path});
return err;
@@ -404,70 +377,19 @@ pub fn init(
else => return err,
};
var dur_movie = dur_movie_raw.validate() catch |err| switch (err) {
error.MissingFieldVersion => {
try log_file.err(io, "tui", "dur_file loaded was invalid: missing field formatVersion!", .{});
return err;
},
error.UnsupportedVersion => {
try log_file.err(io, "tui", "dur_file loaded was invalid: unsupported version ({d})!", .{dur_movie_raw.formatVersion.?});
return err;
},
error.MissingFieldColorFormat => {
try log_file.err(io, "tui", "dur_file loaded was invalid: missing field colorFormat!", .{});
return err;
},
error.UnsupportedColorFormat => {
try log_file.err(io, "tui", "dur_file loaded was invalid: unsupported colorFormat ({s})!", .{dur_movie_raw.colorFormat.?});
return err;
},
error.MissingFieldEncoding => {
try log_file.err(io, "tui", "dur_file loaded was invalid: missing field encoding!", .{});
return err;
},
error.UnsupportedEncoding => {
try log_file.err(io, "tui", "dur_file loaded was invalid: unsupported encoding ({s})!", .{dur_movie_raw.encoding.?});
return err;
},
error.MissingFieldFramerate => {
try log_file.err(io, "tui", "dur_file loaded was invalid: missing field framerate!", .{});
return err;
},
error.InvalidFramerate => {
try log_file.err(io, "tui", "dur_file loaded was invalid: negative framerate value found!", .{});
return err;
},
error.MissingDimensions => {
try log_file.err(io, "tui", "dur_file loaded was invalid: missing field(s) lines and/or columns!", .{});
return err;
},
error.InvalidColumnCount => {
try log_file.err(io, "tui", "dur_file loaded was invalid: columns value falls outside of supported range ({d})!", .{dur_movie_raw.columns.?});
return err;
},
error.InvalidLineCount => {
try log_file.err(io, "tui", "dur_file loaded was invalid: lines value falls outside of supported range ({d})!", .{dur_movie_raw.lines.?});
return err;
},
error.NoFrames => {
try log_file.err(io, "tui", "dur_file loaded was invalid: animation has no frames!", .{});
return err;
},
};
// 4 bit mode with 256 color is unsupported
if (!full_color and dur_movie.colorFormat == .@"256") {
if (!full_color and eql(u8, dur_movie.colorFormat.?, "256")) {
try log_file.err(io, "tui", "dur_file can not be 256 color encoded when not using full_color option!", .{});
dur_movie.deinit();
return error.NotFullColor;
return error.InvalidColorFormat;
}
const offset: IVec2 = .{ x_offset, y_offset };
const start_pos = calculateStartPos(terminal_buffer, &dur_movie, offset_alignment, offset);
const start_pos = calc_start_position(terminal_buffer, &dur_movie, offset_alignment, offset);
// Convert dur fps to frames per ms
const frame_time: u32 = @trunc(1000 / dur_movie.framerate);
const frame_time: u32 = @trunc(1000 / dur_movie.framerate.?);
return .{
.instance = null,
@@ -484,7 +406,7 @@ pub fn init(
.frame_delay = frame_delay,
.dur_movie = dur_movie,
.frame_time = frame_time,
.is_color_format_16 = dur_movie.colorFormat == .@"16",
.is_color_format_16 = eql(u8, dur_movie.colorFormat.?, "16"),
.offset_alignment = offset_alignment,
.offset = offset,
};
@@ -512,7 +434,7 @@ fn deinit(self: *DurFile) void {
fn realloc(self: *DurFile) !void {
// when terminal size changes, we need to recalculate the start_pos based on the new size
self.start_pos = calculateStartPos(self.terminal_buffer, &self.dur_movie, self.offset_alignment, self.offset);
self.start_pos = calc_start_position(self.terminal_buffer, &self.dur_movie, self.offset_alignment, self.offset);
}
fn draw(self: *DurFile) void {
@@ -521,12 +443,12 @@ fn draw(self: *DurFile) void {
const current_frame = self.dur_movie.frames.items[self.frames];
// y is used as an iterator in the durformat, while cell_y gives us the correct placement for the cell (same for x)
for (0..@intCast(self.dur_movie.lines)) |y| {
for (0..@intCast(self.dur_movie.lines.?)) |y| {
const cell_y = @as(i32, @intCast(y)) + self.start_pos[VEC_Y];
var iter = std.unicode.Utf8View.initUnchecked(current_frame.contents[y]).iterator();
for (0..@intCast(self.dur_movie.columns)) |x| {
for (0..@intCast(self.dur_movie.columns.?)) |x| {
const cell_x = @as(i32, @intCast(x)) + self.start_pos[VEC_X];
const codepoint: u21 = iter.nextCodepoint().?;
@@ -540,8 +462,8 @@ fn draw(self: *DurFile) void {
color_map_1 = durcolor_table_to_color16[color_map_1 + 1]; // Add 1, dur source stores it like this for some reason
}
const fg_color = if (self.full_color) convert256ToRgb(color_map_0) else tb_color_16[color_map_0];
const bg_color = if (self.full_color) convert256ToRgb(color_map_1) else tb_color_16[color_map_1];
const fg_color = if (self.full_color) convert_256_to_rgb(color_map_0) else tb_color_16[color_map_0];
const bg_color = if (self.full_color) convert_256_to_rgb(color_map_1) else tb_color_16[color_map_1];
const cell = Cell{ .ch = @intCast(codepoint), .fg = fg_color, .bg = bg_color };

View File

@@ -23,8 +23,6 @@ bigclock_12hr: bool = false,
bigclock_seconds: bool = false,
blank_box: bool = true,
border_fg: u32 = 0x00FFFFFF,
box_position_h: f32 = 0.5,
box_position_v: f32 = 0.4,
box_title: ?[]const u8 = null,
brightness_down_cmd: [:0]const u8 = build_options.prefix_directory ++ "/bin/brightnessctl -q -n s 10%-",
brightness_down_key: ?[]const u8 = "F5",
@@ -74,7 +72,7 @@ lang: []const u8 = "en",
login_cmd: ?[]const u8 = null,
login_defs_path: []const u8 = "/etc/login.defs",
logout_cmd: ?[]const u8 = null,
ly_log: ?[]const u8 = "/var/log/ly.log",
ly_log: []const u8 = "/var/log/ly.log",
margin_box_h: u8 = 2,
margin_box_v: u8 = 1,
numlock: bool = false,

View File

@@ -146,10 +146,12 @@ pub fn main(init: std.process.Init) !void {
// If we can't shutdown or restart due to an error, we print it to standard error. If that fails, just bail out
if (shutdown) {
const shutdown_error = std.process.replace(state.io, .{ .argv = &[_][]const u8{ "/bin/sh", "-c", shutdown_cmd } });
std.log.err("couldn't shutdown: {s}", .{@errorName(shutdown_error)});
stderr.print("error: couldn't shutdown: {s}\n", .{@errorName(shutdown_error)}) catch std.process.exit(1);
stderr.flush() catch std.process.exit(1);
} else if (restart) {
const restart_error = std.process.replace(state.io, .{ .argv = &[_][]const u8{ "/bin/sh", "-c", restart_cmd } });
std.log.err("couldn't restart: {s}", .{@errorName(restart_error)});
stderr.print("error: couldn't restart: {s}\n", .{@errorName(restart_error)}) catch std.process.exit(1);
stderr.flush() catch std.process.exit(1);
} else {
// The user has quit Ly using Ctrl+C
if (commands_allocated) {
@@ -170,8 +172,7 @@ pub fn main(init: std.process.Init) !void {
\\-h, --help Shows all commands.
\\-v, --version Shows the version of Ly.
\\-c, --config <str> Overrides the default configuration path. Example: --config /usr/share/ly
\\--use-kmscon-vt Uses KMSCON instead of the kernel VT.
\\--validate-config <str> Validates the given configuration file.
\\--use-kmscon-vt Use KMSCON instead of kernel VT
);
var diag = clap.Diagnostic{};
@@ -199,39 +200,17 @@ pub fn main(init: std.process.Init) !void {
if (res.args.help != 0) {
try clap.help(stderr, clap.Help, &params, .{});
std.log.info("note: if you want to configure Ly, please check the config file, which is located at " ++ build_options.config_directory ++ "/ly/config.ini.", .{});
_ = try stderr.write("Note: if you want to configure Ly, please check the config file, which is located at " ++ build_options.config_directory ++ "/ly/config.ini.\n");
try stderr.flush();
std.process.exit(0);
}
if (res.args.version != 0) {
std.log.info("ly version " ++ build_options.version, .{});
_ = try stderr.write("Ly version " ++ build_options.version ++ "\n");
try stderr.flush();
std.process.exit(0);
}
if (res.args.config) |path| config_parent_path = path;
if (res.args.@"use-kmscon-vt" != 0) state.use_kmscon_vt = true;
if (res.args.@"validate-config") |path| {
var parser = try IniParser(Config).init(
state.allocator,
state.io,
path,
migrator.configFieldHandler,
);
defer parser.deinit();
for (parser.errors.items) |err| {
std.log.err(
"failed to convert value '{s}' of option '{s}' to type '{s}': {s}",
.{ err.value, err.key, err.type_name, err.error_name },
);
}
if (parser.maybe_load_error) |err| {
std.log.err("failed to load config file: {s}", .{@errorName(err)});
std.process.exit(1);
}
std.log.info("no errors detected!", .{});
std.process.exit(0);
}
}
// Load configuration file
@@ -2065,35 +2044,21 @@ fn positionWidgets(ptr: *anyopaque) !void {
.childrenPosition()
.removeX(TerminalBuffer.strWidth(state.lang.numlock) + TerminalBuffer.strWidth(state.lang.capslock) + 1));
var bb_height = state.box.height;
var bb_width = state.box.width;
const clock_text_len = TerminalBuffer.strWidth(state.bigclock_label.text) * (BigLabel.CHAR_WIDTH + 1);
if (state.config.bigclock != .none) {
bb_height += BigLabel.CHAR_HEIGHT + 2;
bb_width = @max(bb_width, clock_text_len);
}
const max_v_position: f32 = @floatFromInt(state.buffer.height - bb_height - 1);
const max_h_position: f32 = @floatFromInt(state.buffer.width - bb_width - 1);
bb_height = @min(bb_height, state.buffer.height - 2);
bb_width = @min(bb_width, state.buffer.width - 2);
const v_space: f32 = @floatFromInt(state.buffer.height - bb_height);
const v_position: usize = @intFromFloat(std.math.clamp(v_space * state.config.box_position_v, 1.0, max_v_position));
const h_space: f32 = @floatFromInt(state.buffer.width - bb_width);
const h_position: usize = @intFromFloat(std.math.clamp(h_space * state.config.box_position_h, 1.0, max_h_position));
if (state.config.bigclock != .none) {
state.bigclock_label.positionXY(TerminalBuffer.START_POSITION
.addX(h_position + (bb_width - clock_text_len) / 2)
.addY(v_position));
}
state.box.positionXY(TerminalBuffer.START_POSITION
.addX(h_position + (bb_width - state.box.width) / 2)
.addY(v_position + (bb_height - state.box.height)));
.addX((state.buffer.width - @min(state.buffer.width - 2, state.box.width)) / 2)
.addY((state.buffer.height - @min(state.buffer.height - 2, state.box.height)) / 2));
if (state.config.bigclock != .none) {
const half_width = state.buffer.width / 2;
const half_label_width = (TerminalBuffer.strWidth(state.bigclock_label.text) * (BigLabel.CHAR_WIDTH + 1)) / 2;
const half_height = (if (state.buffer.height > state.box.height) state.buffer.height - state.box.height else state.buffer.height) / 2;
state.bigclock_label.positionXY(TerminalBuffer.START_POSITION
.addX(half_width)
.removeXIf(half_label_width, half_width > half_label_width)
.addY(half_height)
.removeYIf(BigLabel.CHAR_HEIGHT + 2, half_height > BigLabel.CHAR_HEIGHT + 2));
}
state.info_line.label.positionY(state.box
.childrenPosition());