25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

852 lines
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. #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 "cucul.h"
  47. #include "caca.h"
  48. #include "caca_internals.h"
  49. /*
  50. * Emulation for missing ACS_* in older curses
  51. */
  52. #ifndef ACS_BLOCK
  53. #define ACS_BLOCK '#'
  54. #endif
  55. #ifndef ACS_BOARD
  56. #define ACS_BOARD '#'
  57. #endif
  58. #ifndef ACS_BTEE
  59. #define ACS_BTEE '+'
  60. #endif
  61. #ifndef ACS_BULLET
  62. #define ACS_BULLET '.'
  63. #endif
  64. #ifndef ACS_CKBOARD
  65. #define ACS_CKBOARD ':'
  66. #endif
  67. #ifndef ACS_DARROW
  68. #define ACS_DARROW 'v'
  69. #endif
  70. #ifndef ACS_DEGREE
  71. #define ACS_DEGREE '\''
  72. #endif
  73. #ifndef ACS_DIAMOND
  74. #define ACS_DIAMOND '+'
  75. #endif
  76. #ifndef ACS_GEQUAL
  77. #define ACS_GEQUAL '>'
  78. #endif
  79. #ifndef ACS_HLINE
  80. #define ACS_HLINE '-'
  81. #endif
  82. #ifndef ACS_LANTERN
  83. #define ACS_LANTERN '#'
  84. #endif
  85. #ifndef ACS_LARROW
  86. #define ACS_LARROW '<'
  87. #endif
  88. #ifndef ACS_LEQUAL
  89. #define ACS_LEQUAL '<'
  90. #endif
  91. #ifndef ACS_LLCORNER
  92. #define ACS_LLCORNER '+'
  93. #endif
  94. #ifndef ACS_LRCORNER
  95. #define ACS_LRCORNER '+'
  96. #endif
  97. #ifndef ACS_LTEE
  98. #define ACS_LTEE '+'
  99. #endif
  100. #ifndef ACS_NEQUAL
  101. #define ACS_NEQUAL '!'
  102. #endif
  103. #ifndef ACS_PI
  104. #define ACS_PI '*'
  105. #endif
  106. #ifndef ACS_STERLING
  107. #define ACS_STERLING 'f'
  108. #endif
  109. #ifndef ACS_PLMINUS
  110. #define ACS_PLMINUS '#'
  111. #endif
  112. #ifndef ACS_PLUS
  113. #define ACS_PLUS '+'
  114. #endif
  115. #ifndef ACS_RARROW
  116. #define ACS_RARROW '>'
  117. #endif
  118. #ifndef ACS_RTEE
  119. #define ACS_RTEE '+'
  120. #endif
  121. #ifndef ACS_S1
  122. #define ACS_S1 '-'
  123. #endif
  124. #ifndef ACS_S3
  125. #define ACS_S3 '-'
  126. #endif
  127. #ifndef ACS_S7
  128. #define ACS_S7 '-'
  129. #endif
  130. #ifndef ACS_S9
  131. #define ACS_S9 '-'
  132. #endif
  133. #ifndef ACS_TTEE
  134. #define ACS_TTEE '+'
  135. #endif
  136. #ifndef ACS_UARROW
  137. #define ACS_UARROW '^'
  138. #endif
  139. #ifndef ACS_ULCORNER
  140. #define ACS_ULCORNER '+'
  141. #endif
  142. #ifndef ACS_URCORNER
  143. #define ACS_URCORNER '+'
  144. #endif
  145. #ifndef ACS_VLINE
  146. #define ACS_VLINE '|'
  147. #endif
  148. /*
  149. * Local functions
  150. */
  151. #if defined HAVE_SIGNAL
  152. static RETSIGTYPE sigwinch_handler(int);
  153. static caca_display_t *sigwinch_d; /* FIXME: we ought to get rid of this */
  154. #endif
  155. #if defined HAVE_GETENV && defined HAVE_PUTENV
  156. static void ncurses_install_terminal(caca_display_t *);
  157. static void ncurses_uninstall_terminal(caca_display_t *);
  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. char *term;
  165. };
  166. static int ncurses_init_graphics(caca_display_t *dp)
  167. {
  168. static int curses_colors[] =
  169. {
  170. /* Standard curses colours */
  171. COLOR_BLACK,
  172. COLOR_BLUE,
  173. COLOR_GREEN,
  174. COLOR_CYAN,
  175. COLOR_RED,
  176. COLOR_MAGENTA,
  177. COLOR_YELLOW,
  178. COLOR_WHITE,
  179. /* Extra values for xterm-16color */
  180. COLOR_BLACK + 8,
  181. COLOR_BLUE + 8,
  182. COLOR_GREEN + 8,
  183. COLOR_CYAN + 8,
  184. COLOR_RED + 8,
  185. COLOR_MAGENTA + 8,
  186. COLOR_YELLOW + 8,
  187. COLOR_WHITE + 8
  188. };
  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. #if defined HAVE_LOCALE_H
  200. setlocale(LC_ALL, "");
  201. #endif
  202. _caca_set_term_title("caca for ncurses");
  203. initscr();
  204. keypad(stdscr, TRUE);
  205. nonl();
  206. raw();
  207. noecho();
  208. nodelay(stdscr, TRUE);
  209. curs_set(0);
  210. /* Activate mouse */
  211. newmask = REPORT_MOUSE_POSITION | ALL_MOUSE_EVENTS;
  212. mousemask(newmask, &dp->drv.p->oldmask);
  213. mouseinterval(-1); /* No click emulation */
  214. /* Set the escape delay to a ridiculously low value */
  215. ESCDELAY = 10;
  216. /* Activate colour */
  217. start_color();
  218. /* If COLORS == 16, it means the terminal supports full bright colours
  219. * using setab and setaf (will use \e[90m \e[91m etc. for colours >= 8),
  220. * we can build 16*16 colour pairs.
  221. * If COLORS == 8, it means the terminal does not know about bright
  222. * colours and we need to get them through A_BOLD and A_BLINK (\e[1m
  223. * and \e[5m). We can only build 8*8 colour pairs. */
  224. max = COLORS >= 16 ? 16 : 8;
  225. for(bg = 0; bg < max; bg++)
  226. for(fg = 0; fg < max; fg++)
  227. {
  228. /* Use ((max + 7 - fg) % max) instead of fg so that colour 0
  229. * is light gray on black. Some terminals don't like this
  230. * colour pair to be redefined. */
  231. int col = ((max + 7 - fg) % max) + max * bg;
  232. init_pair(col, curses_colors[fg], curses_colors[bg]);
  233. dp->drv.p->attr[fg + 16 * bg] = COLOR_PAIR(col);
  234. if(max == 8)
  235. {
  236. /* Bright fg on simple bg */
  237. dp->drv.p->attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col);
  238. /* Simple fg on bright bg */
  239. dp->drv.p->attr[fg + 16 * (bg + 8)] = A_BLINK
  240. | COLOR_PAIR(col);
  241. /* Bright fg on bright bg */
  242. dp->drv.p->attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD
  243. | COLOR_PAIR(col);
  244. }
  245. }
  246. dp->resize.allow = 1;
  247. cucul_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 unsigned int ncurses_get_display_width(caca_display_t const *dp)
  270. {
  271. /* Fallback to a 6x10 font */
  272. return cucul_get_canvas_width(dp->cv) * 6;
  273. }
  274. static unsigned int ncurses_get_display_height(caca_display_t const *dp)
  275. {
  276. /* Fallback to a 6x10 font */
  277. return cucul_get_canvas_height(dp->cv) * 10;
  278. }
  279. static void ncurses_display(caca_display_t *dp)
  280. {
  281. uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv);
  282. uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv);
  283. unsigned int width = cucul_get_canvas_width(dp->cv);
  284. unsigned int height = cucul_get_canvas_height(dp->cv);
  285. int x, y;
  286. for(y = 0; y < (int)height; y++)
  287. {
  288. move(y, 0);
  289. for(x = width; x--; )
  290. {
  291. attrset(dp->drv.p->attr[cucul_attr_to_ansi(*cvattrs++)]);
  292. ncurses_write_utf32(*cvchars++);
  293. }
  294. }
  295. x = cucul_get_cursor_x(dp->cv);
  296. y = cucul_get_cursor_y(dp->cv);
  297. move(y, x);
  298. refresh();
  299. }
  300. static void ncurses_handle_resize(caca_display_t *dp)
  301. {
  302. struct winsize size;
  303. #if defined HAVE_SYS_IOCTL_H
  304. if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0)
  305. {
  306. dp->resize.w = size.ws_col;
  307. dp->resize.h = size.ws_row;
  308. #if defined HAVE_RESIZE_TERM
  309. resize_term(dp->resize.h, dp->resize.w);
  310. #else
  311. resizeterm(dp->resize.h, dp->resize.w);
  312. #endif
  313. wrefresh(curscr);
  314. return;
  315. }
  316. #endif
  317. /* Fallback */
  318. dp->resize.w = cucul_get_canvas_width(dp->cv);
  319. dp->resize.h = cucul_get_canvas_height(dp->cv);
  320. }
  321. static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev)
  322. {
  323. int intkey;
  324. intkey = getch();
  325. if(intkey == ERR)
  326. {
  327. ev->type = CACA_EVENT_NONE;
  328. return 0;
  329. }
  330. if(intkey < 0x7f)
  331. {
  332. ev->type = CACA_EVENT_KEY_PRESS;
  333. ev->data.key.ch = intkey;
  334. ev->data.key.utf32 = intkey;
  335. ev->data.key.utf8[0] = intkey;
  336. ev->data.key.utf8[1] = '\0';
  337. return 1;
  338. }
  339. /* If the key was UTF-8, parse the whole sequence */
  340. if(intkey >= 0x80 && intkey < 0x100)
  341. {
  342. int keys[7]; /* Necessary for ungetch(); */
  343. char utf8[7];
  344. uint32_t utf32;
  345. unsigned int i;
  346. size_t 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 */