mirror of
https://codeberg.org/fairyglade/ly.git
synced 2026-08-09 15:19:13 +02:00
rewrite Input enum
This commit is contained in:
parent
1980b2e479
commit
acad074c59
2 changed files with 27 additions and 32 deletions
|
|
@ -1,3 +1,4 @@
|
|||
const std = @import("std");
|
||||
pub const Animation = enum {
|
||||
none,
|
||||
doom,
|
||||
|
|
@ -19,6 +20,26 @@ pub const Input = enum {
|
|||
session,
|
||||
login,
|
||||
password,
|
||||
|
||||
/// Moves the current Input forwards by one entry. If `reverse`, then the Input
|
||||
/// moves backwards. If `overflow` is true, then the entry will wrap back around
|
||||
pub fn move(self: *Input, reverse: bool, wrap: bool) void {
|
||||
const len = @typeInfo(Input).@"enum".fields.len - 1;
|
||||
const selfNum = @intFromEnum(self.*);
|
||||
if (reverse) {
|
||||
if (wrap) {
|
||||
self.* = @as(Input, @enumFromInt(@intFromEnum(self.*) -% 1));
|
||||
} else if (selfNum != 0) {
|
||||
self.* = @as(Input, @enumFromInt(std.math.clamp(selfNum - 1, 0, len)));
|
||||
}
|
||||
} else {
|
||||
if (wrap) {
|
||||
self.* = @as(Input, @enumFromInt(selfNum +% 1));
|
||||
} else if (selfNum != len) {
|
||||
self.* = @as(Input, @enumFromInt(std.math.clamp(selfNum + 1, 0, len)));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pub const ViMode = enum {
|
||||
|
|
|
|||
38
src/main.zig
38
src/main.zig
|
|
@ -902,37 +902,19 @@ pub fn main() !void {
|
|||
update = true;
|
||||
},
|
||||
termbox.TB_KEY_CTRL_K, termbox.TB_KEY_ARROW_UP => {
|
||||
active_input = switch (active_input) {
|
||||
.session, .info_line => .info_line,
|
||||
.login => .session,
|
||||
.password => .login,
|
||||
};
|
||||
active_input.move(true, false);
|
||||
update = true;
|
||||
},
|
||||
termbox.TB_KEY_CTRL_J, termbox.TB_KEY_ARROW_DOWN => {
|
||||
active_input = switch (active_input) {
|
||||
.info_line => .session,
|
||||
.session => .login,
|
||||
.login, .password => .password,
|
||||
};
|
||||
active_input.move(false, false);
|
||||
update = true;
|
||||
},
|
||||
termbox.TB_KEY_TAB => {
|
||||
active_input = switch (active_input) {
|
||||
.info_line => .session,
|
||||
.session => .login,
|
||||
.login => .password,
|
||||
.password => .info_line,
|
||||
};
|
||||
active_input.move(false, true);
|
||||
update = true;
|
||||
},
|
||||
termbox.TB_KEY_BACK_TAB => {
|
||||
active_input = switch (active_input) {
|
||||
.info_line => .password,
|
||||
.session => .info_line,
|
||||
.login => .session,
|
||||
.password => .login,
|
||||
};
|
||||
active_input.move(true, true);
|
||||
update = true;
|
||||
},
|
||||
termbox.TB_KEY_ENTER => authenticate: {
|
||||
|
|
@ -1089,20 +1071,12 @@ pub fn main() !void {
|
|||
if (!insert_mode) {
|
||||
switch (event.ch) {
|
||||
'k' => {
|
||||
active_input = switch (active_input) {
|
||||
.session, .info_line => .info_line,
|
||||
.login => .session,
|
||||
.password => .login,
|
||||
};
|
||||
active_input.move(true, false);
|
||||
update = true;
|
||||
continue;
|
||||
},
|
||||
'j' => {
|
||||
active_input = switch (active_input) {
|
||||
.info_line => .session,
|
||||
.session => .login,
|
||||
.login, .password => .password,
|
||||
};
|
||||
active_input.move(false, false);
|
||||
update = true;
|
||||
continue;
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue