core: add input binding to control terminal inspector

This commit is contained in:
Mitchell Hashimoto
2023-10-19 20:30:39 -07:00
parent 92d172377e
commit 29bbcbbf92
9 changed files with 73 additions and 2 deletions

View File

@@ -2278,6 +2278,12 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
} else log.warn("runtime doesn't implement toggleFullscreen", .{});
},
.inspector => |mode| {
if (@hasDecl(apprt.Surface, "controlInspector")) {
self.rt_surface.controlInspector(mode);
} else log.warn("runtime doesn't implement controlInspector", .{});
},
.close_surface => self.close(),
.close_window => try self.app.closeSurface(self),

View File

@@ -73,6 +73,9 @@ pub const App = struct {
/// New window with options.
new_window: ?*const fn (SurfaceUD, apprt.Surface.Options) callconv(.C) void = null,
/// Control the inspector visibility
control_inspector: ?*const fn (SurfaceUD, input.InspectorMode) callconv(.C) void = null,
/// Close the current surface given by this function.
close_surface: ?*const fn (SurfaceUD, bool) callconv(.C) void = null,
@@ -326,6 +329,15 @@ pub const Surface = struct {
}
}
pub fn controlInspector(self: *const Surface, mode: input.InspectorMode) void {
const func = self.app.opts.control_inspector orelse {
log.info("runtime embedder does not support the terminal inspector", .{});
return;
};
func(self.opts.userdata, mode);
}
pub fn newSplit(self: *const Surface, direction: input.SplitDirection) !void {
const func = self.app.opts.new_split orelse {
log.info("runtime embedder does not support splits", .{});

View File

@@ -8,6 +8,7 @@ pub const keycodes = @import("input/keycodes.zig");
pub const kitty = @import("input/kitty.zig");
pub const Binding = @import("input/Binding.zig");
pub const KeyEncoder = @import("input/KeyEncoder.zig");
pub const InspectorMode = Binding.Action.InspectorMode;
pub const SplitDirection = Binding.Action.SplitDirection;
pub const SplitFocusDirection = Binding.Action.SplitFocusDirection;

View File

@@ -176,6 +176,10 @@ pub const Action = union(enum) {
/// zoom/unzoom the current split.
toggle_split_zoom: void,
/// Show, hide, or toggle the terminal inspector for the currently
/// focused terminal.
inspector: InspectorMode,
/// Reload the configuration. The exact meaning depends on the app runtime
/// in use but this usually involves re-reading the configuration file
/// and applying any changes. Note that not all changes can be applied at
@@ -220,6 +224,13 @@ pub const Action = union(enum) {
right,
};
// Extern because it is used in the embedded runtime ABI.
pub const InspectorMode = enum(c_int) {
toggle,
show,
hide,
};
/// Parse an action in the format of "key=value" where key is the
/// action name and value is the action parameter. The parameter
/// is optional depending on the action.