Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

850 rindas
21 KiB

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