WIP: merge focus_terminal and open_terminal commands
This commit is contained in:
parent
2f5d4ded3c
commit
9d9bf1dc2a
5 changed files with 37 additions and 11 deletions
|
|
@ -23,7 +23,7 @@
|
|||
["ctrl+6", "focus_split", 5],
|
||||
["ctrl+7", "focus_split", 6],
|
||||
["ctrl+8", "focus_split", 7],
|
||||
["ctrl+`", "focus_terminal"],
|
||||
["ctrl+`", "open_terminal"],
|
||||
["ctrl+j", "toggle_panel"],
|
||||
["ctrl+shift+j", "toggle_maximize_panel"],
|
||||
["ctrl+q", "quit"],
|
||||
|
|
@ -596,7 +596,7 @@
|
|||
["ctrl+6", "focus_split", 5],
|
||||
["ctrl+7", "focus_split", 6],
|
||||
["ctrl+8", "focus_split", 7],
|
||||
["ctrl+`", "focus_terminal"],
|
||||
["ctrl+`", "unfocus_terminal"],
|
||||
["ctrl+j", "toggle_panel"],
|
||||
["ctrl+shift+page_down", "terminal_scroll_down"],
|
||||
["ctrl+shift+page_up", "terminal_scroll_up"],
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ const style = struct {
|
|||
\\open_recent_project
|
||||
\\find_in_files
|
||||
\\open_command_palette
|
||||
\\focus_terminal
|
||||
\\open_terminal
|
||||
\\run_task
|
||||
\\add_task
|
||||
\\open_config
|
||||
|
|
@ -53,7 +53,7 @@ const style = struct {
|
|||
\\open_recent_project
|
||||
\\find_in_files
|
||||
\\open_command_palette
|
||||
\\focus_terminal
|
||||
\\open_terminal
|
||||
\\run_task
|
||||
\\add_task
|
||||
\\open_config
|
||||
|
|
|
|||
|
|
@ -929,7 +929,7 @@ const cmds = struct {
|
|||
else if (self.is_panel_view_showing(terminal_view))
|
||||
try self.toggle_panel_view(terminal_view, .toggle)
|
||||
else
|
||||
try focus_terminal(self, .{});
|
||||
try open_terminal(self, .{});
|
||||
}
|
||||
pub const toggle_panel_meta: Meta = .{ .description = "Toggle panel" };
|
||||
|
||||
|
|
@ -985,20 +985,32 @@ const cmds = struct {
|
|||
pub const toggle_terminal_view_meta: Meta = .{ .description = "Toggle terminal" };
|
||||
|
||||
pub fn open_terminal(self: *Self, ctx: Ctx) Result {
|
||||
try self.toggle_panel_view_with_args(terminal_view, .enable, ctx);
|
||||
}
|
||||
pub const open_terminal_meta: Meta = .{ .description = "Open terminal", .arguments = &.{.string} };
|
||||
const have_args = ctx.args.buf.len > 0 and try ctx.args.match(.{ tp.string, tp.more });
|
||||
|
||||
if (have_args and terminal_view.is_vt_running()) {
|
||||
var msg: std.Io.Writer.Allocating = .init(self.allocator);
|
||||
defer msg.deinit();
|
||||
try msg.writer.writeAll("terminal is already running '");
|
||||
try terminal_view.get_running_cmd(&msg.writer);
|
||||
try msg.writer.writeAll("'");
|
||||
return tp.exit(msg.written());
|
||||
}
|
||||
|
||||
pub fn focus_terminal(self: *Self, _: Ctx) Result {
|
||||
if (self.get_panel_view(terminal_view)) |vt| {
|
||||
vt.toggle_focus();
|
||||
} else {
|
||||
try self.toggle_panel_view(terminal_view, .enable);
|
||||
try self.toggle_panel_view_with_args(terminal_view, .enable, ctx);
|
||||
if (self.get_panel_view(terminal_view)) |vt|
|
||||
vt.focus();
|
||||
}
|
||||
}
|
||||
pub const focus_terminal_meta: Meta = .{ .description = "Open terminal" };
|
||||
pub const open_terminal_meta: Meta = .{ .description = "Open terminal" };
|
||||
|
||||
pub fn unfocus_terminal(self: *Self, _: Ctx) Result {
|
||||
if (self.get_panel_view(terminal_view)) |vt|
|
||||
vt.toggle_focus();
|
||||
}
|
||||
pub const unfocus_terminal_meta: Meta = .{};
|
||||
|
||||
pub fn close_terminal(self: *Self, _: Ctx) Result {
|
||||
if (self.get_panel_view(terminal_view)) |_|
|
||||
|
|
|
|||
|
|
@ -509,6 +509,17 @@ const Vt = struct {
|
|||
};
|
||||
var global_vt: ?Vt = null;
|
||||
|
||||
pub fn is_vt_running() bool {
|
||||
return global_vt != null;
|
||||
}
|
||||
|
||||
pub fn get_running_cmd(writer: *std.Io.Writer) std.Io.Writer.Error!void {
|
||||
const cmd_argv = if (global_vt) |vt| vt.vt.cmd.argv else &.{};
|
||||
if (cmd_argv.len > 0) {
|
||||
_ = argv.write(writer, cmd_argv) catch {};
|
||||
}
|
||||
}
|
||||
|
||||
// Platform-specific pty actor: POSIX uses tp.file_descriptor + SIGCHLD,
|
||||
// Windows uses tp.file_stream with IOCP overlapped reads on the ConPTY output pipe.
|
||||
const pty = if (builtin.os.tag == .windows) pty_windows else pty_posix;
|
||||
|
|
|
|||
|
|
@ -1516,9 +1516,11 @@ const cmds = struct {
|
|||
};
|
||||
|
||||
pub fn run_task_in_terminal(self: *Self, ctx: Ctx) Result {
|
||||
std.log.debug("open_terminal: 1", .{});
|
||||
const expansion = @import("expansion.zig");
|
||||
var task: []const u8 = undefined;
|
||||
if (!try ctx.args.match(.{tp.extract(&task)})) return;
|
||||
std.log.debug("open_terminal: task {s}", .{task});
|
||||
const args = expansion.expand_cbor(self.allocator, ctx.args.buf) catch |e| switch (e) {
|
||||
error.NotFound => return error.Stop,
|
||||
else => |e_| return e_,
|
||||
|
|
@ -1529,6 +1531,7 @@ const cmds = struct {
|
|||
cmd = task;
|
||||
call_add_task(task);
|
||||
var buf: [tp.max_message_size]u8 = undefined;
|
||||
std.log.debug("open_terminal: 2", .{});
|
||||
try command.executeName("open_terminal", try command.fmtbuf(&buf, .{cmd}));
|
||||
}
|
||||
pub const run_task_in_terminal_meta: Meta = .{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue