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

Last change on this file since 4333 was 4333, checked in by Sam Hocevar, 10 years ago

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

File size: 1.9 KB
Line 
1/*
2 *  driver        libcaca Unicode rendering test program
3 *  Copyright (c) 2007 Sam Hocevar <sam@hocevar.net>
4 *                All Rights Reserved
5 *
6 *  This program is free software. It comes without any warranty, to
7 *  the extent permitted by applicable law. You can redistribute it
8 *  and/or modify it under the terms of the Do What The Fuck You Want
9 *  To Public License, Version 2, as published by Sam Hocevar. See
10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12
13#include "config.h"
14
15#if !defined(__KERNEL__)
16#   include <string.h>
17#   include <stdio.h>
18#endif
19
20#include "caca.h"
21
22int main(int argc, char *argv[])
23{
24    char const * const *list;
25    caca_display_t *dp;
26    caca_canvas_t *cv;
27
28    list = caca_get_display_driver_list();
29
30    dp = caca_create_display(NULL);
31    if(dp == NULL)
32    {
33        printf("cannot create display\n");
34        return -1;
35    }
36
37    cv = caca_get_canvas(dp);
38    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);
39
40    while(1)
41    {
42        char const *driver;
43        int i, cur = 0;
44
45        caca_put_str(cv, 1, 0, "Available drivers:");
46
47        driver = caca_get_display_driver(dp);
48
49        for(i = 0; list[i]; i += 2)
50        {
51            int match = !strcmp(list[i], driver);
52
53            if(match)
54                cur = i;
55            caca_draw_line(cv, 0, i + 2, 9999, i + 2, ' ');
56            caca_printf(cv, 2, i + 2, "%c %s (%s)",
57                         match ? '*' : ' ', list[i], list[i + 1]);
58        }
59
60        caca_put_str(cv, 1, i + 2, "Switching driver in 5 seconds");
61
62        caca_refresh_display(dp);
63
64        if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 5000000))
65            break;
66
67        do
68        {
69            cur += 2;
70            if(list[cur] && !strcmp(list[cur], "raw"))
71                cur += 2;
72            if(!list[cur])
73                cur = 0;
74        }
75        while(caca_set_display_driver(dp, list[cur]));
76    }
77
78    caca_free_display(dp);
79
80    return 0;
81}
82
Note: See TracBrowser for help on using the repository browser.