Ignore:
Timestamp:
Dec 16, 2007, 12:55:14 PM (12 years ago)
Author:
Sam Hocevar
Message:
  • The SLang and ncurses drivers now put back the TERM environment variable if they modified it.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/driver_ncurses.c

    r2138 r2142  
    197197#endif
    198198#if defined HAVE_GETENV && defined HAVE_PUTENV
    199 static void ncurses_check_terminal(void);
     199static void ncurses_install_terminal(caca_display_t *);
     200static void ncurses_uninstall_terminal(caca_display_t *);
    200201#endif
    201202static void ncurses_write_utf32(uint32_t);
     
    205206    int attr[16*16];
    206207    mmask_t oldmask;
     208    char *term;
    207209};
    208210
     
    237239
    238240#if defined HAVE_GETENV && defined HAVE_PUTENV
    239     ncurses_check_terminal();
     241    ncurses_install_terminal(dp);
    240242#endif
    241243
     
    315317    noraw();
    316318    endwin();
     319
     320#if defined HAVE_GETENV && defined HAVE_PUTENV
     321    ncurses_uninstall_terminal(dp);
     322#endif
    317323
    318324    free(dp->drv.p);
     
    562568
    563569#if defined HAVE_GETENV && defined HAVE_PUTENV
    564 static void ncurses_check_terminal(void)
     570static void ncurses_install_terminal(caca_display_t *dp)
    565571{
    566572    char *term, *colorterm;
     573
     574    dp->drv.p->term = NULL;
    567575
    568576    term = getenv("TERM");
     
    584592        endwin();
    585593        (void)putenv("TERM=xterm-16color");
     594        dp->drv.p->term = strdup(term);
    586595        return;
    587596    }
     597}
     598
     599static void ncurses_uninstall_terminal(caca_display_t *dp)
     600{
     601    /* Needs to be persistent because we use putenv() */
     602    static char termenv[1024];
     603
     604    if(!dp->drv.p->term)
     605        return;
     606
     607    snprintf(termenv, 1023, "TERM=%s", dp->drv.p->term);
     608    free(dp->drv.p->term);
     609    (void)putenv(termenv);
    588610}
    589611#endif
Note: See TracChangeset for help on using the changeset viewer.