📄 console.c
字号:
/* * Name: capslock_active * Purpose: To find out if Caps Lock is active * Date: August 13, 2002 * Returns: Non zero if Caps Lock is active, * Zero if Caps Lock is not active. * Note: set by the last key read in getkey(). */int capslock_active( void ){ return( capslock_state );}/* * Name: numlock_active * Purpose: To find out if Num Lock is active * Date: September 3, 2002 * Returns: Non zero if Num Lock is active, * Zero if Num Lock is not active. * Note: set by the last key read in getkey(). */int numlock_active( void ){ return( numlock_state );}/* * Name: flush_keyboard * Purpose: flush keys from the keyboard buffer * Date: August 13, 2002 */void flush_keyboard( void ){ FlushConsoleInputBuffer( conin );}/* Name: page * Purpose: Change the text screen page * Author: Jason Hood * Date: August 13, 2002 * Passed: payg: desired page number * Notes: if payg is 0 use the standard buffer; * anything else uses the TDE buffer. */void page( unsigned char payg ){ SetConsoleActiveScreenBuffer( payg ? conout : StdOut ); if (!payg) SetConsoleTitle( title );}/* * Name: xygoto * Purpose: To move the cursor to the required column and line. * Date: August 13, 2002 * Passed: col: desired column (0 up to max) * line: desired line (0 up to max) */void xygoto( int col, int line ){static int hidden;COORD pos;CONSOLE_CURSOR_INFO cci; if (col < 0 || line < 0) { if (!hidden) { hidden = TRUE; cci.bVisible = FALSE; cci.dwSize = mode.insert ? g_display.insert_cursor : g_display.overw_cursor; SetConsoleCursorInfo( conout, &cci ); } } else { pos.X = col; pos.Y = line; SetConsoleCursorPosition( conout, pos ); if (hidden) { hidden = FALSE; cci.bVisible = TRUE; cci.dwSize = mode.insert ? g_display.insert_cursor : g_display.overw_cursor; SetConsoleCursorInfo( conout, &cci ); } }}/* * Name: display_line * Purpose: display a line in the file * Author: Jason Hood * Date: August 13, 2002 * Passed: text: characters to display * attr: attributes to use * len: length to display * line: row of display * col: column of display * Notes: all parameters are assumed valid. */void display_line( unsigned char *text, unsigned char *attr, int len, int line, int col ){COORD pos;WORD a[MAX_COLS];DWORD length; pos.X = col; pos.Y = line; for (length = len; (int)--length >= 0;) a[length] = attr[length]; WriteConsoleOutputCharacter( conout, text, len, pos, &length ); WriteConsoleOutputAttribute( conout, a, len, pos, &length );}/* * Name: c_output * Purpose: Output one character on prompt lines * Date: August 13, 2002 * Passed: c: character to output to screen * col: col to display character * line: line number to display character * attr: attribute of character * Returns: none */void c_output( int c, int col, int line, int attr ){COORD pos;DWORD length; pos.X = col; pos.Y = line; FillConsoleOutputCharacter( conout, (char)c, 1, pos, &length ); FillConsoleOutputAttribute( conout, (WORD)attr, 1, pos, &length );}/* * Name: c_repeat * Purpose: Output one character many times * Author: Jason Hood * Date: November 18, 2003 * Passed: c: character to output to screen * cnt: number of times to output it * col: column to display character * line: line number to display character * attr: attribute of character * Notes: if the count is negative, repeat the row, not the column. */void c_repeat( int c, int cnt, int col, int line, int attr ){COORD pos;DWORD length;int max; if (cnt < 0) { cnt = -cnt; max = g_display.nlines - line; if (cnt > max) cnt = max; if (cnt > 0) { pos.X = col; pos.Y = line; do { FillConsoleOutputCharacter( conout, (char)c, 1, pos, &length ); FillConsoleOutputAttribute( conout, (WORD)attr, 1, pos, &length ); ++pos.Y; } while (--cnt != 0); } } else { max = g_display.ncols - col; if (cnt > max) cnt = max; if (cnt > 0) { pos.X = col; pos.Y = line; FillConsoleOutputCharacter( conout, (char)c, cnt, pos, &length ); FillConsoleOutputAttribute( conout, (WORD)attr, cnt, pos, &length ); } }}/* * Name: s_output * Purpose: To output a string * Date: August 13, 2002 * Passed: s: string to output * line: line to display * col: column to begin display * attr: color to display string * Notes: This function is used to output most strings not part of file text. * * 991023: Possibly output an extra space before and after. */void s_output( const char *s, int line, int col, int attr ){COORD pos;int len;DWORD length; if (g_display.output_space && col != 0) c_output( ' ', col - 1, line, attr ); pos.X = col; pos.Y = line; len = strlen( s ); WriteConsoleOutputCharacter( conout, s, len, pos, &length ); FillConsoleOutputAttribute( conout, (WORD)attr, len, pos, &length ); if (g_display.output_space && col + len < g_display.ncols) c_output( ' ', col + len, line, attr );}/* * Name: hlight_line * Date: August 13, 2002 * Passed: x: column to begin hi lite * y: line to begin hi lite * lgth: number of characters to hi lite * attr: attribute color */void hlight_line( int x, int y, int lgth, int attr ){COORD pos;DWORD length; pos.X = x; pos.Y = y; FillConsoleOutputAttribute( conout, (WORD)attr, lgth, pos, &length );}/* * Name: cls * Purpose: clear screen * Date: August 13, 2002 */void cls( void ){COORD pos = { 0, 0 };int len;DWORD length; len = g_display.nlines * g_display.ncols; FillConsoleOutputCharacter( conout, ' ', len, pos, &length ); FillConsoleOutputAttribute( conout, (WORD)Color( Text ), len, pos, &length );}/* * Name: set_cursor_size * Purpose: To set cursor size according to insert mode. * Date: August 13, 2002 * Passed: csize: desired cursor size */void set_cursor_size( int csize ){CONSOLE_CURSOR_INFO cci; cci.bVisible = TRUE; cci.dwSize = csize; SetConsoleCursorInfo( conout, &cci );}/* * Name: set_overscan_color * Purpose: To set overscan color * Date: August 13, 2002 * Passed: color: overscan color * Notes: not present in a window. */void set_overscan_color( int color ){}/* * Name: save_screen_line * Purpose: To save the characters and attributes of a line on screen. * Date: August 13, 2002 * Passed: col: desired column, usually always zero * line: line on screen to save (0 up to max) * screen_buffer: buffer for screen contents, must be >= 160 chars * Notes: Save the contents of the line on screen where prompt is * to be displayed */void save_screen_line( int col, int line, Char *screen_buffer ){COORD size, pos = { 0, 0 };SMALL_RECT region; size.X = g_display.ncols; size.Y = 1; region.Left = col; region.Right = g_display.ncols - 1; region.Top = region.Bottom = line; ReadConsoleOutput( conout, screen_buffer, size, pos, ®ion );}/* * Name: restore_screen_line * Purpose: To restore the characters and attributes of a line on screen. * Date: August 13, 2002 * Passed: col: usually always zero * line: line to restore (0 up to max) * screen_buffer: buffer for screen contents, must be >= 160 chars * Notes: Restore the contents of the line on screen where the prompt * was displayed */void restore_screen_line( int col, int line, Char *screen_buffer ){COORD size, pos = { 0, 0 };SMALL_RECT region; size.X = g_display.ncols; size.Y = 1; region.Left = col; region.Right = g_display.ncols - 1; region.Top = region.Bottom = line; WriteConsoleOutput( conout, screen_buffer, size, pos, ®ion );}/* * Name: save_area * Purpose: save text and attribute * Date: July 25, 1997 * Passed: buffer: storage for text and attribute * wid: width to save * len: length to save * row: starting row of save * col: starting column of save * * 991023: I should point out that the buffer should be (at least) * (wid + 4) * (len + 1) * sizeof(Char) bytes. */void save_area( Char *buffer, int wid, int len, int row, int col ){COORD size, pos = { 0, 0 };SMALL_RECT region; adjust_area( &wid, &len, &row, &col, NULL ); size.X = wid; size.Y = len; region.Left = col; region.Top = row; region.Right = col + wid - 1; region.Bottom = row + len - 1; ReadConsoleOutput( conout, buffer, size, pos, ®ion );}/* * Name: restore_area * Purpose: restore text and attribute * Date: July 25, 1997 * Passed: buffer: storage for text and attribute * wid: width to restore * len: length to restore * row: starting row for restore * col: starting column for restore * * 991023: I should point out that these parameters should be identical * to those used in the corresponding save_area(). */void restore_area( Char *buffer, int wid, int len, int row, int col ){COORD size, pos = { 0, 0 };SMALL_RECT region; adjust_area( &wid, &len, &row, &col, NULL ); size.X = wid; size.Y = len; region.Left = col; region.Top = row; region.Right = col + wid - 1; region.Bottom = row + len - 1; WriteConsoleOutput( conout, buffer, size, pos, ®ion );}/* * Name: shadow_area * Purpose: draw a shadow around an area * Author: Jason Hood * Date: August 13, 2002 * Passed: wid: width of area * len: length of area * row: starting row of area * col: starting column of area * Notes: the characters being shadowed are not saved. * Use attribute 8 (dark grey on black) as the shadow. */void shadow_area( int wid, int len, int row, int col ){int w;int alen;int i;COORD pos;DWORD length; if (g_display.shadow) { alen = len; adjust_area( &wid, &len, &row, &col, &w ); if (w > 0) { pos.X = col + wid - 1; pos.Y = row; for (i = len; i > 1; i--) { ++pos.Y; FillConsoleOutputAttribute( conout, 8, w, pos, &length ); } } if (alen < len) { pos.X = col + g_display.shadow_width; pos.Y = row + len - 1; wid -= g_display.shadow_width + w; FillConsoleOutputAttribute( conout, 8, wid, pos, &length ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -