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.
 
 
 
 
 
 

888 lines
22 KiB

  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright © 2002—2021 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://www.wtfpl.net/ 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 void 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. #if defined HAVE_LOCALE_H
  187. char const *old_locale;
  188. #endif
  189. mmask_t newmask;
  190. int fg, bg, max;
  191. dp->drv.p = malloc(sizeof(struct driver_private));
  192. #if defined HAVE_GETENV && defined HAVE_PUTENV
  193. ncurses_install_terminal(dp);
  194. #endif
  195. #if defined HAVE_SIGNAL
  196. sigwinch_d = dp;
  197. signal(SIGWINCH, sigwinch_handler);
  198. #endif
  199. _caca_set_term_title("caca for ncurses");
  200. #if defined HAVE_LOCALE_H
  201. old_locale = setlocale(LC_CTYPE, "");
  202. #endif
  203. initscr();
  204. #if defined HAVE_LOCALE_H
  205. setlocale(LC_CTYPE, old_locale);
  206. #endif
  207. keypad(stdscr, TRUE);
  208. nonl();
  209. raw();
  210. noecho();
  211. nodelay(stdscr, TRUE);
  212. curs_set(0);
  213. /* Activate mouse */
  214. newmask = REPORT_MOUSE_POSITION | ALL_MOUSE_EVENTS;
  215. mousemask(newmask, &dp->drv.p->oldmask);
  216. mouseinterval(-1); /* No click emulation */
  217. /* Set the escape delay to a ridiculously low value */
  218. #if defined set_escdelay
  219. set_escdelay(10);
  220. #else
  221. ESCDELAY = 10;
  222. #endif
  223. /* Activate colour */
  224. start_color();
  225. /* If COLORS == 16, it means the terminal supports full bright colours
  226. * using setab and setaf (will use \e[90m \e[91m etc. for colours >= 8),
  227. * we can build 16*16 colour pairs.
  228. * If COLORS == 8, it means the terminal does not know about bright
  229. * colours and we need to get them through A_BOLD and A_BLINK (\e[1m
  230. * and \e[5m). We can only build 8*8 colour pairs. */
  231. max = COLORS >= 16 ? 16 : 8;
  232. for(bg = 0; bg < max; bg++)
  233. for(fg = 0; fg < max; fg++)
  234. {
  235. /* Use ((max + 7 - fg) % max) instead of fg so that colour 0
  236. * is light gray on black. Some terminals don't like this
  237. * colour pair to be redefined. */
  238. int col = ((max + 7 - fg) % max) + max * bg;
  239. init_pair(col, curses_colors[fg], curses_colors[bg]);
  240. dp->drv.p->attr[fg + 16 * bg] = COLOR_PAIR(col);
  241. if(max == 8)
  242. {
  243. /* Bright fg on simple bg */
  244. dp->drv.p->attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col);
  245. /* Simple fg on bright bg */
  246. dp->drv.p->attr[fg + 16 * (bg + 8)] = A_BLINK
  247. | COLOR_PAIR(col);
  248. /* Bright fg on bright bg */
  249. dp->drv.p->attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD
  250. | COLOR_PAIR(col);
  251. }
  252. }
  253. caca_add_dirty_rect(dp->cv, 0, 0, dp->cv->width, dp->cv->height);
  254. dp->resize.allow = 1;
  255. caca_set_canvas_size(dp->cv, COLS, LINES);
  256. dp->resize.allow = 0;
  257. return 0;
  258. }
  259. static int ncurses_end_graphics(caca_display_t *dp)
  260. {
  261. _caca_set_term_title("");
  262. mousemask(dp->drv.p->oldmask, NULL);
  263. curs_set(1);
  264. noraw();
  265. endwin();
  266. #if defined HAVE_GETENV && defined HAVE_PUTENV
  267. ncurses_uninstall_terminal(dp);
  268. #endif
  269. free(dp->drv.p);
  270. return 0;
  271. }
  272. static int ncurses_set_display_title(caca_display_t *dp, char const *title)
  273. {
  274. _caca_set_term_title(title);
  275. return 0;
  276. }
  277. static int ncurses_get_display_width(caca_display_t const *dp)
  278. {
  279. /* Fallback to a 6x10 font */
  280. return caca_get_canvas_width(dp->cv) * 6;
  281. }
  282. static int ncurses_get_display_height(caca_display_t const *dp)
  283. {
  284. /* Fallback to a 6x10 font */
  285. return caca_get_canvas_height(dp->cv) * 10;
  286. }
  287. static void ncurses_display(caca_display_t *dp)
  288. {
  289. int x, y, i;
  290. for(i = 0; i < caca_get_dirty_rect_count(dp->cv); i++)
  291. {
  292. uint32_t const *cvchars, *cvattrs;
  293. int dx, dy, dw, dh;
  294. caca_get_dirty_rect(dp->cv, i, &dx, &dy, &dw, &dh);
  295. cvchars = caca_get_canvas_chars(dp->cv) + dx + dy * dp->cv->width;
  296. cvattrs = caca_get_canvas_attrs(dp->cv) + dx + dy * dp->cv->width;
  297. for(y = dy; y < dy + dh; y++)
  298. {
  299. move(y, dx);
  300. for(x = dx; x < dx + dw; x++)
  301. {
  302. uint32_t attr = *cvattrs++;
  303. (void)attrset(dp->drv.p->attr[caca_attr_to_ansi(attr)]);
  304. if(attr & CACA_BOLD)
  305. attron(A_BOLD);
  306. if(attr & CACA_BLINK)
  307. attron(A_BLINK);
  308. if(attr & CACA_UNDERLINE)
  309. attron(A_UNDERLINE);
  310. ncurses_write_utf32(*cvchars++);
  311. }
  312. cvchars += dp->cv->width - dw;
  313. cvattrs += dp->cv->width - dw;
  314. }
  315. }
  316. x = caca_wherex(dp->cv);
  317. y = caca_wherey(dp->cv);
  318. move(y, x);
  319. refresh();
  320. }
  321. static void ncurses_handle_resize(caca_display_t *dp)
  322. {
  323. struct winsize size;
  324. #if defined HAVE_SYS_IOCTL_H
  325. if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0)
  326. {
  327. dp->resize.w = size.ws_col;
  328. dp->resize.h = size.ws_row;
  329. #if defined HAVE_RESIZE_TERM
  330. resize_term(dp->resize.h, dp->resize.w);
  331. #else
  332. resizeterm(dp->resize.h, dp->resize.w);
  333. #endif
  334. wrefresh(curscr);
  335. return;
  336. }
  337. #endif
  338. /* Fallback */
  339. dp->resize.w = caca_get_canvas_width(dp->cv);
  340. dp->resize.h = caca_get_canvas_height(dp->cv);
  341. }
  342. static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev)
  343. {
  344. int intkey;
  345. intkey = getch();
  346. if(intkey == ERR)
  347. {
  348. ev->type = CACA_EVENT_NONE;
  349. return 0;
  350. }
  351. if(intkey < 0x7f)
  352. {
  353. ev->type = CACA_EVENT_KEY_PRESS;
  354. ev->data.key.ch = intkey;
  355. ev->data.key.utf32 = intkey;
  356. ev->data.key.utf8[0] = intkey;
  357. ev->data.key.utf8[1] = '\0';
  358. return 1;
  359. }
  360. /* If the key was UTF-8, parse the whole sequence */
  361. if(intkey >= 0x80 && intkey < 0x100)
  362. {
  363. int keys[7]; /* Necessary for ungetch(); */
  364. char utf8[7];
  365. uint32_t utf32;
  366. size_t i, bytes = 0;
  367. keys[0] = intkey;
  368. utf8[0] = intkey;
  369. for(i = 1; i < 6; i++)
  370. {
  371. keys[i] = getch();
  372. utf8[i] = (unsigned char)keys[i];
  373. }
  374. utf8[i] = '\0';
  375. utf32 = caca_utf8_to_utf32(utf8, &bytes);
  376. while(i > bytes)
  377. ungetch(keys[--i]);
  378. if(bytes)
  379. {
  380. ev->type = CACA_EVENT_KEY_PRESS;
  381. ev->data.key.ch = 0;
  382. ev->data.key.utf32 = utf32;
  383. strcpy(ev->data.key.utf8, utf8);
  384. return 1;
  385. }
  386. }
  387. if(intkey == KEY_MOUSE)
  388. {
  389. MEVENT mevent;
  390. getmouse(&mevent);
  391. switch(mevent.bstate)
  392. {
  393. #define PRESS(x) ev->data.mouse.button = x; \
  394. ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev)
  395. #define RELEASE(x) ev->data.mouse.button = x; \
  396. ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev)
  397. #define CLICK(x) PRESS(x); RELEASE(x)
  398. case BUTTON1_PRESSED: PRESS(1); break;
  399. case BUTTON1_RELEASED: RELEASE(1); break;
  400. case BUTTON1_CLICKED: CLICK(1); break;
  401. case BUTTON1_DOUBLE_CLICKED: CLICK(1); CLICK(1); break;
  402. case BUTTON1_TRIPLE_CLICKED: CLICK(1); CLICK(1); CLICK(1); break;
  403. #if defined BUTTON1_RESERVED_EVENT
  404. case BUTTON1_RESERVED_EVENT: break;
  405. #endif
  406. case BUTTON2_PRESSED: PRESS(2); break;
  407. case BUTTON2_RELEASED: RELEASE(2); break;
  408. case BUTTON2_CLICKED: CLICK(2); break;
  409. case BUTTON2_DOUBLE_CLICKED: CLICK(2); CLICK(2); break;
  410. case BUTTON2_TRIPLE_CLICKED: CLICK(2); CLICK(2); CLICK(2); break;
  411. #if defined BUTTON2_RESERVED_EVENT
  412. case BUTTON2_RESERVED_EVENT: break;
  413. #endif
  414. case BUTTON3_PRESSED: PRESS(3); break;
  415. case BUTTON3_RELEASED: RELEASE(3); break;
  416. case BUTTON3_CLICKED: CLICK(3); break;
  417. case BUTTON3_DOUBLE_CLICKED: CLICK(3); CLICK(3); break;
  418. case BUTTON3_TRIPLE_CLICKED: CLICK(3); CLICK(3); CLICK(3); break;
  419. #if defined BUTTON3_RESERVED_EVENT
  420. case BUTTON3_RESERVED_EVENT: break;
  421. #endif
  422. case BUTTON4_PRESSED: PRESS(4); break;
  423. case BUTTON4_RELEASED: RELEASE(4); break;
  424. case BUTTON4_CLICKED: CLICK(4); break;
  425. case BUTTON4_DOUBLE_CLICKED: CLICK(4); CLICK(4); break;
  426. case BUTTON4_TRIPLE_CLICKED: CLICK(4); CLICK(4); CLICK(4); break;
  427. #if defined BUTTON4_RESERVED_EVENT
  428. case BUTTON4_RESERVED_EVENT: break;
  429. #endif
  430. default:
  431. break;
  432. #undef PRESS
  433. #undef RELEASE
  434. #undef CLICK
  435. }
  436. if(dp->mouse.x == mevent.x && dp->mouse.y == mevent.y)
  437. return _pop_event(dp, ev);
  438. dp->mouse.x = mevent.x;
  439. dp->mouse.y = mevent.y;
  440. ev->type = CACA_EVENT_MOUSE_MOTION;
  441. ev->data.mouse.x = dp->mouse.x;
  442. ev->data.mouse.y = dp->mouse.y;
  443. return 1;
  444. }
  445. switch(intkey)
  446. {
  447. case KEY_UP: ev->data.key.ch = CACA_KEY_UP; break;
  448. case KEY_DOWN: ev->data.key.ch = CACA_KEY_DOWN; break;
  449. case KEY_LEFT: ev->data.key.ch = CACA_KEY_LEFT; break;
  450. case KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break;
  451. case KEY_IC: ev->data.key.ch = CACA_KEY_INSERT; break;
  452. case KEY_DC: ev->data.key.ch = CACA_KEY_DELETE; break;
  453. case 0x7f:
  454. case KEY_BACKSPACE: ev->data.key.ch = CACA_KEY_BACKSPACE; break;
  455. case KEY_HOME: ev->data.key.ch = CACA_KEY_HOME; break;
  456. case KEY_END: ev->data.key.ch = CACA_KEY_END; break;
  457. case KEY_PPAGE: ev->data.key.ch = CACA_KEY_PAGEUP; break;
  458. case KEY_NPAGE: ev->data.key.ch = CACA_KEY_PAGEDOWN; break;
  459. case KEY_F(1): ev->data.key.ch = CACA_KEY_F1; break;
  460. case KEY_F(2): ev->data.key.ch = CACA_KEY_F2; break;
  461. case KEY_F(3): ev->data.key.ch = CACA_KEY_F3; break;
  462. case KEY_F(4): ev->data.key.ch = CACA_KEY_F4; break;
  463. case KEY_F(5): ev->data.key.ch = CACA_KEY_F5; break;
  464. case KEY_F(6): ev->data.key.ch = CACA_KEY_F6; break;
  465. case KEY_F(7): ev->data.key.ch = CACA_KEY_F7; break;
  466. case KEY_F(8): ev->data.key.ch = CACA_KEY_F8; break;
  467. case KEY_F(9): ev->data.key.ch = CACA_KEY_F9; break;
  468. case KEY_F(10): ev->data.key.ch = CACA_KEY_F10; break;
  469. case KEY_F(11): ev->data.key.ch = CACA_KEY_F11; break;
  470. case KEY_F(12): ev->data.key.ch = CACA_KEY_F12; break;
  471. default:
  472. /* Unknown key */
  473. ev->type = CACA_EVENT_NONE; return 0;
  474. }
  475. ev->type = CACA_EVENT_KEY_PRESS;
  476. ev->data.key.utf32 = 0;
  477. ev->data.key.utf8[0] = '\0';
  478. return 1;
  479. }
  480. static void ncurses_set_cursor(caca_display_t *dp, int flags)
  481. {
  482. if (!flags)
  483. curs_set(0);
  484. else if (curs_set(2) == ERR)
  485. curs_set(1);
  486. }
  487. /*
  488. * XXX: following functions are local
  489. */
  490. #if defined HAVE_SIGNAL
  491. static void sigwinch_handler(int sig)
  492. {
  493. sigwinch_d->resize.resized = 1;
  494. signal(SIGWINCH, sigwinch_handler);
  495. }
  496. #endif
  497. #if defined HAVE_GETENV && defined HAVE_PUTENV
  498. static void ncurses_install_terminal(caca_display_t *dp)
  499. {
  500. char *term, *colorterm;
  501. dp->drv.p->term = NULL;
  502. term = getenv("TERM");
  503. colorterm = getenv("COLORTERM");
  504. if(!term || strcmp(term, "xterm"))
  505. return;
  506. /* If we are using gnome-terminal, it's really a 16 colour terminal.
  507. * Ditto if we are using xfce4-terminal, or Konsole. */
  508. if((colorterm && (!strcmp(colorterm, "gnome-terminal")
  509. || !strcmp(colorterm, "Terminal")))
  510. || getenv("KONSOLE_DCOP_SESSION"))
  511. {
  512. SCREEN *screen;
  513. screen = newterm("xterm-16color", stdout, stdin);
  514. if(screen == NULL)
  515. return;
  516. endwin();
  517. (void)putenv("TERM=xterm-16color");
  518. dp->drv.p->term = strdup(term);
  519. return;
  520. }
  521. }
  522. static void ncurses_uninstall_terminal(caca_display_t *dp)
  523. {
  524. /* Needs to be persistent because we use putenv() */
  525. static char termenv[1024];
  526. if(!dp->drv.p->term)
  527. return;
  528. snprintf(termenv, 1023, "TERM=%s", dp->drv.p->term);
  529. free(dp->drv.p->term);
  530. (void)putenv(termenv);
  531. }
  532. #endif
  533. static void ncurses_write_utf32(uint32_t ch)
  534. {
  535. #if defined HAVE_NCURSESW_NCURSES_H
  536. char buf[10];
  537. int bytes;
  538. #endif
  539. if(ch == CACA_MAGIC_FULLWIDTH)
  540. return;
  541. #if defined HAVE_NCURSESW_NCURSES_H
  542. bytes = caca_utf32_to_utf8(buf, ch);
  543. buf[bytes] = '\0';
  544. addstr(buf);
  545. #else
  546. if(ch < 0x80)
  547. {
  548. addch(ch);
  549. }
  550. else
  551. {
  552. chtype cch;
  553. chtype cch2;
  554. cch = '?';
  555. cch2 = ' ';
  556. if ((ch > 0x0000ff00) && (ch < 0x0000ff5f))
  557. {
  558. cch = ch - 0x0000ff00 + ' ';
  559. }
  560. switch (ch)
  561. {
  562. case 0x000000a0: /* <nbsp> */
  563. case 0x00003000: /*   */
  564. cch = ' ';
  565. break;
  566. case 0x000000a3: /* £ */
  567. cch = ACS_STERLING;
  568. break;
  569. case 0x000000b0: /* ° */
  570. cch = ACS_DEGREE;
  571. break;
  572. case 0x000000b1: /* ± */
  573. cch = ACS_PLMINUS;
  574. break;
  575. case 0x000000b7: /* · */
  576. case 0x00002219: /* ∙ */
  577. case 0x000030fb: /* ・ */
  578. cch = ACS_BULLET;
  579. break;
  580. case 0x000003c0: /* π */
  581. cch = ACS_PI;
  582. break;
  583. case 0x00002018: /* ‘ */
  584. case 0x00002019: /* ’ */
  585. cch = '\'';
  586. break;
  587. case 0x0000201c: /* “ */
  588. case 0x0000201d: /* ” */
  589. cch = '"';
  590. break;
  591. case 0x00002190: /* ← */
  592. cch = ACS_LARROW;
  593. break;
  594. case 0x00002191: /* ↑ */
  595. cch = ACS_UARROW;
  596. break;
  597. case 0x00002192: /* → */
  598. cch = ACS_RARROW;
  599. break;
  600. case 0x00002193: /* ↓ */
  601. cch = ACS_DARROW;
  602. break;
  603. case 0x00002260: /* ≠ */
  604. cch = ACS_NEQUAL;
  605. break;
  606. case 0x00002261: /* ≡ */
  607. cch = '=';
  608. break;
  609. case 0x00002264: /* ≤ */
  610. cch = ACS_LEQUAL;
  611. break;
  612. case 0x00002265: /* ≥ */
  613. cch = ACS_GEQUAL;
  614. break;
  615. case 0x000023ba: /* ⎺ */
  616. cch = ACS_S1;
  617. cch2 = cch;
  618. break;
  619. case 0x000023bb: /* ⎻ */
  620. cch = ACS_S3;
  621. cch2 = cch;
  622. break;
  623. case 0x000023bc: /* ⎼ */
  624. cch = ACS_S7;
  625. cch2 = cch;
  626. break;
  627. case 0x000023bd: /* ⎽ */
  628. cch = ACS_S9;
  629. cch2 = cch;
  630. break;
  631. case 0x00002500: /* ─ */
  632. case 0x00002550: /* ═ */
  633. cch = ACS_HLINE;
  634. cch2 = cch;
  635. break;
  636. case 0x00002502: /* │ */
  637. case 0x00002551: /* ║ */
  638. cch = ACS_VLINE;
  639. break;
  640. case 0x0000250c: /* ┌ */
  641. case 0x00002552: /* ╒ */
  642. case 0x00002553: /* ╓ */
  643. case 0x00002554: /* ╔ */
  644. cch = ACS_ULCORNER;
  645. cch2 = ACS_HLINE;
  646. break;
  647. case 0x00002510: /* ┐ */
  648. case 0x00002555: /* ╕ */
  649. case 0x00002556: /* ╖ */
  650. case 0x00002557: /* ╗ */
  651. cch = ACS_URCORNER;
  652. break;
  653. case 0x00002514: /* └ */
  654. case 0x00002558: /* ╘ */
  655. case 0x00002559: /* ╙ */
  656. case 0x0000255a: /* ╚ */
  657. cch = ACS_LLCORNER;
  658. cch2 = ACS_HLINE;
  659. break;
  660. case 0x00002518: /* ┘ */
  661. case 0x0000255b: /* ╛ */
  662. case 0x0000255c: /* ╜ */
  663. case 0x0000255d: /* ╝ */
  664. cch = ACS_LRCORNER;
  665. break;
  666. case 0x0000251c: /* ├ */
  667. case 0x0000255e: /* ╞ */
  668. case 0x0000255f: /* ╟ */
  669. case 0x00002560: /* ╠ */
  670. cch = ACS_LTEE;
  671. cch2 = ACS_HLINE;
  672. break;
  673. case 0x00002524: /* ┤ */
  674. case 0x00002561: /* ╡ */
  675. case 0x00002562: /* ╢ */
  676. case 0x00002563: /* ╣ */
  677. cch = ACS_RTEE;
  678. break;
  679. case 0x0000252c: /* ┬ */
  680. case 0x00002564: /* ╤ */
  681. case 0x00002565: /* ╥ */
  682. case 0x00002566: /* ╦ */
  683. cch = ACS_TTEE;
  684. cch2 = ACS_HLINE;
  685. break;
  686. case 0x00002534: /* ┴ */
  687. case 0x00002567: /* ╧ */
  688. case 0x00002568: /* ╨ */
  689. case 0x00002569: /* ╩ */
  690. cch = ACS_BTEE;
  691. cch2 = ACS_HLINE;
  692. break;
  693. case 0x0000253c: /* ┼ */
  694. case 0x0000256a: /* ╪ */
  695. case 0x0000256b: /* ╫ */
  696. case 0x0000256c: /* ╬ */
  697. cch = ACS_PLUS;
  698. cch2 = ACS_HLINE;
  699. break;
  700. case 0x00002591: /* ░ */
  701. cch = ACS_BOARD;
  702. cch2 = cch;
  703. break;
  704. case 0x00002592: /* ▒ */
  705. case 0x00002593: /* ▓ */
  706. cch = ACS_CKBOARD;
  707. cch2 = cch;
  708. break;
  709. case 0x00002580: /* ▀ */
  710. case 0x00002584: /* ▄ */
  711. case 0x00002588: /* █ */
  712. case 0x0000258c: /* ▌ */
  713. case 0x00002590: /* ▐ */
  714. case 0x000025a0: /* ■ */
  715. case 0x000025ac: /* ▬ */
  716. case 0x000025ae: /* ▮ */
  717. cch = ACS_BLOCK;
  718. cch2 = cch;
  719. break;
  720. case 0x000025c6: /* ◆ */
  721. case 0x00002666: /* ♦ */
  722. cch = ACS_DIAMOND;
  723. break;
  724. case 0x00002022: /* • */
  725. case 0x000025cb: /* ○ */
  726. case 0x000025cf: /* ● */
  727. case 0x00002603: /* ☃ */
  728. case 0x0000263c: /* ☼ */
  729. cch = ACS_LANTERN;
  730. break;
  731. case 0x0000301c: /* 〜 */
  732. cch = '~';
  733. break;
  734. }
  735. addch(cch);
  736. if(caca_utf32_is_fullwidth(ch))
  737. {
  738. addch(cch2);
  739. }
  740. }
  741. #endif
  742. }
  743. /*
  744. * Driver initialisation
  745. */
  746. int ncurses_install(caca_display_t *dp)
  747. {
  748. dp->drv.id = CACA_DRIVER_NCURSES;
  749. dp->drv.driver = "ncurses";
  750. dp->drv.init_graphics = ncurses_init_graphics;
  751. dp->drv.end_graphics = ncurses_end_graphics;
  752. dp->drv.set_display_title = ncurses_set_display_title;
  753. dp->drv.get_display_width = ncurses_get_display_width;
  754. dp->drv.get_display_height = ncurses_get_display_height;
  755. dp->drv.display = ncurses_display;
  756. dp->drv.handle_resize = ncurses_handle_resize;
  757. dp->drv.get_event = ncurses_get_event;
  758. dp->drv.set_mouse = NULL;
  759. dp->drv.set_cursor = ncurses_set_cursor;
  760. return 0;
  761. }
  762. #endif /* USE_NCURSES */