Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

862 lignes
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 = (uint32_t const *)caca_get_canvas_chars(dp->cv)
  288. + dx + dy * dp->cv->width;
  289. cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv)
  290. + 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. 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_get_cursor_x(dp->cv);
  304. y = caca_get_cursor_y(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. case BUTTON1_RESERVED_EVENT: break;
  391. case BUTTON2_PRESSED: PRESS(2); break;
  392. case BUTTON2_RELEASED: RELEASE(2); break;
  393. case BUTTON2_CLICKED: CLICK(2); break;
  394. case BUTTON2_DOUBLE_CLICKED: CLICK(2); CLICK(2); break;
  395. case BUTTON2_TRIPLE_CLICKED: CLICK(2); CLICK(2); CLICK(2); break;
  396. case BUTTON2_RESERVED_EVENT: break;
  397. case BUTTON3_PRESSED: PRESS(3); break;
  398. case BUTTON3_RELEASED: RELEASE(3); break;
  399. case BUTTON3_CLICKED: CLICK(3); break;
  400. case BUTTON3_DOUBLE_CLICKED: CLICK(3); CLICK(3); break;
  401. case BUTTON3_TRIPLE_CLICKED: CLICK(3); CLICK(3); CLICK(3); break;
  402. case BUTTON3_RESERVED_EVENT: break;
  403. case BUTTON4_PRESSED: PRESS(4); break;
  404. case BUTTON4_RELEASED: RELEASE(4); break;
  405. case BUTTON4_CLICKED: CLICK(4); break;
  406. case BUTTON4_DOUBLE_CLICKED: CLICK(4); CLICK(4); break;
  407. case BUTTON4_TRIPLE_CLICKED: CLICK(4); CLICK(4); CLICK(4); break;
  408. case BUTTON4_RESERVED_EVENT: break;
  409. default:
  410. break;
  411. #undef PRESS
  412. #undef RELEASE
  413. #undef CLICK
  414. }
  415. if(dp->mouse.x == mevent.x && dp->mouse.y == mevent.y)
  416. return _pop_event(dp, ev);
  417. dp->mouse.x = mevent.x;
  418. dp->mouse.y = mevent.y;
  419. ev->type = CACA_EVENT_MOUSE_MOTION;
  420. ev->data.mouse.x = dp->mouse.x;
  421. ev->data.mouse.y = dp->mouse.y;
  422. return 1;
  423. }
  424. switch(intkey)
  425. {
  426. case KEY_UP: ev->data.key.ch = CACA_KEY_UP; break;
  427. case KEY_DOWN: ev->data.key.ch = CACA_KEY_DOWN; break;
  428. case KEY_LEFT: ev->data.key.ch = CACA_KEY_LEFT; break;
  429. case KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break;
  430. case KEY_IC: ev->data.key.ch = CACA_KEY_INSERT; break;
  431. case KEY_DC: ev->data.key.ch = CACA_KEY_DELETE; break;
  432. case 0x7f:
  433. case KEY_BACKSPACE: ev->data.key.ch = CACA_KEY_BACKSPACE; break;
  434. case KEY_HOME: ev->data.key.ch = CACA_KEY_HOME; break;
  435. case KEY_END: ev->data.key.ch = CACA_KEY_END; break;
  436. case KEY_PPAGE: ev->data.key.ch = CACA_KEY_PAGEUP; break;
  437. case KEY_NPAGE: ev->data.key.ch = CACA_KEY_PAGEDOWN; break;
  438. case KEY_F(1): ev->data.key.ch = CACA_KEY_F1; break;
  439. case KEY_F(2): ev->data.key.ch = CACA_KEY_F2; break;
  440. case KEY_F(3): ev->data.key.ch = CACA_KEY_F3; break;
  441. case KEY_F(4): ev->data.key.ch = CACA_KEY_F4; break;
  442. case KEY_F(5): ev->data.key.ch = CACA_KEY_F5; break;
  443. case KEY_F(6): ev->data.key.ch = CACA_KEY_F6; break;
  444. case KEY_F(7): ev->data.key.ch = CACA_KEY_F7; break;
  445. case KEY_F(8): ev->data.key.ch = CACA_KEY_F8; break;
  446. case KEY_F(9): ev->data.key.ch = CACA_KEY_F9; break;
  447. case KEY_F(10): ev->data.key.ch = CACA_KEY_F10; break;
  448. case KEY_F(11): ev->data.key.ch = CACA_KEY_F11; break;
  449. case KEY_F(12): ev->data.key.ch = CACA_KEY_F12; break;
  450. default:
  451. /* Unknown key */
  452. ev->type = CACA_EVENT_NONE; return 0;
  453. }
  454. ev->type = CACA_EVENT_KEY_PRESS;
  455. ev->data.key.utf32 = 0;
  456. ev->data.key.utf8[0] = '\0';
  457. return 1;
  458. }
  459. static void ncurses_set_cursor(caca_display_t *dp, int flags)
  460. {
  461. curs_set(flags ? 2 : 0);
  462. }
  463. /*
  464. * XXX: following functions are local
  465. */
  466. #if defined HAVE_SIGNAL
  467. static RETSIGTYPE sigwinch_handler(int sig)
  468. {
  469. sigwinch_d->resize.resized = 1;
  470. signal(SIGWINCH, sigwinch_handler);
  471. }
  472. #endif
  473. #if defined HAVE_GETENV && defined HAVE_PUTENV
  474. static void ncurses_install_terminal(caca_display_t *dp)
  475. {
  476. char *term, *colorterm;
  477. dp->drv.p->term = NULL;
  478. term = getenv("TERM");
  479. colorterm = getenv("COLORTERM");
  480. if(!term || strcmp(term, "xterm"))
  481. return;
  482. /* If we are using gnome-terminal, it's really a 16 colour terminal.
  483. * Ditto if we are using xfce4-terminal, or Konsole. */
  484. if((colorterm && (!strcmp(colorterm, "gnome-terminal")
  485. || !strcmp(colorterm, "Terminal")))
  486. || getenv("KONSOLE_DCOP_SESSION"))
  487. {
  488. SCREEN *screen;
  489. screen = newterm("xterm-16color", stdout, stdin);
  490. if(screen == NULL)
  491. return;
  492. endwin();
  493. (void)putenv("TERM=xterm-16color");
  494. dp->drv.p->term = strdup(term);
  495. return;
  496. }
  497. }
  498. static void ncurses_uninstall_terminal(caca_display_t *dp)
  499. {
  500. /* Needs to be persistent because we use putenv() */
  501. static char termenv[1024];
  502. if(!dp->drv.p->term)
  503. return;
  504. snprintf(termenv, 1023, "TERM=%s", dp->drv.p->term);
  505. free(dp->drv.p->term);
  506. (void)putenv(termenv);
  507. }
  508. #endif
  509. static void ncurses_write_utf32(uint32_t ch)
  510. {
  511. #if defined HAVE_NCURSESW_NCURSES_H
  512. char buf[10];
  513. int bytes;
  514. #endif
  515. if(ch == CACA_MAGIC_FULLWIDTH)
  516. return;
  517. #if defined HAVE_NCURSESW_NCURSES_H
  518. bytes = caca_utf32_to_utf8(buf, ch);
  519. buf[bytes] = '\0';
  520. addstr(buf);
  521. #else
  522. if(ch < 0x80)
  523. {
  524. addch(ch);
  525. }
  526. else
  527. {
  528. chtype cch;
  529. chtype cch2;
  530. cch = '?';
  531. cch2 = ' ';
  532. if ((ch > 0x0000ff00) && (ch < 0x0000ff5f))
  533. {
  534. cch = ch - 0x0000ff00 + ' ';
  535. }
  536. switch (ch)
  537. {
  538. case 0x000000a0: /* <nbsp> */
  539. case 0x00003000: /*   */
  540. cch = ' ';
  541. break;
  542. case 0x000000a3: /* £ */
  543. cch = ACS_STERLING;
  544. break;
  545. case 0x000000b0: /* ° */
  546. cch = ACS_DEGREE;
  547. break;
  548. case 0x000000b1: /* ± */
  549. cch = ACS_PLMINUS;
  550. break;
  551. case 0x000000b7: /* · */
  552. case 0x00002219: /* ∙ */
  553. case 0x000030fb: /* ・ */
  554. cch = ACS_BULLET;
  555. break;
  556. case 0x000003c0: /* π */
  557. cch = ACS_PI;
  558. break;
  559. case 0x00002018: /* ‘ */
  560. case 0x00002019: /* ’ */
  561. cch = '\'';
  562. break;
  563. case 0x0000201c: /* “ */
  564. case 0x0000201d: /* ” */
  565. cch = '"';
  566. break;
  567. case 0x00002190: /* ← */
  568. cch = ACS_LARROW;
  569. break;
  570. case 0x00002191: /* ↑ */
  571. cch = ACS_UARROW;
  572. break;
  573. case 0x00002192: /* → */
  574. cch = ACS_RARROW;
  575. break;
  576. case 0x00002193: /* ↓ */
  577. cch = ACS_DARROW;
  578. break;
  579. case 0x00002260: /* ≠ */
  580. cch = ACS_NEQUAL;
  581. break;
  582. case 0x00002261: /* ≡ */
  583. cch = '=';
  584. break;
  585. case 0x00002264: /* ≤ */
  586. cch = ACS_LEQUAL;
  587. break;
  588. case 0x00002265: /* ≥ */
  589. cch = ACS_GEQUAL;
  590. break;
  591. case 0x000023ba: /* ⎺ */
  592. cch = ACS_S1;
  593. cch2 = cch;
  594. break;
  595. case 0x000023bb: /* ⎻ */
  596. cch = ACS_S3;
  597. cch2 = cch;
  598. break;
  599. case 0x000023bc: /* ⎼ */
  600. cch = ACS_S7;
  601. cch2 = cch;
  602. break;
  603. case 0x000023bd: /* ⎽ */
  604. cch = ACS_S9;
  605. cch2 = cch;
  606. break;
  607. case 0x00002500: /* ─ */
  608. case 0x00002550: /* ═ */
  609. cch = ACS_HLINE;
  610. cch2 = cch;
  611. break;
  612. case 0x00002502: /* │ */
  613. case 0x00002551: /* ║ */
  614. cch = ACS_VLINE;
  615. break;
  616. case 0x0000250c: /* ┌ */
  617. case 0x00002552: /* ╒ */
  618. case 0x00002553: /* ╓ */
  619. case 0x00002554: /* ╔ */
  620. cch = ACS_ULCORNER;
  621. cch2 = ACS_HLINE;
  622. break;
  623. case 0x00002510: /* ┐ */
  624. case 0x00002555: /* ╕ */
  625. case 0x00002556: /* ╖ */
  626. case 0x00002557: /* ╗ */
  627. cch = ACS_URCORNER;
  628. break;
  629. case 0x00002514: /* └ */
  630. case 0x00002558: /* ╘ */
  631. case 0x00002559: /* ╙ */
  632. case 0x0000255a: /* ╚ */
  633. cch = ACS_LLCORNER;
  634. cch2 = ACS_HLINE;
  635. break;
  636. case 0x00002518: /* ┘ */
  637. case 0x0000255b: /* ╛ */
  638. case 0x0000255c: /* ╜ */
  639. case 0x0000255d: /* ╝ */
  640. cch = ACS_LRCORNER;
  641. break;
  642. case 0x0000251c: /* ├ */
  643. case 0x0000255e: /* ╞ */
  644. case 0x0000255f: /* ╟ */
  645. case 0x00002560: /* ╠ */
  646. cch = ACS_LTEE;
  647. cch2 = ACS_HLINE;
  648. break;
  649. case 0x00002524: /* ┤ */
  650. case 0x00002561: /* ╡ */
  651. case 0x00002562: /* ╢ */
  652. case 0x00002563: /* ╣ */
  653. cch = ACS_RTEE;
  654. break;
  655. case 0x0000252c: /* ┬ */
  656. case 0x00002564: /* ╤ */
  657. case 0x00002565: /* ╥ */
  658. case 0x00002566: /* ╦ */
  659. cch = ACS_TTEE;
  660. cch2 = ACS_HLINE;
  661. break;
  662. case 0x00002534: /* ┴ */
  663. case 0x00002567: /* ╧ */
  664. case 0x00002568: /* ╨ */
  665. case 0x00002569: /* ╩ */
  666. cch = ACS_BTEE;
  667. cch2 = ACS_HLINE;
  668. break;
  669. case 0x0000253c: /* ┼ */
  670. case 0x0000256a: /* ╪ */
  671. case 0x0000256b: /* ╫ */
  672. case 0x0000256c: /* ╬ */
  673. cch = ACS_PLUS;
  674. cch2 = ACS_HLINE;
  675. break;
  676. case 0x00002591: /* ░ */
  677. cch = ACS_BOARD;
  678. cch2 = cch;
  679. break;
  680. case 0x00002592: /* ▒ */
  681. case 0x00002593: /* ▓ */
  682. cch = ACS_CKBOARD;
  683. cch2 = cch;
  684. break;
  685. case 0x00002580: /* ▀ */
  686. case 0x00002584: /* ▄ */
  687. case 0x00002588: /* █ */
  688. case 0x0000258c: /* ▌ */
  689. case 0x00002590: /* ▐ */
  690. case 0x000025a0: /* ■ */
  691. case 0x000025ac: /* ▬ */
  692. case 0x000025ae: /* ▮ */
  693. cch = ACS_BLOCK;
  694. cch2 = cch;
  695. break;
  696. case 0x000025c6: /* ◆ */
  697. case 0x00002666: /* ♦ */
  698. cch = ACS_DIAMOND;
  699. break;
  700. case 0x00002022: /* • */
  701. case 0x000025cb: /* ○ */
  702. case 0x000025cf: /* ● */
  703. case 0x00002603: /* ☃ */
  704. case 0x0000263c: /* ☼ */
  705. cch = ACS_LANTERN;
  706. break;
  707. case 0x0000301c: /* 〜 */
  708. cch = '~';
  709. break;
  710. }
  711. addch(cch);
  712. if(caca_utf32_is_fullwidth(ch))
  713. {
  714. addch(cch2);
  715. }
  716. }
  717. #endif
  718. }
  719. /*
  720. * Driver initialisation
  721. */
  722. int ncurses_install(caca_display_t *dp)
  723. {
  724. dp->drv.id = CACA_DRIVER_NCURSES;
  725. dp->drv.driver = "ncurses";
  726. dp->drv.init_graphics = ncurses_init_graphics;
  727. dp->drv.end_graphics = ncurses_end_graphics;
  728. dp->drv.set_display_title = ncurses_set_display_title;
  729. dp->drv.get_display_width = ncurses_get_display_width;
  730. dp->drv.get_display_height = ncurses_get_display_height;
  731. dp->drv.display = ncurses_display;
  732. dp->drv.handle_resize = ncurses_handle_resize;
  733. dp->drv.get_event = ncurses_get_event;
  734. dp->drv.set_mouse = NULL;
  735. dp->drv.set_cursor = ncurses_set_cursor;
  736. return 0;
  737. }
  738. #endif /* USE_NCURSES */