/* ================== CON_ColorPrint ================== */ static void CON_ColorPrint(WINDOW *win, const char *msg, qboolean stripcodes) { static char buffer[MAXPRINTMSG]; int length = 0; CON_SetColor(win, 7); while(*msg) { if (Q_IsColorString(msg) || *msg == '\n') { // First empty the buffer if (length > 0) { buffer[length] = '\0'; wprintw(win, "%s", buffer); length = 0; } if (*msg == '\n') { // Reset the color and then print a newline CON_SetColor(win, 7); waddch(win, '\n'); msg++; } else { // Set the color CON_SetColor(win, ColorIndex(*(msg + 1))); if (stripcodes) msg += 2; else { if (length >= MAXPRINTMSG - 1) break; buffer[length] = *msg; length++; msg++; if (length >= MAXPRINTMSG - 1) break; buffer[length] = *msg; length++; msg++; } } } else { if (length >= MAXPRINTMSG - 1) break; buffer[length] = *msg; length++; msg++; } } // Empty anything still left in the buffer if( length > 0 ) { buffer[length] = '\0'; wprintw(win, "%s", buffer); } }
/* ================== CON_DrawScrollBar ================== */ static void CON_DrawScrollBar(void) { int scroll; if (lastline <= LOG_LINES) { scroll = 0; } else { scroll = scrollline * (LOG_LINES - 1) / (lastline - LOG_LINES); } if (com_ansiColor && !com_ansiColor->integer) { wbkgdset(scrollwin, SCRLBAR_LINE); } else { wbkgdset(scrollwin, SCRLBAR_LINE | COLOR_PAIR(6)); } werase(scrollwin); wbkgdset(scrollwin, ' '); CON_SetColor(scrollwin, 1); mvwaddch(scrollwin, scroll, 0, SCRLBAR_CURSOR); wnoutrefresh(scrollwin); }
void print_reg_block(int x, int y, int sel, const u16 *regs, const u16 *compare_regs) { for (int j = 0; j < 4 ; j++) { for (int i = 0; i < 8 ; i++) { // Do not even display the loop stack registers. const int reg = j * 8 + i; CON_SetColor(sel == reg ? CON_BRIGHT_YELLOW : CON_GREEN); CON_Printf(x + j * 8, i + y, "%02x ", reg); if (j != 1 || i < 4) { u8 color1 = regs_equal(reg, regs[reg], compare_regs[reg]) ? CON_BRIGHT_WHITE : CON_BRIGHT_RED; for (int k = 0; k < 4; k++) { if (sel == reg && k == small_cursor_x && ui_mode == UIM_EDIT_REG) CON_SetColor(CON_BRIGHT_CYAN); else CON_SetColor(color1); CON_Printf(x + 3 + j * 8 + k, i + y, "%01x", (regs[reg] >> ((3 - k) * 4)) & 0xf); } } } }
/* ================== CON_Init Initialize the console in curses mode, fall back to tty mode on failure ================== */ void CON_Init(void) { int col; #ifndef _WIN32 // If the process is backgrounded (running non interactively) // then SIGTTIN or SIGTOU is emitted, if not caught, turns into a SIGSTP signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); #endif // Make sure we're on a tty if (isatty(STDIN_FILENO) != 1 || isatty(STDOUT_FILENO) != 1 || isatty(STDERR_FILENO) != 1) { CON_Init_tty(); return; } // Initialize curses and set up the root window if (!curses_on) { SCREEN *test = newterm(NULL, stdout, stdin); if (!test) { CON_Init_tty(); CON_Print_tty("Couldn't initialize curses, falling back to tty\n"); return; } endwin(); delscreen(test); initscr(); cbreak(); noecho(); nonl(); intrflush(stdscr, FALSE); nodelay(stdscr, TRUE); keypad(stdscr, TRUE); wnoutrefresh(stdscr); // Set up colors if (has_colors()) { use_default_colors(); start_color(); init_pair(1, COLOR_BLACK, -1); init_pair(2, COLOR_RED, -1); init_pair(3, COLOR_GREEN, -1); init_pair(4, COLOR_YELLOW, -1); init_pair(5, COLOR_BLUE, -1); init_pair(6, COLOR_CYAN, -1); init_pair(7, COLOR_MAGENTA, -1); init_pair(8, -1, -1); } } // Create the border borderwin = newwin(LOG_LINES + 2, LOG_COLS + 2, 1, 0); CON_SetColor(borderwin, 2); box(borderwin, 0, 0); wnoutrefresh(borderwin); // Create the log window logwin = newpad(MAX_LOG_LINES, LOG_COLS); scrollok(logwin, TRUE); idlok(logwin, TRUE); if (curses_on) CON_ColorPrint(logwin, logbuf, qtrue); getyx(logwin, lastline, col); if (col) lastline++; scrollline = lastline - LOG_LINES; if (scrollline < 0) scrollline = 0; pnoutrefresh(logwin, scrollline, 0, 2, 1, LOG_LINES + 1, LOG_COLS + 1); // Create the scroll bar scrollwin = newwin(LOG_LINES, 1, 2, COLS - 1); CON_DrawScrollBar(); CON_SetColor(stdscr, 3); mvaddch(1, COLS - 1, SCRLBAR_UP); mvaddch(LINES - 2, COLS - 1, SCRLBAR_DOWN); // Create the input field inputwin = newwin(1, COLS - Q_PrintStrlen(PROMPT) - 8, LINES - 1, Q_PrintStrlen(PROMPT) + 8); input_field.widthInChars = COLS - Q_PrintStrlen(PROMPT) - 9; if (curses_on) { if (input_field.cursor < input_field.scroll) input_field.scroll = input_field.cursor; else if (input_field.cursor >= input_field.scroll + input_field.widthInChars) input_field.scroll = input_field.cursor - input_field.widthInChars + 1; CON_ColorPrint(inputwin, input_field.buffer + input_field.scroll, qfalse); } CON_UpdateCursor(); wnoutrefresh(inputwin); // Create the clock clockwin = newwin(1, 8, LINES - 1, 0); CON_UpdateClock(); // Display the title and input prompt move(0, (COLS - Q_PrintStrlen(TITLE)) / 2); CON_ColorPrint(stdscr, TITLE, qtrue); move(LINES - 1, 8); CON_ColorPrint(stdscr, PROMPT, qtrue); wnoutrefresh(stdscr); doupdate(); #ifndef _WIN32 // Catch window resizes signal(SIGWINCH, (void *)CON_Resize); #endif curses_on = qtrue; }