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

Last change on this file since 2139 was 2139, checked in by Sam Hocevar, 12 years ago
  • Implemented caca_set_display_driver() to change driver at runtime.
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#include "common.h"
17
18#if !defined(__KERNEL__)
19#   include <string.h>
20#   include <stdio.h>
21#endif
22
23#include "cucul.h"
24#include "caca.h"
25
26int main(int argc, char *argv[])
27{
28    char const * const *list;
29    caca_display_t *dp;
30    cucul_canvas_t *cv;
31
32    list = caca_get_display_driver_list();
33
34    dp = caca_create_display(NULL);
35    if(dp == NULL)
36    {
37        printf("cannot create display\n");
38        return -1;
39    }
40
41    cv = caca_get_canvas(dp);
42    cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
43
44    while(1)
45    {
46        char const *driver;
47        int i, cur = 0;
48
49        cucul_put_str(cv, 1, 0, "Available drivers:");
50
51        driver = caca_get_display_driver(dp);
52
53        for(i = 0; list[i]; i += 2)
54        {
55            int match = !strcmp(list[i], driver);
56
57            if(match)
58                cur = i;
59            cucul_draw_line(cv, 0, i + 2, 9999, i + 2, ' ');
60            cucul_printf(cv, 2, i + 2, "%c %s (%s)",
61                         match ? '*' : ' ', list[i], list[i + 1]);
62        }
63
64        cucul_put_str(cv, 1, i + 2, "Switching driver in 5 seconds");
65
66        caca_refresh_display(dp);
67
68        if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 5000000))
69            break;
70
71        do
72        {
73            cur += 2;
74            if(list[cur] && !strcmp(list[cur], "raw"))
75                cur += 2;
76            if(!list[cur])
77                cur = 0;
78        }
79        while(caca_set_display_driver(dp, list[cur]));
80    }
81
82    caca_free_display(dp);
83
84    return 0;
85}
86
Note: See TracBrowser for help on using the repository browser.