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.
 
 
 
 
 
 

870 regels
21 KiB

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