R_CONS(3)

πŸ“¦
version 6.2.2 Β· 2 versions
  • 6.2.2 Β· alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu stonking (latest)
  • 6.0.7 Β· ubuntu resolute
, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu stonking

πŸ’– 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:

  • 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.

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 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 (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 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
  • int 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 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. 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 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 (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 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 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 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 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 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. 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 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 πŸ”₯

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