6 #define I rz_cons_singleton()
10 static void __fill_tail(
int cols,
int lines) {
14 cols =
RZ_MIN(cols,
sizeof(white));
15 memset(white,
' ', cols - 1);
24 RZ_API void rz_cons_w32_clear(
void) {
26 static CONSOLE_SCREEN_BUFFER_INFO csbi;
33 if (
I->is_wine == 1) {
34 rz_xwrite(1,
"\033[0;0H\033[0m\033[2J", 6 + 4 + 4);
37 hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
39 GetConsoleScreenBufferInfo(hStdout, &csbi);
40 startCoords = (COORD){
44 DWORD nLength = csbi.dwSize.X * (csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
45 FillConsoleOutputCharacter(hStdout,
' ',
46 nLength, startCoords, &dummy);
47 FillConsoleOutputAttribute(hStdout,
48 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
49 nLength, startCoords, &dummy);
52 RZ_API void rz_cons_w32_gotoxy(
int fd,
int x,
int y) {
55 HANDLE *hConsole =
fd == 1 ? &hStdout : &hStderr;
63 if (
I->is_wine == 1) {
67 *hConsole = GetStdHandle(
fd == 1 ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
69 CONSOLE_SCREEN_BUFFER_INFO
info;
70 GetConsoleScreenBufferInfo(*hConsole, &
info);
71 coord.X +=
info.srWindow.Left;
72 coord.Y +=
info.srWindow.Top;
73 SetConsoleCursorPosition(*hConsole, coord);
76 static int wrapline(
const char *
s,
int len) {
82 return n - ((
n >
len) ? l : 1);
86 static int utf8len_fixed(
const char *
s,
int n) {
87 int i = 0, j = 0, fullwidths = 0;
88 while (
s[
i] &&
n > 0) {
89 if ((
s[
i] & 0xc0) != 0x80) {
98 return j + fullwidths;
101 static int bytes_utf8len(
const char *
s,
int n) {
112 static int rz_cons_w32_hprint(
DWORD hdl,
const char *ptr,
int len,
bool vmode) {
113 HANDLE hConsole = GetStdHandle(hdl);
114 int fd = hdl == STD_OUTPUT_HANDLE ? 1 : 2;
116 int bg = 0, fg = 1 | 2 | 4 | 8;
117 const char *ptr_end, *
str = ptr;
124 if (
I->is_wine == -1) {
128 len = strlen((
const char *)ptr);
132 for (; *ptr && ptr < ptr_end; ptr++) {
135 ll = utf8len_fixed(
str, raw_ll);
137 if (vmode &&
lines < 1) {
145 if (ll + linelen >= cols) {
147 ll = (cols - linelen) - 1;
154 raw_ll = bytes_utf8len(
str, ll);
161 int wlen = cols - linelen;
163 if (wlen > 0 && wlen <
sizeof(white)) {
164 memset(white,
' ',
sizeof(white));
170 SetConsoleTextAttribute(hConsole, 1 | 2 | 4 | 8);
174 if (ptr[0] == 0x1b) {
176 ll = utf8len_fixed(
str, raw_ll);
177 if (
str[0] ==
'\n') {
181 int wlen = cols - linelen - 1;
185 memset(white,
' ',
sizeof(white));
195 if (linelen + ll >= cols) {
197 ll = (cols - linelen) - 1;
200 ll = wrapline((
const char *)
str, cols - linelen - 1);
205 raw_ll = bytes_utf8len(
str, ll);
216 eprintf(
"Oops invalid escape char\n");
223 }
else if (esc == 2) {
224 const char *ptr2 =
NULL;
226 for (
i = 0; ptr[
i] &&
state >= 0;
i++) {
230 y = atoi((
const char *)ptr);
232 ptr2 = (
const char *)ptr +
i + 1;
233 }
else if (ptr[
i] >=
'0' && ptr[
i] <=
'9') {
243 }
else if (ptr[
i] >=
'0' && ptr[
i] <=
'9') {
252 rz_cons_w32_gotoxy(
fd,
x, y);
258 if (ptr[0] ==
'0' && ptr[1] ==
';' && ptr[2] ==
'0') {
263 __fill_tail(cols,
lines);
265 rz_cons_w32_gotoxy(
fd, 0, 0);
271 }
else if (ptr[0] ==
'2' && ptr[1] ==
'J') {
277 }
else if (ptr[0] ==
'0' && (ptr[1] ==
'm' || ptr[1] ==
'K')) {
278 SetConsoleTextAttribute(hConsole, 1 | 2 | 4 | 8);
287 }
else if (ptr[0] ==
'2' && ptr[1] ==
'7' && ptr[2] ==
'm') {
288 SetConsoleTextAttribute(hConsole, bg | fg);
295 }
else if (ptr[0] ==
'7' && ptr[1] ==
'm') {
303 }
else if ((ptr[0] ==
'3' || (bright = ptr[0] ==
'9')) && (ptr[2] ==
'm' || ptr[2] ==
';')) {
336 SetConsoleTextAttribute(hConsole, bg | fg | inv);
341 }
else if ((ptr[0] ==
'4' && ptr[2] ==
'm') || (bright = ptr[0] ==
'1' && ptr[1] ==
'0' && ptr[3] ==
'm')) {
343 ut8 col = bright ? ptr[2] : ptr[1];
367 bg = 0x10 | 0x20 | 0x40;
376 SetConsoleTextAttribute(hConsole, bg | fg | inv);
378 ptr = ptr + (bright ? 3 : 2);
387 int wlen = cols - linelen - 1;
390 memset(white,
' ',
sizeof(white));
394 __fill_tail(cols,
lines);
405 RZ_API int rz_cons_w32_print(
const char *ptr,
int len,
bool vmode) {
406 return rz_cons_w32_hprint(STD_OUTPUT_HANDLE, ptr,
len, vmode);
409 RZ_API int rz_cons_win_vhprintf(
DWORD hdl,
bool vmode,
const char *fmt, va_list ap) {
412 FILE *con = hdl == STD_OUTPUT_HANDLE ? stdout : stderr;
413 if (!strchr(fmt,
'%')) {
414 size_t len = strlen(fmt);
416 return fwrite(fmt, 1,
len, con);
418 return rz_cons_w32_hprint(hdl, fmt,
len, vmode);
427 ret = fwrite(
buf, 1, num_chars - 1, con);
429 ret = rz_cons_w32_hprint(hdl,
buf, num_chars - 1, vmode);
437 RZ_API int rz_cons_win_printf(
bool vmode,
const char *fmt, ...) {
443 ret = rz_cons_win_vhprintf(STD_OUTPUT_HANDLE, vmode, fmt, ap);
448 RZ_API int rz_cons_win_eprintf(
bool vmode,
const char *fmt, ...) {
454 ret = rz_cons_win_vhprintf(STD_ERROR_HANDLE, vmode, fmt, ap);
RzBinInfo * info(RzBinFile *bf)
static RzBinSourceLineInfo * lines(RzBinFile *bf)
RZ_API int rz_cons_get_size(int *rows)
RZ_API void rz_cons_strcat(const char *str)
RZ_API int rz_cons_printf(const char *format,...)
RZ_API void Ht_() free(HtName_(Ht) *ht)
return memset(p, 0, total)
void * calloc(size_t number, size_t size)
#define rz_return_val_if_fail(expr, val)
@ RZ_VIRT_TERM_MODE_DISABLE
Windows only: Use console c api for everything (Windows <= 8)
#define RZ_CONS_CLEAR_SCREEN
RZ_API bool rz_file_is_directory(const char *str)
RZ_API bool rz_str_char_fullwidth(const char *s, size_t left)
RZ_API size_t rz_str_len_utf8char(const char *s, int left)
RZ_API size_t rz_str_utf8_charsize(const char *str)
#define rz_xwrite(fd, buf, count)
#define COMMON_LVB_REVERSE_VIDEO
static const z80_opcode fd[]