mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-27 15:10:53 +00:00
Fix aaa color under scr.ansicon=0
This commit is contained in:
parent
7c39d58768
commit
8253009c17
@ -91,8 +91,9 @@ static int bytes_utf8len(const char *s, int n) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_cons_w32_print(const ut8 *ptr, int len, bool vmode) {
|
||||
HANDLE hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
static int r_cons_w32_hprint(DWORD hdl, const ut8 *ptr, int len, bool vmode) {
|
||||
HANDLE hConsole = GetStdHandle (hdl);
|
||||
int fd = hdl == STD_OUTPUT_HANDLE ? 1 : 2;
|
||||
int esc = 0;
|
||||
int bg = 0, fg = 1|2|4|8;
|
||||
const ut8 *ptr_end, *str = ptr;
|
||||
@ -133,7 +134,7 @@ R_API int r_cons_w32_print(const ut8 *ptr, int len, bool vmode) {
|
||||
}
|
||||
if (ll > 0) {
|
||||
raw_ll = bytes_utf8len (str, ll, strlen (str));
|
||||
write (1, str, raw_ll);
|
||||
write (fd, str, raw_ll);
|
||||
linelen += ll;
|
||||
}
|
||||
esc = 0;
|
||||
@ -143,10 +144,10 @@ R_API int r_cons_w32_print(const ut8 *ptr, int len, bool vmode) {
|
||||
char white[1024];
|
||||
if (wlen > 0 && wlen < sizeof (white)) {
|
||||
memset (white, ' ', sizeof (white));
|
||||
write (1, white, wlen-1);
|
||||
write (fd, white, wlen-1);
|
||||
}
|
||||
}
|
||||
write (1, "\n\r", 2);
|
||||
write (fd, "\n\r", 2);
|
||||
// reset colors for next line
|
||||
SetConsoleTextAttribute (hConsole, 1 | 2 | 4 | 8);
|
||||
linelen = 0;
|
||||
@ -164,11 +165,11 @@ R_API int r_cons_w32_print(const ut8 *ptr, int len, bool vmode) {
|
||||
//wlen = 5;
|
||||
if (wlen > 0) {
|
||||
memset (white, ' ', sizeof (white));
|
||||
write (1, white, wlen);
|
||||
write (fd, white, wlen);
|
||||
}
|
||||
}
|
||||
write (1, "\n\r", 2);
|
||||
//write (1, "\r\n", 2);
|
||||
write (fd, "\n\r", 2);
|
||||
//write (fd, "\r\n", 2);
|
||||
//lines--;
|
||||
linelen = 0;
|
||||
}
|
||||
@ -184,7 +185,7 @@ R_API int r_cons_w32_print(const ut8 *ptr, int len, bool vmode) {
|
||||
}
|
||||
if (ll > 0) {
|
||||
raw_ll = bytes_utf8len (str, ll, strlen (str));
|
||||
write (1, str, raw_ll);
|
||||
write (fd, str, raw_ll);
|
||||
linelen += ll;
|
||||
}
|
||||
esc = 1;
|
||||
@ -230,7 +231,7 @@ R_API int r_cons_w32_print(const ut8 *ptr, int len, bool vmode) {
|
||||
}
|
||||
}
|
||||
if (state == -2) {
|
||||
r_cons_w32_gotoxy (1, x, y);
|
||||
r_cons_w32_gotoxy (fd, x, y);
|
||||
ptr += i;
|
||||
str = ptr; // + i-2;
|
||||
continue;
|
||||
@ -243,7 +244,7 @@ R_API int r_cons_w32_print(const ut8 *ptr, int len, bool vmode) {
|
||||
// fill row here
|
||||
__fill_tail (cols, lines);
|
||||
}
|
||||
r_cons_w32_gotoxy (1, 0, 0);
|
||||
r_cons_w32_gotoxy (fd, 0, 0);
|
||||
lines = 0;
|
||||
esc = 0;
|
||||
ptr += 3;
|
||||
@ -370,33 +371,34 @@ R_API int r_cons_w32_print(const ut8 *ptr, int len, bool vmode) {
|
||||
if (wlen > 0) {
|
||||
char white[1024];
|
||||
memset (white, ' ', sizeof (white));
|
||||
write (1, white, wlen);
|
||||
write (fd, white, wlen);
|
||||
}
|
||||
/* fill tail */
|
||||
__fill_tail (cols, lines);
|
||||
} else {
|
||||
int ll = (size_t)(ptr - str);
|
||||
if (ll > 0) {
|
||||
write (1, str, ll);
|
||||
write (fd, str, ll);
|
||||
linelen += ll;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_cons_win_printf(bool vmode, const char *fmt, ...) {
|
||||
va_list ap, ap2;
|
||||
int ret = -1;
|
||||
r_return_val_if_fail (fmt, -1);
|
||||
R_API int r_cons_w32_print(const ut8 *ptr, int len, bool vmode) {
|
||||
return r_cons_w32_hprint (STD_OUTPUT_HANDLE, ptr, len, vmode);
|
||||
}
|
||||
|
||||
va_start (ap, fmt);
|
||||
static int r_cons_win_hprintf_(DWORD hdl, bool vmode, const char *fmt, va_list ap) {
|
||||
va_list ap2;
|
||||
int ret = -1;
|
||||
FILE *con = hdl == STD_OUTPUT_HANDLE ? stdout : stderr;
|
||||
if (!strchr (fmt, '%')) {
|
||||
va_end (ap);
|
||||
size_t len = strlen (fmt);
|
||||
if (I->ansicon) {
|
||||
return fwrite (fmt, 1, len, stdout);
|
||||
return fwrite (fmt, 1, len, con);
|
||||
}
|
||||
return r_cons_w32_print (fmt, len, vmode);
|
||||
return r_cons_w32_hprint (hdl, fmt, len, vmode);
|
||||
}
|
||||
va_copy (ap2, ap);
|
||||
int num_chars = vsnprintf (NULL, 0, fmt, ap2);
|
||||
@ -405,13 +407,34 @@ R_API int r_cons_win_printf(bool vmode, const char *fmt, ...) {
|
||||
if (buf) {
|
||||
(void)vsnprintf (buf, num_chars, fmt, ap);
|
||||
if (I->ansicon) {
|
||||
ret = fwrite (buf, 1, num_chars - 1, stdout);
|
||||
ret = fwrite (buf, 1, num_chars - 1, con);
|
||||
} else {
|
||||
ret = r_cons_w32_print (buf, num_chars - 1, vmode);
|
||||
ret = r_cons_w32_hprint (hdl, buf, num_chars - 1, vmode);
|
||||
}
|
||||
free (buf);
|
||||
}
|
||||
va_end (ap2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_cons_win_printf(bool vmode, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
int ret;
|
||||
r_return_val_if_fail (fmt, -1);
|
||||
|
||||
va_start (ap, fmt);
|
||||
ret = r_cons_win_hprintf_ (STD_OUTPUT_HANDLE, vmode, fmt, ap);
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_cons_win_eprintf(bool vmode, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
int ret;
|
||||
r_return_val_if_fail (fmt, -1);
|
||||
|
||||
va_start (ap, fmt);
|
||||
ret = r_cons_win_hprintf_ (STD_ERROR_HANDLE, vmode, fmt, ap);
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
||||
|
@ -788,6 +788,7 @@ R_API bool r_cons_is_ansicon(void);
|
||||
R_API void r_cons_w32_gotoxy(int fd, int x, int y);
|
||||
R_API int r_cons_w32_print(const ut8 *ptr, int len, bool vmode);
|
||||
R_API int r_cons_win_printf(bool vmode, const char *fmt, ...);
|
||||
R_API int r_cons_win_eprintf(bool vmode, const char *fmt, ...);
|
||||
#endif
|
||||
|
||||
R_API void r_cons_push(void);
|
||||
|
@ -2246,12 +2246,13 @@ R_API const char* r_print_rowlog(RPrint *print, const char *str) {
|
||||
if (!verbose) {
|
||||
return NULL;
|
||||
}
|
||||
if (use_color
|
||||
if (use_color) {
|
||||
#if __WINDOWS__
|
||||
&& print->cons && print->cons->ansicon
|
||||
r_cons_win_eprintf (false,
|
||||
#else
|
||||
eprintf (
|
||||
#endif
|
||||
) {
|
||||
eprintf ("[ ] "Color_YELLOW"%s\r["Color_RESET, str);
|
||||
"[ ] "Color_YELLOW"%s\r["Color_RESET, str);
|
||||
} else {
|
||||
eprintf ("[ ] %s\r[", str);
|
||||
}
|
||||
@ -2262,12 +2263,13 @@ R_API void r_print_rowlog_done(RPrint *print, const char *str) {
|
||||
int use_color = print->flags & R_PRINT_FLAGS_COLOR;
|
||||
bool verbose = print->scr_prompt;
|
||||
if (verbose) {
|
||||
if (use_color
|
||||
if (use_color) {
|
||||
#if __WINDOWS__
|
||||
&& print->cons && print->cons->ansicon
|
||||
r_cons_win_eprintf (false,
|
||||
#else
|
||||
eprintf (
|
||||
#endif
|
||||
) {
|
||||
eprintf ("\r"Color_GREEN"[x]"Color_RESET" %s\n", str);
|
||||
"\r"Color_GREEN"[x]"Color_RESET" %s\n", str);
|
||||
} else {
|
||||
eprintf ("\r[x] %s\n", str);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user