R_CONS(3)
π R_CONS(3) β the radare2 console I/O library, bestie edition π
okay so this is r_cons from the Library Functions Manual β literally the Radare2 Console Input/Output Library API, and no cap it's kind of the moment. pull up a chair π«Ά
β¨ SYNOPSIS β¨
#include <r_cons.h>
like that's it, that's the whole vibe check to get in the door π
πΈ DESCRIPTION πΈ
bestie, r_cons is the library that handles console input/output for radare2. we're talking text output, input handling, color management, canvas drawing, and line editing. it abstracts away all the terminal operations so you get one unified interface for console interactions and don't have to rawdog escape sequences yourself π
key concepts, the main character lineup:
RConsis the main console structure managing output, input, and state.RConsCanvasallows drawing text-based graphics and layouts.RLinehandles line editing and command history.- Color palettes support theming and syntax highlighting.
- Grep functionality filters and processes output.
it's giving "we abstract the terminal so you don't have to" and honestly? iconic π
π INITIALIZATION π
these functions create, clone and free console contexts plus the ancillary state that gets used all over radare2. the whole point is you establish a working RCons instance (or duplicate its execution context) before you do any I/O or visual operations. no setup, no slay. periodt.
RCons * r_cons_new(void)β creates a new console context β¨void r_cons_free(RCons *cons)β frees a console context ποΈRCons * r_cons_singleton(void)β returns the global console singleton instance π
π OUTPUT π
output helpers format, buffer and emit text to the active console. they're the primary API radare2 command handlers use to present results, so they're designed to be safe for repeated, high-frequency use and to play nice with the grep/pager/visual layers. teamwork makes the dream work fr fr π
int r_cons_printf(RCons *cons, const char *format, ...)β prints formatted text to the consolevoid r_cons_print(RCons *cons, const char *str)β prints a string to the consolevoid r_cons_println(RCons *cons, const char *str)β prints a string followed by a newlinevoid r_cons_flush(RCons *cons)β flushes the console output buffer (the "actually send it" button π)void r_cons_newline(RCons *cons)β prints a newline character
π¦ INPUT π¦
input helpers give you both simple blocking reads and richer prompts with optional editing. interactive commands and the visual layer use these to collect user keystrokes or whole lines, and they support timeouts and pushed input for remote/automated workflows. yes, automation besties, you're included π
int r_cons_readchar(RCons *cons)β reads a single character from inputint r_cons_fgets(RCons *cons, char *buf, int len, int argc, const char **argv)β reads a line from input into the bufferchar * r_cons_input(RCons *cons, const char *msg)β prompts for user input with a messagebool r_cons_yesno(RCons *cons, int def, const char *fmt, ...)β prompts for a yes/no answer with default valueint r_cons_yesnobut(RCons *cons, int def, int but, const char *fmt, ...)β prompts for a yes/no answer with an extra single-key action. Returns'y','n', or the lower-case but key. the secret third option, we love to see it π
π§ CONTROL π§
control routines manipulate the terminal state β cursor, screen, raw mode, mouse and similar settings. you use them to prep the terminal for visual rendering, or to temporarily change behaviour while a command runs. it's the backstage crew of the whole show π¬
void r_cons_clear(RCons *cons)β clears the console screenvoid r_cons_gotoxy(RCons *cons, int x, int y)β moves the cursor to the specified positionvoid r_cons_show_cursor(RCons *cons, int cursor)β shows or hides the cursorvoid r_cons_set_raw(RCons *cons, bool is_raw)β sets raw mode for direct input handling
π COLORS π
color management APIs maintain palettes and convert palette entries into escape sequences. the output and canvas codepaths use them to apply consistent theming and highlighting across the entire UI. consistent theming?? we're obsessed π
RColor r_cons_pal_get(RCons *cons, const char *key)β gets a color from the palette by keybool r_cons_pal_set(RCons *cons, const char *key, const char *val)β sets a color in the palettevoid r_cons_pal_init(RCons *cons)β initializes the color palettevoid r_cons_pal_random(RCons *cons)β sets random colors in the palette (chaos mode, slay)char * r_cons_rgb_str(RCons *cons, char *outstr, size_t sz, RColor *rcolor)β converts a color to ANSI escape sequence string
π¨ CANVAS π¨
canvas APIs implement an off-screen textual drawing surface that you can compose and then flush to the console. the visual subsystem and custom UI widgets use canvases to build complex layouts without scattering escape sequences all through your business logic. separation of concerns?? she's beauty, she's grace π β¨
RConsCanvas * r_cons_canvas_new(RCons *cons, int w, int h, int flags)β creates a new canvas with specified dimensionsvoid r_cons_canvas_free(RConsCanvas *c)β frees a canvasvoid r_cons_canvas_write(RConsCanvas *c, const char *_s)β writes text to the canvasvoid r_cons_canvas_gotoxy(RConsCanvas *c, int x, int y)β moves the canvas cursorvoid r_cons_canvas_box(RConsCanvas *c, int x, int y, int w, int h, const char *color)β draws a box on the canvasvoid r_cons_canvas_line(RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style)β draws a line on the canvas
π GREP π
grep helpers filter and tokenize textual output so command code can set filters that limit what actually shows up. typically you apply these before printing long command outputs to the console. future you, scrolling less, thanks present you π«Ά
void r_cons_grep(RCons *cons, const char *grep)β sets grep filtering for outputvoid r_cons_grep_expression(RCons *cons, const char *str)β sets a grep expressionchar * r_cons_grep_strip(char *cmd, const char *quotestr)β strips grep commands from a string
β LINE EDITING β
line-editing utilities give you an editable input line with history and basic editing shortcuts. interactive modes that accept commands from the user use these, along with the higher-level shells embedded in radare2. pressing β and getting your last command back? that's her. that's the moment π
RLine * r_line_new(RCons *cons)β creates a new line editorvoid r_line_free(RLine *line)β frees a line editorconst char * r_line_readline(RCons *cons)β reads a line with editing capabilitiesvoid r_line_set_prompt(RLine *line, const char *prompt)β sets the prompt for line inputbool r_line_hist_add(RLine *line, const char *text)β adds a line to history
π PIXEL π
pixel buffer APIs offer a small raster-like buffer for representing monochrome or low-resolution images. the pixel renderer can convert these to character graphics and flush them out to the console. tiny buffer, big main character energy πΌοΈ
RConsPixel * r_cons_pixel_new(int w, int h)β creates a new pixel buffervoid r_cons_pixel_free(RConsPixel *p)β frees a pixel buffervoid r_cons_pixel_set(RConsPixel *p, int x, int y, ut8 v)β sets a pixel valuevoid r_cons_pixel_flush(RCons *cons, RConsPixel *p, int sx, int sy)β flushes the pixel buffer to console
π₯ EXAMPLES π₯
the examples below show common usage patterns observed across libr/core/ and the libr/cons implementation, including context cloning for background tasks, switching to raw mode for visual rendering, and basic printing/reading flows. let's get into it π
basic output:
RCons *cons = r_cons_new();
r_cons_printf(cons, "Hello, %s!\n", "world");
r_cons_flush(cons);
r_cons_free(cons);
reading input:
RCons *cons = r_cons_new();
char buf[256];
r_cons_fgets(cons, buf, sizeof(buf), 0, NULL);
r_cons_free(cons);
using colors:
RCons *cons = r_cons_new();
RColor red = r_cons_pal_get(cons, "red");
char *color_str = r_cons_rgb_str(cons, NULL, 0, &red);
r_cons_printf(cons, "%sError!%s\n", color_str, Color_RESET);
free(color_str);
r_cons_flush(cons);
r_cons_free(cons);
canvas drawing:
RCons *cons = r_cons_new();
RConsCanvas *canvas = r_cons_canvas_new(cons, 80, 24, 0);
r_cons_canvas_box(canvas, 10, 5, 20, 10, Color_BLUE);
r_cons_canvas_write_at(canvas, "Hello", 15, 10);
r_cons_canvas_print(canvas);
r_cons_canvas_free(canvas);
r_cons_free(cons);
line editing:
RCons *cons = r_cons_new();
RLine *line = r_line_new(cons);
r_line_set_prompt(line, "> ");
const char *input = r_line_readline(cons);
if (input) {
r_cons_printf(cons, "You entered: %s\n", input);
}
r_line_free(line);
r_cons_free(cons);
π SEE ALSO π
go read your siblings, they're also iconic, iykyk π«Ά
π AUTHORS π
the radare2 project team. thank you besties for your service π«‘π
okay that's the whole page, no notes. this one came to you from the Debian fam, dated September 20, 2025, and it's literally the R_CONS(3) manual page. mwah, go write some console code π
β¨π
π¦ where this page comes from
- alpine 3.24: radare2-doc 6.1.6-r0 Β· GPL-3.0-or-later AND LGPL-2.0-or-later AND LGPL-2.1-or-later
- arch rolling: radare2 6.2.2-1 Β· GPL-3.0-only AND LGPL-3.0-only
- nixos 26.05: radare2 6.1.8
- nixpkgs unstable: radare2 6.2.4
- opensuse-leap 16.0: radare2 6.2.2-bp160.1.1 Β· GPL-3.0-only AND LGPL-3.0-only
- opensuse-leap 16.0: radare2 6.2.2-bp160.1.1 Β· GPL-3.0-only AND LGPL-3.0-only
- opensuse-leap 16.0: radare2 6.2.2-bp160.1.1 Β· GPL-3.0-only AND LGPL-3.0-only
- opensuse-leap 16.0: radare2 6.2.2-bp160.1.1 Β· GPL-3.0-only AND LGPL-3.0-only
- ubuntu stonking: radare2 6.1.8+ds-1 Β· LGPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms