core: performAction now returns a bool

This is to facilitate the `performable:` prefix on keybinds that are
implemented using app runtime actions.
This commit is contained in:
Jeffrey C. Ollie
2025-02-08 15:56:29 -06:00
committed by Mitchell Hashimoto
parent 66442cd469
commit 4ad749607a
5 changed files with 79 additions and 70 deletions

View File

@@ -478,13 +478,14 @@ pub const App = struct {
surface.queueInspectorRender();
}
/// Perform a given action.
/// Perform a given action. Returns `true` if the action was able to be
/// performed, `false` otherwise.
pub fn performAction(
self: *App,
target: apprt.Target,
comptime action: apprt.Action.Key,
value: apprt.Action.Value(action),
) !void {
) !bool {
// Special case certain actions before they are sent to the
// embedded apprt.
self.performPreAction(target, action, value);
@@ -499,6 +500,8 @@ pub const App = struct {
target.cval(),
@unionInit(apprt.Action, @tagName(action), value).cval(),
);
return true;
}
fn performPreAction(
@@ -1006,7 +1009,7 @@ pub const Surface = struct {
}
fn queueInspectorRender(self: *Surface) void {
self.app.performAction(
_ = self.app.performAction(
.{ .surface = &self.core_surface },
.render_inspector,
{},
@@ -1457,7 +1460,7 @@ pub const CAPI = struct {
/// Open the configuration.
export fn ghostty_app_open_config(v: *App) void {
v.performAction(.app, .open_config, {}) catch |err| {
_ = v.performAction(.app, .open_config, {}) catch |err| {
log.err("error reloading config err={}", .{err});
return;
};
@@ -1800,7 +1803,7 @@ pub const CAPI = struct {
/// Request that the surface split in the given direction.
export fn ghostty_surface_split(ptr: *Surface, direction: apprt.action.SplitDirection) void {
ptr.app.performAction(
_ = ptr.app.performAction(
.{ .surface = &ptr.core_surface },
.new_split,
direction,
@@ -1815,7 +1818,7 @@ pub const CAPI = struct {
ptr: *Surface,
direction: apprt.action.GotoSplit,
) void {
ptr.app.performAction(
_ = ptr.app.performAction(
.{ .surface = &ptr.core_surface },
.goto_split,
direction,
@@ -1834,7 +1837,7 @@ pub const CAPI = struct {
direction: apprt.action.ResizeSplit.Direction,
amount: u16,
) void {
ptr.app.performAction(
_ = ptr.app.performAction(
.{ .surface = &ptr.core_surface },
.resize_split,
.{ .direction = direction, .amount = amount },
@@ -1846,7 +1849,7 @@ pub const CAPI = struct {
/// Equalize the size of all splits in the current window.
export fn ghostty_surface_split_equalize(ptr: *Surface) void {
ptr.app.performAction(
_ = ptr.app.performAction(
.{ .surface = &ptr.core_surface },
.equalize_splits,
{},

View File

@@ -147,13 +147,14 @@ pub const App = struct {
glfw.postEmptyEvent();
}
/// Perform a given action.
/// Perform a given action. Returns `true` if the action was able to be
/// performed, `false` otherwise.
pub fn performAction(
self: *App,
target: apprt.Target,
comptime action: apprt.Action.Key,
value: apprt.Action.Value(action),
) !void {
) !bool {
switch (action) {
.quit => self.quit = true,
@@ -240,6 +241,8 @@ pub const App = struct {
.toggle_maximize,
=> log.info("unimplemented action={}", .{action}),
}
return true;
}
/// Reload the configuration. This should return the new configuration.

View File

@@ -507,13 +507,14 @@ pub fn terminate(self: *App) void {
self.config.deinit();
}
/// Perform a given action.
/// Perform a given action. Returns `true` if the action was able to be
/// performed, `false` otherwise.
pub fn performAction(
self: *App,
target: apprt.Target,
comptime action: apprt.Action.Key,
value: apprt.Action.Value(action),
) !void {
) !bool {
switch (action) {
.quit => self.quit(),
.new_window => _ = try self.newWindow(switch (target) {
@@ -561,6 +562,8 @@ pub fn performAction(
.color_change,
=> log.warn("unimplemented action={}", .{action}),
}
return true;
}
fn newTab(_: *App, target: apprt.Target) !void {