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.
This commit is contained in:
Mitchell Hashimoto
2025-06-22 11:22:02 -07:00
parent f07816f188
commit 1947afade9
7 changed files with 460 additions and 3 deletions

View File

@@ -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" {