summaryrefslogtreecommitdiff
path: root/src/cli/args.zig
diff options
context:
space:
mode:
authorMitchell Hashimoto <m@mitchellh.com>2025-06-22 11:22:02 -0700
committerMitchell Hashimoto <m@mitchellh.com>2025-06-22 18:18:16 -0400
commit1947afade94ccfd24f49c7efe8aeac735eb08061 (patch)
treec2f1f840557986ff888a650d90e742947642d3d1 /src/cli/args.zig
parentf07816f188a7be8be74cf67733d1ef9c0ac81f63 (diff)
`input` configuration to pass input as stdin on startup
This adds a new configuration `input` that allows passing either raw text or file contents as stdin when starting the terminal. The input is sent byte-for-byte to the terminal, so control characters such as `\n` will be interpreted by the shell and can be used to run programs in the context of the loaded shell. Example: `ghostty --input="hello, world\n"` will start the your default shell, run `echo hello, world`, and then show the prompt.
Diffstat (limited to 'src/cli/args.zig')
-rw-r--r--src/cli/args.zig7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/cli/args.zig b/src/cli/args.zig
index 68972a622..3c34e17fe 100644
--- a/src/cli/args.zig
+++ b/src/cli/args.zig
@@ -414,7 +414,7 @@ pub fn parseIntoField(
return error.InvalidField;
}
-fn parseTaggedUnion(comptime T: type, alloc: Allocator, v: []const u8) !T {
+pub fn parseTaggedUnion(comptime T: type, alloc: Allocator, v: []const u8) !T {
const info = @typeInfo(T).@"union";
assert(@typeInfo(info.tag_type.?) == .@"enum");
@@ -1090,6 +1090,7 @@ test "parseIntoField: tagged union" {
b: u8,
c: void,
d: []const u8,
+ e: [:0]const u8,
} = undefined,
} = .{};
@@ -1108,6 +1109,10 @@ test "parseIntoField: tagged union" {
// Set string field
try parseIntoField(@TypeOf(data), alloc, &data, "value", "d:hello");
try testing.expectEqualStrings("hello", data.value.d);
+
+ // Set sentinel string field
+ try parseIntoField(@TypeOf(data), alloc, &data, "value", "e:hello");
+ try testing.expectEqualStrings("hello", data.value.e);
}
test "parseIntoField: tagged union unknown filed" {