pty: add "colorterm" property

The colorterm property is used (if set) as COLORTERM environment variable.
Note that this variable (despite the name) is not used with
terminfo/termcap. Instead, it's solely used to identify the running
terminal.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-12-12 20:12:21 +01:00
parent eba5178643
commit d50f80a72f
2 changed files with 24 additions and 2 deletions

View File

@ -60,6 +60,7 @@ struct kmscon_pty {
void *data; void *data;
char *term; char *term;
char *colorterm;
char **argv; char **argv;
char *seat; char *seat;
}; };
@ -119,6 +120,7 @@ void kmscon_pty_unref(struct kmscon_pty *pty)
kmscon_pty_close(pty); kmscon_pty_close(pty);
free(pty->seat); free(pty->seat);
free(pty->argv); free(pty->argv);
free(pty->colorterm);
free(pty->term); free(pty->term);
shl_ring_free(pty->msgbuf); shl_ring_free(pty->msgbuf);
ev_eloop_unref(pty->eloop); ev_eloop_unref(pty->eloop);
@ -141,6 +143,22 @@ int kmscon_pty_set_term(struct kmscon_pty *pty, const char *term)
return 0; return 0;
} }
int kmscon_pty_set_colorterm(struct kmscon_pty *pty, const char *colorterm)
{
char *t;
if (!pty || !colorterm)
return -EINVAL;
t = strdup(colorterm);
if (!t)
return -ENOMEM;
free(pty->colorterm);
pty->colorterm = t;
return 0;
}
int kmscon_pty_set_argv(struct kmscon_pty *pty, char **argv) int kmscon_pty_set_argv(struct kmscon_pty *pty, char **argv)
{ {
char **t; char **t;
@ -196,7 +214,8 @@ static bool pty_is_open(struct kmscon_pty *pty)
} }
static void __attribute__((noreturn)) static void __attribute__((noreturn))
exec_child(const char *term, char **argv, const char *seat) exec_child(const char *term, const char *colorterm, char **argv,
const char *seat)
{ {
if (!term) if (!term)
term = "vt220"; term = "vt220";
@ -204,6 +223,8 @@ exec_child(const char *term, char **argv, const char *seat)
argv = (char*[]){ "/bin/login", NULL }; argv = (char*[]){ "/bin/login", NULL };
setenv("TERM", term, 1); setenv("TERM", term, 1);
if (colorterm)
setenv("COLORTERM", colorterm, 1);
if (seat) if (seat)
setenv("XDG_SEAT", seat, 1); setenv("XDG_SEAT", seat, 1);
execvp(argv[0], argv); execvp(argv[0], argv);
@ -322,7 +343,7 @@ static int pty_spawn(struct kmscon_pty *pty, int master,
return -errno; return -errno;
case 0: case 0:
setup_child(master, &ws); setup_child(master, &ws);
exec_child(pty->term, pty->argv, pty->seat); exec_child(pty->term, pty->colorterm, pty->argv, pty->seat);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
default: default:
log_debug("forking child %d", pid); log_debug("forking child %d", pid);

View File

@ -54,6 +54,7 @@ int kmscon_pty_new(struct kmscon_pty **out, kmscon_pty_input_cb input_cb,
void kmscon_pty_ref(struct kmscon_pty *pty); void kmscon_pty_ref(struct kmscon_pty *pty);
void kmscon_pty_unref(struct kmscon_pty *pty); void kmscon_pty_unref(struct kmscon_pty *pty);
int kmscon_pty_set_term(struct kmscon_pty *pty, const char *term); int kmscon_pty_set_term(struct kmscon_pty *pty, const char *term);
int kmscon_pty_set_colorterm(struct kmscon_pty *pty, const char *colorterm);
int kmscon_pty_set_argv(struct kmscon_pty *pty, char **argv); int kmscon_pty_set_argv(struct kmscon_pty *pty, char **argv);
int kmscon_pty_set_seat(struct kmscon_pty *pty, const char *seat); int kmscon_pty_set_seat(struct kmscon_pty *pty, const char *seat);