diff --git a/ly-ui/src/components/Text.zig b/ly-ui/src/components/Text.zig index 0ca5312..d7aaca2 100644 --- a/ly-ui/src/components/Text.zig +++ b/ly-ui/src/components/Text.zig @@ -144,6 +144,10 @@ pub fn handle(self: *Text, maybe_key: ?keyboard.Key) !void { ); } +pub fn writeText(self: *Text, str: []const u8) !void { + for (str) |c| try self.write(c); +} + fn draw(self: *Text) void { if (self.masked) { if (self.maybe_mask) |mask| { diff --git a/res/config.ini b/res/config.ini index 6948a5c..c6e76b5 100644 --- a/res/config.ini +++ b/res/config.ini @@ -292,10 +292,6 @@ login_cmd = null # Linux) login_defs_path = /etc/login.defs -# If true, user need to manually type username instead of selecting from the list -# of discovered users -type_username = false - # Command executed when logging out # If null, no command will be executed # Important: the session will already be terminated when this command is executed, so @@ -374,6 +370,10 @@ start_cmd = $CONFIG_DIRECTORY/ly/startup.sh # Center the session name. text_in_center = false +# If true, user will need to manually type username instead of selecting from the list +# of discovered users +type_username = false + # Default vi mode # normal -> normal mode # insert -> insert mode diff --git a/src/config/Config.zig b/src/config/Config.zig index fd3ee3d..045fdd4 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -73,7 +73,6 @@ input_len: u8 = 34, lang: []const u8 = "en", login_cmd: ?[]const u8 = null, login_defs_path: []const u8 = "/etc/login.defs", -type_username: bool = false, logout_cmd: ?[]const u8 = null, ly_log: ?[]const u8 = "/var/log/ly.log", margin_box_h: u8 = 2, @@ -95,6 +94,7 @@ sleep_cmd: ?[]const u8 = null, sleep_key: []const u8 = "F3", start_cmd: ?[]const u8 = null, text_in_center: bool = false, +type_username: bool = false, vi_default_mode: ViMode = .normal, vi_mode: bool = false, waylandsessions: ?[]const u8 = build_options.prefix_directory ++ "/share/wayland-sessions", diff --git a/src/main.zig b/src/main.zig index 0dfeaed..4da9378 100644 --- a/src/main.zig +++ b/src/main.zig @@ -889,12 +889,12 @@ pub fn main(init: std.process.Init) !void { ); } - if (usernames.items.len == 0 and !state.config.type_username) { + if (usernames.items.len == 0) { // If we have no usernames, simply add an error to the info line. // This effectively means you can't login, since there would be no local // accounts *and* no root account...but at this point, if that's the // case, you have bigger problems to deal with in the first place. :D - try state.info_line.addMessage(state.lang.err_no_users, state.config.error_bg, state.config.error_fg); + if (!state.config.type_username) try state.info_line.addMessage(state.lang.err_no_users, state.config.error_bg, state.config.error_fg); try state.log_file.err(state.io, "sys", "no users found", .{}); } @@ -958,8 +958,6 @@ pub fn main(init: std.process.Init) !void { state.is_autologin = false; check_autologin: { - if (state.config.type_username) break :check_autologin; - const auto_user = state.config.auto_login_user orelse break :check_autologin; const auto_session = state.config.auto_login_session orelse break :check_autologin; @@ -1141,19 +1139,23 @@ pub fn main(init: std.process.Init) !void { // Skip if autologin is active to prevent overriding autologin session var default_input = state.config.default_input; - if (state.config.save and !state.is_autologin and !state.config.type_username) { + if (state.config.save and !state.is_autologin) { if (state.saved_users.last_username_index) |index| load_last_user: { // If the saved index isn't valid, bail out if (index >= state.saved_users.user_list.items.len) break :load_last_user; const user = state.saved_users.user_list.items[index]; - // Find user with saved name, and switch over to it - // If it doesn't exist (anymore), we don't change the value - for (usernames.items, 0..) |username, i| { - if (std.mem.eql(u8, username, user.username)) { - state.login.label.current = i; - break; + if (state.login_text) |box| { + try box.writeText(user.username); + } else { + // Find user with saved name, and switch over to it + // If it doesn't exist (anymore), we don't change the value + for (usernames.items, 0..) |username, i| { + if (std.mem.eql(u8, username, user.username)) { + state.login.label.current = i; + break; + } } } @@ -1617,7 +1619,7 @@ fn authenticate(ptr: *anyopaque) !bool { &state.log_file, auth_options, current_environment, - if (state.config.type_username) state.login_text.?.text.items else state.login.getCurrentUsername(), + if (state.login_text) |box| box.text.items else state.login.getCurrentUsername(), password_text, ) catch |err| { shared_err.writeError(err); @@ -2142,8 +2144,8 @@ fn positionWidgets(ptr: *anyopaque) !void { .childrenPosition() .resetXFrom(state.info_line.label.childrenPosition()) .addY(1)); - if (state.config.type_username) { - state.login_text.?.positionY(state.login_label + if (state.login_text) |box| { + box.positionY(state.login_label .childrenPosition() .addX(state.labels_max_length - TerminalBuffer.strWidth(state.login_label.text) + 1)); } else { @@ -2152,8 +2154,8 @@ fn positionWidgets(ptr: *anyopaque) !void { .addX(state.labels_max_length - TerminalBuffer.strWidth(state.login_label.text) + 1)); } - const login_children_pos = if (state.config.type_username) - state.login_text.?.childrenPosition() + const login_children_pos = if (state.login_text) |box| + box.childrenPosition() else state.login.label.childrenPosition();