htop not working.
sergey6661313 opened this issue · 5 comments
just say:
> htop
Error opening terminal: unknown.
Command returned 256.
Huh! That must be because I don't pass $TERM
. I might experiment with this. Thanks for the issue. :-)
Huh! That must be because I don't pass
$TERM
. I might experiment with this. Thanks for the issue. :-)
This is correct, I tried this, setting the env to something like
const env = [_:null]?[*:0]u8{ "TERM=xterm", null };
makes htop
work 😄
@sschneemelcher Awesome, thanks! 🎉
Note to self (TODO): either pass env to forked process or at least add a comment so others can try it out, then update article and/or readme as needed.
ping:)
Okay, so I took a look at this today. The Zig stdlib has std.os.environ
:
https://github.com/ziglang/zig/blob/1653a9b2597c66cbcc88ea75d8a4b88c163584a5/lib/std/os.zig#L239
/// See also `getenv`. Populated by startup code before main().
pub var environ: [][*:0]u8 = undefined;
That []*:0]u8
is just sitting there in memory, waiting to be used. But std.os.execvpeZ()
wants that environment parameter to be a [*:null]const ?[*:0]const u8
.
Passing it anyway gives me this:
src/main.zig:62:78: error: expected type '[*:null]const ?[*:0]const u8', found '[][*:0]u8'
const result = std.os.execvpeZ(args_ptrs[0].?, &args_ptrs, std.os.environ);
~~~~~~^~~~~~~~
/home/dave/zig/lib/std/os.zig:1857:12: note: parameter type declared here
envp: [*:null]const ?[*:0]const u8,
~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Which is no surprise.
I'm not sure that it would be possible to "add" a null termination to the array through casting alone. It seems like we would need to allocate space and copy the whole environment array in order to add the null termination? I'd love to not have to do that!
I also found std.c.environ
, which looks almost exactly right ([*:null]?[*:0]u8
), but it requires that zigish be built with libc:
/home/dave/zig/lib/std/c.zig:122:30: error: dependency on libc must be explicitly specified in the build command
pub extern "c" var environ: [*:null]?[*:0]u8;
~^~~~~~~~~~~~~~~
which feels like serious overkill!