static void erase_line(int mode) { COORD start; start.Y = console->y + console->top; int count; if (mode == 0) { /* Erase to end */ start.X = console->x; count = console->width - console->x; } else if (mode == 1) { /* Erase to begin */ start.X = 0; count = console->x + 1; } else if (mode == 2) { /* Erase whole line */ start.X = 0; count = console->width; } else { log_error("erase_line(): Invalid mode %d\n", mode); return; } DWORD num_written; FillConsoleOutputAttribute(console->out, get_text_attribute(console), count, start, &num_written); FillConsoleOutputCharacterW(console->out, L' ', count, start, &num_written); }
static void erase_screen(int mode) { COORD start; int count; if (mode == 0) { /* Erase current line to bottom */ start.X = console->x; start.Y = console->y + console->top; count = (console->width - console->x + 1) + (console->height - console->y - 1) * console->width; } else if (mode == 1) { /* Erase top to current line */ start.X = 0; start.Y = console->top; count = console->y * console->width + console->x + 1; } else if (mode == 2) { /* Erase entire screen */ start.X = 0; start.Y = console->top; count = console->width * console->height; } else { log_error("erase_screen(): Invalid mode %d\n", mode); return; } DWORD num_written; FillConsoleOutputAttribute(console->out, get_text_attribute(console), count, start, &num_written); FillConsoleOutputCharacterW(console->out, L' ', count, start, &num_written); }
void console_clear(){ // Note that we must use short for the pointer so that we can // use memsetw. uint32_t i=0; // empty text with white text. uint16_t blankCell = get_text_value(' ', WHITE, BLACK); for (i = 0; i < SCREEN_ROWS; i++) memsetw(video_memory + (i * SCREEN_COLUMNS), blankCell, SCREEN_COLUMNS); // Clear current console options main_console.attributes = get_text_attribute(WHITE, BLACK); main_console.x = 0; main_console.y = 0; update_cursor(); }
static void restore_cursor() { console->x = console->saved_cursor.x; console->y = console->saved_cursor.y; console->at_right_margin = console->saved_cursor.at_right_margin; console->bright = console->saved_cursor.bright; console->reverse = console->saved_cursor.reverse; console->foreground = console->saved_cursor.foreground; console->background = console->saved_cursor.background; console->charset = console->saved_cursor.charset; console->origin_mode = console->saved_cursor.origin_mode; console->wraparound_mode = console->saved_cursor.wraparound_mode; console->top = console->saved_top; set_pos(console->x, console->y); SetConsoleTextAttribute(console->out, get_text_attribute()); }
static void control_escape_sharp(char ch) { switch (ch) { case '8': { /* DECALN: DEC screen alignment test */ /* Fill screen with 'E' */ COORD start; start.X = 0; start.Y = 0; DWORD bytes_written; FillConsoleOutputAttribute(console->out, get_text_attribute(), console->width * console->height, start, &bytes_written); FillConsoleOutputCharacterW(console->out, L'E', console->width * console->height, start, &bytes_written); console->processor = NULL; } default: log_error("control_escape_sharp(): Unhandled character %c\n", ch); console->processor = NULL; } }
/* Handler for control sequencie introducer, "ESC [" */ static void control_escape_csi(char ch) { switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': console->params[console->param_count] = 10 * console->params[console->param_count] + (ch - '0'); break; case ';': if (console->param_count + 1 == CONSOLE_MAX_PARAMS) log_error("Too many console parameters.\n"); else console->param_count++; break; case 'A': /* CUU */ move_up(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'B': /* CUD */ case 'e': /* VPR */ move_down(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'C': /* CUF */ case 'a': /* HPR */ move_right(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'D': /* CUB */ move_left(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'd': /* VPA */ { int y = console->params[0]? console->params[0]: 1; if (y > console->height) y = console->height; set_pos(console->x, y - 1); console->processor = NULL; break; } case 'G': /* CHA */ case '`': /* HPA */ { int x = console->params[0] ? console->params[0] : 1; if (x > console->width) x = console->width; set_pos(x - 1, console->y); console->processor = NULL; break; } case 'H': case 'f': /* Zero or one both represents the first row/column */ if (console->params[0] > 0) console->params[0]--; if (console->params[1] > 0) console->params[1]--; if (console->origin_mode) set_pos(console->params[1], console->scroll_top + console->params[0]); else set_pos(console->params[1], console->params[0]); console->processor = NULL; break; case 'h': if (console->private_mode) change_private_mode(console->params[0], 1); else change_mode(console->params[0], 1); console->processor = NULL; break; case 'J': erase_screen(console->params[0]); console->processor = NULL; break; case 'K': erase_line(console->params[0]); console->processor = NULL; break; case 'l': if (console->private_mode) change_private_mode(console->params[0], 0); else change_mode(console->params[0], 0); console->processor = NULL; break; case 'L': /* IL */ insert_line(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'M': /* DL */ delete_line(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case '@': /* ICH */ insert_character(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'P': /* DCH */ delete_character(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case 'm': for (int i = 0; i <= console->param_count; i++) { switch (console->params[i]) { case 0: /* Reset */ console->bright = 0; console->reverse = 0; console->foreground = 7; console->background = 0; break; case 1: console->bright = 1; break; case 2: console->bright = 0; break; case 7: console->reverse = 1; break; case 27: console->reverse = 0; break; case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37: console->foreground = console->params[i] - 30; break; case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47: console->background = console->params[i] - 40; break; default: log_error("Unknown console attribute: %d\n", console->params[i]); } } /* Set updated text attribute */ SetConsoleTextAttribute(console->out, get_text_attribute(console)); console->processor = NULL; break; case 'r': if (console->params[0] == 0) console->params[0] = 1; if (console->params[1] == 0) console->params[1] = console->height; console->scroll_full_screen = (console->params[0] == 1 && console->params[1] == console->height); console->scroll_top = console->params[0] - 1; console->scroll_bottom = console->params[1] - 1; set_pos(0, 0); console->processor = NULL; break; case 'S': /* SU */ scroll_up(console->params[0]? console->params[0]: 1); console->processor = NULL; break; case '?': console->private_mode = 1; break; default: log_error("control_escape_csi(): Unhandled character %c\n", ch); console->processor = NULL; } }
/* * This updates the current text color and background color of the console. */ void console_set_text_color(uint8_t foreground, uint8_t background){ main_console.attributes = get_text_attribute(foreground, background); }
/* * Calculates the 16-bit value of a character, foreground and background. */ uint16_t get_text_value(uint8_t character, uint8_t foreground, uint8_t background){ return character | (get_text_attribute(foreground, background) << 8); }