diff options
| -rw-r--r-- | src/main.zig | 28 | ||||
| -rw-r--r-- | src/pardes.zig | 20 | ||||
| -rw-r--r-- | test/snapshots/argv.golden | 93 | ||||
| -rw-r--r-- | test/snapshots/argv.snap | 26 | ||||
| -rw-r--r-- | test/snapshots/boot.snap | 4 | ||||
| -rw-r--r-- | test/snapshots/restore.snap | 2 |
6 files changed, 167 insertions, 6 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; diff --git a/test/snapshots/argv.golden b/test/snapshots/argv.golden new file mode 100644 index 00000000..76aa776a --- /dev/null +++ b/test/snapshots/argv.golden @@ -0,0 +1,93 @@ +== snap noargs grid=100x30 cursor=4,4 +|Kill Newcol Tutor Debug Colors NextColor Dump +| TTY /tmp/pardes-snap/argv/cwd Del +| $ echo ARGV''TTY +| ARGVTTY +| $ +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +== snap filearg grid=100x30 cursor=7,2 +|Kill Newcol Tutor Debug Colors NextColor Dump +| NOR /tmp/pardes-snap/argv/cwd/notes.txt Save Del NOR /tmp/pardes-snap/argv/cwd Del +| 3 line 3 +| 4 line 4 notes.txt zmarker.txt +| 5 line 5 +| 6 line 6 +| 7 line 7 +| 8 line 8 +| 9 +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +== snap dirarg grid=100x30 cursor=4,4 +|Kill Newcol Tutor Debug Colors NextColor Dump +| NOR /tmp/pardes-snap/argv/cwd/sub Del +| +| inside.txt +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| diff --git a/test/snapshots/argv.snap b/test/snapshots/argv.snap new file mode 100644 index 00000000..1c3c9f78 --- /dev/null +++ b/test/snapshots/argv.snap @@ -0,0 +1,26 @@ +# argv: bare `pardes` boots one shell already in tty mode; a FILE argument +# opens it focused in the left column (file:LINE scrolls there) with a +# terminal greeting on the launch dir in the right; a DIRECTORY argument +# becomes the cwd the shell spawns in +lines notes.txt 8 +file zmarker.txt x +start 30 100 +wait 8000 $ +stable 700 20000 +text echo ARGV''TTY +key enter +wait 8000 ARGVTTY +stable 700 10000 +snap noargs +start 30 100 notes.txt:3 +wait 8000 Kill Newcol +wait 8000 zmarker.txt +stable 700 20000 +snap filearg +dirmk sub +file sub/inside.txt marker +start 30 100 sub +wait 8000 Kill Newcol +wait 8000 inside.txt +stable 700 20000 +snap dirarg diff --git a/test/snapshots/boot.snap b/test/snapshots/boot.snap index 33b12be0..b51932bf 100644 --- a/test/snapshots/boot.snap +++ b/test/snapshots/boot.snap @@ -1,6 +1,6 @@ -# default startup: 2 columns, 3 shells, each greets with ls; prompts hidden +# -n 1: one shell pane in normal mode, greets with ls; prompts hidden file hello.txt marker-content -start 30 100 +start 30 100 -n 1 wait 8000 Kill Newcol wait 8000 hello.txt stable 700 20000 diff --git a/test/snapshots/restore.snap b/test/snapshots/restore.snap index 8a677877..815edc55 100644 --- a/test/snapshots/restore.snap +++ b/test/snapshots/restore.snap @@ -2,7 +2,7 @@ # under ~/.local/share/pardes in live runs) and the topbar grows Restore <path>; # middle-click Restore loads that dump back into the live session: output on # screen at Dump time survives (pty history), later output does not -start 30 100 +start 30 100 -n 1 wait 8000 Kill Newcol stable 700 20000 key c-b |
