1 #ifndef R2_CONS_H
2 #define R2_CONS_H
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include <r_types.h>
9 #include <r_util/pj.h>
10 #include <r_util/r_graph.h>
11 #include <r_util/r_hex.h>
12 #include <r_util/r_log.h>
13 #include <r_util/r_num.h>
14 #include <r_util/r_panels.h>
15 #include <r_util/r_sandbox.h>
16 #include <r_util/r_signal.h>
17 #include <r_util/r_stack.h>
18 #include <r_util/r_str.h>
19 #include <r_util/r_str_constpool.h>
20 #include <r_util/r_sys.h>
21 #include <r_util/r_file.h>
22 #include <r_vector.h>
23 #include <sdb.h>
24 #include <ht_up.h>
25
26 #include <stdio.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #if __UNIX__
31 #include <termios.h>
32 #include <sys/ioctl.h>
33 #include <sys/wait.h>
34 #include <sys/socket.h>
35 #endif
36 #if __WINDOWS__
37 #include <windows.h>
38 #include <wincon.h>
39 #include <winuser.h>
40 # ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
41 # define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
42 # endif
43 # ifndef ENABLE_VIRTUAL_TERMINAL_INPUT
44 # define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200
45 # endif
46 #else
47 #include <unistd.h>
48 #endif
49
50 /* constants */
51 #define CONS_MAX_USER 102400
52 #define CONS_BUFSZ 0x4f00
53 #define STR_IS_NULL(x) (!x || !x[0])
54
55 /* palette */
56 #define CONS_PALETTE_SIZE 22
57 #define CONS_COLORS_SIZE 21
58
59 #define R_CONS_GREP_WORDS 10
60 #define R_CONS_GREP_WORD_SIZE 64
61 #define R_CONS_GREP_TOKENS 64
62
63 R_LIB_VERSION_HEADER(r_cons);
64
65 #define R_CONS_CMD_DEPTH 100
66
67 typedef int (*RConsGetSize)(int *rows);
68 typedef int (*RConsGetCursor)(int *rows);
69 typedef bool (*RConsIsBreaked)(void);
70 typedef void (*RConsFlush)(void);
71 typedef void (*RConsGrepCallback)(const char *grep);
72
73 typedef struct r_cons_bind_t {
74 RConsGetSize get_size;
75 RConsGetCursor get_cursor;
76 PrintfCallback cb_printf;
77 RConsIsBreaked is_breaked;
78 RConsFlush cb_flush;
79 RConsGrepCallback cb_grep;
80 } RConsBind;
81
82 typedef struct r_cons_grep_t {
83 char strings[R_CONS_GREP_WORDS][R_CONS_GREP_WORD_SIZE];
84 int nstrings;
85 char *str;
86 int counter;
87 bool charCounter;
88 int less;
89 bool hud;
90 bool human;
91 int json;
92 char *json_path;
93 int range_line;
94 int line;
95 int sort;
96 int sort_row;
97 bool sort_invert;
98 int f_line; //first line
99 int l_line; //last line
100 int tokens[R_CONS_GREP_TOKENS];
101 int tokens_used;
102 int amp;
103 int zoom;
104 int zoomy; // if set then its scaled unproportionally
105 int neg;
106 int begin;
107 int end;
108 int icase;
109 } RConsGrep;
110
111 enum { ALPHA_RESET = 0x00, ALPHA_FG = 0x01, ALPHA_BG = 0x02, ALPHA_FGBG = 0x03 };
112 enum { R_CONS_ATTR_BOLD = 1u << 1,
113 R_CONS_ATTR_DIM = 1u << 2,
114 R_CONS_ATTR_ITALIC = 1u << 3,
115 R_CONS_ATTR_UNDERLINE = 1u << 4,
116 R_CONS_ATTR_BLINK = 1u << 5
117 };
118
119 typedef struct rcolor_t {
120 // bold, italic, underline, ...
121 ut8 attr;
122 ut8 a;
123 ut8 r;
124 ut8 g;
125 ut8 b;
126 ut8 r2; // Background color
127 ut8 g2; // Only used when a &= ALPHA_FGBG
128 ut8 b2;
129 st8 id16; // Mapping to 16-color table
130 } RColor;
131
132 typedef struct r_cons_palette_t {
133 RColor b0x00;
134 RColor b0x7f;
135 RColor b0xff;
136 RColor args;
137 RColor bin;
138 RColor btext;
139 RColor call;
140 RColor cjmp;
141 RColor cmp;
142 RColor comment;
143 RColor usercomment;
144 RColor creg;
145 RColor flag;
146 RColor fline;
147 RColor floc;
148 RColor flow;
149 RColor flow2;
150 RColor fname;
151 RColor help;
152 RColor input;
153 RColor invalid;
154 RColor jmp;
155 RColor label;
156 RColor math;
157 RColor mov;
158 RColor nop;
159 RColor num;
160 RColor offset;
161 RColor other;
162 RColor pop;
163 RColor prompt;
164 RColor push;
165 RColor crypto;
166 RColor reg;
167 RColor reset;
168 RColor ret;
169 RColor swi;
170 RColor trap;
171 RColor ucall;
172 RColor ujmp;
173 RColor ai_read;
174 RColor ai_write;
175 RColor ai_exec;
176 RColor ai_seq;
177 RColor ai_ascii;
178 RColor gui_cflow;
179 RColor gui_dataoffset;
180 RColor gui_background;
181 RColor gui_alt_background;
182 RColor gui_border;
183 RColor wordhl;
184 RColor linehl;
185 RColor func_var;
186 RColor func_var_type;
187 RColor func_var_addr;
188 RColor widget_bg;
189 RColor widget_sel;
190
191 /* Graph colors */
192 RColor graph_box;
193 RColor graph_box2;
194 RColor graph_box3;
195 RColor graph_box4;
196 RColor graph_true;
197 RColor graph_false;
198 RColor graph_trufae;
199 RColor graph_traced;
200 RColor graph_current;
201 RColor graph_diff_match;
202 RColor graph_diff_unmatch;
203 RColor graph_diff_unknown;
204 RColor graph_diff_new;
205 } RConsPalette;
206
207 typedef struct r_cons_printable_palette_t {
208 char *b0x00;
209 char *b0x7f;
210 char *b0xff;
211 char *args;
212 char *bin;
213 char *btext;
214 char *call;
215 char *cjmp;
216 char *cmp;
217 char *comment;
218 char *usercomment;
219 char *creg;
220 char *flag;
221 char *fline;
222 char *floc;
223 char *flow;
224 char *flow2;
225 char *fname;
226 char *help;
227 char *input;
228 char *invalid;
229 char *jmp;
230 char *label;
231 char *math;
232 char *mov;
233 char *nop;
234 char *num;
235 char *offset;
236 char *other;
237 char *pop;
238 char *prompt;
239 char *push;
240 char *crypto;
241 char *reg;
242 char *reset;
243 char *ret;
244 char *swi;
245 char *trap;
246 char *ucall;
247 char *ujmp;
248 char *ai_read;
249 char *ai_write;
250 char *ai_exec;
251 char *ai_seq;
252 char *ai_ascii;
253 char *ai_unmap;
254 char *gui_cflow;
255 char *gui_dataoffset;
256 char *gui_background;
257 char *gui_alt_background;
258 char *gui_border;
259 char *wordhl;
260 char *linehl;
261 char *func_var;
262 char *func_var_type;
263 char *func_var_addr;
264 char *widget_bg;
265 char *widget_sel;
266
267 /* graph colors */
268 char *graph_box;
269 char *graph_box2;
270 char *graph_box3;
271 char *graph_box4;
272 char *graph_diff_match;
273 char *graph_diff_unmatch;
274 char *graph_diff_unknown;
275 char *graph_diff_new;
276 char *graph_true;
277 char *graph_false;
278 char *graph_trufae;
279 char *graph_traced;
280 char *graph_current;
281 char **rainbow; // rainbow
282 int rainbow_sz; // size of rainbow
283 } RConsPrintablePalette;
284
285 typedef void (*RConsEvent)(void *);
286
287 #define CONS_MAX_ATTR_SZ 16
288
289 typedef struct r_cons_canvas_t {
290 int w;
291 int h;
292 int x;
293 int y;
294 char **b;
295 int *blen;
296 int *bsize;
297 const char *attr; //The current attr (inserted on each write)
298 HtUP *attrs; // all the different attributes <key: unsigned int loc, const char *attr>
299 RStrConstPool constpool; // Pool for non-compile-time attrs
300 int sx; // scrollx
301 int sy; // scrolly
302 int color;
303 int linemode; // 0 = diagonal , 1 = square
304 } RConsCanvas;
305
306 #define RUNECODE_MIN 0xc8 // 200
307 #define RUNECODE_LINE_VERT 0xc8
308 #define RUNECODE_LINE_CROSS 0xc9
309 #define RUNECODE_CORNER_BR 0xca
310 #define RUNECODE_CORNER_BL 0xcb
311 #define RUNECODE_ARROW_RIGHT 0xcc
312 #define RUNECODE_ARROW_LEFT 0xcd
313 #define RUNECODE_LINE_HORIZ 0xce
314 #define RUNECODE_CORNER_TL 0xcf
315 #define RUNECODE_CORNER_TR 0xd0
316 #define RUNECODE_LINE_UP 0xd1
317 #define RUNECODE_CURVE_CORNER_TL 0xd2
318 #define RUNECODE_CURVE_CORNER_TR 0xd3
319 #define RUNECODE_CURVE_CORNER_BR 0xd4
320 #define RUNECODE_CURVE_CORNER_BL 0xd5
321 #define RUNECODE_MAX 0xd6
322
323 #define RUNECODESTR_MIN 0xc8 // 200
324 #define RUNECODESTR_LINE_VERT "\xc8"
325 #define RUNECODESTR_LINE_CROSS "\xc9"
326 #define RUNECODESTR_CORNER_BR "\xca"
327 #define RUNECODESTR_CORNER_BL "\xcb"
328 #define RUNECODESTR_ARROW_RIGHT "\xcc"
329 #define RUNECODESTR_ARROW_LEFT "\xcd"
330 #define RUNECODESTR_LINE_HORIZ "\xce"
331 #define RUNECODESTR_CORNER_TL "\xcf"
332 #define RUNECODESTR_CORNER_TR "\xd0"
333 #define RUNECODESTR_LINE_UP "\xd1"
334 #define RUNECODESTR_CURVE_CORNER_TL "\xd2"
335 #define RUNECODESTR_CURVE_CORNER_TR "\xd3"
336 #define RUNECODESTR_CURVE_CORNER_BR "\xd4"
337 #define RUNECODESTR_CURVE_CORNER_BL "\xd5"
338 #define RUNECODESTR_MAX 0xd5
339
340 #define RUNE_LINE_VERT "│"
341 #define RUNE_LINE_CROSS "┼" /* ├ */
342 #define RUNE_LINE_HORIZ "─"
343 #define RUNE_LINE_UP "↑"
344 #define RUNE_CORNER_BR "┘"
345 #define RUNE_CORNER_BL "└"
346 #define RUNE_CORNER_TL "┌"
347 #define RUNE_CORNER_TR "┐"
348 #define RUNE_ARROW_RIGHT ">"
349 #define RUNE_ARROW_LEFT "<"
350 #define RUNE_CURVE_CORNER_TL "╭"
351 #define RUNE_CURVE_CORNER_TR "╮"
352 #define RUNE_CURVE_CORNER_BR "╯"
353 #define RUNE_CURVE_CORNER_BL "╰"
354 #define RUNE_LONG_LINE_HORIZ "―"
355 #define UTF_CIRCLE "\u25EF"
356 #define UTF_BLOCK "\u2588"
357
358 // Emoji
359 #define UTF8_POLICE_CARS_REVOLVING_LIGHT ""
360 #define UTF8_WHITE_HEAVY_CHECK_MARK "✅"
361 #define UTF8_SEE_NO_EVIL_MONKEY ""
362 #define UTF8_SKULL_AND_CROSSBONES "☠"
363 #define UTF8_KEYBOARD "⌨"
364 #define UTF8_LEFT_POINTING_MAGNIFYING_GLASS ""
365 #define UTF8_DOOR ""
366
367 // Variation Selectors
368 #define UTF8_VS16 "\xef\xb8\x8f"
369
370 typedef char *(*RConsEditorCallback)(void *core, const char *file, const char *str);
371 typedef int (*RConsClickCallback)(void *core, int x, int y);
372 typedef void (*RConsBreakCallback)(void *core);
373 typedef void *(*RConsSleepBeginCallback)(void *core);
374 typedef void (*RConsSleepEndCallback)(void *core, void *user);
375 typedef void (*RConsQueueTaskOneshot)(void *core, void *task, void *user);
376 typedef void (*RConsFunctionKey)(void *core, int fkey);
377
378 typedef enum { COLOR_MODE_DISABLED = 0, COLOR_MODE_16, COLOR_MODE_256, COLOR_MODE_16M } RConsColorMode;
379
380 typedef struct r_cons_context_t {
381 RConsGrep grep;
382 RStack *cons_stack;
383 char *buffer; // TODO: replace with RStrBuf
384 size_t buffer_len;
385 size_t buffer_sz;
386 RStrBuf *error; // r_cons_eprintf / r_cons_errstr / r_cons_errmode
387 int errmode;
388 bool breaked;
389 RStack *break_stack;
390 RConsEvent event_interrupt;
391 void *event_interrupt_data;
392 int cmd_depth;
393
394 // Used for per-task logging redirection
395 RLogCallback log_callback; // TODO: RList of callbacks
396
397 char *lastOutput;
398 int lastLength;
399 bool lastMode;
400 bool lastEnabled;
401 bool is_interactive;
402 bool pageable;
403
404 int color_mode;
405 RConsPalette cpal;
406 RConsPrintablePalette pal;
407 } RConsContext;
408
409 #define HUD_BUF_SIZE 512
410
411 typedef struct {
412 int x;
413 int y;
414 } RConsCursorPos;
415
416 typedef struct r_cons_t {
417 RConsContext *context;
418 char *lastline;
419 bool is_html;
420 bool was_html;
421 int lines;
422 int rows;
423 int echo; // dump to stdout in realtime
424 int fps;
425 int columns;
426 int force_rows;
427 int force_columns;
428 int fix_rows;
429 int fix_columns;
430 bool break_lines;
431 int noflush;
432 bool show_autocomplete_widget;
433 FILE *fdin; // FILE? and then int ??
434 int fdout; // only used in pipe.c :?? remove?
435 const char *teefile;
436 int (*user_fgets)(char *buf, int len);
437 RConsEvent event_resize;
438 void *event_data;
439 int mouse_event;
440
441 RConsEditorCallback cb_editor;
442 RConsBreakCallback cb_break;
443 RConsSleepBeginCallback cb_sleep_begin;
444 RConsSleepEndCallback cb_sleep_end;
445 RConsClickCallback cb_click;
446 RConsQueueTaskOneshot cb_task_oneshot;
447 RConsFunctionKey cb_fkey;
448
449 void *user; // Used by <RCore*>
450 #if __UNIX__
451 struct termios term_raw, term_buf;
452 #elif __WINDOWS__
453 DWORD term_raw, term_buf, term_xterm;
454 UINT old_cp;
455 #endif
456 RNum *num;
457 /* Pager (like more or less) to use if the output doesn't fit on the
458 * current window. If NULL or "" no pager is used. */
459 char *pager;
460 int blankline;
461 char *highlight;
462 bool enable_highlight;
463 int null; // if set, does not show anything
464 int mouse;
465 int is_wine;
466 struct r_line_t *line;
467 const char **vline;
468 int refcnt;
469 R_DEPRECATE bool newline;
470 int vtmode;
471 bool flush;
472 bool use_utf8; // use utf8 features
473 bool use_utf8_curvy; // use utf8 curved corners
474 bool dotted_lines;
475 int linesleep;
476 int pagesize;
477 char *break_word;
478 int break_word_len;
479 ut64 timeout; // must come from r_time_now_mono()
480 bool grep_color;
481 bool grep_highlight;
482 bool use_tts;
483 bool filter;
484 char* (*rgbstr)(char *str, size_t sz, ut64 addr);
485 bool click_set;
486 int click_x;
487 int click_y;
488 bool show_vals; // show which section in Vv
489 // TODO: move into instance? + avoid unnecessary copies
490 RConsCursorPos cpos;
491 } RCons;
492
493 #define R_CONS_KEY_F1 0xf1
494 #define R_CONS_KEY_F2 0xf2
495 #define R_CONS_KEY_F3 0xf3
496 #define R_CONS_KEY_F4 0xf4
497 #define R_CONS_KEY_F5 0xf5
498 #define R_CONS_KEY_F6 0xf6
499 #define R_CONS_KEY_F7 0xf7
500 #define R_CONS_KEY_F8 0xf8
501 #define R_CONS_KEY_F9 0xf9
502 #define R_CONS_KEY_F10 0xfa
503 #define R_CONS_KEY_F11 0xfb
504 #define R_CONS_KEY_F12 0xfc
505
506 #define R_CONS_KEY_ESC 0x1b
507
508 #define R_CONS_CLEAR_LINE "\x1b[2K\r"
509 #define R_CONS_CLEAR_SCREEN "\x1b[2J\r"
510 #define R_CONS_CLEAR_FROM_CURSOR_TO_END "\x1b[0J\r"
511
512 #define R_CONS_CURSOR_SAVE "\x1b[s"
513 #define R_CONS_CURSOR_RESTORE "\x1b[u"
514 #define R_CONS_GET_CURSOR_POSITION "\x1b[6n"
515 #define R_CONS_CURSOR_UP "\x1b[A"
516 #define R_CONS_CURSOR_DOWN "\x1b[B"
517 #define R_CONS_CURSOR_RIGHT "\x1b[C"
518 #define R_CONS_CURSOR_LEFT "\x1b[D"
519
520 #define Color_BLINK "\x1b[5m"
521 #define Color_INVERT "\x1b[7m"
522 #define Color_INVERT_RESET "\x1b[27m"
523 /* See 'man 4 console_codes' for details:
524 * "ESC c" -- Reset
525 * "ESC ( K" -- Select user mapping
526 * "ESC [ 0 m" -- Reset all display attributes
527 * "ESC [ J" -- Erase to the end of screen
528 * "ESC [ ? 25 h" -- Make cursor visible
529 */
530 #define Color_RESET_TERMINAL "\x1b" "c\x1b(K\x1b[0m\x1b[J\x1b[?25h"
531 #define Color_RESET "\x1b[0m" /* reset all */
532 #define Color_RESET_NOBG "\x1b[27;22;24;25;28;39m" /* Reset everything except background (order is important) */
533 #define Color_RESET_BG "\x1b[49m"
534 #define Color_RESET_ALL "\x1b[0m\x1b[49m"
535 #define Color_BLACK "\x1b[30m"
536 #define Color_BGBLACK "\x1b[40m"
537 #define Color_RED "\x1b[31m"
538 #define Color_BGRED "\x1b[41m"
539 #define Color_WHITE "\x1b[37m"
540 #define Color_BGWHITE "\x1b[47m"
541 #define Color_GREEN "\x1b[32m"
542 #define Color_BGGREEN "\x1b[42m"
543 #define Color_MAGENTA "\x1b[35m"
544 #define Color_BGMAGENTA "\x1b[45m"
545 #define Color_YELLOW "\x1b[33m"
546 #define Color_BGYELLOW "\x1b[43m"
547 #define Color_CYAN "\x1b[36m"
548 #define Color_BGCYAN "\x1b[46m"
549 #define Color_BLUE "\x1b[34m"
550 #define Color_BGBLUE "\x1b[44m"
551 #define Color_GRAY "\x1b[90m"
552 #define Color_BGGRAY "\x1b[100m"
553 /* bright colors */
554 #define Color_BBLACK Color_GRAY
555 #define Color_BBGBLACK Color_BGGRAY
556 #define Color_BRED "\x1b[91m"
557 #define Color_BBGRED "\x1b[101m"
558 #define Color_BWHITE "\x1b[97m"
559 #define Color_BBGWHITE "\x1b[107m"
560 #define Color_BGREEN "\x1b[92m"
561 #define Color_BBGGREEN "\x1b[102m"
562 #define Color_BMAGENTA "\x1b[95m"
563 #define Color_BBGMAGENTA "\x1b[105m"
564 #define Color_BYELLOW "\x1b[93m"
565 #define Color_BBGYELLOW "\x1b[103m"
566 #define Color_BCYAN "\x1b[96m"
567 #define Color_BBGCYAN "\x1b[106m"
568 #define Color_BBLUE "\x1b[94m"
569 #define Color_BBGBLUE "\x1b[104m"
570
571 #ifdef _MSC_VER
572 #define RCOLOR(a, r, g, b, bgr, bgg, bgb, id16) {0, a, r, g, b, bgr, bgg, bgb, id16}
573 #else
574 #define RCOLOR(a, r, g, b, bgr, bgg, bgb, id16) (RColor) {0, a, r, g, b, bgr, bgg, bgb, id16}
575 #endif
576 #define RColor_NULL RCOLOR(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1)
577 #if __WINDOWS__
578 #define RColor_BLACK RCOLOR(ALPHA_FG, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0)
579 #define RColor_BGBLACK RCOLOR(ALPHA_BG, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0)
580 #define RColor_RED RCOLOR(ALPHA_FG, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 1)
581 #define RColor_BGRED RCOLOR(ALPHA_BG, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 1)
582 #define RColor_WHITE RCOLOR(ALPHA_FG, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 7)
583 #define RColor_BGWHITE RCOLOR(ALPHA_BG, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 7)
584 #define RColor_GREEN RCOLOR(ALPHA_FG, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 2)
585 #define RColor_BGGREEN RCOLOR(ALPHA_BG, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 2)
586 #define RColor_MAGENTA RCOLOR(ALPHA_FG, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 5)
587 #define RColor_BGMAGENTA RCOLOR(ALPHA_BG, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 5)
588 #define RColor_YELLOW RCOLOR(ALPHA_FG, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 3)
589 #define RColor_BGYELLOW RCOLOR(ALPHA_BG, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 3)
590 #define RColor_CYAN RCOLOR(ALPHA_FG, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 6)
591 #define RColor_BGCYAN RCOLOR(ALPHA_BG, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 6)
592 #define RColor_BLUE RCOLOR(ALPHA_FG, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 4)
593 #define RColor_BGBLUE RCOLOR(ALPHA_BG, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 4)
594 #define RColor_BBLACK RCOLOR(ALPHA_FG, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 8)
595 #define RColor_BBGBLACK RCOLOR(ALPHA_BG, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 8)
596 #define RColor_BRED RCOLOR(ALPHA_FG, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 9)
597 #define RColor_BBGRED RCOLOR(ALPHA_BG, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 9)
598 #define RColor_BWHITE RCOLOR(ALPHA_FG, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 15)
599 #define RColor_BBGWHITE RCOLOR(ALPHA_BG, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 15)
600 #define RColor_BGREEN RCOLOR(ALPHA_FG, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 10)
601 #define RColor_BBGGREEN RCOLOR(ALPHA_BG, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 10)
602 #define RColor_BMAGENTA RCOLOR(ALPHA_FG, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 13)
603 #define RColor_BBGMAGENTA RCOLOR(ALPHA_BG, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 13)
604 #define RColor_BYELLOW RCOLOR(ALPHA_FG, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 11)
605 #define RColor_BBGYELLOW RCOLOR(ALPHA_BG, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 11)
606 #define RColor_BCYAN RCOLOR(ALPHA_FG, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 14)
607 #define RColor_BBGCYAN RCOLOR(ALPHA_BG, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 14)
608 #define RColor_BBLUE RCOLOR(ALPHA_FG, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 12)
609 #define RColor_BBGBLUE RCOLOR(ALPHA_BG, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 12)
610 #else
611 // Campbell (https://devblogs.microsoft.com/commandline/updating-the-windows-console-colors/).
612 // Not used on Windows since cmd.exe doesn't support bold (needed for easier
613 // differentiation between normal and bright color text for some colors).
614 #define RColor_BLACK RCOLOR(ALPHA_FG, 12, 12, 12, 0x00, 0x00, 0x00, 0)
615 #define RColor_BGBLACK RCOLOR(ALPHA_BG, 12, 12, 12, 0x00, 0x00, 0x00, 0)
616 #define RColor_RED RCOLOR(ALPHA_FG, 197, 15, 31, 0x00, 0x00, 0x00, 1)
617 #define RColor_BGRED RCOLOR(ALPHA_BG, 197, 15, 31, 0x00, 0x00, 0x00, 1)
618 #define RColor_WHITE RCOLOR(ALPHA_FG, 204, 204, 204, 0x00, 0x00, 0x00, 7)
619 #define RColor_BGWHITE RCOLOR(ALPHA_BG, 204, 204, 204, 0x00, 0x00, 0x00, 7)
620 #define RColor_GREEN RCOLOR(ALPHA_FG, 19, 161, 14, 0x00, 0x00, 0x00, 2)
621 #define RColor_BGGREEN RCOLOR(ALPHA_BG, 19, 161, 14, 0x00, 0x00, 0x00, 2)
622 #define RColor_MAGENTA RCOLOR(ALPHA_FG, 136, 23, 152, 0x00, 0x00, 0x00, 5)
623 #define RColor_BGMAGENTA RCOLOR(ALPHA_BG, 136, 23, 152, 0x00, 0x00, 0x00, 5)
624 #define RColor_YELLOW RCOLOR(ALPHA_FG, 193, 156, 0, 0x00, 0x00, 0x00, 3)
625 #define RColor_BGYELLOW RCOLOR(ALPHA_BG, 193, 156, 0, 0x00, 0x00, 0x00, 3)
626 #define RColor_CYAN RCOLOR(ALPHA_FG, 58, 150, 221, 0x00, 0x00, 0x00, 6)
627 #define RColor_BGCYAN RCOLOR(ALPHA_BG, 58, 150, 221, 0x00, 0x00, 0x00, 6)
628 #define RColor_BLUE RCOLOR(ALPHA_FG, 0, 55, 218, 0x00, 0x00, 0x00, 4)
629 #define RColor_BGBLUE RCOLOR(ALPHA_BG, 0, 55, 218, 0x00, 0x00, 0x00, 4)
630 #define RColor_BBLACK RCOLOR(ALPHA_FG, 118, 118, 118, 0x00, 0x00, 0x00, 8)
631 #define RColor_BBGBLACK RCOLOR(ALPHA_BG, 118, 118, 118, 0x00, 0x00, 0x00, 8)
632 #define RColor_BRED RCOLOR(ALPHA_FG, 231, 72, 86, 0x00, 0x00, 0x00, 9)
633 #define RColor_BBGRED RCOLOR(ALPHA_BG, 231, 72, 86, 0x00, 0x00, 0x00, 9)
634 #define RColor_BWHITE RCOLOR(ALPHA_FG, 242, 242, 242, 0x00, 0x00, 0x00, 15)
635 #define RColor_BBGWHITE RCOLOR(ALPHA_BG, 242, 242, 242, 0x00, 0x00, 0x00, 15)
636 #define RColor_BGREEN RCOLOR(ALPHA_FG, 22, 198, 12, 0x00, 0x00, 0x00, 10)
637 #define RColor_BBGGREEN RCOLOR(ALPHA_BG, 22, 198, 12, 0x00, 0x00, 0x00, 10)
638 #define RColor_BMAGENTA RCOLOR(ALPHA_FG, 180, 0, 158, 0x00, 0x00, 0x00, 13)
639 #define RColor_BBGMAGENTA RCOLOR(ALPHA_BG, 180, 0, 158, 0x00, 0x00, 0x00, 13)
640 #define RColor_BYELLOW RCOLOR(ALPHA_FG, 249, 241, 165, 0x00, 0x00, 0x00, 11)
641 #define RColor_BBGYELLOW RCOLOR(ALPHA_BG, 249, 241, 165, 0x00, 0x00, 0x00, 11)
642 #define RColor_BCYAN RCOLOR(ALPHA_FG, 97, 214, 214, 0x00, 0x00, 0x00, 14)
643 #define RColor_BBGCYAN RCOLOR(ALPHA_BG, 97, 214, 214, 0x00, 0x00, 0x00, 14)
644 #define RColor_BBLUE RCOLOR(ALPHA_FG, 59, 120, 255, 0x00, 0x00, 0x00, 12)
645 #define RColor_BBGBLUE RCOLOR(ALPHA_BG, 59, 120, 255, 0x00, 0x00, 0x00, 12)
646 #endif
647 #define RColor_GRAY RColor_BBLACK
648 #define RColor_BGGRAY RColor_BBGBLACK
649
650 #define Colors_PLAIN { \
651 Color_BLACK, Color_RED, Color_WHITE, \
652 Color_GREEN, Color_MAGENTA, Color_YELLOW, \
653 Color_CYAN, Color_BLUE, Color_GRAY}
654
655 enum {
656 PAL_PROMPT = 0,
657 PAL_ADDRESS,
658 PAL_DEFAULT,
659 PAL_CHANGED,
660 PAL_JUMP,
661 PAL_CALL,
662 PAL_PUSH,
663 PAL_TRAP,
664 PAL_CMP,
665 PAL_RET,
666 PAL_NOP,
667 PAL_METADATA,
668 PAL_HEADER,
669 PAL_PRINTABLE,
670 PAL_LINES0,
671 PAL_LINES1,
672 PAL_LINES2,
673 PAL_00,
674 PAL_7F,
675 PAL_FF
676 };
677
678 /* canvas line colors */
679 enum {
680 LINE_NONE = 0,
681 LINE_TRUE,
682 LINE_FALSE,
683 LINE_UNCJMP,
684 LINE_NOSYM_VERT,
685 LINE_NOSYM_HORIZ
686 };
687
688 typedef enum {
689 INSERT_MODE = 'i',
690 CONTROL_MODE = 'c'
691 } RViMode;
692
693 #define DOT_STYLE_NORMAL 0
694 #define DOT_STYLE_CONDITIONAL 1
695 #define DOT_STYLE_BACKEDGE 2
696
697 typedef struct r_cons_canvas_line_style_t {
698 int color;
699 int symbol;
700 int dot_style;
701 } RCanvasLineStyle;
702
703 // UTF-8 symbols indexes
704 // XXX. merge with RUNE/RUNECODE/RUNECODESTR
705 #if 0
706 #define LINE_VERT 0
707 #define LINE_CROSS 1
708 #define LINE_HORIZ 2
709 #define LINE_UP 3
710 #define CORNER_BR 4
711 #define CORNER_BL 5
712 #define CORNER_TL 6
713 #define CORNER_TR 7
714 #define ARROW_RIGHT 8
715 #define ARROW_LEFT 9
716 #else
717 #define LINE_VERT 0
718 #define LINE_CROSS 1
719 #define LINE_HORIZ 2
720 #define LINE_UP 3
721 #define CORNER_TL 6
722 #define CORNER_BR 4
723 #define CORNER_BL 5
724 #define CORNER_TR 6
725 #define ARROW_RIGHT 8
726 #define ARROW_LEFT 9
727 #endif
728
729
730 #ifdef R_API
731 R_API void r_cons_image(const ut8 *buf, int bufsz, int width, int mode);
732 R_API RConsCanvas* r_cons_canvas_new(int w, int h);
733 R_API void r_cons_canvas_free(RConsCanvas *c);
734 R_API void r_cons_canvas_clear(RConsCanvas *c);
735 R_API void r_cons_canvas_print(RConsCanvas *c);
736 R_API void r_cons_canvas_print_region(RConsCanvas *c);
737 R_API char *r_cons_canvas_to_string(RConsCanvas *c);
738 R_API void r_cons_canvas_attr(RConsCanvas *c,const char * attr);
739 R_API void r_cons_canvas_write(RConsCanvas *c, const char *_s);
740 R_API bool r_cons_canvas_gotoxy(RConsCanvas *c, int x, int y);
741 R_API void r_cons_canvas_goto_write(RConsCanvas *c,int x,int y, const char * s);
742 R_API void r_cons_canvas_box(RConsCanvas *c, int x, int y, int w, int h, const char *color);
743 R_API void r_cons_canvas_circle(RConsCanvas *c, int x, int y, int w, int h, const char *color);
744 R_API void r_cons_canvas_line(RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style);
745 R_API void r_cons_canvas_line_diagonal(RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style);
746 R_API void r_cons_canvas_line_square(RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style);
747 R_API int r_cons_canvas_resize(RConsCanvas *c, int w, int h);
748 R_API void r_cons_canvas_fill(RConsCanvas *c, int x, int y, int w, int h, char ch);
749 R_API void r_cons_canvas_line_square_defined (RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style, int bendpoint, int isvert);
750 R_API void r_cons_canvas_line_back_edge (RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style, int ybendpoint1, int xbendpoint, int ybendpoint2, int isvert);
751 R_API RCons *r_cons_new(void);
752 R_API RCons *r_cons_singleton(void);
753 R_API RCons *r_cons_free(void);
754 R_API char *r_cons_lastline(int *size);
755 R_API char *r_cons_lastline_utf8_ansi_len(int *len);
756 R_API void r_cons_set_click(int x, int y);
757 R_API bool r_cons_get_click(int *x, int *y);
758
759 typedef void (*RConsBreak)(void *);
760 R_API bool r_cons_is_breaked(void);
761 R_API bool r_cons_is_interactive(void);
762 R_API bool r_cons_default_context_is_interactive(void);
763 R_API void *r_cons_sleep_begin(void);
764 R_API void r_cons_sleep_end(void *user);
765
766 /* ^C */
767 R_API void r_cons_break_push(RConsBreak cb, void *user);
768 R_API void r_cons_break_pop(void);
769 R_API void r_cons_break_clear(void);
770 R_API void r_cons_breakword(const char *s);
771 R_API void r_cons_break_end(void);
772 R_API void r_cons_break_timeout(int timeout);
773
774 /* pipe */
775 R_API int r_cons_pipe_open(const char *file, int fdn, int append);
776 R_API void r_cons_pipe_close(int fd);
777
778 #if __WINDOWS__
779 R_API int r_cons_is_vtcompat(void);
780 R_API void r_cons_w32_clear(void);
781 R_API void r_cons_w32_gotoxy(int fd, int x, int y);
782 R_API int r_cons_w32_print(const char *ptr, int len, bool vmode);
783 R_API int r_cons_win_printf(bool vmode, const char *fmt, ...) R_PRINTF_CHECK(2, 3);
784 R_API int r_cons_win_eprintf(bool vmode, const char *fmt, ...) R_PRINTF_CHECK(2, 3);
785 R_API int r_cons_win_vhprintf(DWORD hdl, bool vmode, const char *fmt, va_list ap);
786 #endif
787
788 #if 0
789
790 Flush Print Buffer
791 0 0 0 null
792 0 0 1 quiet
793 0 1 0 echo
794 0 1 1 buffer
795 1 0 1 flush
796
797 #endif
798
799 enum {
800 R_CONS_ERRMODE_NULL, // no buffer no print = null
801 R_CONS_ERRMODE_QUIET, // buffer no print = quiet
802 R_CONS_ERRMODE_ECHO, // no buffer, print = like eprintf()
803 R_CONS_ERRMODE_BUFFER, // no buffer, print = like eprintf()
804 R_CONS_ERRMODE_FLUSH, // no buffer, print = like eprintf + log
805 };
806
807 R_API void r_cons_push(void);
808 R_API void r_cons_pop(void);
809 R_API RConsContext *r_cons_context_new(R_NULLABLE RConsContext *parent);
810 R_API void r_cons_context_free(RConsContext *context);
811 R_API void r_cons_context_load(RConsContext *context);
812 R_API void r_cons_context_reset(void);
813 R_API bool r_cons_context_is_main(void);
814 R_API void r_cons_context_break(RConsContext *context);
815 R_API void r_cons_context_break_push(RConsContext *context, RConsBreak cb, void *user, bool sig);
816 R_API void r_cons_context_break_pop(RConsContext *context, bool sig);
817
818 /* control */
819 R_API char *r_cons_editor(const char *file, const char *str);
820 R_API void r_cons_reset(void);
821 R_API void r_cons_reset_colors(void);
822 R_API char *r_cons_errstr(void);
823 R_API void r_cons_errmode(int mode);
824 R_API void r_cons_errmodes(const char *mode);
825 R_API int r_cons_eprintf(const char *format, ...);
826 R_API void r_cons_eflush(void);
827 R_API void r_cons_print_clear(void);
828 R_API void r_cons_echo(const char *msg);
829 R_API void r_cons_zero(void);
830 R_API void r_cons_highlight(const char *word);
831 R_API void r_cons_clear(void);
832 R_API void r_cons_clear_buffer(void);
833 R_API void r_cons_clear00(void);
834 R_API void r_cons_clear_line(int err);
835 R_API void r_cons_fill_line(void);
836 R_API void r_cons_stdout_open(const char *file, int append);
837 R_API int r_cons_stdout_set_fd(int fd);
838 R_API void r_cons_gotoxy(int x, int y);
839 R_API int r_cons_get_cur_line(void);
840 R_API void r_cons_line(int x, int y, int x2, int y2, int ch);
841 R_API void r_cons_show_cursor(int cursor);
842 R_API char *r_cons_swap_ground(const char *col);
843 R_API bool r_cons_drop(int n);
844 R_API void r_cons_chop(void);
845 R_API void r_cons_set_raw(bool b);
846 R_API void r_cons_set_interactive(bool b);
847 R_API void r_cons_set_last_interactive(void);
848 R_API void r_cons_set_utf8(bool b);
849 R_API void r_cons_grep(const char *grep);
850
851 /* output */
852 R_API int r_cons_printf(const char *format, ...) R_PRINTF_CHECK(1, 2);
853 R_API void r_cons_printf_list(const char *format, va_list ap);
854 R_API void r_cons_strcat(const char *str);
855 R_API void r_cons_strcat_at(const char *str, int x, char y, int w, int h);
856 #define r_cons_print(x) r_cons_strcat (x)
857 R_API void r_cons_println(const char* str);
858
859 R_API void r_cons_strcat_justify(const char *str, int j, char c);
860 R_API void r_cons_printat(const char *str, int x, char y);
861 R_API int r_cons_memcat(const char *str, int len);
862 R_API void r_cons_newline(void);
863 R_API void r_cons_filter(void);
864 R_API void r_cons_flush(void);
865 R_API void r_cons_print_fps (int col);
866 R_API void r_cons_last(void);
867 R_API int r_cons_less_str(const char *str, const char *exitkeys);
868 R_API void r_cons_less(void);
869 R_API void r_cons_2048(bool color);
870 R_API void r_cons_memset(char ch, int len);
871 R_API void r_cons_visual_flush(void);
872 R_API void r_cons_visual_write(char *buffer);
873 R_API bool r_cons_is_utf8(void);
874 R_API void r_cons_cmd_help(const char * help[], bool use_color);
875 R_API void r_cons_log_stub(const char *output, const char *funcname, const char *filename,
876 unsigned int lineno, unsigned int level, const char *tag, const char *fmtstr, ...) R_PRINTF_CHECK(7, 8);
877
878
879 /* input */
880 R_API int r_cons_controlz(int ch);
881 R_API int r_cons_readchar(void);
882 R_API bool r_cons_readpush(const char *str, int len);
883 R_API void r_cons_readflush(void);
884 R_API void r_cons_switchbuf(bool active);
885 R_API int r_cons_readchar_timeout(ut32 usec);
886 R_API int r_cons_any_key(const char *msg);
887 R_API int r_cons_eof(void);
888
889 R_API int r_cons_palette_init(const unsigned char *pal);
890 R_API int r_cons_pal_set(const char *key, const char *val);
891 R_API void r_cons_pal_update_event(void);
892 R_API void r_cons_pal_free(RConsContext *ctx);
893 R_API void r_cons_pal_init(RConsContext *ctx);
894 R_API void r_cons_pal_copy(RConsContext *dst, RConsContext *src);
895 R_API char *r_cons_pal_parse(const char *str, RColor *outcol);
896 R_API void r_cons_pal_random(void);
897 R_API RColor r_cons_pal_get(const char *key);
898 R_API RColor r_cons_pal_get_i(int index);
899 R_API const char *r_cons_pal_get_name(int index);
900 R_API int r_cons_pal_len(void);
901 R_API int r_cons_rgb_parse(const char *p, ut8 *r, ut8 *g, ut8 *b, ut8 *a);
902 R_API char *r_cons_rgb_tostring(ut8 r, ut8 g, ut8 b);
903 R_API void r_cons_pal_list(int rad, const char *arg);
904 R_API void r_cons_pal_show(void);
905 R_API int r_cons_get_size(int *rows);
906 R_API bool r_cons_isatty(void);
907 R_API int r_cons_get_cursor(int *rows);
908 R_API int r_cons_arrow_to_hjkl(int ch);
909 R_API char *r_cons_html_filter(const char *ptr, int *newlen);
910 R_API char *r_cons_rainbow_get(int idx, int last, bool bg);
911 R_API void r_cons_rainbow_free(RConsContext *ctx);
912 R_API void r_cons_rainbow_new(RConsContext *ctx, int sz);
913
914 R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv);
915 R_API char *r_cons_hud(RList *list, const char *prompt);
916 R_API char *r_cons_hud_path(const char *path, int dir);
917 R_API char *r_cons_hud_string(const char *s);
918 R_API char *r_cons_hud_file(const char *f);
919
920 R_API const char *r_cons_get_buffer(void);
921 R_API int r_cons_get_buffer_len(void);
922 R_API void r_cons_grep_help(void);
923 R_API void r_cons_grep_parsecmd(char *cmd, const char *quotestr);
924 R_API char * r_cons_grep_strip(char *cmd, const char *quotestr);
925 R_API void r_cons_grep_process(char * grep);
926 R_API int r_cons_grep_line(char *buf, int len); // must be static
927 R_API void r_cons_grepbuf(void);
928
929 R_API void r_cons_rgb(ut8 r, ut8 g, ut8 b, ut8 a);
930 R_API void r_cons_rgb_fgbg(ut8 r, ut8 g, ut8 b, ut8 R, ut8 G, ut8 B);
931 R_API void r_cons_rgb_init(void);
932 R_API char *r_cons_rgb_str_mode(RConsColorMode mode, char *outstr, size_t sz, RColor *rcolor);
933 R_API char *r_cons_rgb_str(char *outstr, size_t sz, RColor *rcolor);
934 R_API char *r_cons_rgb_str_off(char *outstr, size_t sz, ut64 off);
935 R_API void r_cons_color(int fg, int r, int g, int b);
936
937 R_API RColor r_cons_color_random(ut8 alpha);
938 R_API void r_cons_invert(int set, int color);
939 R_API bool r_cons_yesno(int def, const char *fmt, ...) R_PRINTF_CHECK(2, 3);
940 R_API char *r_cons_input(const char *msg);
941 R_API char *r_cons_password(const char *msg);
942 R_API bool r_cons_set_cup(bool enable);
943 R_API void r_cons_column(int c);
944 R_API int r_cons_get_column(void);
945 R_API char *r_cons_message(const char *msg);
946 R_API void r_cons_set_title(const char *str);
947 R_API bool r_cons_enable_mouse(const bool enable);
948 R_API void r_cons_enable_highlight(const bool enable);
949 R_API void r_cons_bind(RConsBind *bind);
950 R_API const char* r_cons_get_rune(const ut8 ch);
951 #endif
952
953 /* r_line */
954 #define R_LINE_BUFSIZE 4096
955 #define R_LINE_HISTSIZE 256
956
957 #define R_EDGES_X_INC 4
958
959 #define R_SELWIDGET_MAXH 15
960 #define R_SELWIDGET_MAXW 30
961 #define R_SELWIDGET_DIR_UP 0
962 #define R_SELWIDGET_DIR_DOWN 1
963
964 typedef struct r_selection_widget_t {
965 const char **options;
966 int options_len;
967 int selection;
968 int w, h;
969 int scroll;
970 bool complete_common;
971 bool direction;
972 } RSelWidget;
973
974 typedef struct r_line_hist_t {
975 char **data;
976 char *match;
977 int size;
978 int index;
979 int top;
980 int autosave;
981 bool do_setup_match;
982 } RLineHistory;
983
984 typedef struct r_line_buffer_t {
985 char data[R_LINE_BUFSIZE];
986 int index;
987 int length;
988 } RLineBuffer;
989
990 typedef struct r_hud_t {
991 int current_entry_n;
992 int top_entry_n;
993 char activate;
994 int vi;
995 } RLineHud;
996
997 typedef struct r_line_t RLine; // forward declaration
998 typedef struct r_line_comp_t RLineCompletion;
999
1000 typedef enum { R_LINE_PROMPT_DEFAULT, R_LINE_PROMPT_OFFSET, R_LINE_PROMPT_FILE } RLinePromptType;
1001
1002 typedef int (*RLineCompletionCb)(RLineCompletion *completion, RLineBuffer *buf, RLinePromptType prompt_type, void *user);
1003
1004 struct r_line_comp_t {
1005 bool opt;
1006 size_t args_limit;
1007 bool quit;
1008 RPVector args; /* <char *> */
1009 RLineCompletionCb run;
1010 void *run_user;
1011 };
1012
1013 typedef char* (*RLineEditorCb)(void *core, const char *str);
1014 typedef int (*RLineHistoryUpCb)(RLine* line);
1015 typedef int (*RLineHistoryDownCb)(RLine* line);
1016
1017 struct r_line_t {
1018 RLineCompletion completion;
1019 RLineBuffer buffer;
1020 RLineHistory history;
1021 RSelWidget *sel_widget;
1022 /* callbacks */
1023 RLineHistoryUpCb cb_history_up;
1024 RLineHistoryDownCb cb_history_down;
1025 RLineEditorCb cb_editor;
1026 // RLineFunctionKeyCb cb_fkey;
1027 RConsFunctionKey cb_fkey;
1028 /* state , TODO: use more bool */
1029 int echo;
1030 int has_echo;
1031 char *prompt;
1032 RList/*<str>*/ *kill_ring;
1033 int kill_ring_ptr;
1034 char *clipboard;
1035 int disable;
1036 void *user;
1037 int (*hist_up)(void *user);
1038 int (*hist_down)(void *user);
1039 char *contents;
1040 bool zerosep;
1041 bool enable_vi_mode;
1042 int vi_mode;
1043 bool prompt_mode;
1044 RLinePromptType prompt_type;
1045 int offset_hist_index;
1046 int file_hist_index;
1047 RLineHud *hud;
1048 RList *sdbshell_hist;
1049 RListIter *sdbshell_hist_iter;
1050 int vtmode;
1051 }; /* RLine */
1052
1053 #ifdef R_API
1054
1055 R_API RLine *r_line_new(void);
1056 R_API RLine *r_line_singleton(void);
1057 R_API void r_line_free(void);
1058 R_API char *r_line_get_prompt(void);
1059 R_API void r_line_set_prompt(const char *prompt);
1060 R_API int r_line_dietline_init(void);
1061 R_API void r_line_clipboard_push (const char *str);
1062 R_API void r_line_hist_free(void);
1063
1064 typedef int (RLineReadCallback)(void *user, const char *line);
1065 R_API const char *r_line_readline(void);
1066 R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user);
1067
1068 R_API int r_line_hist_load(const char *file);
1069 R_API int r_line_hist_add(const char *line);
1070 R_API int r_line_hist_save(const char *file);
1071 R_API int r_line_hist_label(const char *label, void (*cb)(const char*));
1072 R_API void r_line_label_show(void);
1073 R_API int r_line_hist_list(void);
1074 R_API const char *r_line_hist_get(int n);
1075
1076 R_API int r_line_set_hist_callback(RLine *line, RLineHistoryUpCb cb_up, RLineHistoryDownCb cb_down);
1077 R_API int r_line_hist_cmd_up(RLine *line);
1078 R_API int r_line_hist_cmd_down(RLine *line);
1079
1080 R_API void r_line_completion_init(RLineCompletion *completion, size_t args_limit);
1081 R_API void r_line_completion_fini(RLineCompletion *completion);
1082 R_API void r_line_completion_push(RLineCompletion *completion, const char *str);
1083 R_API void r_line_completion_set(RLineCompletion *completion, int argc, const char **argv);
1084 R_API void r_line_completion_clear(RLineCompletion *completion);
1085
1086 #define R_CONS_INVERT(x,y) (y? (x?Color_INVERT: Color_INVERT_RESET): (x?"[":"]"))
1087
1088 #endif
1089
1090 typedef int (*RPanelsMenuCallback)(void *user);
1091 typedef struct r_panels_menu_item {
1092 int n_sub, selectedIndex;
1093 char *name;
1094 struct r_panels_menu_item **sub;
1095 RPanelsMenuCallback cb;
1096 RPanel *p;
1097 } RPanelsMenuItem;
1098
1099 typedef struct r_panels_menu_t {
1100 RPanelsMenuItem *root;
1101 RPanelsMenuItem **history;
1102 int depth;
1103 int n_refresh;
1104 RPanel **refreshPanels;
1105 } RPanelsMenu;
1106
1107 typedef enum {
1108 PANEL_MODE_DEFAULT,
1109 PANEL_MODE_MENU,
1110 PANEL_MODE_ZOOM,
1111 PANEL_MODE_WINDOW,
1112 PANEL_MODE_HELP
1113 } RPanelsMode;
1114
1115 typedef enum {
1116 PANEL_FUN_SNOW,
1117 PANEL_FUN_SAKURA,
1118 PANEL_FUN_NOFUN
1119 } RPanelsFun;
1120
1121 typedef enum {
1122 PANEL_LAYOUT_DEFAULT_STATIC = 0,
1123 PANEL_LAYOUT_DEFAULT_DYNAMIC = 1
1124 } RPanelsLayout;
1125
1126 typedef struct {
1127 int x;
1128 int y;
1129 } RPanelsSnow;
1130
1131 typedef struct {
1132 RStrBuf *data;
1133 RPanelPos pos;
1134 int idx;
1135 int offset;
1136 } RModal;
1137
1138 typedef struct r_panels_t {
1139 RConsCanvas *can;
1140 RPanel **panel;
1141 int n_panels;
1142 int columnWidth;
1143 int curnode;
1144 int mouse_orig_x;
1145 int mouse_orig_y;
1146 bool autoUpdate;
1147 bool mouse_on_edge_x;
1148 bool mouse_on_edge_y;
1149 RPanelsMenu *panels_menu;
1150 Sdb *db;
1151 Sdb *rotate_db;
1152 Sdb *modal_db;
1153 HtPP *mht;
1154 RPanelsMode mode;
1155 RPanelsFun fun;
1156 RPanelsMode prevMode;
1157 RPanelsLayout layout;
1158 RList *snows;
1159 char *name;
1160 } RPanels;
1161
1162 typedef enum {
1163 DEFAULT,
1164 ROTATE,
1165 DEL,
1166 QUIT,
1167 } RPanelsRootState;
1168
1169 typedef struct r_panels_root_t {
1170 int n_panels;
1171 int cur_panels;
1172 Sdb *pdc_caches;
1173 Sdb *cur_pdc_cache;
1174 RPanels **panels;
1175 RPanelsRootState root_state;
1176 } RPanelsRoot;
1177
1178
1179 #ifdef __sun
cfmakeraw(struct termios * tm)1180 static inline void cfmakeraw(struct termios *tm) {
1181 tm->c_cflag &= ~(CSIZE | PARENB);
1182 tm->c_cflag |= CS8;
1183 tm->c_iflag &= ~(IMAXBEL | IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
1184 tm->c_oflag &= ~OPOST;
1185 tm->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
1186 }
1187 #endif
1188
1189 #ifdef __cplusplus
1190 }
1191 #endif
1192 #endif
1193