Review part 1

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion 2026-07-05 21:35:26 +02:00
commit f413d118e4
No known key found for this signature in database
4 changed files with 27 additions and 21 deletions

View file

@ -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| {

View file

@ -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

View file

@ -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",

View file

@ -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();