widgets(terminal): add initial_working_directory option
This commit is contained in:
parent
6043f0569a
commit
7005bb237c
3 changed files with 9 additions and 0 deletions
|
@ -45,6 +45,7 @@ pub fn main() !void {
|
||||||
.y_pixel = 0,
|
.y_pixel = 0,
|
||||||
},
|
},
|
||||||
.scrollback_size = 0,
|
.scrollback_size = 0,
|
||||||
|
.initial_working_directory = env.get("HOME") orelse @panic("no $HOME"),
|
||||||
};
|
};
|
||||||
const shell = env.get("SHELL") orelse "bash";
|
const shell = env.get("SHELL") orelse "bash";
|
||||||
const argv = [_][]const u8{shell};
|
const argv = [_][]const u8{shell};
|
||||||
|
|
|
@ -9,6 +9,8 @@ const posix = std.posix;
|
||||||
|
|
||||||
argv: []const []const u8,
|
argv: []const []const u8,
|
||||||
|
|
||||||
|
working_directory: ?[]const u8,
|
||||||
|
|
||||||
// Set after spawn()
|
// Set after spawn()
|
||||||
pid: ?std.posix.pid_t = null,
|
pid: ?std.posix.pid_t = null,
|
||||||
|
|
||||||
|
@ -44,6 +46,10 @@ pub fn spawn(self: *Command, allocator: std.mem.Allocator) !void {
|
||||||
posix.close(self.pty.tty);
|
posix.close(self.pty.tty);
|
||||||
if (self.pty.pty > 2) posix.close(self.pty.pty);
|
if (self.pty.pty > 2) posix.close(self.pty.pty);
|
||||||
|
|
||||||
|
if (self.working_directory) |wd| {
|
||||||
|
try std.posix.chdir(wd);
|
||||||
|
}
|
||||||
|
|
||||||
// exec
|
// exec
|
||||||
const err = std.posix.execvpeZ(argv_buf.ptr[0].?, argv_buf.ptr, envp);
|
const err = std.posix.execvpeZ(argv_buf.ptr[0].?, argv_buf.ptr, envp);
|
||||||
_ = err catch {};
|
_ = err catch {};
|
||||||
|
|
|
@ -32,6 +32,7 @@ const log = std.log.scoped(.terminal);
|
||||||
pub const Options = struct {
|
pub const Options = struct {
|
||||||
scrollback_size: usize = 500,
|
scrollback_size: usize = 500,
|
||||||
winsize: Winsize = .{ .rows = 24, .cols = 80, .x_pixel = 0, .y_pixel = 0 },
|
winsize: Winsize = .{ .rows = 24, .cols = 80, .x_pixel = 0, .y_pixel = 0 },
|
||||||
|
initial_working_directory: ?[]const u8 = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Mode = struct {
|
pub const Mode = struct {
|
||||||
|
@ -97,6 +98,7 @@ pub fn init(
|
||||||
.argv = argv,
|
.argv = argv,
|
||||||
.env_map = env,
|
.env_map = env,
|
||||||
.pty = pty,
|
.pty = pty,
|
||||||
|
.working_directory = opts.initial_working_directory,
|
||||||
};
|
};
|
||||||
var tabs = try std.ArrayList(u16).initCapacity(allocator, opts.winsize.cols / 8);
|
var tabs = try std.ArrayList(u16).initCapacity(allocator, opts.winsize.cols / 8);
|
||||||
var col: u16 = 0;
|
var col: u16 = 0;
|
||||||
|
|
Loading…
Reference in a new issue