widgets(terminal): set working_directory at spawn
Fixes #49. If a user has passed an initial working directory, set that as the set that as the terminal's working directory when we spawn the widget.
This commit is contained in:
parent
09a4de63e5
commit
dff7681c30
1 changed files with 14 additions and 0 deletions
|
@ -94,6 +94,10 @@ pub fn init(
|
||||||
unicode: *const vaxis.Unicode,
|
unicode: *const vaxis.Unicode,
|
||||||
opts: Options,
|
opts: Options,
|
||||||
) !Terminal {
|
) !Terminal {
|
||||||
|
// Verify we have an absolute path
|
||||||
|
if (opts.initial_working_directory) |pwd| {
|
||||||
|
if (!std.fs.path.isAbsolute(pwd)) return error.InvalidWorkingDirectory;
|
||||||
|
}
|
||||||
const pty = try Pty.init();
|
const pty = try Pty.init();
|
||||||
try pty.setSize(opts.winsize);
|
try pty.setSize(opts.winsize);
|
||||||
const cmd: Command = .{
|
const cmd: Command = .{
|
||||||
|
@ -160,6 +164,16 @@ pub fn spawn(self: *Terminal) !void {
|
||||||
|
|
||||||
try self.cmd.spawn(self.allocator);
|
try self.cmd.spawn(self.allocator);
|
||||||
|
|
||||||
|
self.working_directory.clearRetainingCapacity();
|
||||||
|
if (self.cmd.working_directory) |pwd| {
|
||||||
|
try self.working_directory.appendSlice(pwd);
|
||||||
|
} else {
|
||||||
|
const pwd = std.fs.cwd();
|
||||||
|
var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||||
|
const out_path = try std.os.getFdPath(pwd.fd, &buffer);
|
||||||
|
try self.working_directory.appendSlice(out_path);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// add to our global list
|
// add to our global list
|
||||||
global_vt_mutex.lock();
|
global_vt_mutex.lock();
|
||||||
|
|
Loading…
Reference in a new issue