source: libcaca/trunk/examples/driver.c @ 2299

Last change on this file since 2299 was 2299, checked in by Sam Hocevar, 12 years ago
  • Remove #include <stdint.h> etc. from "common.h". Instead, make sure that <cucul.h> will provide the C99 types, even if libcaca has been installed.
  • Rename what's left of "common.h" to "stubs.h".
  • Remove all references to erroneous <inttypes.h> from source files.
File size: 2.0 KB
Line 
1/*
2 *  driver        libcaca Unicode rendering test program
3 *  Copyright (c) 2007 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id$
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#include "config.h"
16
17#if !defined(__KERNEL__)
18#   include <string.h>
19#   include <stdio.h>
20#endif
21
22#include "cucul.h"
23#include "caca.h"
24
25int main(int argc, char *argv[])
26{
27    char const * const *list;
28    caca_display_t *dp;
29    cucul_canvas_t *cv;
30
31    list = caca_get_display_driver_list();
32
33    dp = caca_create_display(NULL);
34    if(dp == NULL)
35    {
36        printf("cannot create display\n");
37        return -1;
38    }
39
40    cv = caca_get_canvas(dp);
41    cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
42
43    while(1)
44    {
45        char const *driver;
46        int i, cur = 0;
47
48        cucul_put_str(cv, 1, 0, "Available drivers:");
49
50        driver = caca_get_display_driver(dp);
51
52        for(i = 0; list[i]; i += 2)
53        {
54            int match = !strcmp(list[i], driver);
55
56            if(match)
57                cur = i;
58            cucul_draw_line(cv, 0, i + 2, 9999, i + 2, ' ');
59            cucul_printf(cv, 2, i + 2, "%c %s (%s)",
60                         match ? '*' : ' ', list[i], list[i + 1]);
61        }
62
63        cucul_put_str(cv, 1, i + 2, "Switching driver in 5 seconds");
64
65        caca_refresh_display(dp);
66
67        if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 5000000))
68            break;
69
70        do
71        {
72            cur += 2;
73            if(list[cur] && !strcmp(list[cur], "raw"))
74                cur += 2;
75            if(!list[cur])
76                cur = 0;
77        }
78        while(caca_set_display_driver(dp, list[cur]));
79    }
80
81    caca_free_display(dp);
82
83    return 0;
84}
85
Note: See TracBrowser for help on using the repository browser.