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.
 
 
 
 
 
 

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