libcaca-tutorial(3caca)

🌸 NAME 🌸

libcaca-tutorial β€” a libcaca tutorial, bestie. Section 3caca of the libcaca manual, and yes we're getting into it πŸ’…


✨ the hello-world-est program ever

okay so FIRST we're gonna look at a very simple working program, literally just to vibe-check that the basic libcaca functionalities are, like, actually functioning 🫢

#include <caca.h>

int main(void)
{
    caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev;

    dp = caca_create_display(NULL);
    if(!dp) return 1;
    cv = caca_get_canvas(dp);

    caca_set_display_title(dp, "Hello!");
    caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
    caca_put_str(cv, 0, 0, "This is a message");
    caca_refresh_display(dp);
    caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
    caca_free_display(dp);

    return 0;
}

πŸ¦‹ what does it even do tho

okay so breaking it down piece by piece, no cap:

  • Create a display. Physically, the display is either a window or a context in a terminal (ncurses, slang) or even the whole entire screen (VGA). like, it's giving versatile πŸ‘‘
  • Get the display's associated canvas. A canvas is the surface where literally everything happens: writing characters, sprites, strings, images... it is unavoidable, bestie, you genuinely cannot skip this one. Here the size of the canvas is set by the display.
  • Set the display's window name β€” only available in windowed displays, does nothing otherwise (so don't come for it if it's quiet in the terminal, it's just built different πŸ™ˆ).
  • Set the current canvas colours to black background and white foreground. iconic combo, honestly.
  • Write the string "This is a message" onto the canvas, using the current colour pair. slay.
  • Refresh the display, causing the text to be effectively displayed. like actually showing up on screen, which is kind of the whole point πŸ’€
  • Wait for an event of type CACA_EVENT_KEY_PRESS. just chillin' until you press something, fr fr.
  • Free the display (release memory). and here's the cute part: since it was created together with the display, the canvas will be automatically freed as well. two birds, zero extra calls, we love to see it ✨

πŸŽ€ compiling it

You can then compile this code on an UNIX-like system using the following commands (requiring pkg-config and gcc):

gcc `pkg-config --libs --cflags caca` example.c -o example

backticks and all, don't @ me, that's just how it goes 🧚


ngl that's the whole tutorial β€” go build something cute with it πŸ’–

✨ Version 0.99.beta20 ✨ β€” dated Wed May 13 2026 09:45:08, and that's the libcaca-tutorial(3caca) page, periodt πŸ’…πŸ¦‹

πŸ“¦ where this page comes from