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.

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