[35] | 1 | /* |
---|
[268] | 2 | * libcaca ASCII-Art library |
---|
[527] | 3 | * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> |
---|
[268] | 4 | * All Rights Reserved |
---|
[35] | 5 | * |
---|
[268] | 6 | * This library is free software; you can redistribute it and/or |
---|
[522] | 7 | * modify it under the terms of the Do What The Fuck You Want To |
---|
| 8 | * Public License, Version 2, as published by Sam Hocevar. See |
---|
| 9 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
[35] | 10 | */ |
---|
[17] | 11 | |
---|
[540] | 12 | /** \file driver_ncurses.c |
---|
[268] | 13 | * \version \$Id: driver_ncurses.c 557 2006-03-08 22:29:00Z sam $ |
---|
| 14 | * \author Sam Hocevar <sam@zoy.org> |
---|
[540] | 15 | * \brief Ncurses driver |
---|
[205] | 16 | * |
---|
[540] | 17 | * This file contains the libcaca Ncurses input and output driver |
---|
[205] | 18 | */ |
---|
| 19 | |
---|
[63] | 20 | #include "config.h" |
---|
| 21 | |
---|
[539] | 22 | #if defined(USE_NCURSES) |
---|
| 23 | |
---|
| 24 | #if defined(HAVE_NCURSES_H) |
---|
| 25 | # include <ncurses.h> |
---|
| 26 | #else |
---|
| 27 | # include <curses.h> |
---|
| 28 | #endif |
---|
| 29 | |
---|
[550] | 30 | #include <stdlib.h> |
---|
| 31 | #include <string.h> |
---|
| 32 | |
---|
[348] | 33 | #if defined(HAVE_SIGNAL_H) |
---|
| 34 | # include <signal.h> |
---|
| 35 | #endif |
---|
| 36 | #if defined(HAVE_SYS_IOCTL_H) |
---|
| 37 | # include <sys/ioctl.h> |
---|
| 38 | #endif |
---|
| 39 | |
---|
[185] | 40 | #include "caca.h" |
---|
| 41 | #include "caca_internals.h" |
---|
[524] | 42 | #include "cucul.h" |
---|
| 43 | #include "cucul_internals.h" |
---|
[17] | 44 | |
---|
[281] | 45 | /* |
---|
| 46 | * Local functions |
---|
| 47 | */ |
---|
[540] | 48 | |
---|
[539] | 49 | #if defined(HAVE_SIGNAL) |
---|
[348] | 50 | static RETSIGTYPE sigwinch_handler(int); |
---|
[527] | 51 | static caca_t *sigwinch_kk; /* FIXME: we ought to get rid of this */ |
---|
[348] | 52 | #endif |
---|
[550] | 53 | #if defined(HAVE_GETENV) && defined(HAVE_PUTENV) |
---|
| 54 | static void ncurses_check_terminal(void); |
---|
| 55 | #endif |
---|
[348] | 56 | |
---|
[550] | 57 | struct driver_private |
---|
| 58 | { |
---|
| 59 | int attr[16*16]; |
---|
| 60 | mmask_t oldmask; |
---|
| 61 | }; |
---|
| 62 | |
---|
[540] | 63 | static int ncurses_init_graphics(caca_t *kk) |
---|
[539] | 64 | { |
---|
| 65 | static int curses_colors[] = |
---|
| 66 | { |
---|
| 67 | /* Standard curses colours */ |
---|
| 68 | COLOR_BLACK, |
---|
| 69 | COLOR_BLUE, |
---|
| 70 | COLOR_GREEN, |
---|
| 71 | COLOR_CYAN, |
---|
| 72 | COLOR_RED, |
---|
| 73 | COLOR_MAGENTA, |
---|
| 74 | COLOR_YELLOW, |
---|
| 75 | COLOR_WHITE, |
---|
| 76 | /* Extra values for xterm-16color */ |
---|
| 77 | COLOR_BLACK + 8, |
---|
| 78 | COLOR_BLUE + 8, |
---|
| 79 | COLOR_GREEN + 8, |
---|
| 80 | COLOR_CYAN + 8, |
---|
| 81 | COLOR_RED + 8, |
---|
| 82 | COLOR_MAGENTA + 8, |
---|
| 83 | COLOR_YELLOW + 8, |
---|
| 84 | COLOR_WHITE + 8 |
---|
| 85 | }; |
---|
[300] | 86 | |
---|
[539] | 87 | mmask_t newmask; |
---|
| 88 | int fg, bg, max; |
---|
[483] | 89 | |
---|
[550] | 90 | kk->drv.p = malloc(sizeof(struct driver_private)); |
---|
| 91 | |
---|
| 92 | #if defined(HAVE_GETENV) && defined(HAVE_PUTENV) |
---|
| 93 | ncurses_check_terminal(); |
---|
| 94 | #endif |
---|
| 95 | |
---|
[539] | 96 | #if defined(HAVE_SIGNAL) |
---|
[524] | 97 | sigwinch_kk = kk; |
---|
[348] | 98 | signal(SIGWINCH, sigwinch_handler); |
---|
| 99 | #endif |
---|
| 100 | |
---|
[539] | 101 | initscr(); |
---|
| 102 | keypad(stdscr, TRUE); |
---|
| 103 | nonl(); |
---|
| 104 | raw(); |
---|
| 105 | noecho(); |
---|
| 106 | nodelay(stdscr, TRUE); |
---|
| 107 | curs_set(0); |
---|
[227] | 108 | |
---|
[539] | 109 | /* Activate mouse */ |
---|
| 110 | newmask = REPORT_MOUSE_POSITION | ALL_MOUSE_EVENTS; |
---|
[550] | 111 | mousemask(newmask, &kk->drv.p->oldmask); |
---|
[539] | 112 | mouseinterval(-1); /* No click emulation */ |
---|
[231] | 113 | |
---|
[539] | 114 | /* Set the escape delay to a ridiculously low value */ |
---|
| 115 | ESCDELAY = 10; |
---|
[227] | 116 | |
---|
[539] | 117 | /* Activate colour */ |
---|
| 118 | start_color(); |
---|
[227] | 119 | |
---|
[539] | 120 | /* If COLORS == 16, it means the terminal supports full bright colours |
---|
| 121 | * using setab and setaf (will use \e[90m \e[91m etc. for colours >= 8), |
---|
| 122 | * we can build 16*16 colour pairs. |
---|
| 123 | * If COLORS == 8, it means the terminal does not know about bright |
---|
| 124 | * colours and we need to get them through A_BOLD and A_BLINK (\e[1m |
---|
| 125 | * and \e[5m). We can only build 8*8 colour pairs. */ |
---|
| 126 | max = COLORS >= 16 ? 16 : 8; |
---|
[227] | 127 | |
---|
[539] | 128 | for(bg = 0; bg < max; bg++) |
---|
| 129 | for(fg = 0; fg < max; fg++) |
---|
| 130 | { |
---|
| 131 | /* Use ((max + 7 - fg) % max) instead of fg so that colour 0 |
---|
| 132 | * is light gray on black. Some terminals don't like this |
---|
| 133 | * colour pair to be redefined. */ |
---|
| 134 | int col = ((max + 7 - fg) % max) + max * bg; |
---|
| 135 | init_pair(col, curses_colors[fg], curses_colors[bg]); |
---|
[550] | 136 | kk->drv.p->attr[fg + 16 * bg] = COLOR_PAIR(col); |
---|
[227] | 137 | |
---|
[539] | 138 | if(max == 8) |
---|
[265] | 139 | { |
---|
[539] | 140 | /* Bright fg on simple bg */ |
---|
[550] | 141 | kk->drv.p->attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col); |
---|
[539] | 142 | /* Simple fg on bright bg */ |
---|
[550] | 143 | kk->drv.p->attr[fg + 16 * (bg + 8)] = A_BLINK |
---|
[539] | 144 | | COLOR_PAIR(col); |
---|
| 145 | /* Bright fg on bright bg */ |
---|
[550] | 146 | kk->drv.p->attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD |
---|
[263] | 147 | | COLOR_PAIR(col); |
---|
[227] | 148 | } |
---|
[265] | 149 | } |
---|
[263] | 150 | |
---|
[539] | 151 | cucul_set_size(kk->qq, COLS, LINES); |
---|
[300] | 152 | |
---|
[227] | 153 | return 0; |
---|
| 154 | } |
---|
| 155 | |
---|
[540] | 156 | static int ncurses_end_graphics(caca_t *kk) |
---|
[251] | 157 | { |
---|
[550] | 158 | mousemask(kk->drv.p->oldmask, NULL); |
---|
[539] | 159 | curs_set(1); |
---|
| 160 | noraw(); |
---|
| 161 | endwin(); |
---|
[300] | 162 | |
---|
[550] | 163 | free(kk->drv.p); |
---|
| 164 | |
---|
[251] | 165 | return 0; |
---|
| 166 | } |
---|
| 167 | |
---|
[540] | 168 | static int ncurses_set_window_title(caca_t *kk, char const *title) |
---|
[343] | 169 | { |
---|
| 170 | return 0; |
---|
| 171 | } |
---|
| 172 | |
---|
[540] | 173 | static unsigned int ncurses_get_window_width(caca_t *kk) |
---|
[352] | 174 | { |
---|
| 175 | /* Fallback to a 6x10 font */ |
---|
[524] | 176 | return kk->qq->width * 6; |
---|
[352] | 177 | } |
---|
| 178 | |
---|
[540] | 179 | static unsigned int ncurses_get_window_height(caca_t *kk) |
---|
[352] | 180 | { |
---|
| 181 | /* Fallback to a 6x10 font */ |
---|
[524] | 182 | return kk->qq->height * 10; |
---|
[352] | 183 | } |
---|
| 184 | |
---|
[540] | 185 | static void ncurses_display(caca_t *kk) |
---|
[227] | 186 | { |
---|
[539] | 187 | int x, y; |
---|
| 188 | uint8_t *attr = kk->qq->attr; |
---|
| 189 | uint32_t *chars = kk->qq->chars; |
---|
| 190 | for(y = 0; y < (int)kk->qq->height; y++) |
---|
[265] | 191 | { |
---|
[539] | 192 | move(y, 0); |
---|
| 193 | for(x = kk->qq->width; x--; ) |
---|
[527] | 194 | { |
---|
[557] | 195 | uint32_t c = *chars++; |
---|
| 196 | |
---|
[550] | 197 | attrset(kk->drv.p->attr[*attr++]); |
---|
[557] | 198 | if(c > 0x00000020 && c < 0x00000080) |
---|
| 199 | addch((char)c); |
---|
| 200 | else |
---|
| 201 | addch(' '); |
---|
[527] | 202 | } |
---|
[265] | 203 | } |
---|
[539] | 204 | refresh(); |
---|
[227] | 205 | } |
---|
| 206 | |
---|
[553] | 207 | static void ncurses_handle_resize(caca_t *kk) |
---|
[347] | 208 | { |
---|
[539] | 209 | struct winsize size; |
---|
[347] | 210 | |
---|
[539] | 211 | if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) |
---|
[347] | 212 | { |
---|
[553] | 213 | kk->resize.w = size.ws_col; |
---|
| 214 | kk->resize.h = size.ws_row; |
---|
[364] | 215 | #if defined(HAVE_RESIZE_TERM) |
---|
[553] | 216 | resize_term(kk->resize.h, kk->resize.w); |
---|
[364] | 217 | #else |
---|
[553] | 218 | resizeterm(*kk->resize.h, *kk->resize.w); |
---|
[364] | 219 | #endif |
---|
[539] | 220 | wrefresh(curscr); |
---|
[553] | 221 | return; |
---|
[347] | 222 | } |
---|
[553] | 223 | |
---|
| 224 | /* Fallback */ |
---|
| 225 | kk->resize.w = kk->qq->width; |
---|
| 226 | kk->resize.h = kk->qq->height; |
---|
[347] | 227 | } |
---|
| 228 | |
---|
[548] | 229 | static unsigned int ncurses_get_event(caca_t *kk) |
---|
| 230 | { |
---|
| 231 | unsigned int event; |
---|
| 232 | int intkey; |
---|
| 233 | |
---|
| 234 | intkey = getch(); |
---|
| 235 | if(intkey == ERR) |
---|
| 236 | return CACA_EVENT_NONE; |
---|
| 237 | |
---|
| 238 | if(intkey < 0x100) |
---|
| 239 | { |
---|
| 240 | return CACA_EVENT_KEY_PRESS | intkey; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | if(intkey == KEY_MOUSE) |
---|
| 244 | { |
---|
| 245 | MEVENT mevent; |
---|
| 246 | getmouse(&mevent); |
---|
| 247 | |
---|
| 248 | switch(mevent.bstate) |
---|
| 249 | { |
---|
| 250 | case BUTTON1_PRESSED: |
---|
| 251 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); |
---|
| 252 | break; |
---|
| 253 | case BUTTON1_RELEASED: |
---|
| 254 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); |
---|
| 255 | break; |
---|
| 256 | case BUTTON1_CLICKED: |
---|
| 257 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); |
---|
| 258 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); |
---|
| 259 | break; |
---|
| 260 | case BUTTON1_DOUBLE_CLICKED: |
---|
| 261 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); |
---|
| 262 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); |
---|
| 263 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); |
---|
| 264 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); |
---|
| 265 | break; |
---|
| 266 | case BUTTON1_TRIPLE_CLICKED: |
---|
| 267 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); |
---|
| 268 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); |
---|
| 269 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); |
---|
| 270 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); |
---|
| 271 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 1); |
---|
| 272 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 1); |
---|
| 273 | break; |
---|
| 274 | case BUTTON1_RESERVED_EVENT: |
---|
| 275 | break; |
---|
| 276 | |
---|
| 277 | case BUTTON2_PRESSED: |
---|
| 278 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); |
---|
| 279 | break; |
---|
| 280 | case BUTTON2_RELEASED: |
---|
| 281 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); |
---|
| 282 | break; |
---|
| 283 | case BUTTON2_CLICKED: |
---|
| 284 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); |
---|
| 285 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); |
---|
| 286 | break; |
---|
| 287 | case BUTTON2_DOUBLE_CLICKED: |
---|
| 288 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); |
---|
| 289 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); |
---|
| 290 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); |
---|
| 291 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); |
---|
| 292 | break; |
---|
| 293 | case BUTTON2_TRIPLE_CLICKED: |
---|
| 294 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); |
---|
| 295 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); |
---|
| 296 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); |
---|
| 297 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); |
---|
| 298 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 2); |
---|
| 299 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 2); |
---|
| 300 | break; |
---|
| 301 | case BUTTON2_RESERVED_EVENT: |
---|
| 302 | break; |
---|
| 303 | |
---|
| 304 | case BUTTON3_PRESSED: |
---|
| 305 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); |
---|
| 306 | break; |
---|
| 307 | case BUTTON3_RELEASED: |
---|
| 308 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); |
---|
| 309 | break; |
---|
| 310 | case BUTTON3_CLICKED: |
---|
| 311 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); |
---|
| 312 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); |
---|
| 313 | break; |
---|
| 314 | case BUTTON3_DOUBLE_CLICKED: |
---|
| 315 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); |
---|
| 316 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); |
---|
| 317 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); |
---|
| 318 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); |
---|
| 319 | break; |
---|
| 320 | case BUTTON3_TRIPLE_CLICKED: |
---|
| 321 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); |
---|
| 322 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); |
---|
| 323 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); |
---|
| 324 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); |
---|
| 325 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 3); |
---|
| 326 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 3); |
---|
| 327 | break; |
---|
| 328 | case BUTTON3_RESERVED_EVENT: |
---|
| 329 | break; |
---|
| 330 | |
---|
| 331 | case BUTTON4_PRESSED: |
---|
| 332 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); |
---|
| 333 | break; |
---|
| 334 | case BUTTON4_RELEASED: |
---|
| 335 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); |
---|
| 336 | break; |
---|
| 337 | case BUTTON4_CLICKED: |
---|
| 338 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); |
---|
| 339 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); |
---|
| 340 | break; |
---|
| 341 | case BUTTON4_DOUBLE_CLICKED: |
---|
| 342 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); |
---|
| 343 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); |
---|
| 344 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); |
---|
| 345 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); |
---|
| 346 | break; |
---|
| 347 | case BUTTON4_TRIPLE_CLICKED: |
---|
| 348 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); |
---|
| 349 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); |
---|
| 350 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); |
---|
| 351 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); |
---|
| 352 | _push_event(kk, CACA_EVENT_MOUSE_PRESS | 4); |
---|
| 353 | _push_event(kk, CACA_EVENT_MOUSE_RELEASE | 4); |
---|
| 354 | break; |
---|
| 355 | case BUTTON4_RESERVED_EVENT: |
---|
| 356 | break; |
---|
| 357 | |
---|
| 358 | default: |
---|
| 359 | break; |
---|
| 360 | } |
---|
| 361 | |
---|
[551] | 362 | if(kk->mouse.x == (unsigned int)mevent.x && |
---|
| 363 | kk->mouse.y == (unsigned int)mevent.y) |
---|
[548] | 364 | return _pop_event(kk); |
---|
| 365 | |
---|
[551] | 366 | kk->mouse.x = mevent.x; |
---|
| 367 | kk->mouse.y = mevent.y; |
---|
[548] | 368 | |
---|
[551] | 369 | return CACA_EVENT_MOUSE_MOTION | (kk->mouse.x << 12) | kk->mouse.y; |
---|
[548] | 370 | } |
---|
| 371 | |
---|
| 372 | event = CACA_EVENT_KEY_PRESS; |
---|
| 373 | |
---|
| 374 | switch(intkey) |
---|
| 375 | { |
---|
| 376 | case KEY_UP: return event | CACA_KEY_UP; |
---|
| 377 | case KEY_DOWN: return event | CACA_KEY_DOWN; |
---|
| 378 | case KEY_LEFT: return event | CACA_KEY_LEFT; |
---|
| 379 | case KEY_RIGHT: return event | CACA_KEY_RIGHT; |
---|
| 380 | |
---|
| 381 | case KEY_IC: return event | CACA_KEY_INSERT; |
---|
| 382 | case KEY_DC: return event | CACA_KEY_DELETE; |
---|
| 383 | case KEY_HOME: return event | CACA_KEY_HOME; |
---|
| 384 | case KEY_END: return event | CACA_KEY_END; |
---|
| 385 | case KEY_PPAGE: return event | CACA_KEY_PAGEUP; |
---|
| 386 | case KEY_NPAGE: return event | CACA_KEY_PAGEDOWN; |
---|
| 387 | |
---|
| 388 | case KEY_F(1): return event | CACA_KEY_F1; |
---|
| 389 | case KEY_F(2): return event | CACA_KEY_F2; |
---|
| 390 | case KEY_F(3): return event | CACA_KEY_F3; |
---|
| 391 | case KEY_F(4): return event | CACA_KEY_F4; |
---|
| 392 | case KEY_F(5): return event | CACA_KEY_F5; |
---|
| 393 | case KEY_F(6): return event | CACA_KEY_F6; |
---|
| 394 | case KEY_F(7): return event | CACA_KEY_F7; |
---|
| 395 | case KEY_F(8): return event | CACA_KEY_F8; |
---|
| 396 | case KEY_F(9): return event | CACA_KEY_F9; |
---|
| 397 | case KEY_F(10): return event | CACA_KEY_F10; |
---|
| 398 | case KEY_F(11): return event | CACA_KEY_F11; |
---|
| 399 | case KEY_F(12): return event | CACA_KEY_F12; |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | return CACA_EVENT_NONE; |
---|
| 403 | } |
---|
| 404 | |
---|
[539] | 405 | /* |
---|
| 406 | * XXX: following functions are local |
---|
| 407 | */ |
---|
[281] | 408 | |
---|
[539] | 409 | #if defined(HAVE_SIGNAL) |
---|
[348] | 410 | static RETSIGTYPE sigwinch_handler(int sig) |
---|
| 411 | { |
---|
[553] | 412 | sigwinch_kk->resize.resized = 1; |
---|
[348] | 413 | |
---|
| 414 | signal(SIGWINCH, sigwinch_handler);; |
---|
| 415 | } |
---|
| 416 | #endif |
---|
| 417 | |
---|
[550] | 418 | #if defined(HAVE_GETENV) && defined(HAVE_PUTENV) |
---|
| 419 | static void ncurses_check_terminal(void) |
---|
| 420 | { |
---|
| 421 | char *term, *colorterm, *other; |
---|
| 422 | |
---|
| 423 | term = getenv("TERM"); |
---|
| 424 | colorterm = getenv("COLORTERM"); |
---|
| 425 | |
---|
| 426 | if(term && !strcmp(term, "xterm")) |
---|
| 427 | { |
---|
| 428 | /* If we are using gnome-terminal, it's really a 16 colour terminal */ |
---|
| 429 | if(colorterm && !strcmp(colorterm, "gnome-terminal")) |
---|
| 430 | { |
---|
| 431 | SCREEN *screen; |
---|
| 432 | screen = newterm("xterm-16color", stdout, stdin); |
---|
| 433 | if(screen == NULL) |
---|
| 434 | return; |
---|
| 435 | endwin(); |
---|
| 436 | (void)putenv("TERM=xterm-16color"); |
---|
| 437 | return; |
---|
| 438 | } |
---|
| 439 | |
---|
| 440 | /* Ditto if we are using Konsole */ |
---|
| 441 | other = getenv("KONSOLE_DCOP_SESSION"); |
---|
| 442 | if(other) |
---|
| 443 | { |
---|
| 444 | SCREEN *screen; |
---|
| 445 | screen = newterm("xterm-16color", stdout, stdin); |
---|
| 446 | if(screen == NULL) |
---|
| 447 | return; |
---|
| 448 | endwin(); |
---|
| 449 | (void)putenv("TERM=xterm-16color"); |
---|
| 450 | return; |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | } |
---|
| 454 | #endif |
---|
| 455 | |
---|
[539] | 456 | /* |
---|
| 457 | * Driver initialisation |
---|
| 458 | */ |
---|
[527] | 459 | |
---|
[539] | 460 | void ncurses_init_driver(caca_t *kk) |
---|
[511] | 461 | { |
---|
[550] | 462 | kk->drv.driver = CACA_DRIVER_NCURSES; |
---|
[527] | 463 | |
---|
[550] | 464 | kk->drv.init_graphics = ncurses_init_graphics; |
---|
| 465 | kk->drv.end_graphics = ncurses_end_graphics; |
---|
| 466 | kk->drv.set_window_title = ncurses_set_window_title; |
---|
| 467 | kk->drv.get_window_width = ncurses_get_window_width; |
---|
| 468 | kk->drv.get_window_height = ncurses_get_window_height; |
---|
| 469 | kk->drv.display = ncurses_display; |
---|
| 470 | kk->drv.handle_resize = ncurses_handle_resize; |
---|
| 471 | kk->drv.get_event = ncurses_get_event; |
---|
[511] | 472 | } |
---|
| 473 | |
---|
[539] | 474 | #endif /* USE_NCURSES */ |
---|
[527] | 475 | |
---|