source: libcaca/trunk/caca/driver_ncurses.c @ 2304

Last change on this file since 2304 was 2304, checked in by Sam Hocevar, 15 years ago
  • Get rid of the last long types in the API.
  • Use size_t and ssize_t where appropriate.
  • Property svn:keywords set to Id
File size: 20.9 KB
Line 
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: driver_ncurses.c 2304 2008-04-19 19:25:47Z sam $
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/*
17 *  This file contains the libcaca Ncurses input and output driver
18 */
19
20#include "config.h"
21
22#if defined USE_NCURSES
23
24#if defined HAVE_NCURSESW_NCURSES_H
25#   include <ncursesw/ncurses.h>
26#elif defined HAVE_NCURSES_NCURSES_H
27#   include <ncurses/ncurses.h>
28#elif defined HAVE_NCURSES_H
29#   include <ncurses.h>
30#else
31#   include <curses.h>
32#endif
33
34#include <stdlib.h>
35#include <string.h>
36
37#if defined HAVE_UNISTD_H
38#   include <unistd.h>
39#endif
40#if defined HAVE_SIGNAL_H
41#   include <signal.h>
42#endif
43#if defined HAVE_SYS_IOCTL_H
44#   include <sys/ioctl.h>
45#endif
46#if defined HAVE_LOCALE_H
47#   include <locale.h>
48#endif
49#if defined HAVE_TERMIOS_H
50#   include <termios.h>
51#endif
52
53#include "cucul.h"
54#include "caca.h"
55#include "caca_internals.h"
56
57/*
58 * Emulation for missing ACS_* in older curses
59 */
60
61#ifndef ACS_BLOCK
62#define ACS_BLOCK '#'
63#endif
64
65#ifndef ACS_BOARD
66#define ACS_BOARD '#'
67#endif
68
69#ifndef ACS_BTEE
70#define ACS_BTEE '+'
71#endif
72
73#ifndef ACS_BULLET
74#define ACS_BULLET '.'
75#endif
76
77#ifndef ACS_CKBOARD
78#define ACS_CKBOARD ':'
79#endif
80
81#ifndef ACS_DARROW
82#define ACS_DARROW 'v'
83#endif
84
85#ifndef ACS_DEGREE
86#define ACS_DEGREE '\''
87#endif
88
89#ifndef ACS_DIAMOND
90#define ACS_DIAMOND '+'
91#endif
92
93#ifndef ACS_GEQUAL
94#define ACS_GEQUAL '>'
95#endif
96
97#ifndef ACS_HLINE
98#define ACS_HLINE '-'
99#endif
100
101#ifndef ACS_LANTERN
102#define ACS_LANTERN '#'
103#endif
104
105#ifndef ACS_LARROW
106#define ACS_LARROW '<'
107#endif
108
109#ifndef ACS_LEQUAL
110#define ACS_LEQUAL '<'
111#endif
112
113#ifndef ACS_LLCORNER
114#define ACS_LLCORNER '+'
115#endif
116
117#ifndef ACS_LRCORNER
118#define ACS_LRCORNER '+'
119#endif
120
121#ifndef ACS_LTEE
122#define ACS_LTEE '+'
123#endif
124
125#ifndef ACS_NEQUAL
126#define ACS_NEQUAL '!'
127#endif
128
129#ifndef ACS_PI
130#define ACS_PI '*'
131#endif
132
133#ifndef ACS_STERLING
134#define ACS_STERLING 'f'
135#endif
136
137#ifndef ACS_PLMINUS
138#define ACS_PLMINUS '#'
139#endif
140
141#ifndef ACS_PLUS
142#define ACS_PLUS '+'
143#endif
144
145#ifndef ACS_RARROW
146#define ACS_RARROW '>'
147#endif
148
149#ifndef ACS_RTEE
150#define ACS_RTEE '+'
151#endif
152
153#ifndef ACS_S1
154#define ACS_S1 '-'
155#endif
156
157#ifndef ACS_S3
158#define ACS_S3 '-'
159#endif
160
161#ifndef ACS_S7
162#define ACS_S7 '-'
163#endif
164
165#ifndef ACS_S9
166#define ACS_S9 '-'
167#endif
168
169#ifndef ACS_TTEE
170#define ACS_TTEE '+'
171#endif
172
173#ifndef ACS_UARROW
174#define ACS_UARROW '^'
175#endif
176
177#ifndef ACS_ULCORNER
178#define ACS_ULCORNER '+'
179#endif
180
181#ifndef ACS_URCORNER
182#define ACS_URCORNER '+'
183#endif
184
185#ifndef ACS_VLINE
186#define ACS_VLINE '|'
187#endif
188
189/*
190 * Local functions
191 */
192
193#if defined HAVE_SIGNAL
194static RETSIGTYPE sigwinch_handler(int);
195static caca_display_t *sigwinch_d; /* FIXME: we ought to get rid of this */
196#endif
197#if defined HAVE_GETENV && defined HAVE_PUTENV
198static void ncurses_install_terminal(caca_display_t *);
199static void ncurses_uninstall_terminal(caca_display_t *);
200#endif
201static void ncurses_write_utf32(uint32_t);
202
203struct driver_private
204{
205    int attr[16*16];
206    mmask_t oldmask;
207    char *term;
208};
209
210static int ncurses_init_graphics(caca_display_t *dp)
211{
212    static int curses_colors[] =
213    {
214        /* Standard curses colours */
215        COLOR_BLACK,
216        COLOR_BLUE,
217        COLOR_GREEN,
218        COLOR_CYAN,
219        COLOR_RED,
220        COLOR_MAGENTA,
221        COLOR_YELLOW,
222        COLOR_WHITE,
223        /* Extra values for xterm-16color */
224        COLOR_BLACK + 8,
225        COLOR_BLUE + 8,
226        COLOR_GREEN + 8,
227        COLOR_CYAN + 8,
228        COLOR_RED + 8,
229        COLOR_MAGENTA + 8,
230        COLOR_YELLOW + 8,
231        COLOR_WHITE + 8
232    };
233
234    mmask_t newmask;
235    int fg, bg, max;
236
237    dp->drv.p = malloc(sizeof(struct driver_private));
238
239#if defined HAVE_GETENV && defined HAVE_PUTENV
240    ncurses_install_terminal(dp);
241#endif
242
243#if defined HAVE_SIGNAL
244    sigwinch_d = dp;
245    signal(SIGWINCH, sigwinch_handler);
246#endif
247
248#if defined HAVE_LOCALE_H
249    setlocale(LC_ALL, "");
250#endif
251
252    _caca_set_term_title("caca for ncurses");
253
254    initscr();
255    keypad(stdscr, TRUE);
256    nonl();
257    raw();
258    noecho();
259    nodelay(stdscr, TRUE);
260    curs_set(0);
261
262    /* Activate mouse */
263    newmask = REPORT_MOUSE_POSITION | ALL_MOUSE_EVENTS;
264    mousemask(newmask, &dp->drv.p->oldmask);
265    mouseinterval(-1); /* No click emulation */
266
267    /* Set the escape delay to a ridiculously low value */
268    ESCDELAY = 10;
269
270    /* Activate colour */
271    start_color();
272
273    /* If COLORS == 16, it means the terminal supports full bright colours
274     * using setab and setaf (will use \e[90m \e[91m etc. for colours >= 8),
275     * we can build 16*16 colour pairs.
276     * If COLORS == 8, it means the terminal does not know about bright
277     * colours and we need to get them through A_BOLD and A_BLINK (\e[1m
278     * and \e[5m). We can only build 8*8 colour pairs. */
279    max = COLORS >= 16 ? 16 : 8;
280
281    for(bg = 0; bg < max; bg++)
282        for(fg = 0; fg < max; fg++)
283        {
284            /* Use ((max + 7 - fg) % max) instead of fg so that colour 0
285             * is light gray on black. Some terminals don't like this
286             * colour pair to be redefined. */
287            int col = ((max + 7 - fg) % max) + max * bg;
288            init_pair(col, curses_colors[fg], curses_colors[bg]);
289            dp->drv.p->attr[fg + 16 * bg] = COLOR_PAIR(col);
290
291            if(max == 8)
292            {
293                /* Bright fg on simple bg */
294                dp->drv.p->attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col);
295                /* Simple fg on bright bg */
296                dp->drv.p->attr[fg + 16 * (bg + 8)] = A_BLINK
297                                                    | COLOR_PAIR(col);
298                /* Bright fg on bright bg */
299                dp->drv.p->attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD
300                                                        | COLOR_PAIR(col);
301            }
302        }
303
304    dp->resize.allow = 1;
305    cucul_set_canvas_size(dp->cv, COLS, LINES);
306    dp->resize.allow = 0;
307
308    return 0;
309}
310
311static int ncurses_end_graphics(caca_display_t *dp)
312{
313    _caca_set_term_title("");
314    mousemask(dp->drv.p->oldmask, NULL);
315    curs_set(1);
316    noraw();
317    endwin();
318
319#if defined HAVE_GETENV && defined HAVE_PUTENV
320    ncurses_uninstall_terminal(dp);
321#endif
322
323    free(dp->drv.p);
324
325    return 0;
326}
327
328static int ncurses_set_display_title(caca_display_t *dp, char const *title)
329{
330    _caca_set_term_title(title);
331
332    return 0;
333}
334
335static unsigned int ncurses_get_display_width(caca_display_t const *dp)
336{
337    /* Fallback to a 6x10 font */
338    return cucul_get_canvas_width(dp->cv) * 6;
339}
340
341static unsigned int ncurses_get_display_height(caca_display_t const *dp)
342{
343    /* Fallback to a 6x10 font */
344    return cucul_get_canvas_height(dp->cv) * 10;
345}
346
347static void ncurses_display(caca_display_t *dp)
348{
349    uint32_t const *cvchars = (uint32_t const *)cucul_get_canvas_chars(dp->cv);
350    uint32_t const *cvattrs = (uint32_t const *)cucul_get_canvas_attrs(dp->cv);
351    unsigned int width = cucul_get_canvas_width(dp->cv);
352    unsigned int height = cucul_get_canvas_height(dp->cv);
353    int x, y;
354
355    for(y = 0; y < (int)height; y++)
356    {
357        move(y, 0);
358        for(x = width; x--; )
359        {
360            attrset(dp->drv.p->attr[cucul_attr_to_ansi(*cvattrs++)]);
361            ncurses_write_utf32(*cvchars++);
362        }
363    }
364   
365    x = cucul_get_cursor_x(dp->cv);
366    y = cucul_get_cursor_y(dp->cv);
367    move(y, x);
368
369    refresh();
370}
371
372static void ncurses_handle_resize(caca_display_t *dp)
373{
374    struct winsize size;
375
376#if defined HAVE_SYS_IOCTL_H
377    if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0)
378    {
379        dp->resize.w = size.ws_col;
380        dp->resize.h = size.ws_row;
381#if defined HAVE_RESIZE_TERM
382        resize_term(dp->resize.h, dp->resize.w);
383#else
384        resizeterm(dp->resize.h, dp->resize.w);
385#endif
386        wrefresh(curscr);
387        return;
388    }
389#endif
390
391    /* Fallback */
392    dp->resize.w = cucul_get_canvas_width(dp->cv);
393    dp->resize.h = cucul_get_canvas_height(dp->cv);
394}
395
396static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev)
397{
398    int intkey;
399
400    intkey = getch();
401    if(intkey == ERR)
402    {
403        ev->type = CACA_EVENT_NONE;
404        return 0;
405    }
406
407    if(intkey < 0x7f)
408    {
409        ev->type = CACA_EVENT_KEY_PRESS;
410        ev->data.key.ch = intkey;
411        ev->data.key.utf32 = intkey;
412        ev->data.key.utf8[0] = intkey;
413        ev->data.key.utf8[1] = '\0';
414        return 1;
415    }
416
417    /* If the key was UTF-8, parse the whole sequence */
418    if(intkey >= 0x80 && intkey < 0x100)
419    {
420        int keys[7]; /* Necessary for ungetch(); */
421        char utf8[7];
422        uint32_t utf32;
423        unsigned int i;
424        size_t bytes = 0;
425
426        keys[0] = intkey;
427        utf8[0] = intkey;
428
429        for(i = 1; i < 6; i++)
430        {
431            keys[i] = getch();
432            utf8[i] = (unsigned char)keys[i];
433        }
434
435        utf8[i] = '\0';
436        utf32 = cucul_utf8_to_utf32(utf8, &bytes);
437
438        while(i > bytes)
439            ungetch(keys[--i]);
440
441        if(bytes)
442        {
443            ev->type = CACA_EVENT_KEY_PRESS;
444            ev->data.key.ch = 0;
445            ev->data.key.utf32 = utf32;
446            strcpy(ev->data.key.utf8, utf8);
447            return 1;
448        }
449    }
450
451    if(intkey == KEY_MOUSE)
452    {
453        MEVENT mevent;
454        getmouse(&mevent);
455
456        switch(mevent.bstate)
457        {
458#define PRESS(x) ev->data.mouse.button = x; \
459                 ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev)
460#define RELEASE(x) ev->data.mouse.button = x; \
461                   ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev)
462#define CLICK(x) PRESS(x); RELEASE(x)
463            case BUTTON1_PRESSED: PRESS(1); break;
464            case BUTTON1_RELEASED: RELEASE(1); break;
465            case BUTTON1_CLICKED: CLICK(1); break;
466            case BUTTON1_DOUBLE_CLICKED: CLICK(1); CLICK(1); break;
467            case BUTTON1_TRIPLE_CLICKED: CLICK(1); CLICK(1); CLICK(1); break;
468            case BUTTON1_RESERVED_EVENT: break;
469
470            case BUTTON2_PRESSED: PRESS(2); break;
471            case BUTTON2_RELEASED: RELEASE(2); break;
472            case BUTTON2_CLICKED: CLICK(2); break;
473            case BUTTON2_DOUBLE_CLICKED: CLICK(2); CLICK(2); break;
474            case BUTTON2_TRIPLE_CLICKED: CLICK(2); CLICK(2); CLICK(2); break;
475            case BUTTON2_RESERVED_EVENT: break;
476
477            case BUTTON3_PRESSED: PRESS(3); break;
478            case BUTTON3_RELEASED: RELEASE(3); break;
479            case BUTTON3_CLICKED: CLICK(3); break;
480            case BUTTON3_DOUBLE_CLICKED: CLICK(3); CLICK(3); break;
481            case BUTTON3_TRIPLE_CLICKED: CLICK(3); CLICK(3); CLICK(3); break;
482            case BUTTON3_RESERVED_EVENT: break;
483
484            case BUTTON4_PRESSED: PRESS(4); break;
485            case BUTTON4_RELEASED: RELEASE(4); break;
486            case BUTTON4_CLICKED: CLICK(4); break;
487            case BUTTON4_DOUBLE_CLICKED: CLICK(4); CLICK(4); break;
488            case BUTTON4_TRIPLE_CLICKED: CLICK(4); CLICK(4); CLICK(4); break;
489            case BUTTON4_RESERVED_EVENT: break;
490
491            default:
492                break;
493#undef PRESS
494#undef RELEASE
495#undef CLICK
496        }
497
498        if(dp->mouse.x == (unsigned int)mevent.x &&
499           dp->mouse.y == (unsigned int)mevent.y)
500            return _pop_event(dp, ev);
501
502        dp->mouse.x = mevent.x;
503        dp->mouse.y = mevent.y;
504
505        ev->type = CACA_EVENT_MOUSE_MOTION;
506        ev->data.mouse.x = dp->mouse.x;
507        ev->data.mouse.y = dp->mouse.y;
508        return 1;
509    }
510
511    switch(intkey)
512    {
513        case KEY_UP: ev->data.key.ch = CACA_KEY_UP; break;
514        case KEY_DOWN: ev->data.key.ch = CACA_KEY_DOWN; break;
515        case KEY_LEFT: ev->data.key.ch = CACA_KEY_LEFT; break;
516        case KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break;
517
518        case KEY_IC: ev->data.key.ch = CACA_KEY_INSERT; break;
519        case KEY_DC: ev->data.key.ch = CACA_KEY_DELETE; break;
520        case 0x7f:
521        case KEY_BACKSPACE: ev->data.key.ch = CACA_KEY_BACKSPACE; break;
522        case KEY_HOME: ev->data.key.ch = CACA_KEY_HOME; break;
523        case KEY_END: ev->data.key.ch = CACA_KEY_END; break;
524        case KEY_PPAGE: ev->data.key.ch = CACA_KEY_PAGEUP; break;
525        case KEY_NPAGE: ev->data.key.ch = CACA_KEY_PAGEDOWN; break;
526
527        case KEY_F(1): ev->data.key.ch = CACA_KEY_F1; break;
528        case KEY_F(2): ev->data.key.ch = CACA_KEY_F2; break;
529        case KEY_F(3): ev->data.key.ch = CACA_KEY_F3; break;
530        case KEY_F(4): ev->data.key.ch = CACA_KEY_F4; break;
531        case KEY_F(5): ev->data.key.ch = CACA_KEY_F5; break;
532        case KEY_F(6): ev->data.key.ch = CACA_KEY_F6; break;
533        case KEY_F(7): ev->data.key.ch = CACA_KEY_F7; break;
534        case KEY_F(8): ev->data.key.ch = CACA_KEY_F8; break;
535        case KEY_F(9): ev->data.key.ch = CACA_KEY_F9; break;
536        case KEY_F(10): ev->data.key.ch = CACA_KEY_F10; break;
537        case KEY_F(11): ev->data.key.ch = CACA_KEY_F11; break;
538        case KEY_F(12): ev->data.key.ch = CACA_KEY_F12; break;
539
540        default:
541            /* Unknown key */
542            ev->type = CACA_EVENT_NONE; return 0;
543    }
544
545    ev->type = CACA_EVENT_KEY_PRESS;
546    ev->data.key.utf32 = 0;
547    ev->data.key.utf8[0] = '\0';
548    return 1;
549}
550
551static void ncurses_set_cursor(caca_display_t *dp, int flags)
552{
553    curs_set(flags ? 2 : 0);
554}
555
556/*
557 * XXX: following functions are local
558 */
559
560#if defined HAVE_SIGNAL
561static RETSIGTYPE sigwinch_handler(int sig)
562{
563    sigwinch_d->resize.resized = 1;
564
565    signal(SIGWINCH, sigwinch_handler);
566}
567#endif
568
569#if defined HAVE_GETENV && defined HAVE_PUTENV
570static void ncurses_install_terminal(caca_display_t *dp)
571{
572    char *term, *colorterm;
573
574    dp->drv.p->term = NULL;
575
576    term = getenv("TERM");
577    colorterm = getenv("COLORTERM");
578
579    if(!term || strcmp(term, "xterm"))
580        return;
581
582    /* If we are using gnome-terminal, it's really a 16 colour terminal.
583     * Ditto if we are using xfce4-terminal, or Konsole. */
584    if((colorterm && (!strcmp(colorterm, "gnome-terminal")
585                       || !strcmp(colorterm, "Terminal")))
586         || getenv("KONSOLE_DCOP_SESSION"))
587    {
588        SCREEN *screen;
589        screen = newterm("xterm-16color", stdout, stdin);
590        if(screen == NULL)
591            return;
592        endwin();
593        (void)putenv("TERM=xterm-16color");
594        dp->drv.p->term = strdup(term);
595        return;
596    }
597}
598
599static void ncurses_uninstall_terminal(caca_display_t *dp)
600{
601    /* Needs to be persistent because we use putenv() */
602    static char termenv[1024];
603
604    if(!dp->drv.p->term)
605        return;
606
607    snprintf(termenv, 1023, "TERM=%s", dp->drv.p->term);
608    free(dp->drv.p->term);
609    (void)putenv(termenv);
610}
611#endif
612
613static void ncurses_write_utf32(uint32_t ch)
614{
615#if defined HAVE_NCURSESW_NCURSES_H
616    char buf[10];
617    int bytes;
618#endif
619
620    if(ch == CUCUL_MAGIC_FULLWIDTH)
621        return;
622
623#if defined HAVE_NCURSESW_NCURSES_H
624    bytes = cucul_utf32_to_utf8(buf, ch);
625    buf[bytes] = '\0';
626    addstr(buf);
627#else
628    if(ch < 0x80)
629    {
630        addch(ch);
631    }
632    else
633    {
634        chtype cch;
635        chtype cch2;
636
637        cch = '?';
638        cch2 = ' ';
639        if ((ch > 0x0000ff00) && (ch < 0x0000ff5f))
640        {
641            cch = ch - 0x0000ff00 + ' ';
642        }
643        switch (ch)
644        {
645        case 0x000000a0: /* <nbsp> */
646        case 0x00003000: /*   */
647            cch = ' ';
648            break;
649        case 0x000000a3: /* £ */
650            cch = ACS_STERLING;
651            break;
652        case 0x000000b0: /* ° */
653            cch = ACS_DEGREE;
654            break;
655        case 0x000000b1: /* ± */
656            cch = ACS_PLMINUS;
657            break;
658        case 0x000000b7: /* · */
659        case 0x00002219: /* ∙ */
660        case 0x000030fb: /* ・ */
661            cch = ACS_BULLET;
662            break;
663        case 0x000003c0: /* π */
664            cch = ACS_PI;
665            break;
666        case 0x00002018: /* ‘ */
667        case 0x00002019: /* ’ */
668            cch = '\'';
669            break;
670        case 0x0000201c: /* “ */
671        case 0x0000201d: /* ” */
672            cch = '"';
673            break;
674        case 0x00002190: /* ← */
675            cch = ACS_LARROW;
676            break;
677        case 0x00002191: /* ↑ */
678            cch = ACS_UARROW;
679            break;
680        case 0x00002192: /* → */
681            cch = ACS_RARROW;
682            break;
683        case 0x00002193: /* ↓ */
684            cch = ACS_DARROW;
685            break;
686        case 0x00002260: /* ≠ */
687            cch = ACS_NEQUAL;
688            break;
689        case 0x00002261: /* ≡ */
690            cch = '=';
691            break;
692        case 0x00002264: /* ≤ */
693            cch = ACS_LEQUAL;
694            break;
695        case 0x00002265: /* ≥ */
696            cch = ACS_GEQUAL;
697            break;
698        case 0x000023ba: /* ⎺ */
699            cch = ACS_S1;
700            cch2 = cch;
701            break;
702        case 0x000023bb: /* ⎻ */
703            cch = ACS_S3;
704            cch2 = cch;
705            break;
706        case 0x000023bc: /* ⎼ */
707            cch = ACS_S7;
708            cch2 = cch;
709            break;
710        case 0x000023bd: /* ⎽ */
711            cch = ACS_S9;
712            cch2 = cch;
713            break;
714        case 0x00002500: /* ─ */
715        case 0x00002550: /* ═ */
716            cch = ACS_HLINE;
717            cch2 = cch;
718            break;
719        case 0x00002502: /* │ */
720        case 0x00002551: /* ║ */
721            cch = ACS_VLINE;
722            break;
723        case 0x0000250c: /* ┌ */
724        case 0x00002552: /* ╒ */
725        case 0x00002553: /* ╓ */
726        case 0x00002554: /* ╔ */
727            cch = ACS_ULCORNER;
728            cch2 = ACS_HLINE;
729            break;
730        case 0x00002510: /* ┐ */
731        case 0x00002555: /* ╕ */
732        case 0x00002556: /* ╖ */
733        case 0x00002557: /* ╗ */
734            cch = ACS_URCORNER;
735            break;
736        case 0x00002514: /* └ */
737        case 0x00002558: /* ╘ */
738        case 0x00002559: /* ╙ */
739        case 0x0000255a: /* ╚ */
740            cch = ACS_LLCORNER;
741            cch2 = ACS_HLINE;
742            break;
743        case 0x00002518: /* ┘ */
744        case 0x0000255b: /* ╛ */
745        case 0x0000255c: /* ╜ */
746        case 0x0000255d: /* ╝ */
747            cch = ACS_LRCORNER;
748            break;
749        case 0x0000251c: /* ├ */
750        case 0x0000255e: /* ╞ */
751        case 0x0000255f: /* ╟ */
752        case 0x00002560: /* ╠ */
753            cch = ACS_LTEE;
754            cch2 = ACS_HLINE;
755            break;
756        case 0x00002524: /* ┤ */
757        case 0x00002561: /* ╡ */
758        case 0x00002562: /* ╢ */
759        case 0x00002563: /* ╣ */
760            cch = ACS_RTEE;
761            break;
762        case 0x0000252c: /* ┬ */
763        case 0x00002564: /* ╤ */
764        case 0x00002565: /* ╥ */
765        case 0x00002566: /* ╦ */
766            cch = ACS_TTEE;
767            cch2 = ACS_HLINE;
768            break;
769        case 0x00002534: /* ┴ */
770        case 0x00002567: /* ╧ */
771        case 0x00002568: /* ╨ */
772        case 0x00002569: /* ╩ */
773            cch = ACS_BTEE;
774            cch2 = ACS_HLINE;
775            break;
776        case 0x0000253c: /* ┼ */
777        case 0x0000256a: /* ╪ */
778        case 0x0000256b: /* ╫ */
779        case 0x0000256c: /* ╬ */
780            cch = ACS_PLUS;
781            cch2 = ACS_HLINE;
782            break;
783        case 0x00002591: /* ░ */
784            cch = ACS_BOARD;
785            cch2 = cch;
786            break;
787        case 0x00002592: /* ▒ */
788        case 0x00002593: /* ▓ */
789            cch = ACS_CKBOARD;
790            cch2 = cch;
791            break;
792        case 0x00002580: /* ▀ */
793        case 0x00002584: /* ▄ */
794        case 0x00002588: /* █ */
795        case 0x0000258c: /* ▌ */
796        case 0x00002590: /* ▐ */
797        case 0x000025a0: /* ■ */
798        case 0x000025ac: /* ▬ */
799        case 0x000025ae: /* ▮ */
800            cch = ACS_BLOCK;
801            cch2 = cch;
802            break;
803        case 0x000025c6: /* ◆ */
804        case 0x00002666: /* ♦ */
805            cch = ACS_DIAMOND;
806            break;
807        case 0x00002022: /* • */
808        case 0x000025cb: /* ○ */
809        case 0x000025cf: /* ● */
810        case 0x00002603: /* ☃ */
811        case 0x0000263c: /* ☼ */
812            cch = ACS_LANTERN;
813            break;
814        case 0x0000301c: /* 〜 */
815            cch = '~';
816            break;
817        }
818        addch(cch);
819        if(cucul_utf32_is_fullwidth(ch))
820        {
821            addch(cch2);
822        }
823    }
824#endif
825}
826
827/*
828 * Driver initialisation
829 */
830
831int ncurses_install(caca_display_t *dp)
832{
833    dp->drv.id = CACA_DRIVER_NCURSES;
834    dp->drv.driver = "ncurses";
835
836    dp->drv.init_graphics = ncurses_init_graphics;
837    dp->drv.end_graphics = ncurses_end_graphics;
838    dp->drv.set_display_title = ncurses_set_display_title;
839    dp->drv.get_display_width = ncurses_get_display_width;
840    dp->drv.get_display_height = ncurses_get_display_height;
841    dp->drv.display = ncurses_display;
842    dp->drv.handle_resize = ncurses_handle_resize;
843    dp->drv.get_event = ncurses_get_event;
844    dp->drv.set_mouse = NULL;
845    dp->drv.set_cursor = ncurses_set_cursor;
846
847    return 0;
848}
849
850#endif /* USE_NCURSES */
851
Note: See TracBrowser for help on using the repository browser.