char *fb_ConsoleReadStr( char *buffer, int len ) { int k, x, y, cols, pos = 0; char ch[2] = { 0, '\0' }; if (!__fb_con.inited) return fgets(buffer, len, stdin); fb_ConsoleGetSize(&cols, NULL); do { while( ((k = fb_hGetCh(TRUE)) == -1) || (k > 0xFF) ) fb_Delay( 10 ); /* drop subsequent keypresses, if any; this is needed to avoid escape * sequence parsing problems in the fb_ConsoleGetXY() call below. */ while( fb_hGetCh(TRUE) >= 0 ) fb_Delay( 10 ); fb_ConsoleGetXY(&x, &y); if (k == 8) { if (pos > 0) { x--; if (x <= 0) { x = cols; y--; if (y <= 0) x = y = 1; } fb_hTermOut(SEQ_LOCATE, x-1, y-1); fb_hTermOut(SEQ_DEL_CHAR, 0, 0); pos--; } } else if (k != '\t') { if (pos < len - 1) { buffer[pos++] = ch[0] = k; fb_ConsolePrintBuffer(ch, 0); if (x == cols) fputc( '\n', stdout ); } } } while (k != '\r'); fputc( '\n', stdout ); buffer[pos] = '\0'; return buffer; }
int fb_ConsoleWidth( int cols, int rows ) { int cur = (__fb_con.inited ? (__fb_con.w | (__fb_con.h << 16)) : (80 | (25 << 16))); if ((cols > 0) || (rows > 0)) { BG_LOCK(); if (cols <= 0) cols = __fb_con.w; if (rows <= 0) rows = __fb_con.h; fb_hTermOut(SEQ_WINDOW_SIZE, rows, cols); BG_UNLOCK(); fb_ConsoleClear( 0 ); } return cur; }
void fb_ConsoleViewUpdate( void ) { #if defined( HOST_DOS ) int top = fb_ConsoleGetTopRow( ); if( top >= 0 ) ++top; else top = 1; fb_ConsoleLocate( top, 1, -1 ); #elif defined( HOST_UNIX ) if (!__fb_con.inited) return; fb_hTermOut(SEQ_SCROLL_REGION, fb_ConsoleGetBotRow(), fb_ConsoleGetTopRow()); #elif defined( HOST_WIN32 ) fb_hUpdateConsoleWindow( ); #endif }
int fb_hConsoleGfxMode ( void (*gfx_exit)(void), void (*save)(void), void (*restore)(void), void (*key_handler)(int, int, int, int) ) { BG_LOCK(); fb_hStartBgThread( ); __fb_con.gfx_exit = gfx_exit; if (gfx_exit) { __fb_ctx.hooks.multikeyproc = NULL; __fb_ctx.hooks.inkeyproc = NULL; __fb_ctx.hooks.getkeyproc = NULL; __fb_ctx.hooks.keyhitproc = NULL; __fb_ctx.hooks.sleepproc = NULL; gfx_save = save; gfx_restore = restore; gfx_key_handler = key_handler; if (keyboard_init()) { BG_UNLOCK(); return -1; } ioctl(key_fd, KDSETMODE, KD_GRAPHICS); } else { if (key_fd >= 0) { ioctl(key_fd, KDSETMODE, KD_TEXT); keyboard_exit(); fb_hTermOut(SEQ_EXIT_GFX_MODE, 0, 0); } } BG_UNLOCK(); return 0; }
int fb_ConsoleColor( int fc, int bc, int flags ) { const char map[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; int old_fg = __fb_con.fg_color; int old_bg = __fb_con.bg_color; int force = FALSE; if (!__fb_con.inited) return old_fg | (old_bg << 16); if (!(flags & FB_COLOR_FG_DEFAULT)) __fb_con.fg_color = (fc & 0xF); if (!(flags & FB_COLOR_BG_DEFAULT)) __fb_con.bg_color = (bc & 0xF); if ((__fb_con.inited == INIT_CONSOLE) || (__fb_con.term_type != TERM_XTERM)) { /* console and any terminal but xterm do not support extended color attributes and only allow 16+8 colors */ if (__fb_con.fg_color != old_fg) { if ((__fb_con.fg_color ^ old_fg) & 0x8) { /* bright mode changed: reset attributes and force setting both back and fore colors */ fb_hTermOut(SEQ_RESET_COLOR, 0, 0); if (__fb_con.fg_color & 0x8) fb_hTermOut(SEQ_BRIGHT_COLOR, 0, 0); force = TRUE; } fb_hTermOut(SEQ_FG_COLOR, 0, map[__fb_con.fg_color & 0x7]); } if ((__fb_con.bg_color != old_bg) || (force)) fb_hTermOut(SEQ_BG_COLOR, 0, map[__fb_con.bg_color & 0x7]); } else { /* generic xterm supports 16+16 colors */ if (__fb_con.fg_color != old_fg) fb_hTermOut(SEQ_SET_COLOR_EX, map[__fb_con.fg_color & 0x7] + (__fb_con.fg_color & 0x8 ? 90 : 30), 0); if (__fb_con.bg_color != old_bg) fb_hTermOut(SEQ_SET_COLOR_EX, map[__fb_con.bg_color & 0x7] + (__fb_con.bg_color & 0x8 ? 100 : 40), 0); } return old_fg | (old_bg << 16); }
char *fb_ConsoleReadStr( char *buffer, int len ) { #if defined( HOST_UNIX ) int k, x, y, cols, pos = 0; char ch[2] = { 0, '\0' }; if (!__fb_con.inited) return fgets(buffer, len, stdin); fb_ConsoleGetSize(&cols, NULL); do { while( ((k = fb_hGetCh(TRUE)) == -1) || (k & 0x100) ) fb_Delay( 10 ); /* drop subsequent keypresses, if any; this is needed to avoid escape * sequence parsing problems in the fb_ConsoleGetXY() call below. */ while( fb_hGetCh(TRUE) >= 0 ) fb_Delay( 10 ); fb_ConsoleGetXY(&x, &y); if (k == 8) { if (pos > 0) { x--; if (x <= 0) { x = cols; y--; if (y <= 0) x = y = 1; } fb_hTermOut(SEQ_LOCATE, x-1, y-1); fb_hTermOut(SEQ_DEL_CHAR, 0, 0); pos--; } } else if (k != '\t') { if (pos < len - 1) { buffer[pos++] = ch[0] = k; fb_ConsolePrintBuffer(ch, 0); if (x == cols) fputc('\n', __fb_con.f_out); } } } while (k != '\r'); fputc('\n', __fb_con.f_out); buffer[pos] = '\0'; return buffer; #elif defined( HOST_WIN32 ) char *res; fb_hRestoreConsoleWindow( ); FB_CON_CORRECT_POSITION(); fb_hConsolePutBackEvents( ); res = fgets( buffer, len, stdin ); fb_hUpdateConsoleWindow( ); return res; #else return fgets( buffer, len, stdin ); #endif }