Browse Source

* Factored terminal title setting code.

* Do not try to set the terminal title if TERM=linux.
tags/v0.99.beta14
Sam Hocevar sam 18 years ago
parent
commit
fcee80f87d
4 changed files with 30 additions and 20 deletions
  1. +3
    -0
      caca/caca_internals.h
  2. +3
    -10
      caca/driver_ncurses.c
  3. +3
    -10
      caca/driver_slang.c
  4. +21
    -0
      caca/graphics.c

+ 3
- 0
caca/caca_internals.h View File

@@ -156,4 +156,7 @@ extern void _push_event(caca_display_t *, caca_event_t *);
extern int _pop_event(caca_display_t *, caca_event_t *);
#endif

/* Internal window functions */
extern void _caca_set_term_title(char const *);

#endif /* __CACA_INTERNALS_H__ */

+ 3
- 10
caca/driver_ncurses.c View File

@@ -59,7 +59,6 @@ static caca_display_t *sigwinch_d; /* FIXME: we ought to get rid of this */
#if defined HAVE_GETENV && defined HAVE_PUTENV
static void ncurses_check_terminal(void);
#endif
static void ncurses_set_title(char const *);
static void ncurses_write_utf32(uint32_t);

struct driver_private
@@ -110,7 +109,7 @@ static int ncurses_init_graphics(caca_display_t *dp)
setlocale(LC_ALL, "");
#endif

ncurses_set_title("caca for ncurses");
_caca_set_term_title("caca for ncurses");

initscr();
keypad(stdscr, TRUE);
@@ -169,7 +168,7 @@ static int ncurses_init_graphics(caca_display_t *dp)

static int ncurses_end_graphics(caca_display_t *dp)
{
ncurses_set_title("");
_caca_set_term_title("");
mousemask(dp->drv.p->oldmask, NULL);
curs_set(1);
noraw();
@@ -182,7 +181,7 @@ static int ncurses_end_graphics(caca_display_t *dp)

static int ncurses_set_display_title(caca_display_t *dp, char const *title)
{
ncurses_set_title(title);
_caca_set_term_title(title);

return 0;
}
@@ -435,12 +434,6 @@ static void ncurses_check_terminal(void)
}
#endif

static void ncurses_set_title(char const *str)
{
fprintf(stdout, "\x1b]0;%s\x07\n", str);
fflush(stdout);
}

static void ncurses_write_utf32(uint32_t ch)
{
#if defined HAVE_NCURSESW_NCURSES_H


+ 3
- 10
caca/driver_slang.c View File

@@ -103,7 +103,6 @@ static int const slang_assoc[16*16] =
* Local functions
*/
static void slang_init_palette(void);
static void slang_set_title(char const *);
static void slang_write_utf32(uint32_t);

#if defined(HAVE_SIGNAL)
@@ -125,7 +124,7 @@ static int slang_init_graphics(caca_display_t *dp)
signal(SIGWINCH, sigwinch_handler);
#endif

slang_set_title("caca for S-Lang");
_caca_set_term_title("caca for S-Lang");

/* Initialise slang library */
SLsig_block_signals();
@@ -175,7 +174,7 @@ static int slang_init_graphics(caca_display_t *dp)

static int slang_end_graphics(caca_display_t *dp)
{
slang_set_title("");
_caca_set_term_title("");
SLtt_set_mouse_mode(0, 0);
SLtt_set_cursor_visibility(1);
SLang_reset_tty();
@@ -186,7 +185,7 @@ static int slang_end_graphics(caca_display_t *dp)

static int slang_set_display_title(caca_display_t *dp, char const *title)
{
slang_set_title(title);
_caca_set_term_title(title);

return 0;
}
@@ -447,12 +446,6 @@ static void slang_init_palette(void)
#endif
}

static void slang_set_title(char const *str)
{
fprintf(stdout, "\x1b]0;%s\x07\n", str);
fflush(stdout);
}

static void slang_write_utf32(uint32_t ch)
{
#ifdef HAVE_SLSMG_UTF8_ENABLE


+ 21
- 0
caca/graphics.c View File

@@ -18,6 +18,12 @@
#include "config.h"
#include "common.h"

#if !defined(__KERNEL__)
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
#endif

#include "caca.h"
#include "caca_internals.h"
#include "cucul.h"
@@ -208,3 +214,18 @@ void _caca_handle_resize(caca_display_t *dp)
_cucul_set_canvas_size(dp->cv, dp->resize.w, dp->resize.h);
}

void _caca_set_term_title(char const *str)
{
#if defined(HAVE_GETENV)
char *term;

term = getenv("TERM");

if(!term || !strcmp(term, "linux"))
return;
#endif

fprintf(stdout, "\x1b]0;%s\x07", str);
fflush(stdout);
}


Loading…
Cancel
Save