Skip to content

Commit 619bfc3

Browse files
committed
pty: set TERM env for the pty process
1 parent 9e9c2ac commit 619bfc3

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/protocol.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ static bool spawn_process(struct pss_tty *pss, uint16_t columns, uint16_t rows)
110110
pty_process *process = process_init((void *) pss, server->loop, argv);
111111
if (columns > 0) process->columns = columns;
112112
if (rows > 0) process->rows = rows;
113+
strncpy(process->term, server->terminal_type, sizeof(process->term));
113114
if (pty_spawn(process, process_read_cb, process_exit_cb) != 0) {
114115
lwsl_err("pty_spawn: %d (%s)\n", errno, strerror(errno));
115116
process_free(process);

src/pty.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ int pty_spawn(pty_process *process, pty_read_cb read_cb, pty_exit_cb exit_cb) {
334334
cmdline = join_args(process->argv);
335335
if (cmdline == NULL) goto cleanup;
336336

337+
// TODO: restore env after process creation
338+
if (!SetEnvironmentVariable("TERM", process->term)) {
339+
print_error("SetEnvironmentVariable");
340+
}
341+
337342
if (!CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, flags, NULL, NULL, &process->si.StartupInfo, &pi)) {
338343
print_error("CreateProcessW");
339344
goto cleanup;
@@ -421,6 +426,7 @@ int pty_spawn(pty_process *process, pty_read_cb read_cb, pty_exit_cb exit_cb) {
421426
return status;
422427
} else if (pid == 0) {
423428
setsid();
429+
setenv("TERM", process->term, true);
424430
int ret = execvp(process->argv[0], process->argv);
425431
if (ret < 0) {
426432
perror("execvp failed\n");

src/pty.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ typedef void (*pty_exit_cb)(void *, pty_process *);
3939
struct pty_process_ {
4040
int pid, exit_code, exit_signal;
4141
uint16_t columns, rows;
42+
char term[30];
4243
bool killed;
4344
#ifdef _WIN32
4445
STARTUPINFOEXW si;

0 commit comments

Comments
 (0)