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.
 
 
 
 
 
 

873 line
21 KiB

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