mirror of https://github.com/fairyglade/ly.git
Remove maximum length config options + don't localize config parse error
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
parent
48f28e40c4
commit
548a411ae2
|
@ -86,13 +86,8 @@ margin_box_v = 1
|
|||
# Input boxes length
|
||||
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
|
||||
# Available inputs: session, login, password
|
||||
# Available inputs: info_line, session, login, password
|
||||
default_input = login
|
||||
|
||||
# Load the saved desktop and username
|
||||
|
|
|
@ -6,7 +6,6 @@ err_alloc = failed memory allocation
|
|||
err_bounds = out-of-bounds index
|
||||
err_brightness_change = failed to change brightness
|
||||
err_chdir = failed to open home folder
|
||||
err_config = unable to parse config file
|
||||
err_console_dev = failed to access console
|
||||
err_dgn_oob = log message
|
||||
err_domain = invalid domain
|
||||
|
|
|
@ -6,7 +6,6 @@ err_alloc = échec d'allocation mémoire
|
|||
err_bounds = indice hors-limite
|
||||
err_brightness_change = échec du changement de luminosité
|
||||
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_dgn_oob = message
|
||||
err_domain = domaine invalide
|
||||
|
|
|
@ -28,9 +28,6 @@ lang: []const u8 = "en",
|
|||
load: bool = true,
|
||||
margin_box_h: u8 = 2,
|
||||
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",
|
||||
min_refresh_delta: u16 = 5,
|
||||
numlock: bool = false,
|
||||
|
|
|
@ -5,14 +5,14 @@ const ini = @import("zigini");
|
|||
const Save = @import("Save.zig");
|
||||
const enums = @import("../enums.zig");
|
||||
|
||||
var animate = false;
|
||||
var maybe_animate: ?bool = null;
|
||||
|
||||
pub var mapped_config_fields = false;
|
||||
|
||||
pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniField {
|
||||
if (std.mem.eql(u8, field.key, "animate")) {
|
||||
// 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;
|
||||
return null;
|
||||
|
@ -59,9 +59,12 @@ pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniFie
|
|||
return mapped_field;
|
||||
}
|
||||
|
||||
if (std.mem.eql(u8, field.key, "wayland_specifier")) {
|
||||
// The option doesn't exist anymore
|
||||
|
||||
if (std.mem.eql(u8, field.key, "wayland_specifier") or
|
||||
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;
|
||||
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.
|
||||
// For example, the "animate" field could come after "animation"
|
||||
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 {
|
||||
|
|
37
src/main.zig
37
src/main.zig
|
@ -217,14 +217,15 @@ pub fn main() !void {
|
|||
var buffer = TerminalBuffer.init(config, labels_max_length, random);
|
||||
|
||||
// Initialize components
|
||||
var info_line = try InfoLine.init(allocator, &buffer, 255);
|
||||
var info_line = InfoLine.init(allocator, &buffer);
|
||||
defer info_line.deinit();
|
||||
|
||||
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();
|
||||
|
||||
session.addEnvironment(.{ .Name = lang.shell }, "", .shell) catch {
|
||||
|
@ -256,10 +257,10 @@ pub fn main() !void {
|
|||
try session.crawl(config.waylandsessions, .wayland);
|
||||
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();
|
||||
|
||||
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();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
draw_lock_state: {
|
||||
const lock_state = interop.getLockState(config.console_dev) catch {
|
||||
try info_line.addMessage(lang.err_console_dev, config.error_bg, config.error_fg);
|
||||
break :draw_lock_state;
|
||||
};
|
||||
// draw_lock_state: {
|
||||
// const lock_state = interop.getLockState(config.console_dev) catch {
|
||||
// try info_line.addMessage(lang.err_console_dev, config.error_bg, config.error_fg);
|
||||
// break :draw_lock_state;
|
||||
// };
|
||||
|
||||
var lock_state_x = buffer.width - @min(buffer.width, lang.numlock.len);
|
||||
const lock_state_y: usize = if (config.clock != null) 1 else 0;
|
||||
// var lock_state_x = buffer.width - @min(buffer.width, lang.numlock.len);
|
||||
// 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) {
|
||||
lock_state_x -= lang.capslock.len + 1;
|
||||
if (lock_state.capslock) buffer.drawLabel(lang.capslock, lock_state_x, lock_state_y);
|
||||
}
|
||||
}
|
||||
// if (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);
|
||||
// }
|
||||
// }
|
||||
|
||||
session.label.draw();
|
||||
login.draw();
|
||||
|
|
|
@ -18,9 +18,9 @@ const Message = struct {
|
|||
|
||||
label: MessageLabel,
|
||||
|
||||
pub fn init(allocator: Allocator, buffer: *TerminalBuffer, max_length: usize) !InfoLine {
|
||||
pub fn init(allocator: Allocator, buffer: *TerminalBuffer) InfoLine {
|
||||
return .{
|
||||
.label = try MessageLabel.init(allocator, buffer, max_length, drawItem),
|
||||
.label = MessageLabel.init(allocator, buffer, drawItem),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -34,9 +34,9 @@ pub const Entry = struct { @"Desktop Entry": DesktopEntry = .{} };
|
|||
label: EnvironmentLabel,
|
||||
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 .{
|
||||
.label = try EnvironmentLabel.init(allocator, buffer, max_length, drawItem),
|
||||
.label = EnvironmentLabel.init(allocator, buffer, drawItem),
|
||||
.lang = lang,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ y: usize,
|
|||
masked: bool,
|
||||
maybe_mask: ?u8,
|
||||
|
||||
pub fn init(allocator: Allocator, buffer: *TerminalBuffer, max_length: usize, masked: bool, maybe_mask: ?u8) !Text {
|
||||
const text = try DynamicString.initCapacity(allocator, max_length);
|
||||
pub fn init(allocator: Allocator, buffer: *TerminalBuffer, masked: bool, maybe_mask: ?u8) Text {
|
||||
const text = DynamicString.init(allocator);
|
||||
|
||||
return .{
|
||||
.allocator = allocator,
|
||||
|
|
|
@ -23,11 +23,11 @@ pub fn CyclableLabel(comptime ItemType: type) type {
|
|||
first_char_x: usize,
|
||||
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 .{
|
||||
.allocator = allocator,
|
||||
.buffer = buffer,
|
||||
.list = try ItemList.initCapacity(allocator, max_length),
|
||||
.list = ItemList.init(allocator),
|
||||
.current = 0,
|
||||
.visible_length = 0,
|
||||
.x = 0,
|
||||
|
|
Loading…
Reference in New Issue