mirror of
https://codeberg.org/fairyglade/ly.git
synced 2026-08-24 14:34:19 +02:00
tty_cache: better checks for early exits
This commit is contained in:
parent
8e679fab72
commit
cf199f6ba0
1 changed files with 25 additions and 28 deletions
49
src/main.zig
49
src/main.zig
|
|
@ -322,6 +322,7 @@ pub fn main(init: std.process.Init) !void {
|
|||
|
||||
while (reader.seek < reader.buffer.len) {
|
||||
var line = reader.takeDelimiterInclusive('\n') catch break;
|
||||
if (std.mem.startsWith(u8, line, "ly/tty")) continue;
|
||||
|
||||
var user = std.mem.splitScalar(u8, line[0..(line.len - 1)], ':');
|
||||
const username = user.next() orelse continue;
|
||||
|
|
@ -2612,37 +2613,33 @@ fn updateTtyCache(state: *UiState, real_users: union(enum) { user_list: []UserLi
|
|||
|
||||
while (reader.seek < reader.buffer.len) {
|
||||
var line = reader.takeDelimiterInclusive('\n') catch break;
|
||||
if (!std.mem.startsWith(u8, line, "ly/tty")) continue;
|
||||
|
||||
if (std.mem.startsWith(u8, line, "ly/tty")) {
|
||||
line = line["ly/tty".len..];
|
||||
var entry = std.mem.splitScalar(u8, line[0..(line.len - 1)], ':');
|
||||
const tty_num_str = entry.next() orelse continue;
|
||||
const saved_username = entry.next() orelse continue;
|
||||
line = line["ly/tty".len..];
|
||||
var entry = std.mem.splitScalar(u8, line[0..(line.len - 1)], ':');
|
||||
const tty_num_str = entry.next() orelse continue;
|
||||
const saved_username = entry.next() orelse continue;
|
||||
|
||||
const tty_num = std.fmt.parseInt(usize, tty_num_str, 10) catch continue;
|
||||
const tty_num = std.fmt.parseInt(usize, tty_num_str, 10) catch continue;
|
||||
if (tty_num >= std.math.maxInt(u8)) continue;
|
||||
|
||||
switch (real_users) {
|
||||
.usernames => |usernames| {
|
||||
for (usernames, 0..) |username, u_index| {
|
||||
if (std.mem.eql(u8, username, saved_username)) {
|
||||
if (tty_num < std.math.maxInt(u8)) {
|
||||
state.tty_cache[tty_num] = @intCast(u_index);
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch (real_users) {
|
||||
.usernames => |usernames| {
|
||||
for (usernames, 0..) |username, u_index| {
|
||||
if (std.mem.eql(u8, username, saved_username)) {
|
||||
state.tty_cache[tty_num] = @intCast(u_index);
|
||||
break;
|
||||
}
|
||||
},
|
||||
.user_list => |user_list| {
|
||||
for (user_list, 0..) |user, u_index| {
|
||||
if (std.mem.eql(u8, user.name, saved_username)) {
|
||||
if (tty_num < std.math.maxInt(u8)) {
|
||||
state.tty_cache[tty_num] = @intCast(u_index);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
.user_list => |user_list| {
|
||||
for (user_list, 0..) |user, u_index| {
|
||||
if (std.mem.eql(u8, user.name, saved_username)) {
|
||||
state.tty_cache[tty_num] = @intCast(u_index);
|
||||
break;
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue