Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

driver_ncurses.c 20 KiB

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