1libcaca-tutorial(3caca) libcaca libcaca-tutorial(3caca)
2
3
4
6 libcaca-tutorial - A libcaca tutorial
7
8 First, a very simple working program, to check for basic libcaca
9 functionalities.
10
11 #include <caca.h>
12
13 int main(void)
14 {
15 caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev;
16
17 dp = caca_create_display(NULL);
18 if(!dp) return 1;
19 cv = caca_get_canvas(dp);
20
21 caca_set_display_title(dp, "Hello!");
22 caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
23 caca_put_str(cv, 0, 0, "This is a message");
24 caca_refresh_display(dp);
25 caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
26 caca_free_display(dp);
27
28 return 0;
29 }
30
31 What does it do?
32
33 • Create a display. Physically, the display is either a window or a
34 context in a terminal (ncurses, slang) or even the whole screen
35 (VGA).
36
37 • Get the display's associated canvas. A canvas is the surface where
38 everything happens: writing characters, sprites, strings, images...
39 It is unavoidable. Here the size of the canvas is set by the display.
40
41 • Set the display's window name (only available in windowed displays,
42 does nothing otherwise).
43
44 • Set the current canvas colours to black background and white
45 foreground.
46
47 • Write the string 'This is a message' onto the canvas, using the
48 current colour pair.
49
50 • Refresh the display, causing the text to be effectively displayed.
51
52 • Wait for an event of type CACA_EVENT_KEY_PRESS.
53
54 • Free the display (release memory). Since it was created together with
55 the display, the canvas will be automatically freed as well.
56
57 You can then compile this code on an UNIX-like system using the
58 following commans (requiring pkg-config and gcc):
59
60 gcc `pkg-config --libs --cflags caca` example.c -o example
61
62
63Version 0.99.beta20 Sun Sep 24 2023 libcaca-tutorial(3caca)