summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.zig28
-rw-r--r--src/pardes.zig20
2 files changed, 45 insertions, 3 deletions
diff --git a/src/main.zig b/src/main.zig
index 5275ea28..2e75de3d 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -39,7 +39,11 @@ pub const debug = if (is_emscripten) struct {} else struct {
};
const help_text =
- \\Usage: pardes [options]
+ \\Usage: pardes [options] [file|dir]
+ \\
+ \\With no arguments the shell pane starts in tty mode. A FILE argument
+ \\(optionally file:LINE) opens it focused beside a terminal on the launch
+ \\directory; a DIRECTORY argument becomes the cwd shells spawn in.
\\
\\Options:
\\ --tty start as one shell pane already in tty mode
@@ -77,7 +81,10 @@ fn webMain() !void {
fn nativeMain(init: std.process.Init) !void {
var opts: pardes.Options = .{};
- const args = try init.minimal.args.toSlice(init.arena.allocator());
+ const arena = init.arena.allocator();
+ const args = try init.minimal.args.toSlice(arena);
+ if (args.len == 1) opts.tty_only = true; // bare `pardes` boots straight into tty mode
+ var positional = false;
var i: usize = 1;
while (i < args.len) : (i += 1) {
const a = args[i];
@@ -100,6 +107,23 @@ fn nativeMain(init: std.process.Init) !void {
} else if (std.mem.eql(u8, a, "-h") or std.mem.eql(u8, a, "--help")) {
try std.Io.File.stdout().writeStreamingAll(init.io, help_text);
return;
+ } else if (a.len > 0 and a[0] != '-' and !positional) {
+ // one positional: a directory becomes the cwd shells spawn in
+ // (chdir succeeds only on dirs); anything else resolves as a file
+ positional = true;
+ if (std.c.chdir(a.ptr) != 0) {
+ var cwdbuf: [4096]u8 = undefined;
+ const cwd = std.c.getcwd(&cwdbuf, cwdbuf.len) orelse return error.BadArgs;
+ var realbuf: [4096]u8 = undefined;
+ switch (@import("look.zig").resolve(a, std.mem.span(@as([*:0]u8, @ptrCast(cwd))), &realbuf)) {
+ .file => |t| {
+ opts.file = try arena.dupe(u8, t.path);
+ opts.file_line = t.line;
+ },
+ .image => |t| opts.file = try arena.dupe(u8, t.path),
+ else => return error.BadArgs,
+ }
+ }
} else {
return error.BadArgs;
}
diff --git a/src/pardes.zig b/src/pardes.zig
index 0219d474..fc216b24 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -670,6 +670,10 @@ pub const Options = struct {
tty_only: bool = false,
/// initial shell panes: 1 (default) or 3 for the classic two-column boot
shells: u8 = 1,
+ /// argv FILE (resolved absolute): boot with it focused as a doc pane in
+ /// the left column, a terminal on the launch directory in the right
+ file: ?[]const u8 = null,
+ file_line: usize = 0,
tty_toggle: u21 = 'b',
/// load a dump of another instance instead of spawning shells (acme -l)
load_path: ?[]const u8 = null,
@@ -749,7 +753,21 @@ pub const Pardes = struct {
syntax.compileStartupQueries();
const p = try gpa.create(Pardes);
p.* = .{ .gpa = gpa, .opts = opts, .screen_w = opts.cols, .screen_h = opts.rows, .scratch = .init(gpa) };
- if (opts.tty_only) {
+ if (opts.file) |path| {
+ // FILE argv boot: the doc focused in the left column, a terminal
+ // on the launch directory in the right (files left, shells right)
+ _ = if (look.isImagePath(path))
+ try p.openImageView(0, path, !p.kitty_ok)
+ else
+ try p.openFileView(0, path, opts.file_line);
+ const sh = try p.newPane(1);
+ sh.greet = true;
+ p.ncol = 2;
+ p.col_n[0] = 1;
+ p.col_terms[0][0] = 0;
+ p.col_n[1] = 1;
+ p.col_terms[1][0] = 1;
+ } else if (opts.tty_only) {
_ = try p.newPane(0);
p.panes[0].?.mode = .tty;
p.ncol = 1;