Default to scr.color=COLOR_MODE_16 for Alacritty on Windows ##cons

This commit is contained in:
Khairul Azhar Kasmiran 2019-05-28 00:21:17 +08:00 committed by radare
parent ffa473dde2
commit 3aed0e88d5
11 changed files with 31 additions and 19 deletions

View File

@ -115,10 +115,10 @@ static void cons_context_init(RConsContext *context, R_NULLABLE RConsContext *pa
context->log_callback = NULL;
if (parent) {
context->color = parent->color;
context->color_mode = parent->color_mode;
r_cons_pal_copy (context, parent);
} else {
context->color = COLOR_MODE_DISABLED;
context->color_mode = COLOR_MODE_DISABLED;
r_cons_pal_init (context);
}
}
@ -165,7 +165,7 @@ static inline void r_cons_write(const char *obuf, int olen) {
R_API RColor r_cons_color_random(ut8 alpha) {
RColor rcolor = {0};
if (I.context->color > COLOR_MODE_16) {
if (I.context->color_mode > COLOR_MODE_16) {
rcolor.r = r_num_rand (0xff);
rcolor.g = r_num_rand (0xff);
rcolor.b = r_num_rand (0xff);

View File

@ -458,8 +458,8 @@ static void selection_widget_draw() {
}
sel_widget->w = R_MIN (sel_widget->w, R_SELWIDGET_MAXW);
char *background_color = cons->context->color ? cons->context->pal.widget_bg : Color_INVERT_RESET;
char *selected_color = cons->context->color ? cons->context->pal.widget_sel : Color_INVERT;
char *background_color = cons->context->color_mode ? cons->context->pal.widget_bg : Color_INVERT_RESET;
char *selected_color = cons->context->color_mode ? cons->context->pal.widget_sel : Color_INVERT;
bool scrollbar = sel_widget->options_len > R_SELWIDGET_MAXH;
int scrollbar_y = 0, scrollbar_l = 0;
if (scrollbar) {

View File

@ -479,7 +479,7 @@ R_API void r_cons_grepbuf() {
Color_RESET,
NULL
};
char *out = r_print_json_indent (buf, I (context->color), " ", palette);
char *out = r_print_json_indent (buf, I (context->color_mode), " ", palette);
if (!out) {
return;
}

View File

@ -128,7 +128,7 @@ static RList *hud_filter(RList *list, char *user_input, int top_entry_n, int *cu
r_list_append (res, r_str_newf (" %c %s", first_line? '-': ' ', p));
} else {
// otherwise we need to emphasize the matching part
if (I (context->color)) {
if (I (context->color_mode)) {
int last_color_change = 0;
int last_mask = 0;
char *str = r_str_newf (" %c ", first_line? '-': ' ');

View File

@ -462,7 +462,7 @@ R_API void r_cons_pal_show() {
colors[i].bgcode,
colors[i].name);
}
switch (r_cons_singleton ()->context->color) {
switch (r_cons_singleton ()->context->color_mode) {
case COLOR_MODE_256: // 256 color palette
r_cons_pal_show_gs ();
r_cons_pal_show_256 ();
@ -595,7 +595,7 @@ static void cons_pal_update_event(RConsContext *ctx) {
if (*color) {
R_FREE (*color);
}
*color = r_cons_rgb_str_mode (ctx->color, NULL, 0, rcolor);
*color = r_cons_rgb_str_mode (ctx->color_mode, NULL, 0, rcolor);
const char *rgb = sdb_fmt ("rgb:%02x%02x%02x", rcolor->r, rcolor->g, rcolor->b);
sdb_set (db, rgb, "1", 0);
}

View File

@ -272,7 +272,7 @@ R_API char *r_cons_rgb_str_mode(RConsColorMode mode, char *outstr, size_t sz, RC
/* Return the computed color string for the specified color */
R_API char *r_cons_rgb_str(char *outstr, size_t sz, RColor *rcolor) {
return r_cons_rgb_str_mode (r_cons_singleton ()->context->color, outstr, sz, rcolor);
return r_cons_rgb_str_mode (r_cons_singleton ()->context->color_mode, outstr, sz, rcolor);
}
R_API char *r_cons_rgb_tostring(ut8 r, ut8 g, ut8 b) {

View File

@ -1136,7 +1136,7 @@ static bool cb_color(void *user, void *data) {
} else if (!strcmp (node->value, "false")) {
node->i_value = 0;
}
r_cons_singleton ()->context->color = (node->i_value > COLOR_MODE_16M)
r_cons_singleton ()->context->color_mode = (node->i_value > COLOR_MODE_16M)
? COLOR_MODE_16M: node->i_value;
r_cons_pal_update_event ();
r_print_set_flags (core->print, core->print->flags);
@ -1145,9 +1145,9 @@ static bool cb_color(void *user, void *data) {
static bool cb_color_getter(void *user, RConfigNode *node) {
(void)user;
node->i_value = r_cons_singleton ()->context->color;
node->i_value = r_cons_singleton ()->context->color_mode;
char buf[128];
r_config_node_value_format_i (buf, sizeof (buf), r_cons_singleton ()->context->color, node);
r_config_node_value_format_i (buf, sizeof (buf), r_cons_singleton ()->context->color_mode, node);
if (!node->value || strcmp (node->value, buf) != 0) {
free (node->value);
node->value = strdup (buf);

View File

@ -414,7 +414,7 @@ R_API int r_core_visual_hud(RCore *core) {
char *homehud = r_str_home (R2_HOME_HUD);
char *res = NULL;
char *p = 0;
r_cons_singleton ()->context->color = use_color;
r_cons_singleton ()->context->color_mode = use_color;
r_core_visual_showcursor (core, true);
if (c && *c && r_file_exists (c)) {
@ -469,9 +469,9 @@ R_API void r_core_visual_jump(RCore *core, ut8 ch) {
R_API void r_core_visual_append_help(RStrBuf *p, const char *title, const char **help) {
int i, max_length = 0, padding = 0;
RConsContext *cons_ctx = r_cons_singleton ()->context;
const char *pal_args_color = cons_ctx->color ? cons_ctx->pal.args : "",
*pal_help_color = cons_ctx->color ? cons_ctx->pal.help : "",
*pal_reset = cons_ctx->color ? cons_ctx->pal.reset : "";
const char *pal_args_color = cons_ctx->color_mode ? cons_ctx->pal.args : "",
*pal_help_color = cons_ctx->color_mode ? cons_ctx->pal.help : "",
*pal_reset = cons_ctx->color_mode ? cons_ctx->pal.reset : "";
for (i = 0; help[i]; i += 2) {
max_length = R_MAX (max_length, strlen (help[i]));
}

View File

@ -3920,7 +3920,7 @@ R_API void r_core_visual_colors(RCore *core) {
char *color = calloc (1, 64), cstr[32];
char preview_cmd[128] = "pd $r";
int ch, opt = 0, oopt = -1;
bool truecolor = r_cons_singleton ()->context->color == COLOR_MODE_16M;
bool truecolor = r_cons_singleton ()->context->color_mode == COLOR_MODE_16M;
char *rgb_xxx_fmt = truecolor ? "rgb:%2.2x%2.2x%2.2x ":"rgb:%x%x%x ";
const char *k;
RColor rcolor;

View File

@ -419,7 +419,7 @@ typedef struct r_cons_context_t {
bool is_interactive;
bool pageable;
RConsColorMode color;
int color_mode;
RConsPalette cpal;
RConsPrintablePalette pal;
} RConsContext;

View File

@ -399,6 +399,18 @@ static bool mustSaveHistory(RConfig *c) {
// Try to set the correct scr.color for the current terminal.
static void set_color_default(void) {
#ifdef __WINDOWS__
char *alacritty = r_sys_getenv ("ALACRITTY_LOG");
if (alacritty) {
// Despite the setting of env vars to the contrary, Alacritty on
// Windows may not actually support >16 colors out-of-the-box
// (https://github.com/jwilm/alacritty/issues/1662).
// TODO: Windows 10 version check.
r_config_set_i (r.config, "scr.color", COLOR_MODE_16);
free (alacritty);
return;
}
#endif
char *tmp = r_sys_getenv ("COLORTERM");
if (tmp) {
if ((r_str_endswith (tmp, "truecolor") || r_str_endswith (tmp, "24bit"))) {