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.
 
 
 
 
 
 

829 lines
20 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. #include "common.h"
  20. #if defined USE_NCURSES
  21. #if defined HAVE_NCURSESW_NCURSES_H
  22. # include <ncursesw/ncurses.h>
  23. #elif defined HAVE_NCURSES_NCURSES_H
  24. # include <ncurses/ncurses.h>
  25. #elif defined HAVE_NCURSES_H
  26. # include <ncurses.h>
  27. #else
  28. # include <curses.h>
  29. #endif
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #if defined HAVE_UNISTD_H
  33. # include <unistd.h>
  34. #endif
  35. #if defined HAVE_SIGNAL_H
  36. # include <signal.h>
  37. #endif
  38. #if defined HAVE_SYS_IOCTL_H
  39. # include <sys/ioctl.h>
  40. #endif
  41. #if defined HAVE_LOCALE_H
  42. # include <locale.h>
  43. #endif
  44. #if defined HAVE_TERMIOS_H
  45. # include <termios.h>
  46. #endif
  47. #include "cucul.h"
  48. #include "caca.h"
  49. #include "caca_internals.h"
  50. /*
  51. * Emulation for missing ACS_* in older curses
  52. */
  53. #ifndef ACS_BLOCK
  54. #define ACS_BLOCK '#'
  55. #endif
  56. #ifndef ACS_BOARD
  57. #define ACS_BOARD '#'
  58. #endif
  59. #ifndef ACS_BTEE
  60. #define ACS_BTEE '+'
  61. #endif
  62. #ifndef ACS_BULLET
  63. #define ACS_BULLET '.'
  64. #endif
  65. #ifndef ACS_CKBOARD
  66. #define ACS_CKBOARD ':'
  67. #endif
  68. #ifndef ACS_DARROW
  69. #define ACS_DARROW 'v'
  70. #endif
  71. #ifndef ACS_DEGREE
  72. #define ACS_DEGREE '\''
  73. #endif
  74. #ifndef ACS_DIAMOND
  75. #define ACS_DIAMOND '+'
  76. #endif
  77. #ifndef ACS_GEQUAL
  78. #define ACS_GEQUAL '>'
  79. #endif
  80. #ifndef ACS_HLINE
  81. #define ACS_HLINE '-'
  82. #endif
  83. #ifndef ACS_LANTERN
  84. #define ACS_LANTERN '#'
  85. #endif
  86. #ifndef ACS_LARROW
  87. #define ACS_LARROW '<'
  88. #endif
  89. #ifndef ACS_LEQUAL
  90. #define ACS_LEQUAL '<'
  91. #endif
  92. #ifndef ACS_LLCORNER
  93. #define ACS_LLCORNER '+'
  94. #endif
  95. #ifndef ACS_LRCORNER
  96. #define ACS_LRCORNER '+'
  97. #endif
  98. #ifndef ACS_LTEE
  99. #define ACS_LTEE '+'
  100. #endif
  101. #ifndef ACS_NEQUAL
  102. #define ACS_NEQUAL '!'
  103. #endif
  104. #ifndef ACS_PI
  105. #define ACS_PI '*'
  106. #endif
  107. #ifndef ACS_STERLING
  108. #define ACS_STERLING 'f'
  109. #endif
  110. #ifndef ACS_PLMINUS
  111. #define ACS_PLMINUS '#'
  112. #endif
  113. #ifndef ACS_PLUS
  114. #define ACS_PLUS '+'
  115. #endif
  116. #ifndef ACS_RARROW
  117. #define ACS_RARROW '>'
  118. #endif
  119. #ifndef ACS_RTEE
  120. #define ACS_RTEE '+'
  121. #endif
  122. #ifndef ACS_S1
  123. #define ACS_S1 '-'
  124. #endif
  125. #ifndef ACS_S3
  126. #define ACS_S3 '-'
  127. #endif
  128. #ifndef ACS_S7
  129. #define ACS_S7 '-'
  130. #endif
  131. #ifndef ACS_S9
  132. #define ACS_S9 '-'
  133. #endif
  134. #ifndef ACS_TTEE
  135. #define ACS_TTEE '+'
  136. #endif
  137. #ifndef ACS_UARROW
  138. #define ACS_UARROW '^'
  139. #endif
  140. #ifndef ACS_ULCORNER
  141. #define ACS_ULCORNER '+'
  142. #endif
  143. #ifndef ACS_URCORNER
  144. #define ACS_URCORNER '+'
  145. #endif
  146. #ifndef ACS_VLINE
  147. #define ACS_VLINE '|'
  148. #endif
  149. /*
  150. * Local functions
  151. */
  152. #if defined HAVE_SIGNAL
  153. static RETSIGTYPE sigwinch_handler(int);
  154. static caca_display_t *sigwinch_d; /* FIXME: we ought to get rid of this */
  155. #endif
  156. #if defined HAVE_GETENV && defined HAVE_PUTENV
  157. static void ncurses_check_terminal(void);
  158. #endif
  159. static void ncurses_write_utf32(uint32_t);
  160. struct driver_private
  161. {
  162. int attr[16*16];
  163. mmask_t oldmask;
  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_check_terminal();
  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. cucul_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. free(dp->drv.p);
  258. return 0;
  259. }
  260. static int ncurses_set_display_title(caca_display_t *dp, char const *title)
  261. {
  262. _caca_set_term_title(title);
  263. return 0;
  264. }
  265. static unsigned int ncurses_get_display_width(caca_display_t const *dp)
  266. {
  267. /* Fallback to a 6x10 font */
  268. return cucul_get_canvas_width(dp->cv) * 6;
  269. }
  270. static unsigned int ncurses_get_display_height(caca_display_t const *dp)
  271. {
  272. /* Fallback to a 6x10 font */
  273. return cucul_get_canvas_height(dp->cv) * 10;
  274. }
  275. static void ncurses_display(caca_display_t *dp)
  276. {
  277. uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv);
  278. uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv);
  279. unsigned int width = cucul_get_canvas_width(dp->cv);
  280. unsigned int height = cucul_get_canvas_height(dp->cv);
  281. int x, y;
  282. for(y = 0; y < (int)height; y++)
  283. {
  284. move(y, 0);
  285. for(x = width; x--; )
  286. {
  287. attrset(dp->drv.p->attr[cucul_attr_to_ansi(*cvattrs++)]);
  288. ncurses_write_utf32(*cvchars++);
  289. }
  290. }
  291. x = cucul_get_cursor_x(dp->cv);
  292. y = cucul_get_cursor_y(dp->cv);
  293. move(y, x);
  294. refresh();
  295. }
  296. static void ncurses_handle_resize(caca_display_t *dp)
  297. {
  298. struct winsize size;
  299. #if defined HAVE_SYS_IOCTL_H
  300. if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0)
  301. {
  302. dp->resize.w = size.ws_col;
  303. dp->resize.h = size.ws_row;
  304. #if defined HAVE_RESIZE_TERM
  305. resize_term(dp->resize.h, dp->resize.w);
  306. #else
  307. resizeterm(dp->resize.h, dp->resize.w);
  308. #endif
  309. wrefresh(curscr);
  310. return;
  311. }
  312. #endif
  313. /* Fallback */
  314. dp->resize.w = cucul_get_canvas_width(dp->cv);
  315. dp->resize.h = cucul_get_canvas_height(dp->cv);
  316. }
  317. static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev)
  318. {
  319. int intkey;
  320. intkey = getch();
  321. if(intkey == ERR)
  322. {
  323. ev->type = CACA_EVENT_NONE;
  324. return 0;
  325. }
  326. if(intkey < 0x7f)
  327. {
  328. ev->type = CACA_EVENT_KEY_PRESS;
  329. ev->data.key.ch = intkey;
  330. ev->data.key.utf32 = intkey;
  331. ev->data.key.utf8[0] = intkey;
  332. ev->data.key.utf8[1] = '\0';
  333. return 1;
  334. }
  335. /* If the key was UTF-8, parse the whole sequence */
  336. if(intkey >= 0x80 && intkey < 0x100)
  337. {
  338. int keys[7]; /* Necessary for ungetch(); */
  339. char utf8[7];
  340. uint32_t utf32;
  341. unsigned int i, bytes = 0;
  342. keys[0] = intkey;
  343. utf8[0] = intkey;
  344. for(i = 1; i < 6; i++)
  345. {
  346. keys[i] = getch();
  347. utf8[i] = (unsigned char)keys[i];
  348. }
  349. utf8[i] = '\0';
  350. utf32 = cucul_utf8_to_utf32(utf8, &bytes);
  351. while(i > bytes)
  352. ungetch(keys[--i]);
  353. if(bytes)
  354. {
  355. ev->type = CACA_EVENT_KEY_PRESS;
  356. ev->data.key.ch = 0;
  357. ev->data.key.utf32 = utf32;
  358. strcpy(ev->data.key.utf8, utf8);
  359. return 1;
  360. }
  361. }
  362. if(intkey == KEY_MOUSE)
  363. {
  364. MEVENT mevent;
  365. getmouse(&mevent);
  366. switch(mevent.bstate)
  367. {
  368. #define PRESS(x) ev->data.mouse.button = x; \
  369. ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev)
  370. #define RELEASE(x) ev->data.mouse.button = x; \
  371. ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev)
  372. #define CLICK(x) PRESS(x); RELEASE(x)
  373. case BUTTON1_PRESSED: PRESS(1); break;
  374. case BUTTON1_RELEASED: RELEASE(1); break;
  375. case BUTTON1_CLICKED: CLICK(1); break;
  376. case BUTTON1_DOUBLE_CLICKED: CLICK(1); CLICK(1); break;
  377. case BUTTON1_TRIPLE_CLICKED: CLICK(1); CLICK(1); CLICK(1); break;
  378. case BUTTON1_RESERVED_EVENT: break;
  379. case BUTTON2_PRESSED: PRESS(2); break;
  380. case BUTTON2_RELEASED: RELEASE(2); break;
  381. case BUTTON2_CLICKED: CLICK(2); break;
  382. case BUTTON2_DOUBLE_CLICKED: CLICK(2); CLICK(2); break;
  383. case BUTTON2_TRIPLE_CLICKED: CLICK(2); CLICK(2); CLICK(2); break;
  384. case BUTTON2_RESERVED_EVENT: break;
  385. case BUTTON3_PRESSED: PRESS(3); break;
  386. case BUTTON3_RELEASED: RELEASE(3); break;
  387. case BUTTON3_CLICKED: CLICK(3); break;
  388. case BUTTON3_DOUBLE_CLICKED: CLICK(3); CLICK(3); break;
  389. case BUTTON3_TRIPLE_CLICKED: CLICK(3); CLICK(3); CLICK(3); break;
  390. case BUTTON3_RESERVED_EVENT: break;
  391. case BUTTON4_PRESSED: PRESS(4); break;
  392. case BUTTON4_RELEASED: RELEASE(4); break;
  393. case BUTTON4_CLICKED: CLICK(4); break;
  394. case BUTTON4_DOUBLE_CLICKED: CLICK(4); CLICK(4); break;
  395. case BUTTON4_TRIPLE_CLICKED: CLICK(4); CLICK(4); CLICK(4); break;
  396. case BUTTON4_RESERVED_EVENT: break;
  397. default:
  398. break;
  399. #undef PRESS
  400. #undef RELEASE
  401. #undef CLICK
  402. }
  403. if(dp->mouse.x == (unsigned int)mevent.x &&
  404. dp->mouse.y == (unsigned int)mevent.y)
  405. return _pop_event(dp, ev);
  406. dp->mouse.x = mevent.x;
  407. dp->mouse.y = mevent.y;
  408. ev->type = CACA_EVENT_MOUSE_MOTION;
  409. ev->data.mouse.x = dp->mouse.x;
  410. ev->data.mouse.y = dp->mouse.y;
  411. return 1;
  412. }
  413. switch(intkey)
  414. {
  415. case KEY_UP: ev->data.key.ch = CACA_KEY_UP; break;
  416. case KEY_DOWN: ev->data.key.ch = CACA_KEY_DOWN; break;
  417. case KEY_LEFT: ev->data.key.ch = CACA_KEY_LEFT; break;
  418. case KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break;
  419. case KEY_IC: ev->data.key.ch = CACA_KEY_INSERT; break;
  420. case KEY_DC: ev->data.key.ch = CACA_KEY_DELETE; break;
  421. case 0x7f:
  422. case KEY_BACKSPACE: ev->data.key.ch = CACA_KEY_BACKSPACE; break;
  423. case KEY_HOME: ev->data.key.ch = CACA_KEY_HOME; break;
  424. case KEY_END: ev->data.key.ch = CACA_KEY_END; break;
  425. case KEY_PPAGE: ev->data.key.ch = CACA_KEY_PAGEUP; break;
  426. case KEY_NPAGE: ev->data.key.ch = CACA_KEY_PAGEDOWN; break;
  427. case KEY_F(1): ev->data.key.ch = CACA_KEY_F1; break;
  428. case KEY_F(2): ev->data.key.ch = CACA_KEY_F2; break;
  429. case KEY_F(3): ev->data.key.ch = CACA_KEY_F3; break;
  430. case KEY_F(4): ev->data.key.ch = CACA_KEY_F4; break;
  431. case KEY_F(5): ev->data.key.ch = CACA_KEY_F5; break;
  432. case KEY_F(6): ev->data.key.ch = CACA_KEY_F6; break;
  433. case KEY_F(7): ev->data.key.ch = CACA_KEY_F7; break;
  434. case KEY_F(8): ev->data.key.ch = CACA_KEY_F8; break;
  435. case KEY_F(9): ev->data.key.ch = CACA_KEY_F9; break;
  436. case KEY_F(10): ev->data.key.ch = CACA_KEY_F10; break;
  437. case KEY_F(11): ev->data.key.ch = CACA_KEY_F11; break;
  438. case KEY_F(12): ev->data.key.ch = CACA_KEY_F12; break;
  439. default:
  440. /* Unknown key */
  441. ev->type = CACA_EVENT_NONE; return 0;
  442. }
  443. ev->type = CACA_EVENT_KEY_PRESS;
  444. ev->data.key.utf32 = 0;
  445. ev->data.key.utf8[0] = '\0';
  446. return 1;
  447. }
  448. static void ncurses_set_cursor(caca_display_t *dp, int flags)
  449. {
  450. curs_set(flags ? 2 : 0);
  451. }
  452. /*
  453. * XXX: following functions are local
  454. */
  455. #if defined HAVE_SIGNAL
  456. static RETSIGTYPE sigwinch_handler(int sig)
  457. {
  458. sigwinch_d->resize.resized = 1;
  459. signal(SIGWINCH, sigwinch_handler);
  460. }
  461. #endif
  462. #if defined HAVE_GETENV && defined HAVE_PUTENV
  463. static void ncurses_check_terminal(void)
  464. {
  465. char *term, *colorterm;
  466. term = getenv("TERM");
  467. colorterm = getenv("COLORTERM");
  468. if(!term || strcmp(term, "xterm"))
  469. return;
  470. /* If we are using gnome-terminal, it's really a 16 colour terminal.
  471. * Ditto if we are using xfce4-terminal, or Konsole. */
  472. if((colorterm && (!strcmp(colorterm, "gnome-terminal")
  473. || !strcmp(colorterm, "Terminal")))
  474. || getenv("KONSOLE_DCOP_SESSION"))
  475. {
  476. SCREEN *screen;
  477. screen = newterm("xterm-16color", stdout, stdin);
  478. if(screen == NULL)
  479. return;
  480. endwin();
  481. (void)putenv("TERM=xterm-16color");
  482. return;
  483. }
  484. }
  485. #endif
  486. static void ncurses_write_utf32(uint32_t ch)
  487. {
  488. #if defined HAVE_NCURSESW_NCURSES_H
  489. char buf[10];
  490. int bytes;
  491. #endif
  492. if(ch == CUCUL_MAGIC_FULLWIDTH)
  493. return;
  494. #if defined HAVE_NCURSESW_NCURSES_H
  495. bytes = cucul_utf32_to_utf8(buf, ch);
  496. buf[bytes] = '\0';
  497. addstr(buf);
  498. #else
  499. if(ch < 0x80)
  500. {
  501. addch(ch);
  502. }
  503. else
  504. {
  505. chtype cch;
  506. chtype cch2;
  507. cch = '?';
  508. cch2 = ' ';
  509. if ((ch > 0x0000ff00) && (ch < 0x0000ff5f))
  510. {
  511. cch = ch - 0x0000ff00 + ' ';
  512. }
  513. switch (ch)
  514. {
  515. case 0x000000a0: /* <nbsp> */
  516. case 0x00003000: /*   */
  517. cch = ' ';
  518. break;
  519. case 0x000000a3: /* £ */
  520. cch = ACS_STERLING;
  521. break;
  522. case 0x000000b0: /* ° */
  523. cch = ACS_DEGREE;
  524. break;
  525. case 0x000000b1: /* ± */
  526. cch = ACS_PLMINUS;
  527. break;
  528. case 0x000000b7: /* · */
  529. case 0x00002219: /* ∙ */
  530. case 0x000030fb: /* ・ */
  531. cch = ACS_BULLET;
  532. break;
  533. case 0x000003c0: /* π */
  534. cch = ACS_PI;
  535. break;
  536. case 0x00002018: /* ‘ */
  537. case 0x00002019: /* ’ */
  538. cch = '\'';
  539. break;
  540. case 0x0000201c: /* “ */
  541. case 0x0000201d: /* ” */
  542. cch = '"';
  543. break;
  544. case 0x00002190: /* ← */
  545. cch = ACS_LARROW;
  546. break;
  547. case 0x00002191: /* ↑ */
  548. cch = ACS_UARROW;
  549. break;
  550. case 0x00002192: /* → */
  551. cch = ACS_RARROW;
  552. break;
  553. case 0x00002193: /* ↓ */
  554. cch = ACS_DARROW;
  555. break;
  556. case 0x00002260: /* ≠ */
  557. cch = ACS_NEQUAL;
  558. break;
  559. case 0x00002261: /* ≡ */
  560. cch = '=';
  561. break;
  562. case 0x00002264: /* ≤ */
  563. cch = ACS_LEQUAL;
  564. break;
  565. case 0x00002265: /* ≥ */
  566. cch = ACS_GEQUAL;
  567. break;
  568. case 0x000023ba: /* ⎺ */
  569. cch = ACS_S1;
  570. cch2 = cch;
  571. break;
  572. case 0x000023bb: /* ⎻ */
  573. cch = ACS_S3;
  574. cch2 = cch;
  575. break;
  576. case 0x000023bc: /* ⎼ */
  577. cch = ACS_S7;
  578. cch2 = cch;
  579. break;
  580. case 0x000023bd: /* ⎽ */
  581. cch = ACS_S9;
  582. cch2 = cch;
  583. break;
  584. case 0x00002500: /* ─ */
  585. case 0x00002550: /* ═ */
  586. cch = ACS_HLINE;
  587. cch2 = cch;
  588. break;
  589. case 0x00002502: /* │ */
  590. case 0x00002551: /* ║ */
  591. cch = ACS_VLINE;
  592. break;
  593. case 0x0000250c: /* ┌ */
  594. case 0x00002552: /* ╒ */
  595. case 0x00002553: /* ╓ */
  596. case 0x00002554: /* ╔ */
  597. cch = ACS_ULCORNER;
  598. cch2 = ACS_HLINE;
  599. break;
  600. case 0x00002510: /* ┐ */
  601. case 0x00002555: /* ╕ */
  602. case 0x00002556: /* ╖ */
  603. case 0x00002557: /* ╗ */
  604. cch = ACS_URCORNER;
  605. break;
  606. case 0x00002514: /* └ */
  607. case 0x00002558: /* ╘ */
  608. case 0x00002559: /* ╙ */
  609. case 0x0000255a: /* ╚ */
  610. cch = ACS_LLCORNER;
  611. cch2 = ACS_HLINE;
  612. break;
  613. case 0x00002518: /* ┘ */
  614. case 0x0000255b: /* ╛ */
  615. case 0x0000255c: /* ╜ */
  616. case 0x0000255d: /* ╝ */
  617. cch = ACS_LRCORNER;
  618. break;
  619. case 0x0000251c: /* ├ */
  620. case 0x0000255e: /* ╞ */
  621. case 0x0000255f: /* ╟ */
  622. case 0x00002560: /* ╠ */
  623. cch = ACS_LTEE;
  624. cch2 = ACS_HLINE;
  625. break;
  626. case 0x00002524: /* ┤ */
  627. case 0x00002561: /* ╡ */
  628. case 0x00002562: /* ╢ */
  629. case 0x00002563: /* ╣ */
  630. cch = ACS_RTEE;
  631. break;
  632. case 0x0000252c: /* ┬ */
  633. case 0x00002564: /* ╤ */
  634. case 0x00002565: /* ╥ */
  635. case 0x00002566: /* ╦ */
  636. cch = ACS_TTEE;
  637. cch2 = ACS_HLINE;
  638. break;
  639. case 0x00002534: /* ┴ */
  640. case 0x00002567: /* ╧ */
  641. case 0x00002568: /* ╨ */
  642. case 0x00002569: /* ╩ */
  643. cch = ACS_BTEE;
  644. cch2 = ACS_HLINE;
  645. break;
  646. case 0x0000253c: /* ┼ */
  647. case 0x0000256a: /* ╪ */
  648. case 0x0000256b: /* ╫ */
  649. case 0x0000256c: /* ╬ */
  650. cch = ACS_PLUS;
  651. cch2 = ACS_HLINE;
  652. break;
  653. case 0x00002591: /* ░ */
  654. cch = ACS_BOARD;
  655. cch2 = cch;
  656. break;
  657. case 0x00002592: /* ▒ */
  658. case 0x00002593: /* ▓ */
  659. cch = ACS_CKBOARD;
  660. cch2 = cch;
  661. break;
  662. case 0x00002580: /* ▀ */
  663. case 0x00002584: /* ▄ */
  664. case 0x00002588: /* █ */
  665. case 0x0000258c: /* ▌ */
  666. case 0x00002590: /* ▐ */
  667. case 0x000025a0: /* ■ */
  668. case 0x000025ac: /* ▬ */
  669. case 0x000025ae: /* ▮ */
  670. cch = ACS_BLOCK;
  671. cch2 = cch;
  672. break;
  673. case 0x000025c6: /* ◆ */
  674. case 0x00002666: /* ♦ */
  675. cch = ACS_DIAMOND;
  676. break;
  677. case 0x00002022: /* • */
  678. case 0x000025cb: /* ○ */
  679. case 0x000025cf: /* ● */
  680. case 0x00002603: /* ☃ */
  681. case 0x0000263c: /* ☼ */
  682. cch = ACS_LANTERN;
  683. break;
  684. case 0x0000301c: /* 〜 */
  685. cch = '~';
  686. break;
  687. }
  688. addch(cch);
  689. if(cucul_utf32_is_fullwidth(ch))
  690. {
  691. addch(cch2);
  692. }
  693. }
  694. #endif
  695. }
  696. /*
  697. * Driver initialisation
  698. */
  699. int ncurses_install(caca_display_t *dp)
  700. {
  701. dp->drv.driver = CACA_DRIVER_NCURSES;
  702. dp->drv.init_graphics = ncurses_init_graphics;
  703. dp->drv.end_graphics = ncurses_end_graphics;
  704. dp->drv.set_display_title = ncurses_set_display_title;
  705. dp->drv.get_display_width = ncurses_get_display_width;
  706. dp->drv.get_display_height = ncurses_get_display_height;
  707. dp->drv.display = ncurses_display;
  708. dp->drv.handle_resize = ncurses_handle_resize;
  709. dp->drv.get_event = ncurses_get_event;
  710. dp->drv.set_mouse = NULL;
  711. dp->drv.set_cursor = ncurses_set_cursor;
  712. return 0;
  713. }
  714. #endif /* USE_NCURSES */