void console_write_latin1_string (uint8_t * str) { int i; for (int i = 0; i < strlen (str); i++) console_write_char (str[i], 0, 0, 0, CONSOLE_COLS - 1); }
static void _console_write_integer(int x, int base) { static char* characterLookup = "0123456789abcdef"; int negative = 0; if (x < 0) { x = -x; negative = 1; } int length = 0; int temp = x; do { ++length; } while ((temp /= base)); char buffer[length + 1]; for (int i = length - 1; i >= 0; --i) { buffer[i] = characterLookup[x % base]; x /= base; } buffer[length] = '\0'; if (negative) { console_write_char('-'); } console_write_str(buffer); }
void console_write_wchar_string (const wchar_t *str, size_t len) { for (size_t i = 0; i < len; i ++) { if (col == CONSOLE_COLS - 1) { row ++; col = 0; if (row == CONSOLE_ROWS) { console_scroll_up (1); row --; } } console_write_char (str[i], 0, 0, 0, 0, CONSOLE_COLS - 1); } }
int loop(){ int key_event; int retval; char new_char; while(true){ retval = read(KEYBOARD_QUEUE_FD, &key_event, 1); if (retval){ if ((new_char = ascii_interpreter(key_event)) != -1){ console_write_char(new_char); } else { // TODO: cambiar de consola, etc... // Handlear enter, // Handlear backspace, etc.. } } } }
void console_write_latin1_string (const char * str) { size_t i = 0; while (str[i] != '\0') { if (col == CONSOLE_COLS - 1) { row ++; col = 0; if (row == CONSOLE_ROWS) { console_scroll_up (1); row --; } } console_write_char ((uint8_t)(str[i]), 0, 0, 0, 0, CONSOLE_COLS - 1); i = i + 1; } }
void console_write_ucs4_string (const uint32_t *str) { size_t i = 0; while (str[i] != 0) { if (col == CONSOLE_COLS - 1) { row ++; col = 0; if (row == CONSOLE_ROWS) { console_scroll_up (1); row --; } } console_write_char (str[i], 0, 0, 0, 0, CONSOLE_COLS - 1); i = i + 1; } }
void console_write_string(const char *str) { if(!str) str = "NULL"; while(*str) console_write_char(*str++); }
void console_write_block(char *data, size_t size) { int i; for(i = 0; i < size; ++i) console_write_char(*data++); }
//---------------------------------------------------------------------------- //Ausgabe eines Strings void console_write_str(char *str) { while (str && *str) console_write_char(*str++); }
//------------------------------------------------------------------------------ void console_write_P (const char *Buffer,...) { va_list ap; va_start (ap, Buffer); int format_flag; char str_buffer[20]; char move = 0; char len, b; char by; char *ptr; //Ausgabe der Zeichen for(;;) { by = *Buffer++; if(by==0) break; // end of format string if (by == '%') { by = *Buffer++; while (isdigit(by)) { // potential overflow of move move = by - '0' + move * 10; by = *Buffer++; } switch (by) { case 's': ptr = va_arg(ap,char *); console_write_str(ptr); break; case 'c': //Int to char format_flag = va_arg(ap,int); console_write_char (format_flag++); break; case 'i': case 'd': itoa(va_arg(ap,int), str_buffer,10); goto ConversionLoop; case 'u': utoa(va_arg(ap,unsigned int), str_buffer,10); goto ConversionLoop; case 'x': itoa(va_arg(ap,int), str_buffer,16); //**************************** ConversionLoop: //**************************** len = strlen (str_buffer); b = '0'; while ( len < move ) { console_write_char (b); len++; } console_write_str (str_buffer); move = 0; break; } // switch } else
void console_test_pattern (void) { for (int i = 0; i < FIXED8x12_COUNT; i++) { console_write_char (fixed8x12_glyphs[i].encoding, 0, 0, 0, 59); if (col == CONSOLE_COLS - 1) { row++; col = 0; } } row++; col = 0; console_set_bgcolor (COLOR_BG_DEFAULT); console_write_latin1_string ("DEFAULT"); console_set_bgcolor (COLOR_BG_BLACK); console_write_latin1_string ("BLACK"); console_set_bgcolor (COLOR_BG_RED); console_write_latin1_string ("RED"); console_set_bgcolor (COLOR_BG_GREEN); console_write_latin1_string ("GREEN"); console_set_bgcolor (COLOR_BG_YELLOW); console_write_latin1_string ("YELLOW"); console_set_bgcolor (COLOR_BG_BLUE); console_write_latin1_string ("BLUE"); console_set_bgcolor (COLOR_BG_MAGENTA); console_write_latin1_string ("MAGENTA"); console_set_bgcolor (COLOR_BG_CYAN); console_write_latin1_string ("CYAN"); console_set_bgcolor (COLOR_BG_WHITE); console_write_latin1_string ("WHITE"); console_set_bgcolor (COLOR_BG_TRANSPARENT); console_write_latin1_string ("CLEAR"); for (int i = 0; i < 3; i++) { row++; col = 0; console_set_fgcolor (COLOR_FG_DEFAULT); if (i == 0) { console_set_intensity (INTENSITY_BOLD); console_write_latin1_string ("BOLD "); } else if (i == 1) { console_set_intensity (INTENSITY_FAINT); console_write_latin1_string ("FAINT "); } else if (i == 2) { console_set_intensity (INTENSITY_NORMAL); console_write_latin1_string ("NORMAL "); } console_set_fgcolor (COLOR_FG_BLACK); console_write_latin1_string ("BLACK"); console_set_fgcolor (COLOR_FG_RED); console_write_latin1_string ("RED"); console_set_fgcolor (COLOR_FG_GREEN); console_write_latin1_string ("GREEN"); console_set_fgcolor (COLOR_FG_YELLOW); console_write_latin1_string ("YELLOW"); console_set_fgcolor (COLOR_FG_BLUE); console_write_latin1_string ("BLUE"); console_set_fgcolor (COLOR_FG_MAGENTA); console_write_latin1_string ("MAGENTA"); console_set_fgcolor (COLOR_FG_CYAN); console_write_latin1_string ("CYAN"); console_set_fgcolor (COLOR_FG_WHITE); console_write_latin1_string ("WHITE"); console_set_fgcolor (COLOR_FG_TRANSPARENT); console_write_latin1_string ("CLEAR"); } row++; col = 0; console_set_fgcolor (COLOR_FG_DEFAULT); console_set_bgcolor (COLOR_BG_DEFAULT); console_set_blink (BLINK_NONE); console_write_latin1_string ("STEADY"); console_set_blink (BLINK_SLOW); console_write_latin1_string ("BLINK1"); console_set_blink (BLINK_FAST); console_write_latin1_string ("BLINK2"); console_set_blink (BLINK_NONE); console_set_underline (UNDERLINE_NONE); console_write_latin1_string ("NORMAL"); console_set_underline (UNDERLINE_SINGLY); console_write_latin1_string ("UNDERLINE1"); console_set_underline (UNDERLINE_DOUBLY); console_write_latin1_string ("UNDERLINE2"); console_set_underline (UNDERLINE_NONE); row++; col = 0; console_set_polarity (POLARITY_POSITIVE); console_write_latin1_string ("POSITIVE"); console_set_polarity (POLARITY_NEGATIVE); console_write_latin1_string ("NEGATIVE"); console_set_polarity (POLARITY_POSITIVE); row++; col = 0; console_write_latin1_string ("DELETE LEFT"); console_delete_left (1); }
void console_write_str(char* str) { while (*str != '\0') { console_write_char(*str++); } }
void console_test_pattern (void) { for (int i = 0; i < FIXED8x12_COUNT; i++) { console_write_char (fixed8x12_glyphs[i].encoding, 0, 0, 0, 0, CONSOLE_COLS - 1); if (col == CONSOLE_COLS - 1) { row ++; col = 0; } } row++; col = 0; console_write_utf8_string("¿Qué?"); const wchar_t ws1[] = L"¿Qué?"; console_write_wchar_string(ws1, wcslen(ws1)); //ecma48_init(); //const char s1[] = "hello\r\n"; //const char s2[] = "\tWhat's up!\r\n"; //const char s3[] = "\x1b[7mERR\x1b[0m \x1b[1mWARN\x1b[0m"; //ecma48_execute(s1, strlen(s1)); //ecma48_execute(s2, strlen(s2)); //ecma48_execute(s3, strlen(s3)); #if 0 row++; col = 0; console_set_bgcolor (COLOR_BG_DEFAULT); console_write_latin1_string ("DEFAULT"); console_set_bgcolor (COLOR_BG_BLACK); console_write_latin1_string ("BLACK"); console_set_bgcolor (COLOR_BG_RED); console_write_latin1_string ("RED"); console_set_bgcolor (COLOR_BG_GREEN); console_write_latin1_string ("GREEN"); console_set_bgcolor (COLOR_BG_YELLOW); console_write_latin1_string ("YELLOW"); console_set_bgcolor (COLOR_BG_BLUE); console_write_latin1_string ("BLUE"); console_set_bgcolor (COLOR_BG_MAGENTA); console_write_latin1_string ("MAGENTA"); console_set_bgcolor (COLOR_BG_CYAN); console_write_latin1_string ("CYAN"); console_set_bgcolor (COLOR_BG_WHITE); console_write_latin1_string ("WHITE"); console_set_bgcolor (COLOR_BG_TRANSPARENT); console_write_latin1_string ("CLEAR"); for (int i = 0; i < 3; i++) { row++; col = 0; console_set_fgcolor (COLOR_FG_DEFAULT); if (i == 0) { console_set_intensity (INTENSITY_BOLD); console_write_latin1_string ("BOLD "); } else if (i == 1) { console_set_intensity (INTENSITY_FAINT); console_write_latin1_string ("FAINT "); } else if (i == 2) { console_set_intensity (INTENSITY_NORMAL); console_write_latin1_string ("NORMAL "); } console_set_fgcolor (COLOR_FG_BLACK); console_write_latin1_string ("BLACK"); console_set_fgcolor (COLOR_FG_RED); console_write_latin1_string ("RED"); console_set_fgcolor (COLOR_FG_GREEN); console_write_latin1_string ("GREEN"); console_set_fgcolor (COLOR_FG_YELLOW); console_write_latin1_string ("YELLOW"); console_set_fgcolor (COLOR_FG_BLUE); console_write_latin1_string ("BLUE"); console_set_fgcolor (COLOR_FG_MAGENTA); console_write_latin1_string ("MAGENTA"); console_set_fgcolor (COLOR_FG_CYAN); console_write_latin1_string ("CYAN"); console_set_fgcolor (COLOR_FG_WHITE); console_write_latin1_string ("WHITE"); console_set_fgcolor (COLOR_FG_TRANSPARENT); console_write_latin1_string ("CLEAR"); } row++; col = 0; console_set_fgcolor (COLOR_FG_DEFAULT); console_set_bgcolor (COLOR_BG_DEFAULT); console_set_blink (BLINK_NONE); console_write_latin1_string ("STEADY"); console_set_blink (BLINK_SLOW); console_write_latin1_string ("BLINK1"); console_set_blink (BLINK_FAST); console_write_latin1_string ("BLINK2"); console_set_blink (BLINK_NONE); console_set_underline (UNDERLINE_NONE); console_write_latin1_string ("NORMAL"); console_set_underline (UNDERLINE_SINGLY); console_write_latin1_string ("UNDERLINE1"); console_set_underline (UNDERLINE_DOUBLY); console_write_latin1_string ("UNDERLINE2"); console_set_underline (UNDERLINE_NONE); row++; col = 0; console_set_polarity (POLARITY_POSITIVE); console_write_latin1_string ("POSITIVE"); console_set_polarity (POLARITY_NEGATIVE); console_write_latin1_string ("NEGATIVE"); console_set_polarity (POLARITY_POSITIVE); row++; col = 0; console_write_latin1_string ("DELETE ->*<- LEFT"); col = 9; console_delete_left (2); row++; col = 0; console_write_latin1_string ("DELETE ->*<- RIGHT"); col = 9; console_delete_right (2); row ++; col = 0; console_write_latin1_string ("ERASE ->*<- LEFT"); col = 8; console_erase_left (2); row ++; col = 0; console_write_latin1_string ("ERASE ->*<- RIGHT"); col = 8; console_erase_right (2); console_scroll_down(2); #endif }
void console_write_utf8_string (const char *str) { char buffer[BUFSIZ + MB_LEN_MAX]; mbstate_t state; int filled = 0; int eof = 0; /* Initialize the state. */ memset (&state, '\0', sizeof (state)); while (!eof) { ssize_t nread; char *inp = buffer; wchar_t outbuf[BUFSIZ]; wchar_t *outp = outbuf; /* Fill up the buffer from the input file. */ nread = strlen(str); if (nread == 0) eof = 1; else if (nread >= BUFSIZ) abort(); else memcpy(buffer + filled, str, nread); /* 'filled' is now the number of bytes in 'buffer'. */ filled += nread; /* Convert those bytes to wide characters-as many as we can. */ while (1) { size_t thislen = mbrtowc (outp, inp, filled, &state); /* Stop converting at invalid character; this can mean we have read just the first part of a valid character. */ if (thislen == (size_t) -1) break; /* End at NULL */ if (thislen == 0) break; /* Advance past this character. */ inp += thislen; filled -= thislen; ++outp; } /* Write the wide characters we just made. */ for (int x = 0; x < (outp - outbuf); x ++) console_write_char (outbuf[x], 0, 0, 0, 0, CONSOLE_COLS - 1); /* See if we have a _real_ invalid character. */ if ((eof && filled > 0) || filled >= MB_CUR_MAX) { // error (0, 0, "invalid multibyte character"); eof = 1; return; } /* If any characters must be carried forward, put them at the beginning of 'buffer'. */ if (filled > 0) memmove (buffer, inp, filled); else eof = 1; } }
void console_write_latin1_string (uint8_t * str) { for (size_t i = 0; i < strlen ((const char *) str); i++) console_write_char (str[i], 0, 0, 0, 0, CONSOLE_COLS - 1); }
/* * This prints a string to the current console. */ void console_write_string(char *str){ uint32_t i; for (i = 0; i < strlen(str); i++) console_write_char(str[i]); }