Cutter: Colurful Console - Support colors in the embedded Console

Created on 12 Sep 2018  路  9Comments  路  Source: rizinorg/cutter

Make Console widget prettier by adding a support for colors.

Currently it is only B&W:

image

Enhancement UI good first issue

All 9 comments

I would like to give it a shot..., It would be great if you allow it

This would be great @tkhurana96! Thank you! :)

Let me explain a bit about this issue --

Cutter is a GUI of the reverse engineering platform radare2 which aims to export the capabilities of the framework into a clean, fast and user-friendly QT C++ graphic user interface.

One of our widgets is the Console widget. Basically, it gives the user the options to execute radare2 commands from Cutter. But while radare2 commands supports colors - we don't have them in our current widget.

So for example, when I execute the radare2 command px (print hexadecimal) from the radare2 shell - I'll get a colorful output:
image
colors might differ between consoles

But if I'll do the same in the Console widget of Cutter, I'll get only black and white:

image

The console widget is implemented here:
https://github.com/radareorg/cutter/blob/master/src/widgets/ConsoleWidget.cpp


If you are not familiar with Cutter, I suggest you start by following the building instructions which are detailed here:
https://radareorg.github.io/cutter/index.html
basically, you need to install QT and build the project.


Come and join us on Telegram or IRC :)
Telegram: https://t.me/r2cutter

cutter on irc.freenode.net

@ITAYCOHEN, I will get started with building the project using the link you shared

@ITAYC0HEN Will start really soon working on it馃榾

Hi all, I was able to build the project succesfully, and I have gone through the code too. My finding till now is that radare2 is not sending the ANSI color sequences for commands. I have reached this portion of code:

R_API char *r_core_cmd_str(RCore *core, const char *cmd) {
    const char *static_str;
    char *retstr = NULL;
    r_cons_push ();
    if (r_core_cmd (core, cmd, 0) == -1) {
        //eprintf ("Invalid command: %s\n", cmd);
        return NULL;
    }
    r_cons_filter ();
    static_str = r_cons_get_buffer ();
    retstr = strdup (static_str? static_str: "");
    r_cons_pop ();
    return retstr;
}

@ITAYC0HEN Can you guide me what does r_cons_push does ? I tried looking into it, but couldn't get a sense of it. I am basically trying to find out how are commands(that are sent from cutter) being parsed and executed by radare. Because the return value of the above the function is the output of a command being executed, we can find why radare doesn't puts ANSI codes in the output

For radare2 to send the ANSI color, you have to make sure that the variable scr.color is different than 0.
Some commands overwrite it by default (setting it to 0), using the TempConfig class.

@xarkes Thanks, I tried setting scr.color to 2 and it works :smile: !! So, I was able to enable colors in radare2 output, here is the PR #823. Now the parsing of ANSI sequences for rendering on Qt console remains.

Screenshot of px command execution.

_Screenshot 1_ contains logs of cutter wherein the output of px from radare2 is printed to console as it is, and it is displayed with colors by the terminal.

_Screenshot 2_ contains the console in cutter where in the output of px from radare2 is printed to Qt Console in Cutter as it is and it is displayed as ANSI codes.

_Screenshot 1:_
cutter_log_px_output_with_ansi_parsed

_Screenshot 2:_
cutter_console_with_ansi_codes

Explanation:

In CommandTask.cpp's runTask method, before executing the task I save the old value for config scr.color and set it to a new value. And after the task has executed, but before signalling finished I restore the old value into scr.color.

Yeah I think that's because the console doesn't support ANSI codes.
You might want to try with scr.html = true, I think this widget can handle html.

I think that it should be closed #823

Was this page helpful?
0 / 5 - 0 ratings

Related issues

karliss picture karliss  路  3Comments

ITAYC0HEN picture ITAYC0HEN  路  4Comments

nauliajati picture nauliajati  路  3Comments

kidmose picture kidmose  路  5Comments

optizone picture optizone  路  3Comments