Provided by: radare2_6.0.7+ds-1_amd64 

NAME
r_cons — Radare2 Console Input/Output Library API
SYNOPSIS
#include <r_cons.h>
DESCRIPTION
The r_cons library provides console input/output functionality for radare2, including text output, input
handling, color management, canvas drawing, and line editing. It abstracts terminal operations and
provides a unified interface for console interactions.
Key concepts:
• RCons is the main console structure managing output, input, and state.
• RConsCanvas allows drawing text-based graphics and layouts.
• RLine handles line editing and command history.
• Color palettes support theming and syntax highlighting.
• Grep functionality filters and processes output.
INITIALIZATION
Initialization functions create, clone and free console contexts and ancillary state used throughout
radare2; these are intended to establish a working `RCons` instance (or duplicate its execution context)
before any I/O or visual operations are performed.
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 are the primary API used by
radare2 command handlers to present results, so they are designed to be safe for repeated, high-frequency
use and to cooperate with grep/pager/visual layers.
int r_cons_printf(RCons *cons, const char *format, ...)
Prints formatted text to the console.
void r_cons_print(RCons *cons, const char *str)
Prints a string to the console.
void r_cons_println(RCons *cons, const char *str)
Prints a string followed by a newline.
void r_cons_flush(RCons *cons)
Flushes the console output buffer.
void r_cons_newline(RCons *cons)
Prints a newline character.
INPUT
Input helpers provide both simple blocking reads and richer prompts with optional editing; these are used
by interactive commands and the visual layer to collect user keystrokes or whole lines, and support
timeouts and pushed input for remote/automated workflows.
int r_cons_readchar(RCons *cons)
Reads a single character from input.
int r_cons_fgets(RCons *cons, char *buf, int len, int argc, const char **argv)
Reads a line from input into the buffer.
char * r_cons_input(RCons *cons, const char *msg)
Prompts for user input with a message.
bool r_cons_yesno(RCons *cons, int def, const char *fmt, ...)
Prompts for a yes/no answer with default value.
CONTROL
Control routines manipulate the terminal state (cursor, screen, raw mode, mouse and similar settings).
They are used to prepare the terminal for visual rendering or to temporarily change behaviour while a
command runs.
void r_cons_clear(RCons *cons)
Clears the console screen.
void r_cons_gotoxy(RCons *cons, int x, int y)
Moves the cursor to the specified position.
void r_cons_show_cursor(RCons *cons, int cursor)
Shows or hides the cursor.
void 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; these
functions are used by output and canvas codepaths to apply consistent theming and highlighting across the
UI.
RColor r_cons_pal_get(RCons *cons, const char *key)
Gets a color from the palette by key.
bool r_cons_pal_set(RCons *cons, const char *key, const char *val)
Sets a color in the palette.
void r_cons_pal_init(RCons *cons)
Initializes the color palette.
void r_cons_pal_random(RCons *cons)
Sets random colors in the palette.
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 can be composed and flushed to the
console; the visual subsystem and custom UI widgets use canvases to build complex layouts without
scattering escape sequences through business logic.
RConsCanvas * r_cons_canvas_new(RCons *cons, int w, int h, int flags)
Creates a new canvas with specified dimensions.
void r_cons_canvas_free(RConsCanvas *c)
Frees a canvas.
void r_cons_canvas_write(RConsCanvas *c, const char *_s)
Writes text to the canvas.
void r_cons_canvas_gotoxy(RConsCanvas *c, int x, int y)
Moves the canvas cursor.
void r_cons_canvas_box(RConsCanvas *c, int x, int y, int w, int h, const char *color)
Draws a box on the canvas.
void 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 provide filtering and tokenization of textual output so command code can set filters that
limit what is displayed; these are typically applied before printing long command outputs to the console.
void r_cons_grep(RCons *cons, const char *grep)
Sets grep filtering for output.
void r_cons_grep_expression(RCons *cons, const char *str)
Sets a grep expression.
char * r_cons_grep_strip(char *cmd, const char *quotestr)
Strips grep commands from a string.
LINE EDITING
Line-editing utilities expose an editable input line with history and basic editing shortcuts; they are
used by interactive modes that accept commands from the user and by higher-level shells embedded in
radare2.
RLine * r_line_new(RCons *cons)
Creates a new line editor.
void r_line_free(RLine *line)
Frees a line editor.
const char * r_line_readline(RCons *cons)
Reads a line with editing capabilities.
void r_line_set_prompt(RLine *line, const char *prompt)
Sets the prompt for line input.
bool 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
that may be converted to character graphics and flushed to the console by the pixel renderer.
RConsPixel * r_cons_pixel_new(int w, int h)
Creates a new pixel buffer.
void r_cons_pixel_free(RConsPixel *p)
Frees a pixel buffer.
void r_cons_pixel_set(RConsPixel *p, int x, int y, ut8 v)
Sets a pixel value.
void r_cons_pixel_flush(RCons *cons, RConsPixel *p, int sx, int sy)
Flushes the pixel buffer to console.
EXAMPLES
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. 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
r_core(3), r_util(3)
AUTHORS
The radare2 project team.
Debian September 20, 2025 R_CONS(3)