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