libcaca-migrating(3caca)

๐Ÿ’– NAME ๐Ÿ’–

libcaca-migrating(3caca) is the Migrating from libcaca 0.x to the 1.0 API glow-up guide, bestie ๐Ÿ’… โ€” this section literally walks you through migrating a libcaca 0.x app to the latest API version. no cap.

๐Ÿฆ‹ Overview ๐Ÿฆ‹

okay so the most important change in the libcaca 1.0 API? object-oriented design, periodt. Peep these two examples for a rough idea of what changed:

#include <caca.h>

/* libcaca program - 0.x API */
int main(void)
{
    /* Initialise libcaca */
    caca_init();
    /* Set window title */
    caca_set_window_title("Window");
    /* Choose drawing colours */
    caca_set_color(CACA_COLOR_BLACK,
                   CACA_COLOR_WHITE);
    /* Draw a string at (0, 0) */
    caca_putstr(0, 0, "Hello world!");
    /* Refresh display */
    caca_refresh();
    /* Wait for a key press event */
    caca_wait_event(CACA_EVENT_KEY_PRESS);
    /* Clean up library */
    caca_end();

    return 0;
}
#include <caca.h>

/* libcaca program - 1.0 API */
int main(void)
{
    /* Initialise libcaca */
    caca_canvas_t *cv;
    caca_display_t *dp;
    dp = caca_create_display(NULL);
    cv = caca_get_canvas(dp);
    /* Set window title */
    caca_set_display_title(dp, "Window");
    /* Choose drawing colours */
    caca_set_color_ansi(cv, CACA_BLACK,
                                   CACA_WHITE);
    /* Draw a string at (0, 0) */
    caca_put_str(cv, 0, 0, "Hello world!");
    /* Refresh display */
    caca_refresh_display();
    /* Wait for a key press event */
    caca_get_event(dp, CACA_EVENT_KEY_PRESS,
                   NULL, -1);
    /* Clean up library */
    caca_free_display(dp);

    return 0;
}

Note the following important things:

  • Most functions now take an object handle as their first argument. ๐Ÿ‘‘

๐Ÿ’… Migration strategy ๐Ÿ’…

You have two ways to migrate your application to use libcaca 1.x:

  • Port your code using the function equivalence list. This is the preferred way because new functions are thread safe and offer much more features to both the programmer and the end user. โœจ
  • Use the legacy compatibility layer. ๐Ÿซถ

Using the compatibility layer is as easy as adding the following three lines:

#include <caca.h>

/* libcaca program - 0.x API */
...

#include <caca.h>
#ifdef CACA_API_VERSION_1
#   include <caca0.h>
#endif

/* libcaca program - 0.x API */
...

The modified code is guaranteed to build both with libcaca 0.x and libcaca 1.0. ๐ŸŽ€

๐Ÿงฉ Function equivalence list ๐Ÿงฉ

โœจ Basic functions โœจ

  • caca_init() โ€” use caca_create_canvas() to create a libcaca canvas, followed by caca_create_display() to attach a libcaca display to it. Alternatively, caca_create_display() with a NULL argument will create a canvas automatically. ๐Ÿช„
  • caca_set_delay() โ€” use caca_set_display_time(). โฑ๏ธ
  • caca_get_feature() โ€” deprecated. ๐Ÿ’€
  • caca_set_feature() โ€” deprecated, see caca_set_dither_antialias(), caca_set_dither_color() and caca_set_dither_mode() instead. ๐ŸŽ›๏ธ
  • caca_get_feature_name() โ€” deprecated, see caca_get_dither_mode_list(), caca_get_dither_antialias_list() and caca_get_dither_color_list() instead. ๐Ÿ“‹
  • caca_get_rendertime() โ€” use caca_get_display_time(). โณ
  • caca_get_width() โ€” use caca_get_canvas_width(). ๐Ÿ“
  • caca_get_height() โ€” use caca_get_canvas_height(). ๐Ÿ“
  • caca_set_window_title() โ€” use caca_set_display_title(). ๐ŸชŸ
  • caca_get_window_width() โ€” use caca_get_display_width(). ๐Ÿ–ฅ๏ธ
  • caca_get_window_height() โ€” use caca_get_display_height(). ๐Ÿ–ฅ๏ธ
  • caca_refresh() โ€” use caca_refresh_display(). ๐Ÿ”„
  • caca_end() โ€” use caca_free_display() to detach the libcaca display, followed by caca_free_canvas() to free the underlying libcaca canvas. Alternatively, if the canvas was created by caca_create_display(), it will be automatically destroyed by caca_free_display(). ๐Ÿงน

๐ŸŽฎ Event handling ๐ŸŽฎ

  • caca_get_event() โ€” unchanged, but the event information retrieval changed a lot. ๐Ÿ˜ญ
  • caca_wait_event() โ€” use caca_get_event() with a timeout argument of -1. โณ
  • caca_get_mouse_x() โ€” unchanged. ๐Ÿ–ฑ๏ธ
  • caca_get_mouse_y() โ€” unchanged. ๐Ÿ–ฑ๏ธ

๐Ÿ”ค Character printing ๐Ÿ”ค

  • caca_set_color() โ€” use caca_set_color_ansi() or caca_set_color_argb(). ๐ŸŽจ
  • caca_get_fg_color() โ€” use caca_get_attr(). ๐ŸŽจ
  • caca_get_bg_color() โ€” use caca_get_attr(). ๐ŸŽจ
  • caca_get_color_name() โ€” this function is now deprecated due to major uselessness. ๐Ÿ’€
  • caca_putchar() โ€” use caca_put_char(). ๐Ÿ”ก
  • caca_putstr() โ€” use caca_put_str(). ๐Ÿ”ค
  • caca_printf() โ€” unchanged. ๐Ÿ–จ๏ธ
  • caca_clear() โ€” use caca_clear_canvas(). ๐Ÿงฝ

๐ŸŽจ Primitives drawing ๐ŸŽจ

These functions are almost unchanged, except for Unicode support and the fact that they now act on a given canvas. ๐Ÿ–Œ๏ธ

  • caca_draw_line() โ€” unchanged. ๐Ÿ“
  • caca_draw_polyline() โ€” unchanged. ๐Ÿ“
  • caca_draw_thin_line() โ€” unchanged. ๐Ÿ“
  • caca_draw_thin_polyline() โ€” unchanged. ๐Ÿ“
  • caca_draw_circle() โ€” unchanged. โญ•
  • caca_draw_ellipse() โ€” unchanged. ๐Ÿฅš
  • caca_draw_thin_ellipse() โ€” unchanged. ๐Ÿฅš
  • caca_fill_ellipse() โ€” unchanged. ๐Ÿฅš
  • caca_draw_box() โ€” unchanged, but the argument meaning changed (width and height instead of corner coordinates). ๐Ÿ“ฆ
  • caca_draw_thin_box() โ€” use caca_draw_thin_box() or caca_draw_cp437_box(), also the argument meaning changed (width and height instead of corner coordinates). ๐Ÿ“ฆ
  • caca_fill_box() โ€” unchanged, but the argument meaning changed (width and height instead of corner coordinates). ๐Ÿ“ฆ
  • caca_draw_triangle() โ€” unchanged. ๐Ÿ”บ
  • caca_draw_thin_triangle() โ€” unchanged. ๐Ÿ”บ
  • caca_fill_triangle() โ€” unchanged. ๐Ÿ”บ

๐Ÿงฎ Mathematical functions ๐Ÿงฎ

  • caca_rand() โ€” unchanged, but the second argument is different, make sure you take that into account. ๐ŸŽฒ
  • caca_sqrt() โ€” this function is now deprecated, use your system's sqrt() call instead. ๐Ÿงฎ

๐Ÿงš Sprite handling ๐Ÿงš

The newly introduced canvases can have several frames. Sprites are hence completely deprecated. ๐Ÿงš

  • caca_load_sprite() โ€” use caca_import_file(). ๐Ÿ“‚
  • caca_get_sprite_frames() โ€” use caca_get_frame_count(). ๐ŸŽž๏ธ
  • caca_get_sprite_width() โ€” use caca_get_canvas_width(). ๐Ÿ“
  • caca_get_sprite_height() โ€” use caca_get_canvas_height(). ๐Ÿ“
  • caca_get_sprite_dx() โ€” use caca_get_canvas_handle_x(). ๐Ÿงญ
  • caca_get_sprite_dy() โ€” use caca_get_canvas_handle_y(). ๐Ÿงญ
  • caca_draw_sprite() โ€” use caca_set_frame() and caca_blit(). ๐Ÿ–ผ๏ธ
  • caca_free_sprite() โ€” use caca_free_canvas(). ๐Ÿงน

๐Ÿ–ผ๏ธ Bitmap handling ๐Ÿ–ผ๏ธ

Bitmaps have been renamed to dithers, because these objects do not in fact store any pixels, they just have information on how bitmaps will be dithered. ๐ŸŽจ

  • caca_create_bitmap() โ€” use caca_create_dither(). ๐Ÿ› ๏ธ
  • caca_set_bitmap_palette() โ€” use caca_set_dither_palette(). ๐ŸŽจ
  • caca_draw_bitmap() โ€” use caca_dither_bitmap(). ๐Ÿ–ผ๏ธ
  • caca_free_bitmap() โ€” use caca_free_dither(). ๐Ÿงน

๐Ÿ› ๏ธ Compilation ๐Ÿ› ๏ธ

The caca-config utility is deprecated in favour of the standard pkg-config interface:

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

caca-config is still provided as a convenience tool but may be removed in the future. โš ๏ธ


๐Ÿ’Œ final sign-off, bestie: this manual page is libcaca-migrating(3caca) from libcaca version 0.99.beta20, dated Wed May 13 2026 09:45:08. now go forth and migrate, you absolute icon ๐Ÿ’…โœจ๐Ÿซถ
๐Ÿ“ฆ where this page comes from