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()โ usecaca_create_canvas()to create a libcaca canvas, followed bycaca_create_display()to attach a libcaca display to it. Alternatively,caca_create_display()with aNULLargument will create a canvas automatically. ๐ชcaca_set_delay()โ usecaca_set_display_time(). โฑ๏ธcaca_get_feature()โ deprecated. ๐caca_set_feature()โ deprecated, seecaca_set_dither_antialias(),caca_set_dither_color()andcaca_set_dither_mode()instead. ๐๏ธcaca_get_feature_name()โ deprecated, seecaca_get_dither_mode_list(),caca_get_dither_antialias_list()andcaca_get_dither_color_list()instead. ๐caca_get_rendertime()โ usecaca_get_display_time(). โณcaca_get_width()โ usecaca_get_canvas_width(). ๐caca_get_height()โ usecaca_get_canvas_height(). ๐caca_set_window_title()โ usecaca_set_display_title(). ๐ชcaca_get_window_width()โ usecaca_get_display_width(). ๐ฅ๏ธcaca_get_window_height()โ usecaca_get_display_height(). ๐ฅ๏ธcaca_refresh()โ usecaca_refresh_display(). ๐caca_end()โ usecaca_free_display()to detach the libcaca display, followed bycaca_free_canvas()to free the underlying libcaca canvas. Alternatively, if the canvas was created bycaca_create_display(), it will be automatically destroyed bycaca_free_display(). ๐งน
๐ฎ Event handling ๐ฎ
caca_get_event()โ unchanged, but the event information retrieval changed a lot. ๐ญcaca_wait_event()โ usecaca_get_event()with a timeout argument of-1. โณcaca_get_mouse_x()โ unchanged. ๐ฑ๏ธcaca_get_mouse_y()โ unchanged. ๐ฑ๏ธ
๐ค Character printing ๐ค
caca_set_color()โ usecaca_set_color_ansi()orcaca_set_color_argb(). ๐จcaca_get_fg_color()โ usecaca_get_attr(). ๐จcaca_get_bg_color()โ usecaca_get_attr(). ๐จcaca_get_color_name()โ this function is now deprecated due to major uselessness. ๐caca_putchar()โ usecaca_put_char(). ๐กcaca_putstr()โ usecaca_put_str(). ๐คcaca_printf()โ unchanged. ๐จ๏ธcaca_clear()โ usecaca_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()โ usecaca_draw_thin_box()orcaca_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'ssqrt()call instead. ๐งฎ
๐ง Sprite handling ๐ง
The newly introduced canvases can have several frames. Sprites are hence completely deprecated. ๐ง
caca_load_sprite()โ usecaca_import_file(). ๐caca_get_sprite_frames()โ usecaca_get_frame_count(). ๐๏ธcaca_get_sprite_width()โ usecaca_get_canvas_width(). ๐caca_get_sprite_height()โ usecaca_get_canvas_height(). ๐caca_get_sprite_dx()โ usecaca_get_canvas_handle_x(). ๐งญcaca_get_sprite_dy()โ usecaca_get_canvas_handle_y(). ๐งญcaca_draw_sprite()โ usecaca_set_frame()andcaca_blit(). ๐ผ๏ธcaca_free_sprite()โ usecaca_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()โ usecaca_create_dither(). ๐ ๏ธcaca_set_bitmap_palette()โ usecaca_set_dither_palette(). ๐จcaca_draw_bitmap()โ usecaca_dither_bitmap(). ๐ผ๏ธcaca_free_bitmap()โ usecaca_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 islibcaca-migrating(3caca)from libcaca version0.99.beta20, datedWed May 13 2026 09:45:08. now go forth and migrate, you absolute icon ๐ โจ๐ซถ
๐ฆ where this page comes from
- opensuse-leap 16.0: libcaca-devel 0.99.beta20-160000.3.1 ยท WTFPL
- opensuse-leap 16.0: libcaca-devel 0.99.beta20-160000.3.1 ยท WTFPL
- opensuse-leap 16.0: libcaca-devel 0.99.beta20-160000.3.1 ยท WTFPL
- opensuse-leap 16.0: libcaca-devel 0.99.beta20-160000.3.1 ยท WTFPL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms