Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

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