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