Fix/Changes according to the Comments

This commit is contained in:
garopoulos 2026-03-19 16:49:27 +02:00
commit 2cad6f25f0
2 changed files with 57 additions and 41 deletions

View file

@ -19,12 +19,12 @@ const EnvironmentLabel = CyclableLabel(Env, *UserList);
const Session = @This();
label: *EnvironmentLabel,
user_list: *UserList,
user_list: ?*UserList,
pub fn init(
allocator: Allocator,
buffer: *TerminalBuffer,
user_list: *UserList,
user_list: ?*UserList,
width: usize,
text_in_center: bool,
fg: u32,
@ -73,7 +73,9 @@ pub fn addEnvironment(self: *Session, environment: Environment) !void {
const env = Env{ .environment = environment, .index = self.label.list.items.len };
try self.label.addItem(env);
addedSession(env, self.user_list);
if (self.user_list) |user_list| {
addedSession(env, user_list);
}
}
fn draw(self: *Session) void {

View file

@ -655,20 +655,6 @@ pub fn main() !void {
);
defer state.session_specifier_label.deinit();
state.session = try Session.init(
state.allocator,
&state.buffer,
&state.login,
state.box.width - 2 * state.box.horizontal_margin - state.labels_max_length - 1,
state.config.text_in_center,
state.buffer.fg,
state.buffer.bg,
);
defer state.session.deinit();
try state.buffer.registerKeybind(&state.session.label.keybinds, "H", &viGoLeft, &state);
try state.buffer.registerKeybind(&state.session.label.keybinds, "L", &viGoRight, &state);
state.login_label = Label.init(
state.lang.login,
null,
@ -679,18 +665,6 @@ pub fn main() !void {
);
defer state.login_label.deinit();
state.login = try UserList.init(
state.allocator,
&state.buffer,
usernames,
&state.saved_users,
&state.session,
state.box.width - 2 * state.box.horizontal_margin - state.labels_max_length - 1,
state.config.text_in_center,
state.buffer.fg,
state.buffer.bg,
);
if (state.config.type_username) {
state.login_text = try Text.init(
state.allocator,
@ -703,12 +677,34 @@ pub fn main() !void {
state.buffer.bg,
);
state.login_text_widget = state.login_text.widget();
} else {
state.login = try UserList.init(
state.allocator,
&state.buffer,
usernames,
&state.saved_users,
&state.session,
state.box.width - 2 * state.box.horizontal_margin - state.labels_max_length - 1,
state.config.text_in_center,
state.buffer.fg,
state.buffer.bg,
);
}
defer if (state.config.type_username) state.login_text.deinit() else state.login.deinit();
defer state.login.deinit();
state.session = try Session.init(
state.allocator,
&state.buffer,
if (state.config.type_username) null else &state.login,
state.box.width - 2 * state.box.horizontal_margin - state.labels_max_length - 1,
state.config.text_in_center,
state.buffer.fg,
state.buffer.bg,
);
defer state.session.deinit();
try state.buffer.registerKeybind(&state.login.label.keybinds, "H", &viGoLeft, &state);
try state.buffer.registerKeybind(&state.login.label.keybinds, "L", &viGoRight, &state);
try state.buffer.registerKeybind(&state.session.label.keybinds, "H", &viGoLeft, &state);
try state.buffer.registerKeybind(&state.session.label.keybinds, "L", &viGoRight, &state);
addOtherEnvironment(&state.session, state.lang, .shell, null) catch |err| {
try state.info_line.addMessage(
@ -888,10 +884,12 @@ pub fn main() !void {
);
state.session.label.current = session_index;
for (state.login.label.list.items, 0..) |username, i| {
if (std.mem.eql(u8, username.name, auto_user)) {
state.login.label.current = i;
break;
if (!state.config.type_username) {
for (state.login.label.list.items, 0..) |username, i| {
if (std.mem.eql(u8, username.name, auto_user)) {
state.login.label.current = i;
break;
}
}
}
state.is_autologin = true;
@ -1030,10 +1028,16 @@ pub fn main() !void {
// 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.config.type_username) {
try state.login_text.text.appendSlice(state.allocator, user.username);
state.login_text.end = user.username.len;
state.login_text.cursor = user.username.len;
} else {
for (usernames.items, 0..) |username, i| {
if (std.mem.eql(u8, username, user.username)) {
state.login.label.current = i;
break;
}
}
}
@ -1346,7 +1350,17 @@ fn authenticate(ptr: *anyopaque) !bool {
var file_writer = file.writer(&file_buffer);
var writer = &file_writer.interface;
if (!state.config.type_username) {
if (state.config.type_username) {
const typed_name = state.login_text.text.items;
var found_index: usize = 0;
for (state.saved_users.user_list.items, 0..) |user, i| {
if (std.mem.eql(u8, user.username, typed_name)) {
found_index = i;
break;
}
}
try writer.print("{d}\n", .{found_index});
} else {
try writer.print("{d}\n", .{state.login.label.current});
}