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

Last change on this file since 2138 was 2138, checked in by Sam Hocevar, 13 years ago
  • Implement caca_create_display_with_driver() to specify an output driver without using environment variables..
  • Implement caca_get_display_driver() to return the current display's output driver.
  • Add a simple example program to test caca_create_display_with_driver().
File size: 1.6 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 <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    if(argc <= 1)
33    {
34        printf("Available drivers:\n");
35
36        while(*list)
37        {
38            printf("  %s (%s)\n", list[0], list[1]);
39            list += 2;
40        }
41
42        return 0;
43    }
44
45    cv = cucul_create_canvas(0, 0);
46    if(cv == NULL)
47    {
48        printf("cannot create canvas\n");
49        return -1;
50    }
51    dp = caca_create_display_with_driver(cv, argv[1]);
52    if(dp == NULL)
53    {
54        printf("cannot create display\n");
55        return -1;
56    }
57
58    cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
59    cucul_draw_line(cv, 0, 0, 9999, 0, ' ');
60    cucul_printf(cv, 1, 0, "Current driver: %s", argv[1]);
61
62    caca_refresh_display(dp);
63
64    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
65
66    caca_free_display(dp);
67    cucul_free_canvas(cv);
68
69    return 0;
70}
71
Note: See TracBrowser for help on using the repository browser.