mirror of
https://codeberg.org/fairyglade/ly.git
synced 2026-08-21 04:54:18 +02:00
Merge branch 'master' into custom-commands
This commit is contained in:
commit
396df52ced
9 changed files with 129 additions and 65 deletions
|
|
@ -18,7 +18,7 @@ const Message = struct {
|
|||
fg: u32,
|
||||
};
|
||||
|
||||
label: MessageLabel,
|
||||
label: *MessageLabel,
|
||||
|
||||
pub fn init(
|
||||
allocator: Allocator,
|
||||
|
|
@ -26,9 +26,9 @@ pub fn init(
|
|||
width: usize,
|
||||
arrow_fg: u32,
|
||||
arrow_bg: u32,
|
||||
) InfoLine {
|
||||
) !InfoLine {
|
||||
return .{
|
||||
.label = MessageLabel.init(
|
||||
.label = try MessageLabel.init(
|
||||
allocator,
|
||||
buffer,
|
||||
drawItem,
|
||||
|
|
@ -49,7 +49,7 @@ pub fn deinit(self: *InfoLine) void {
|
|||
pub fn widget(self: *InfoLine) Widget {
|
||||
return Widget.init(
|
||||
"InfoLine",
|
||||
null,
|
||||
self.label.keybinds,
|
||||
self,
|
||||
deinit,
|
||||
null,
|
||||
|
|
@ -91,8 +91,8 @@ fn draw(self: *InfoLine) void {
|
|||
self.label.draw();
|
||||
}
|
||||
|
||||
fn handle(self: *InfoLine, maybe_key: ?keyboard.Key, insert_mode: bool) !void {
|
||||
self.label.handle(maybe_key, insert_mode);
|
||||
fn handle(self: *InfoLine, maybe_key: ?keyboard.Key) !void {
|
||||
self.label.handle(maybe_key);
|
||||
}
|
||||
|
||||
fn drawItem(label: *MessageLabel, message: Message, x: usize, y: usize, width: usize) void {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const EnvironmentLabel = CyclableLabel(Env, *UserList);
|
|||
|
||||
const Session = @This();
|
||||
|
||||
label: EnvironmentLabel,
|
||||
label: *EnvironmentLabel,
|
||||
user_list: *UserList,
|
||||
|
||||
pub fn init(
|
||||
|
|
@ -29,9 +29,9 @@ pub fn init(
|
|||
text_in_center: bool,
|
||||
fg: u32,
|
||||
bg: u32,
|
||||
) Session {
|
||||
) !Session {
|
||||
return .{
|
||||
.label = EnvironmentLabel.init(
|
||||
.label = try EnvironmentLabel.init(
|
||||
allocator,
|
||||
buffer,
|
||||
drawItem,
|
||||
|
|
@ -58,7 +58,7 @@ pub fn deinit(self: *Session) void {
|
|||
pub fn widget(self: *Session) Widget {
|
||||
return Widget.init(
|
||||
"Session",
|
||||
null,
|
||||
self.label.keybinds,
|
||||
self,
|
||||
deinit,
|
||||
null,
|
||||
|
|
@ -80,8 +80,8 @@ fn draw(self: *Session) void {
|
|||
self.label.draw();
|
||||
}
|
||||
|
||||
fn handle(self: *Session, maybe_key: ?keyboard.Key, insert_mode: bool) !void {
|
||||
self.label.handle(maybe_key, insert_mode);
|
||||
fn handle(self: *Session, maybe_key: ?keyboard.Key) !void {
|
||||
self.label.handle(maybe_key);
|
||||
}
|
||||
|
||||
fn addedSession(env: Env, user_list: *UserList) void {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const UserLabel = CyclableLabel(User, *Session);
|
|||
|
||||
const UserList = @This();
|
||||
|
||||
label: UserLabel,
|
||||
label: *UserLabel,
|
||||
|
||||
pub fn init(
|
||||
allocator: Allocator,
|
||||
|
|
@ -35,7 +35,7 @@ pub fn init(
|
|||
bg: u32,
|
||||
) !UserList {
|
||||
var user_list = UserList{
|
||||
.label = UserLabel.init(
|
||||
.label = try UserLabel.init(
|
||||
allocator,
|
||||
buffer,
|
||||
drawItem,
|
||||
|
|
@ -92,7 +92,7 @@ pub fn deinit(self: *UserList) void {
|
|||
pub fn widget(self: *UserList) Widget {
|
||||
return Widget.init(
|
||||
"UserList",
|
||||
null,
|
||||
self.label.keybinds,
|
||||
self,
|
||||
deinit,
|
||||
null,
|
||||
|
|
@ -111,8 +111,8 @@ fn draw(self: *UserList) void {
|
|||
self.label.draw();
|
||||
}
|
||||
|
||||
fn handle(self: *UserList, maybe_key: ?keyboard.Key, insert_mode: bool) !void {
|
||||
self.label.handle(maybe_key, insert_mode);
|
||||
fn handle(self: *UserList, maybe_key: ?keyboard.Key) !void {
|
||||
self.label.handle(maybe_key);
|
||||
}
|
||||
|
||||
fn usernameChanged(user: User, maybe_session: ?*Session) void {
|
||||
|
|
|
|||
37
src/main.zig
37
src/main.zig
|
|
@ -577,7 +577,7 @@ pub fn main() !void {
|
|||
&updateBox,
|
||||
);
|
||||
|
||||
state.info_line = InfoLine.init(
|
||||
state.info_line = try InfoLine.init(
|
||||
state.allocator,
|
||||
&state.buffer,
|
||||
state.box.width - 2 * state.box.horizontal_margin,
|
||||
|
|
@ -586,6 +586,9 @@ pub fn main() !void {
|
|||
);
|
||||
defer state.info_line.deinit();
|
||||
|
||||
try state.buffer.registerKeybind(&state.info_line.label.keybinds, "H", &viGoLeft, &state);
|
||||
try state.buffer.registerKeybind(&state.info_line.label.keybinds, "L", &viGoRight, &state);
|
||||
|
||||
if (maybe_res == null) {
|
||||
var longest = diag.name.longest();
|
||||
if (longest.kind == .positional)
|
||||
|
|
@ -687,7 +690,7 @@ pub fn main() !void {
|
|||
);
|
||||
defer state.session_specifier_label.deinit();
|
||||
|
||||
state.session = Session.init(
|
||||
state.session = try Session.init(
|
||||
state.allocator,
|
||||
&state.buffer,
|
||||
&state.login,
|
||||
|
|
@ -698,6 +701,9 @@ pub fn main() !void {
|
|||
);
|
||||
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,
|
||||
|
|
@ -721,6 +727,9 @@ pub fn main() !void {
|
|||
);
|
||||
defer state.login.deinit();
|
||||
|
||||
try state.buffer.registerKeybind(&state.login.label.keybinds, "H", &viGoLeft, &state);
|
||||
try state.buffer.registerKeybind(&state.login.label.keybinds, "L", &viGoRight, &state);
|
||||
|
||||
addOtherEnvironment(&state.session, state.lang, .shell, null) catch |err| {
|
||||
try state.info_line.addMessage(
|
||||
state.lang.err_alloc,
|
||||
|
|
@ -829,9 +838,12 @@ pub fn main() !void {
|
|||
);
|
||||
defer state.password_label.deinit();
|
||||
|
||||
state.insert_mode = !state.config.vi_mode or state.config.vi_default_mode == .insert;
|
||||
|
||||
state.password = try Text.init(
|
||||
state.allocator,
|
||||
&state.buffer,
|
||||
state.insert_mode,
|
||||
true,
|
||||
state.config.asterisk,
|
||||
state.box.width - 2 * state.box.horizontal_margin - state.labels_max_length - 1,
|
||||
|
|
@ -840,6 +852,9 @@ pub fn main() !void {
|
|||
);
|
||||
defer state.password.deinit();
|
||||
|
||||
try state.buffer.registerKeybind(&state.password.keybinds, "H", &viGoLeft, &state);
|
||||
try state.buffer.registerKeybind(&state.password.keybinds, "L", &viGoRight, &state);
|
||||
|
||||
state.password_widget = state.password.widget();
|
||||
|
||||
state.version_label = Label.init(
|
||||
|
|
@ -1016,7 +1031,6 @@ pub fn main() !void {
|
|||
|
||||
state.auth_fails = 0;
|
||||
state.animate = state.config.animation != .none;
|
||||
state.insert_mode = !state.config.vi_mode or state.config.vi_default_mode == .insert;
|
||||
state.edge_margin = Position.init(
|
||||
state.config.edge_margin,
|
||||
state.config.edge_margin,
|
||||
|
|
@ -1249,7 +1263,6 @@ pub fn main() !void {
|
|||
widgets.items,
|
||||
active_widget,
|
||||
state.config.inactivity_delay,
|
||||
&state.insert_mode, // FIXME: Hack
|
||||
positionWidgets,
|
||||
handleInactivity,
|
||||
&state,
|
||||
|
|
@ -1290,6 +1303,7 @@ fn disableInsertMode(ptr: *anyopaque) !bool {
|
|||
|
||||
if (state.config.vi_mode and state.insert_mode) {
|
||||
state.insert_mode = false;
|
||||
state.password.should_insert = false;
|
||||
state.buffer.drawNextFrame(true);
|
||||
}
|
||||
return false;
|
||||
|
|
@ -1300,10 +1314,25 @@ fn enableInsertMode(ptr: *anyopaque) !bool {
|
|||
if (state.insert_mode) return true;
|
||||
|
||||
state.insert_mode = true;
|
||||
state.password.should_insert = true;
|
||||
state.buffer.drawNextFrame(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
fn viGoLeft(ptr: *anyopaque) !bool {
|
||||
var self: *UiState = @ptrCast(@alignCast(ptr));
|
||||
if (self.insert_mode) return true;
|
||||
|
||||
return try self.buffer.simulateKeybind("Left");
|
||||
}
|
||||
|
||||
fn viGoRight(ptr: *anyopaque) !bool {
|
||||
var state: *UiState = @ptrCast(@alignCast(ptr));
|
||||
if (state.insert_mode) return true;
|
||||
|
||||
return try state.buffer.simulateKeybind("Right");
|
||||
}
|
||||
|
||||
fn viMoveCursorUp(ptr: *anyopaque) !bool {
|
||||
var state: *UiState = @ptrCast(@alignCast(ptr));
|
||||
if (state.insert_mode) return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue