You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

849 lines
21 KiB

  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * 2007 Ben Wiley Sittler <bsittler@gmail.com>
  5. * All Rights Reserved
  6. *
  7. * $Id$
  8. *
  9. * This library is free software. It comes without any warranty, to
  10. * the extent permitted by applicable law. You can redistribute it
  11. * and/or modify it under the terms of the Do What The Fuck You Want
  12. * To Public License, Version 2, as published by Sam Hocevar. See
  13. * http://sam.zoy.org/wtfpl/COPYING for more details.
  14. */
  15. /*
  16. * This file contains the libcaca Ncurses input and output driver
  17. */
  18. #include "config.h"
  19. #if defined USE_NCURSES
  20. #if defined HAVE_NCURSESW_NCURSES_H
  21. # include <ncursesw/ncurses.h>
  22. #elif defined HAVE_NCURSES_NCURSES_H
  23. # include <ncurses/ncurses.h>
  24. #elif defined HAVE_NCURSES_H
  25. # include <ncurses.h>
  26. #else
  27. # include <curses.h>
  28. #endif
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #if defined HAVE_UNISTD_H
  32. # include <unistd.h>
  33. #endif
  34. #if defined HAVE_SIGNAL_H
  35. # include <signal.h>
  36. #endif
  37. #if defined HAVE_SYS_IOCTL_H
  38. # include <sys/ioctl.h>
  39. #endif
  40. #if defined HAVE_LOCALE_H
  41. # include <locale.h>
  42. #endif
  43. #if defined HAVE_TERMIOS_H
  44. # include <termios.h>
  45. #endif
  46. #include "caca.h"
  47. #include "caca_internals.h"
  48. /*
  49. * Emulation for missing ACS_* in older curses
  50. */
  51. #ifndef ACS_BLOCK
  52. #define ACS_BLOCK '#'
  53. #endif
  54. #ifndef ACS_BOARD
  55. #define ACS_BOARD '#'
  56. #endif
  57. #ifndef ACS_BTEE
  58. #define ACS_BTEE '+'
  59. #endif
  60. #ifndef ACS_BULLET
  61. #define ACS_BULLET '.'
  62. #endif
  63. #ifndef ACS_CKBOARD
  64. #define ACS_CKBOARD ':'
  65. #endif
  66. #ifndef ACS_DARROW
  67. #define ACS_DARROW 'v'
  68. #endif
  69. #ifndef ACS_DEGREE
  70. #define ACS_DEGREE '\''
  71. #endif
  72. #ifndef ACS_DIAMOND
  73. #define ACS_DIAMOND '+'
  74. #endif
  75. #ifndef ACS_GEQUAL
  76. #define ACS_GEQUAL '>'
  77. #endif
  78. #ifndef ACS_HLINE
  79. #define ACS_HLINE '-'
  80. #endif
  81. #ifndef ACS_LANTERN
  82. #define ACS_LANTERN '#'
  83. #endif
  84. #ifndef ACS_LARROW
  85. #define ACS_LARROW '<'
  86. #endif
  87. #ifndef ACS_LEQUAL
  88. #define ACS_LEQUAL '<'
  89. #endif
  90. #ifndef ACS_LLCORNER
  91. #define ACS_LLCORNER '+'
  92. #endif
  93. #ifndef ACS_LRCORNER
  94. #define ACS_LRCORNER '+'
  95. #endif
  96. #ifndef ACS_LTEE
  97. #define ACS_LTEE '+'
  98. #endif
  99. #ifndef ACS_NEQUAL
  100. #define ACS_NEQUAL '!'
  101. #endif
  102. #ifndef ACS_PI
  103. #define ACS_PI '*'
  104. #endif
  105. #ifndef ACS_STERLING
  106. #define ACS_STERLING 'f'
  107. #endif
  108. #ifndef ACS_PLMINUS
  109. #define ACS_PLMINUS '#'
  110. #endif
  111. #ifndef ACS_PLUS
  112. #define ACS_PLUS '+'
  113. #endif
  114. #ifndef ACS_RARROW
  115. #define ACS_RARROW '>'
  116. #endif
  117. #ifndef ACS_RTEE
  118. #define ACS_RTEE '+'
  119. #endif
  120. #ifndef ACS_S1
  121. #define ACS_S1 '-'
  122. #endif
  123. #ifndef ACS_S3
  124. #define ACS_S3 '-'
  125. #endif
  126. #ifndef ACS_S7
  127. #define ACS_S7 '-'
  128. #endif
  129. #ifndef ACS_S9
  130. #define ACS_S9 '-'
  131. #endif
  132. #ifndef ACS_TTEE
  133. #define ACS_TTEE '+'
  134. #endif
  135. #ifndef ACS_UARROW
  136. #define ACS_UARROW '^'
  137. #endif
  138. #ifndef ACS_ULCORNER
  139. #define ACS_ULCORNER '+'
  140. #endif
  141. #ifndef ACS_URCORNER
  142. #define ACS_URCORNER '+'
  143. #endif
  144. #ifndef ACS_VLINE
  145. #define ACS_VLINE '|'
  146. #endif
  147. /*
  148. * Local functions
  149. */
  150. #if defined HAVE_SIGNAL
  151. static RETSIGTYPE sigwinch_handler(int);
  152. static caca_display_t *sigwinch_d; /* FIXME: we ought to get rid of this */
  153. #endif
  154. #if defined HAVE_GETENV && defined HAVE_PUTENV
  155. static void ncurses_install_terminal(caca_display_t *);
  156. static void ncurses_uninstall_terminal(caca_display_t *);
  157. #endif
  158. static void ncurses_write_utf32(uint32_t);
  159. struct driver_private
  160. {
  161. int attr[16*16];
  162. mmask_t oldmask;
  163. char *term;
  164. };
  165. static int ncurses_init_graphics(caca_display_t *dp)
  166. {
  167. static int curses_colors[] =
  168. {
  169. /* Standard curses colours */
  170. COLOR_BLACK,
  171. COLOR_BLUE,
  172. COLOR_GREEN,
  173. COLOR_CYAN,
  174. COLOR_RED,
  175. COLOR_MAGENTA,
  176. COLOR_YELLOW,
  177. COLOR_WHITE,
  178. /* Extra values for xterm-16color */
  179. COLOR_BLACK + 8,
  180. COLOR_BLUE + 8,
  181. COLOR_GREEN + 8,
  182. COLOR_CYAN + 8,
  183. COLOR_RED + 8,
  184. COLOR_MAGENTA + 8,
  185. COLOR_YELLOW + 8,
  186. COLOR_WHITE + 8
  187. };
  188. mmask_t newmask;
  189. int fg, bg, max;
  190. dp->drv.p = malloc(sizeof(struct driver_private));
  191. #if defined HAVE_GETENV && defined HAVE_PUTENV
  192. ncurses_install_terminal(dp);
  193. #endif
  194. #if defined HAVE_SIGNAL
  195. sigwinch_d = dp;
  196. signal(SIGWINCH, sigwinch_handler);
  197. #endif
  198. #if defined HAVE_LOCALE_H
  199. setlocale(LC_ALL, "");
  200. #endif
  201. _caca_set_term_title("caca for ncurses");
  202. initscr();
  203. keypad(stdscr, TRUE);
  204. nonl();
  205. raw();
  206. noecho();
  207. nodelay(stdscr, TRUE);
  208. curs_set(0);
  209. /* Activate mouse */
  210. newmask = REPORT_MOUSE_POSITION | ALL_MOUSE_EVENTS;
  211. mousemask(newmask, &dp->drv.p->oldmask);
  212. mouseinterval(-1); /* No click emulation */
  213. /* Set the escape delay to a ridiculously low value */
  214. ESCDELAY = 10;
  215. /* Activate colour */
  216. start_color();
  217. /* If COLORS == 16, it means the terminal supports full bright colours
  218. * using setab and setaf (will use \e[90m \e[91m etc. for colours >= 8),
  219. * we can build 16*16 colour pairs.
  220. * If COLORS == 8, it means the terminal does not know about bright
  221. * colours and we need to get them through A_BOLD and A_BLINK (\e[1m
  222. * and \e[5m). We can only build 8*8 colour pairs. */
  223. max = COLORS >= 16 ? 16 : 8;
  224. for(bg = 0; bg < max; bg++)
  225. for(fg = 0; fg < max; fg++)
  226. {
  227. /* Use ((max + 7 - fg) % max) instead of fg so that colour 0
  228. * is light gray on black. Some terminals don't like this
  229. * colour pair to be redefined. */
  230. int col = ((max + 7 - fg) % max) + max * bg;
  231. init_pair(col, curses_colors[fg], curses_colors[bg]);
  232. dp->drv.p->attr[fg + 16 * bg] = COLOR_PAIR(col);
  233. if(max == 8)
  234. {
  235. /* Bright fg on simple bg */
  236. dp->drv.p->attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col);
  237. /* Simple fg on bright bg */
  238. dp->drv.p->attr[fg + 16 * (bg + 8)] = A_BLINK
  239. | COLOR_PAIR(col);
  240. /* Bright fg on bright bg */
  241. dp->drv.p->attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD
  242. | COLOR_PAIR(col);
  243. }
  244. }
  245. dp->resize.allow = 1;
  246. caca_set_canvas_size(dp->cv, COLS, LINES);
  247. dp->resize.allow = 0;
  248. return 0;
  249. }
  250. static int ncurses_end_graphics(caca_display_t *dp)
  251. {
  252. _caca_set_term_title("");
  253. mousemask(dp->drv.p->oldmask, NULL);
  254. curs_set(1);
  255. noraw();
  256. endwin();
  257. #if defined HAVE_GETENV && defined HAVE_PUTENV
  258. ncurses_uninstall_terminal(dp);
  259. #endif
  260. free(dp->drv.p);
  261. return 0;
  262. }
  263. static int ncurses_set_display_title(caca_display_t *dp, char const *title)
  264. {
  265. _caca_set_term_title(title);
  266. return 0;
  267. }
  268. static int ncurses_get_display_width(caca_display_t const *dp)
  269. {
  270. /* Fallback to a 6x10 font */
  271. return caca_get_canvas_width(dp->cv) * 6;
  272. }
  273. static int ncurses_get_display_height(caca_display_t const *dp)
  274. {
  275. /* Fallback to a 6x10 font */
  276. return caca_get_canvas_height(dp->cv) * 10;
  277. }
  278. static void ncurses_display(caca_display_t *dp)
  279. {
  280. uint32_t const *cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv);
  281. uint32_t const *cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv);
  282. int width = caca_get_canvas_width(dp->cv);
  283. int height = caca_get_canvas_height(dp->cv);
  284. int x, y;
  285. for(y = 0; y < (int)height; y++)
  286. {
  287. move(y, 0);
  288. for(x = width; x--; )
  289. {
  290. attrset(dp->drv.p->attr[caca_attr_to_ansi(*cvattrs++)]);
  291. ncurses_write_utf32(*cvchars++);
  292. }
  293. }
  294. x = caca_get_cursor_x(dp->cv);
  295. y = caca_get_cursor_y(dp->cv);
  296. move(y, x);
  297. refresh();
  298. }
  299. static void ncurses_handle_resize(caca_display_t *dp)
  300. {
  301. struct winsize size;
  302. #if defined HAVE_SYS_IOCTL_H
  303. if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0)
  304. {
  305. dp->resize.w = size.ws_col;
  306. dp->resize.h = size.ws_row;
  307. #if defined HAVE_RESIZE_TERM
  308. resize_term(dp->resize.h, dp->resize.w);
  309. #else
  310. resizeterm(dp->resize.h, dp->resize.w);
  311. #endif
  312. wrefresh(curscr);
  313. return;
  314. }
  315. #endif
  316. /* Fallback */
  317. dp->resize.w = caca_get_canvas_width(dp->cv);
  318. dp->resize.h = caca_get_canvas_height(dp->cv);
  319. }
  320. static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev)
  321. {
  322. int intkey;
  323. intkey = getch();
  324. if(intkey == ERR)
  325. {
  326. ev->type = CACA_EVENT_NONE;
  327. return 0;
  328. }
  329. if(intkey < 0x7f)
  330. {
  331. ev->type = CACA_EVENT_KEY_PRESS;
  332. ev->data.key.ch = intkey;
  333. ev->data.key.utf32 = intkey;
  334. ev->data.key.utf8[0] = intkey;
  335. ev->data.key.utf8[1] = '\0';
  336. return 1;
  337. }
  338. /* If the key was UTF-8, parse the whole sequence */
  339. if(intkey >= 0x80 && intkey < 0x100)
  340. {
  341. int keys[7]; /* Necessary for ungetch(); */
  342. char utf8[7];
  343. uint32_t utf32;
  344. size_t i, bytes = 0;
  345. keys[0] = intkey;
  346. utf8[0] = intkey;
  347. for(i = 1; i < 6; i++)
  348. {
  349. keys[i] = getch();
  350. utf8[i] = (unsigned char)keys[i];
  351. }
  352. utf8[i] = '\0';
  353. utf32 = caca_utf8_to_utf32(utf8, &bytes);
  354. while(i > bytes)
  355. ungetch(keys[--i]);
  356. if(bytes)
  357. {
  358. ev->type = CACA_EVENT_KEY_PRESS;
  359. ev->data.key.ch = 0;
  360. ev->data.key.utf32 = utf32;
  361. strcpy(ev->data.key.utf8, utf8);
  362. return 1;
  363. }
  364. }
  365. if(intkey == KEY_MOUSE)
  366. {
  367. MEVENT mevent;
  368. getmouse(&mevent);
  369. switch(mevent.bstate)
  370. {
  371. #define PRESS(x) ev->data.mouse.button = x; \
  372. ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev)
  373. #define RELEASE(x) ev->data.mouse.button = x; \
  374. ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev)
  375. #define CLICK(x) PRESS(x); RELEASE(x)
  376. case BUTTON1_PRESSED: PRESS(1); break;
  377. case BUTTON1_RELEASED: RELEASE(1); break;
  378. case BUTTON1_CLICKED: CLICK(1); break;
  379. case BUTTON1_DOUBLE_CLICKED: CLICK(1); CLICK(1); break;
  380. case BUTTON1_TRIPLE_CLICKED: CLICK(1); CLICK(1); CLICK(1); break;
  381. case BUTTON1_RESERVED_EVENT: break;
  382. case BUTTON2_PRESSED: PRESS(2); break;
  383. case BUTTON2_RELEASED: RELEASE(2); break;
  384. case BUTTON2_CLICKED: CLICK(2); break;
  385. case BUTTON2_DOUBLE_CLICKED: CLICK(2); CLICK(2); break;
  386. case BUTTON2_TRIPLE_CLICKED: CLICK(2); CLICK(2); CLICK(2); break;
  387. case BUTTON2_RESERVED_EVENT: break;
  388. case BUTTON3_PRESSED: PRESS(3); break;
  389. case BUTTON3_RELEASED: RELEASE(3); break;
  390. case BUTTON3_CLICKED: CLICK(3); break;
  391. case BUTTON3_DOUBLE_CLICKED: CLICK(3); CLICK(3); break;
  392. case BUTTON3_TRIPLE_CLICKED: CLICK(3); CLICK(3); CLICK(3); break;
  393. case BUTTON3_RESERVED_EVENT: break;
  394. case BUTTON4_PRESSED: PRESS(4); break;
  395. case BUTTON4_RELEASED: RELEASE(4); break;
  396. case BUTTON4_CLICKED: CLICK(4); break;
  397. case BUTTON4_DOUBLE_CLICKED: CLICK(4); CLICK(4); break;
  398. case BUTTON4_TRIPLE_CLICKED: CLICK(4); CLICK(4); CLICK(4); break;
  399. case BUTTON4_RESERVED_EVENT: break;
  400. default:
  401. break;
  402. #undef PRESS
  403. #undef RELEASE
  404. #undef CLICK
  405. }
  406. if(dp->mouse.x == mevent.x && dp->mouse.y == mevent.y)
  407. return _pop_event(dp, ev);
  408. dp->mouse.x = mevent.x;
  409. dp->mouse.y = mevent.y;
  410. ev->type = CACA_EVENT_MOUSE_MOTION;
  411. ev->data.mouse.x = dp->mouse.x;
  412. ev->data.mouse.y = dp->mouse.y;
  413. return 1;
  414. }
  415. switch(intkey)
  416. {
  417. case KEY_UP: ev->data.key.ch = CACA_KEY_UP; break;
  418. case KEY_DOWN: ev->data.key.ch = CACA_KEY_DOWN; break;
  419. case KEY_LEFT: ev->data.key.ch = CACA_KEY_LEFT; break;
  420. case KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break;
  421. case KEY_IC: ev->data.key.ch = CACA_KEY_INSERT; break;
  422. case KEY_DC: ev->data.key.ch = CACA_KEY_DELETE; break;
  423. case 0x7f:
  424. case KEY_BACKSPACE: ev->data.key.ch = CACA_KEY_BACKSPACE; break;
  425. case KEY_HOME: ev->data.key.ch = CACA_KEY_HOME; break;
  426. case KEY_END: ev->data.key.ch = CACA_KEY_END; break;
  427. case KEY_PPAGE: ev->data.key.ch = CACA_KEY_PAGEUP; break;
  428. case KEY_NPAGE: ev->data.key.ch = CACA_KEY_PAGEDOWN; break;
  429. case KEY_F(1): ev->data.key.ch = CACA_KEY_F1; break;
  430. case KEY_F(2): ev->data.key.ch = CACA_KEY_F2; break;
  431. case KEY_F(3): ev->data.key.ch = CACA_KEY_F3; break;
  432. case KEY_F(4): ev->data.key.ch = CACA_KEY_F4; break;
  433. case KEY_F(5): ev->data.key.ch = CACA_KEY_F5; break;
  434. case KEY_F(6): ev->data.key.ch = CACA_KEY_F6; break;
  435. case KEY_F(7): ev->data.key.ch = CACA_KEY_F7; break;
  436. case KEY_F(8): ev->data.key.ch = CACA_KEY_F8; break;
  437. case KEY_F(9): ev->data.key.ch = CACA_KEY_F9; break;
  438. case KEY_F(10): ev->data.key.ch = CACA_KEY_F10; break;
  439. case KEY_F(11): ev->data.key.ch = CACA_KEY_F11; break;
  440. case KEY_F(12): ev->data.key.ch = CACA_KEY_F12; break;
  441. default:
  442. /* Unknown key */
  443. ev->type = CACA_EVENT_NONE; return 0;
  444. }
  445. ev->type = CACA_EVENT_KEY_PRESS;
  446. ev->data.key.utf32 = 0;
  447. ev->data.key.utf8[0] = '\0';
  448. return 1;
  449. }
  450. static void ncurses_set_cursor(caca_display_t *dp, int flags)
  451. {
  452. curs_set(flags ? 2 : 0);
  453. }
  454. /*
  455. * XXX: following functions are local
  456. */
  457. #if defined HAVE_SIGNAL
  458. static RETSIGTYPE sigwinch_handler(int sig)
  459. {
  460. sigwinch_d->resize.resized = 1;
  461. signal(SIGWINCH, sigwinch_handler);
  462. }
  463. #endif
  464. #if defined HAVE_GETENV && defined HAVE_PUTENV
  465. static void ncurses_install_terminal(caca_display_t *dp)
  466. {
  467. char *term, *colorterm;
  468. dp->drv.p->term = NULL;
  469. term = getenv("TERM");
  470. colorterm = getenv("COLORTERM");
  471. if(!term || strcmp(term, "xterm"))
  472. return;
  473. /* If we are using gnome-terminal, it's really a 16 colour terminal.
  474. * Ditto if we are using xfce4-terminal, or Konsole. */
  475. if((colorterm && (!strcmp(colorterm, "gnome-terminal")
  476. || !strcmp(colorterm, "Terminal")))
  477. || getenv("KONSOLE_DCOP_SESSION"))
  478. {
  479. SCREEN *screen;
  480. screen = newterm("xterm-16color", stdout, stdin);
  481. if(screen == NULL)
  482. return;
  483. endwin();
  484. (void)putenv("TERM=xterm-16color");
  485. dp->drv.p->term = strdup(term);
  486. return;
  487. }
  488. }
  489. static void ncurses_uninstall_terminal(caca_display_t *dp)
  490. {
  491. /* Needs to be persistent because we use putenv() */
  492. static char termenv[1024];
  493. if(!dp->drv.p->term)
  494. return;
  495. snprintf(termenv, 1023, "TERM=%s", dp->drv.p->term);
  496. free(dp->drv.p->term);
  497. (void)putenv(termenv);
  498. }
  499. #endif
  500. static void ncurses_write_utf32(uint32_t ch)
  501. {
  502. #if defined HAVE_NCURSESW_NCURSES_H
  503. char buf[10];
  504. int bytes;
  505. #endif
  506. if(ch == CACA_MAGIC_FULLWIDTH)
  507. return;
  508. #if defined HAVE_NCURSESW_NCURSES_H
  509. bytes = caca_utf32_to_utf8(buf, ch);
  510. buf[bytes] = '\0';
  511. addstr(buf);
  512. #else
  513. if(ch < 0x80)
  514. {
  515. addch(ch);
  516. }
  517. else
  518. {
  519. chtype cch;
  520. chtype cch2;
  521. cch = '?';
  522. cch2 = ' ';
  523. if ((ch > 0x0000ff00) && (ch < 0x0000ff5f))
  524. {
  525. cch = ch - 0x0000ff00 + ' ';
  526. }
  527. switch (ch)
  528. {
  529. case 0x000000a0: /* <nbsp> */
  530. case 0x00003000: /*   */
  531. cch = ' ';
  532. break;
  533. case 0x000000a3: /* £ */
  534. cch = ACS_STERLING;
  535. break;
  536. case 0x000000b0: /* ° */
  537. cch = ACS_DEGREE;
  538. break;
  539. case 0x000000b1: /* ± */
  540. cch = ACS_PLMINUS;
  541. break;
  542. case 0x000000b7: /* · */
  543. case 0x00002219: /* ∙ */
  544. case 0x000030fb: /* ・ */
  545. cch = ACS_BULLET;
  546. break;
  547. case 0x000003c0: /* π */
  548. cch = ACS_PI;
  549. break;
  550. case 0x00002018: /* ‘ */
  551. case 0x00002019: /* ’ */
  552. cch = '\'';
  553. break;
  554. case 0x0000201c: /* “ */
  555. case 0x0000201d: /* ” */
  556. cch = '"';
  557. break;
  558. case 0x00002190: /* ← */
  559. cch = ACS_LARROW;
  560. break;
  561. case 0x00002191: /* ↑ */
  562. cch = ACS_UARROW;
  563. break;
  564. case 0x00002192: /* → */
  565. cch = ACS_RARROW;
  566. break;
  567. case 0x00002193: /* ↓ */
  568. cch = ACS_DARROW;
  569. break;
  570. case 0x00002260: /* ≠ */
  571. cch = ACS_NEQUAL;
  572. break;
  573. case 0x00002261: /* ≡ */
  574. cch = '=';
  575. break;
  576. case 0x00002264: /* ≤ */
  577. cch = ACS_LEQUAL;
  578. break;
  579. case 0x00002265: /* ≥ */
  580. cch = ACS_GEQUAL;
  581. break;
  582. case 0x000023ba: /* ⎺ */
  583. cch = ACS_S1;
  584. cch2 = cch;
  585. break;
  586. case 0x000023bb: /* ⎻ */
  587. cch = ACS_S3;
  588. cch2 = cch;
  589. break;
  590. case 0x000023bc: /* ⎼ */
  591. cch = ACS_S7;
  592. cch2 = cch;
  593. break;
  594. case 0x000023bd: /* ⎽ */
  595. cch = ACS_S9;
  596. cch2 = cch;
  597. break;
  598. case 0x00002500: /* ─ */
  599. case 0x00002550: /* ═ */
  600. cch = ACS_HLINE;
  601. cch2 = cch;
  602. break;
  603. case 0x00002502: /* │ */
  604. case 0x00002551: /* ║ */
  605. cch = ACS_VLINE;
  606. break;
  607. case 0x0000250c: /* ┌ */
  608. case 0x00002552: /* ╒ */
  609. case 0x00002553: /* ╓ */
  610. case 0x00002554: /* ╔ */
  611. cch = ACS_ULCORNER;
  612. cch2 = ACS_HLINE;
  613. break;
  614. case 0x00002510: /* ┐ */
  615. case 0x00002555: /* ╕ */
  616. case 0x00002556: /* ╖ */
  617. case 0x00002557: /* ╗ */
  618. cch = ACS_URCORNER;
  619. break;
  620. case 0x00002514: /* └ */
  621. case 0x00002558: /* ╘ */
  622. case 0x00002559: /* ╙ */
  623. case 0x0000255a: /* ╚ */
  624. cch = ACS_LLCORNER;
  625. cch2 = ACS_HLINE;
  626. break;
  627. case 0x00002518: /* ┘ */
  628. case 0x0000255b: /* ╛ */
  629. case 0x0000255c: /* ╜ */
  630. case 0x0000255d: /* ╝ */
  631. cch = ACS_LRCORNER;
  632. break;
  633. case 0x0000251c: /* ├ */
  634. case 0x0000255e: /* ╞ */
  635. case 0x0000255f: /* ╟ */
  636. case 0x00002560: /* ╠ */
  637. cch = ACS_LTEE;
  638. cch2 = ACS_HLINE;
  639. break;
  640. case 0x00002524: /* ┤ */
  641. case 0x00002561: /* ╡ */
  642. case 0x00002562: /* ╢ */
  643. case 0x00002563: /* ╣ */
  644. cch = ACS_RTEE;
  645. break;
  646. case 0x0000252c: /* ┬ */
  647. case 0x00002564: /* ╤ */
  648. case 0x00002565: /* ╥ */
  649. case 0x00002566: /* ╦ */
  650. cch = ACS_TTEE;
  651. cch2 = ACS_HLINE;
  652. break;
  653. case 0x00002534: /* ┴ */
  654. case 0x00002567: /* ╧ */
  655. case 0x00002568: /* ╨ */
  656. case 0x00002569: /* ╩ */
  657. cch = ACS_BTEE;
  658. cch2 = ACS_HLINE;
  659. break;
  660. case 0x0000253c: /* ┼ */
  661. case 0x0000256a: /* ╪ */
  662. case 0x0000256b: /* ╫ */
  663. case 0x0000256c: /* ╬ */
  664. cch = ACS_PLUS;
  665. cch2 = ACS_HLINE;
  666. break;
  667. case 0x00002591: /* ░ */
  668. cch = ACS_BOARD;
  669. cch2 = cch;
  670. break;
  671. case 0x00002592: /* ▒ */
  672. case 0x00002593: /* ▓ */
  673. cch = ACS_CKBOARD;
  674. cch2 = cch;
  675. break;
  676. case 0x00002580: /* ▀ */
  677. case 0x00002584: /* ▄ */
  678. case 0x00002588: /* █ */
  679. case 0x0000258c: /* ▌ */
  680. case 0x00002590: /* ▐ */
  681. case 0x000025a0: /* ■ */
  682. case 0x000025ac: /* ▬ */
  683. case 0x000025ae: /* ▮ */
  684. cch = ACS_BLOCK;
  685. cch2 = cch;
  686. break;
  687. case 0x000025c6: /* ◆ */
  688. case 0x00002666: /* ♦ */
  689. cch = ACS_DIAMOND;
  690. break;
  691. case 0x00002022: /* • */
  692. case 0x000025cb: /* ○ */
  693. case 0x000025cf: /* ● */
  694. case 0x00002603: /* ☃ */
  695. case 0x0000263c: /* ☼ */
  696. cch = ACS_LANTERN;
  697. break;
  698. case 0x0000301c: /* 〜 */
  699. cch = '~';
  700. break;
  701. }
  702. addch(cch);
  703. if(caca_utf32_is_fullwidth(ch))
  704. {
  705. addch(cch2);
  706. }
  707. }
  708. #endif
  709. }
  710. /*
  711. * Driver initialisation
  712. */
  713. int ncurses_install(caca_display_t *dp)
  714. {
  715. dp->drv.id = CACA_DRIVER_NCURSES;
  716. dp->drv.driver = "ncurses";
  717. dp->drv.init_graphics = ncurses_init_graphics;
  718. dp->drv.end_graphics = ncurses_end_graphics;
  719. dp->drv.set_display_title = ncurses_set_display_title;
  720. dp->drv.get_display_width = ncurses_get_display_width;
  721. dp->drv.get_display_height = ncurses_get_display_height;
  722. dp->drv.display = ncurses_display;
  723. dp->drv.handle_resize = ncurses_handle_resize;
  724. dp->drv.get_event = ncurses_get_event;
  725. dp->drv.set_mouse = NULL;
  726. dp->drv.set_cursor = ncurses_set_cursor;
  727. return 0;
  728. }
  729. #endif /* USE_NCURSES */