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.
Location:
libcaca/trunk/caca
Files:
2 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
  • libcaca/trunk/caca/driver_slang.c

    r2138 r2142  
    111111#endif
    112112#if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
    113 static void slang_check_terminal(void);
    114 #endif
     113static void slang_install_terminal(caca_display_t *);
     114static void slang_uninstall_terminal(caca_display_t *);
     115#endif
     116
     117struct driver_private
     118{
     119    char *term;
     120};
    115121
    116122static int slang_init_graphics(caca_display_t *dp)
    117123{
     124    dp->drv.p = malloc(sizeof(struct driver_private));
     125
    118126#if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
    119     slang_check_terminal();
     127    slang_install_terminal(dp);
    120128#endif
    121129
     
    184192    SLang_reset_tty();
    185193    SLsmg_reset_smg();
     194
     195#if defined HAVE_GETENV && defined HAVE_PUTENV
     196    slang_uninstall_terminal(dp);
     197#endif
     198
     199    free(dp->drv.p);
    186200
    187201    return 0;
     
    495509
    496510#if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
    497 static void slang_check_terminal(void)
     511static void slang_install_terminal(caca_display_t *dp)
    498512{
    499513    char *term, *colorterm;
     514
     515    dp->drv.p->term = NULL;
    500516
    501517    term = getenv("TERM");
     
    512528    {
    513529        (void)putenv("TERM=xterm-16color");
     530        dp->drv.p->term = strdup(term);
    514531        return;
    515532    }
     533}
     534
     535static void slang_uninstall_terminal(caca_display_t *dp)
     536{
     537    /* Needs to be persistent because we use putenv() */
     538    static char termenv[1024];
     539
     540    if(!dp->drv.p->term)
     541        return;
     542
     543    snprintf(termenv, 1023, "TERM=%s", dp->drv.p->term);
     544    free(dp->drv.p->term);
     545    (void)putenv(termenv);
    516546}
    517547#endif
Note: See TracChangeset for help on using the changeset viewer.