Browse Source

* The SLang and ncurses drivers now put back the TERM environment variable

if they modified it.
tags/v0.99.beta14
Sam Hocevar sam 17 years ago
parent
commit
3602fc98be
2 changed files with 58 additions and 6 deletions
  1. +25
    -3
      caca/driver_ncurses.c
  2. +33
    -3
      caca/driver_slang.c

+ 25
- 3
caca/driver_ncurses.c View File

@@ -196,7 +196,8 @@ static RETSIGTYPE sigwinch_handler(int);
static caca_display_t *sigwinch_d; /* FIXME: we ought to get rid of this */ static caca_display_t *sigwinch_d; /* FIXME: we ought to get rid of this */
#endif #endif
#if defined HAVE_GETENV && defined HAVE_PUTENV #if defined HAVE_GETENV && defined HAVE_PUTENV
static void ncurses_check_terminal(void);
static void ncurses_install_terminal(caca_display_t *);
static void ncurses_uninstall_terminal(caca_display_t *);
#endif #endif
static void ncurses_write_utf32(uint32_t); static void ncurses_write_utf32(uint32_t);


@@ -204,6 +205,7 @@ struct driver_private
{ {
int attr[16*16]; int attr[16*16];
mmask_t oldmask; mmask_t oldmask;
char *term;
}; };


static int ncurses_init_graphics(caca_display_t *dp) static int ncurses_init_graphics(caca_display_t *dp)
@@ -236,7 +238,7 @@ static int ncurses_init_graphics(caca_display_t *dp)
dp->drv.p = malloc(sizeof(struct driver_private)); dp->drv.p = malloc(sizeof(struct driver_private));


#if defined HAVE_GETENV && defined HAVE_PUTENV #if defined HAVE_GETENV && defined HAVE_PUTENV
ncurses_check_terminal();
ncurses_install_terminal(dp);
#endif #endif


#if defined HAVE_SIGNAL #if defined HAVE_SIGNAL
@@ -315,6 +317,10 @@ static int ncurses_end_graphics(caca_display_t *dp)
noraw(); noraw();
endwin(); endwin();


#if defined HAVE_GETENV && defined HAVE_PUTENV
ncurses_uninstall_terminal(dp);
#endif

free(dp->drv.p); free(dp->drv.p);


return 0; return 0;
@@ -561,10 +567,12 @@ static RETSIGTYPE sigwinch_handler(int sig)
#endif #endif


#if defined HAVE_GETENV && defined HAVE_PUTENV #if defined HAVE_GETENV && defined HAVE_PUTENV
static void ncurses_check_terminal(void)
static void ncurses_install_terminal(caca_display_t *dp)
{ {
char *term, *colorterm; char *term, *colorterm;


dp->drv.p->term = NULL;

term = getenv("TERM"); term = getenv("TERM");
colorterm = getenv("COLORTERM"); colorterm = getenv("COLORTERM");


@@ -583,9 +591,23 @@ static void ncurses_check_terminal(void)
return; return;
endwin(); endwin();
(void)putenv("TERM=xterm-16color"); (void)putenv("TERM=xterm-16color");
dp->drv.p->term = strdup(term);
return; return;
} }
} }

static void ncurses_uninstall_terminal(caca_display_t *dp)
{
/* Needs to be persistent because we use putenv() */
static char termenv[1024];

if(!dp->drv.p->term)
return;

snprintf(termenv, 1023, "TERM=%s", dp->drv.p->term);
free(dp->drv.p->term);
(void)putenv(termenv);
}
#endif #endif


static void ncurses_write_utf32(uint32_t ch) static void ncurses_write_utf32(uint32_t ch)


+ 33
- 3
caca/driver_slang.c View File

@@ -110,13 +110,21 @@ static RETSIGTYPE sigwinch_handler(int);
static caca_display_t *sigwinch_d; /* FIXME: we ought to get rid of this */ static caca_display_t *sigwinch_d; /* FIXME: we ought to get rid of this */
#endif #endif
#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) #if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
static void slang_check_terminal(void);
static void slang_install_terminal(caca_display_t *);
static void slang_uninstall_terminal(caca_display_t *);
#endif #endif


struct driver_private
{
char *term;
};

static int slang_init_graphics(caca_display_t *dp) static int slang_init_graphics(caca_display_t *dp)
{ {
dp->drv.p = malloc(sizeof(struct driver_private));

#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) #if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
slang_check_terminal();
slang_install_terminal(dp);
#endif #endif


#if defined(HAVE_SIGNAL) #if defined(HAVE_SIGNAL)
@@ -184,6 +192,12 @@ static int slang_end_graphics(caca_display_t *dp)
SLang_reset_tty(); SLang_reset_tty();
SLsmg_reset_smg(); SLsmg_reset_smg();


#if defined HAVE_GETENV && defined HAVE_PUTENV
slang_uninstall_terminal(dp);
#endif

free(dp->drv.p);

return 0; return 0;
} }


@@ -494,10 +508,12 @@ static RETSIGTYPE sigwinch_handler(int sig)
#endif #endif


#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) #if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
static void slang_check_terminal(void)
static void slang_install_terminal(caca_display_t *dp)
{ {
char *term, *colorterm; char *term, *colorterm;


dp->drv.p->term = NULL;

term = getenv("TERM"); term = getenv("TERM");
colorterm = getenv("COLORTERM"); colorterm = getenv("COLORTERM");


@@ -511,9 +527,23 @@ static void slang_check_terminal(void)
|| getenv("KONSOLE_DCOP_SESSION")) || getenv("KONSOLE_DCOP_SESSION"))
{ {
(void)putenv("TERM=xterm-16color"); (void)putenv("TERM=xterm-16color");
dp->drv.p->term = strdup(term);
return; return;
} }
} }

static void slang_uninstall_terminal(caca_display_t *dp)
{
/* Needs to be persistent because we use putenv() */
static char termenv[1024];

if(!dp->drv.p->term)
return;

snprintf(termenv, 1023, "TERM=%s", dp->drv.p->term);
free(dp->drv.p->term);
(void)putenv(termenv);
}
#endif #endif


/* /*


Loading…
Cancel
Save