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.
 
 
 
 
 
 

860 lines
21 KiB

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