Remove maximum length config options + don't localize config parse error

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2024-07-31 14:31:28 +02:00
parent 48f28e40c4
commit 548a411ae2
10 changed files with 38 additions and 44 deletions

View File

@@ -86,13 +86,8 @@ margin_box_v = 1
# Input boxes length # Input boxes length
input_len = 34 input_len = 34
# Max input sizes
max_desktop_len = 100
max_login_len = 255
max_password_len = 255
# Input box active by default on startup # Input box active by default on startup
# Available inputs: session, login, password # Available inputs: info_line, session, login, password
default_input = login default_input = login
# Load the saved desktop and username # Load the saved desktop and username

View File

@@ -6,7 +6,6 @@ err_alloc = failed memory allocation
err_bounds = out-of-bounds index err_bounds = out-of-bounds index
err_brightness_change = failed to change brightness err_brightness_change = failed to change brightness
err_chdir = failed to open home folder err_chdir = failed to open home folder
err_config = unable to parse config file
err_console_dev = failed to access console err_console_dev = failed to access console
err_dgn_oob = log message err_dgn_oob = log message
err_domain = invalid domain err_domain = invalid domain

View File

@@ -6,7 +6,6 @@ err_alloc = échec d'allocation mémoire
err_bounds = indice hors-limite err_bounds = indice hors-limite
err_brightness_change = échec du changement de luminosité err_brightness_change = échec du changement de luminosité
err_chdir = échec de l'ouverture du répertoire home err_chdir = échec de l'ouverture du répertoire home
err_config = échec de l'analyse du fichier de configuration
err_console_dev = échec d'accès à la console err_console_dev = échec d'accès à la console
err_dgn_oob = message err_dgn_oob = message
err_domain = domaine invalide err_domain = domaine invalide

View File

@@ -28,9 +28,6 @@ lang: []const u8 = "en",
load: bool = true, load: bool = true,
margin_box_h: u8 = 2, margin_box_h: u8 = 2,
margin_box_v: u8 = 1, margin_box_v: u8 = 1,
max_desktop_len: u8 = 100,
max_login_len: u8 = 255,
max_password_len: u8 = 255,
mcookie_cmd: [:0]const u8 = "/usr/bin/mcookie", mcookie_cmd: [:0]const u8 = "/usr/bin/mcookie",
min_refresh_delta: u16 = 5, min_refresh_delta: u16 = 5,
numlock: bool = false, numlock: bool = false,

View File

@@ -5,14 +5,14 @@ const ini = @import("zigini");
const Save = @import("Save.zig"); const Save = @import("Save.zig");
const enums = @import("../enums.zig"); const enums = @import("../enums.zig");
var animate = false; var maybe_animate: ?bool = null;
pub var mapped_config_fields = false; pub var mapped_config_fields = false;
pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniField { pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniField {
if (std.mem.eql(u8, field.key, "animate")) { if (std.mem.eql(u8, field.key, "animate")) {
// The option doesn't exist anymore, but we save its value for "animation" // The option doesn't exist anymore, but we save its value for "animation"
animate = std.mem.eql(u8, field.value, "true"); maybe_animate = std.mem.eql(u8, field.value, "true");
mapped_config_fields = true; mapped_config_fields = true;
return null; return null;
@@ -59,9 +59,12 @@ pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniFie
return mapped_field; return mapped_field;
} }
if (std.mem.eql(u8, field.key, "wayland_specifier")) { if (std.mem.eql(u8, field.key, "wayland_specifier") or
// The option doesn't exist anymore std.mem.eql(u8, field.key, "max_desktop_len") or
std.mem.eql(u8, field.key, "max_login_len") or
std.mem.eql(u8, field.key, "max_password_len"))
{
// The options don't exist anymore
mapped_config_fields = true; mapped_config_fields = true;
return null; return null;
} }
@@ -72,9 +75,9 @@ pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniFie
// This is the stuff we only handle after reading the config. // This is the stuff we only handle after reading the config.
// For example, the "animate" field could come after "animation" // For example, the "animate" field could come after "animation"
pub fn lateConfigFieldHandler(animation: *enums.Animation) void { pub fn lateConfigFieldHandler(animation: *enums.Animation) void {
if (!mapped_config_fields) return; if (maybe_animate == null) return;
if (!animate) animation.* = .none; if (!maybe_animate.?) animation.* = .none;
} }
pub fn tryMigrateSaveFile(user_buf: *[32]u8, path: []const u8) Save { pub fn tryMigrateSaveFile(user_buf: *[32]u8, path: []const u8) Save {

View File

@@ -217,14 +217,15 @@ pub fn main() !void {
var buffer = TerminalBuffer.init(config, labels_max_length, random); var buffer = TerminalBuffer.init(config, labels_max_length, random);
// Initialize components // Initialize components
var info_line = try InfoLine.init(allocator, &buffer, 255); var info_line = InfoLine.init(allocator, &buffer);
defer info_line.deinit(); defer info_line.deinit();
if (config_load_failed) { if (config_load_failed) {
try info_line.addMessage(lang.err_config, config.error_bg, config.error_fg); // We can't localize this since the config failed to load so we'd fallback to the default language anyway
try info_line.addMessage("unable to parse config file", config.error_bg, config.error_fg);
} }
var session = try Session.init(allocator, &buffer, config.max_desktop_len, lang); var session = Session.init(allocator, &buffer, lang);
defer session.deinit(); defer session.deinit();
session.addEnvironment(.{ .Name = lang.shell }, "", .shell) catch { session.addEnvironment(.{ .Name = lang.shell }, "", .shell) catch {
@@ -256,10 +257,10 @@ pub fn main() !void {
try session.crawl(config.waylandsessions, .wayland); try session.crawl(config.waylandsessions, .wayland);
if (build_options.enable_x11_support) try session.crawl(config.xsessions, .x11); if (build_options.enable_x11_support) try session.crawl(config.xsessions, .x11);
var login = try Text.init(allocator, &buffer, config.max_login_len, false, null); var login = Text.init(allocator, &buffer, false, null);
defer login.deinit(); defer login.deinit();
var password = try Text.init(allocator, &buffer, config.max_password_len, true, config.asterisk); var password = Text.init(allocator, &buffer, true, config.asterisk);
defer password.deinit(); defer password.deinit();
var active_input = config.default_input; var active_input = config.default_input;
@@ -496,22 +497,22 @@ pub fn main() !void {
buffer.drawLabel(label_txt, buffer.box_x, buffer.box_y + buffer.box_height); buffer.drawLabel(label_txt, buffer.box_x, buffer.box_y + buffer.box_height);
} }
draw_lock_state: { // draw_lock_state: {
const lock_state = interop.getLockState(config.console_dev) catch { // const lock_state = interop.getLockState(config.console_dev) catch {
try info_line.addMessage(lang.err_console_dev, config.error_bg, config.error_fg); // try info_line.addMessage(lang.err_console_dev, config.error_bg, config.error_fg);
break :draw_lock_state; // break :draw_lock_state;
}; // };
var lock_state_x = buffer.width - @min(buffer.width, lang.numlock.len); // var lock_state_x = buffer.width - @min(buffer.width, lang.numlock.len);
const lock_state_y: usize = if (config.clock != null) 1 else 0; // const lock_state_y: usize = if (config.clock != null) 1 else 0;
if (lock_state.numlock) buffer.drawLabel(lang.numlock, lock_state_x, lock_state_y); // if (lock_state.numlock) buffer.drawLabel(lang.numlock, lock_state_x, lock_state_y);
if (lock_state_x >= lang.capslock.len + 1) { // if (lock_state_x >= lang.capslock.len + 1) {
lock_state_x -= lang.capslock.len + 1; // lock_state_x -= lang.capslock.len + 1;
if (lock_state.capslock) buffer.drawLabel(lang.capslock, lock_state_x, lock_state_y); // if (lock_state.capslock) buffer.drawLabel(lang.capslock, lock_state_x, lock_state_y);
} // }
} // }
session.label.draw(); session.label.draw();
login.draw(); login.draw();

View File

@@ -18,9 +18,9 @@ const Message = struct {
label: MessageLabel, label: MessageLabel,
pub fn init(allocator: Allocator, buffer: *TerminalBuffer, max_length: usize) !InfoLine { pub fn init(allocator: Allocator, buffer: *TerminalBuffer) InfoLine {
return .{ return .{
.label = try MessageLabel.init(allocator, buffer, max_length, drawItem), .label = MessageLabel.init(allocator, buffer, drawItem),
}; };
} }

View File

@@ -34,9 +34,9 @@ pub const Entry = struct { @"Desktop Entry": DesktopEntry = .{} };
label: EnvironmentLabel, label: EnvironmentLabel,
lang: Lang, lang: Lang,
pub fn init(allocator: Allocator, buffer: *TerminalBuffer, max_length: usize, lang: Lang) !Session { pub fn init(allocator: Allocator, buffer: *TerminalBuffer, lang: Lang) Session {
return .{ return .{
.label = try EnvironmentLabel.init(allocator, buffer, max_length, drawItem), .label = EnvironmentLabel.init(allocator, buffer, drawItem),
.lang = lang, .lang = lang,
}; };
} }

View File

@@ -22,8 +22,8 @@ y: usize,
masked: bool, masked: bool,
maybe_mask: ?u8, maybe_mask: ?u8,
pub fn init(allocator: Allocator, buffer: *TerminalBuffer, max_length: usize, masked: bool, maybe_mask: ?u8) !Text { pub fn init(allocator: Allocator, buffer: *TerminalBuffer, masked: bool, maybe_mask: ?u8) Text {
const text = try DynamicString.initCapacity(allocator, max_length); const text = DynamicString.init(allocator);
return .{ return .{
.allocator = allocator, .allocator = allocator,

View File

@@ -23,11 +23,11 @@ pub fn CyclableLabel(comptime ItemType: type) type {
first_char_x: usize, first_char_x: usize,
draw_item_fn: DrawItemFn, draw_item_fn: DrawItemFn,
pub fn init(allocator: Allocator, buffer: *TerminalBuffer, max_length: usize, draw_item_fn: DrawItemFn) !Self { pub fn init(allocator: Allocator, buffer: *TerminalBuffer, draw_item_fn: DrawItemFn) Self {
return .{ return .{
.allocator = allocator, .allocator = allocator,
.buffer = buffer, .buffer = buffer,
.list = try ItemList.initCapacity(allocator, max_length), .list = ItemList.init(allocator),
.current = 0, .current = 0,
.visible_length = 0, .visible_length = 0,
.x = 0, .x = 0,