⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console.c

📁 一个开源著名的TDE编辑器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Name:    waitkey * Purpose: nothing right now * Date:    November 13, 1993 * Passed:  enh_keyboard:  boolean - TRUE if 101 keyboard, FALSE otherwise * Returns: 1 if no key ready, 0 if key is waiting * Notes:   we might do something with this function later... */int  waitkey( int enh_keyboard ){   return( 0 );}/* * Name:    capslock_active * Purpose: To find out if Caps Lock is active * Date:    September 1, 1993 * Author:  Byrial Jensen * Returns: Non zero if Caps Lock is active, *          Zero if Caps Lock is not active. * Note:    How is capslock tested with Linux? - jmh * jmh 990426: Discovered KDGKBLED ioctl. */int  capslock_active( void ){int  kbled;   if (ioctl( 0, KDGKBLED, &kbled ) == -1)      kbled = 0;   return( kbled & LED_CAP );}/* * Name:    numlock_active * Purpose: To find out if Num Lock is active * Date:    September 8, 2002 * Returns: Non zero if Num Lock is active, *          Zero if Num Lock is not active. * * jmh 031125: this function is only used to let Shift switch between keypad *              function and number, but since there is no current separation *              between the keypad and editing keys, ignore it. */int  numlock_active( void ){#if 0int  kbled;   if (ioctl( 0, KDGKBLED, &kbled ) == -1)      kbled = 0;   return( kbled & LED_NUM );#else   return( 1 );#endif}/* * Name:    flush_keyboard * Purpose: flush keys from the keyboard buffer.  flushinp is a curses func. * Date:    November 13, 1993 * Passed:  none */void flush_keyboard( void ){   flushinp( );}/* Name:    page * Purpose: Change the text screen page * Author:  Jason Hood * Date:    April 18, 1999 * Passed:  payg:   desired page number * Notes:   if payg is 1, read from /dev/vcsa0 *          if payg is 0, write to /dev/vcsa0 *          Assumes screen size does not change between calls. *          Assumes stdout is not redirected (to relocate the cursor). *          If unable to open /dev/vcsa0 this function has no effect. * * jmh 010808: try and open /dev/vcsa if /dev/vcsa0 fails. * jmh 030403: ignored in an xterm. * jmh 031126: open the current vt (doesn't require root privileges) */void page( unsigned char payg ){int  fd;static struct {   char lines, cols,        x, y;} dim;static char *scrn = NULL;static int  size;static char vt[] = "/dev/vcsa??";struct stat stb;   if (xterm)      return;   if (vt[9] == '?') {      if (fstat( 0, &stb ) == 0) {         fd = stb.st_rdev & 0xff;         if (fd < 10) {            vt[9]  = fd + '0';            vt[10] = '\0';         } else {            vt[9]  = fd / 10 + '0';            vt[10] = fd % 10 + '0';         }      }   }   if ((fd = open( vt, O_RDWR )) == -1)      return;   if (payg == 1) {      read( fd, &dim, 4 );      size = dim.lines * dim.cols * 2;      if (scrn != NULL)         free( scrn );      scrn = malloc( size );      read( fd, scrn, size );   } else if (scrn != NULL) {      lseek( fd, 4, SEEK_SET );      write( fd, scrn, size );      /*       * Unfortunately, writing these doesn't update them.       */      printf( "\033[%d;%dH", (int)dim.y+1, (int)dim.x+1 );      fflush( stdout );   }   close( fd );}/* * Name:    xygoto * Purpose: To move the cursor to the required column and line. * Date:    November 13, 1993 * Passed:  col:    desired column (0 up to max) *          line:   desired line (0 up to max) * Notes;   on the PC, we use col = -1 and line = -1 to turn the cursor off. *            in unix, we try to trap the -1's. *          curs_set is a curses function. */void xygoto( int col, int line ){   if (col < 0 || line < 0) {      curs_set( CURSES_INVISBL );      g_display.curses_cursor = CURSES_INVISBL;   } else {      /*       * if the unix cursor is invisible, lets turn it back on.       */      if (g_display.curses_cursor == CURSES_INVISBL)         set_cursor_size( mode.insert ? g_display.insert_cursor :                                        g_display.overw_cursor );      move( line, col );   }}/* * Name:    c_xlat * Purpose: Translate character to chtype, recognising undisplayable chars. * Author:  Jason Hood * Date:    November 26, 2003 * Passed:  c:     character *          attr:  attribute * Returns: chtype of character and attribute * Note:    use the diagnostic color for undisplayable characters (which were *           found by experimentation). */static chtype c_xlat( int c, int attr ){text_t uc;   uc = (text_t)c;   if (uc < 32) {#if defined( PC_CHARS )      if (uc == 0 || uc == 8 || uc == 10 || (uc >= 12 && uc <= 15) || uc == 27)#endif         return( (uc+64) | tde_color_table[Color( Diag )] );   }   if (uc == 127 || uc == 0x9b)      return( '.' | tde_color_table[Color( Diag )] );   return( uc | pc_chars | tde_color_table[attr] );}/* * Name:    display_line * Purpose: display a line in the file * Author:  Jason Hood * Date:    October 28, 1999 * 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( text_ptr text, unsigned char *attr, int len,                   int line, int col ){   move( line, col );   do      addch( c_xlat( *text++, *attr++ ) );   while (--len != 0);}/* * Name:    c_output * Purpose: Output one character on prompt lines * Date:    November 13, 1993 * 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 ){   mvaddch( line, col, c_xlat( c, attr ) );}/* * 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 ){chtype ch;   ch = c_xlat( c, attr );   move( line, col );   if (cnt < 0)      vline( ch, -cnt );   else      hline( ch, cnt );}/* * Name:    s_output * Purpose: To output a string * Date:    November 13, 1993 * 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 ){int  max = g_display.ncols;   if (g_display.output_space && col != 0)      mvaddch( line, col - 1, ' ' | tde_color_table[attr] );   else      move( line, col );   while (*s  &&  col++ < max)      addch( c_xlat( *s++, attr ) );   if (g_display.output_space && col != max)      addch( ' ' | tde_color_table[attr] );}/* * Name:    hlight_line * Date:    November 13, 1993 * 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 ){   if (x + lgth > g_display.ncols)      lgth = g_display.ncols - x;   if (lgth > 0) {      move( y, x );      do         addch( (inch( ) & A_CHARTEXT) | pc_chars | tde_color_table[attr] );      while (--lgth != 0);   }   refresh( );}/* * Name:    cls * Purpose: clear screen * Date:    November 13, 1993 * Notes:   Call the curses clear screen function. */void cls( void ){   touchwin( curscr );   clear( );   refresh( );}/* * Name:    set_cursor_size * Purpose: To set cursor size according to insert mode. * Date:    November 13, 1993 * Passed:  csize:  not used in unix curses * Notes:   use the global display structures to set the cursor size *          curs_set( ) is a curses function. */void set_cursor_size( int csize ){   curs_set( csize );   g_display.curses_cursor = csize;}/* * Name:    set_overscan_color * Purpose: To set overscan color * Date:    November 13, 1993 * Passed:  color:  overscan color * Notes:   i'm not sure how to set the overscan in Linux (yet?). * * jmh 031125: access the VGA hardware directly (console, root). */void set_overscan_color( int color ){   if (port_access) {      inb( 0x3da );             /* switch flip-flop to index mode */      outb( 0x31, 0x3c0 );      /* display enable, register 0x11 */      outb( color, 0x3c0 );     /* overscan color */   }}/* * Name:    save_screen_line * Purpose: To save the characters and attributes of a line on screen. * Date:    November 13, 1993 * 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 >= 80 chtype * Notes:   Save the contents of the line on screen where prompt is *           to be displayed. */void save_screen_line( int col, int line, chtype *screen_buffer ){   mvinchstr( line, col, screen_buffer );}/* * Name:    restore_screen_line * Purpose: To restore the characters and attributes of a line on screen. * Date:    November 13, 1993 * Passed:  col:    usually always zero *          line:   line to restore (0 up to max) *          screen_buffer:  buffer for screen contents, must be >= 80 chtype * Notes:   Restore the contents of the line on screen where the prompt *           was displayed */void restore_screen_line( int col, int line, chtype *screen_buffer ){   mvaddchstr( line, col, screen_buffer );   refresh( );}/* * Name:    save_area * Purpose: save text and attribute * Date:    November 13, 1993 * 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 * Notes:   use curses to get char and attr * * jmh 991022:  I should point out that the buffer should be (at least) *                (wid + 4) * (len + 1) * sizeof(chtype) bytes. */void save_area( chtype *buffer, int wid, int len, int row, int col ){int  i;   adjust_area( &wid, &len, &row, &col, NULL );   len--;   for (i = 0; len >= 0; len--) {      mvinchnstr( row+len, col, buffer, wid );      buffer += wid;   }}/* * Name:    restore_area * Purpose: restore text and attribute * Date:    November 13, 1993 * 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 * Notes:   use curses to set char and attr * * jmh 991022:  I should point out that these parameters should be identical *                to those used in the corresponding save_area(). */void restore_area( chtype *buffer, int wid, int len, int row, int col ){int  i;   adjust_area( &wid, &len, &row, &col, NULL );   len--;   for (i = 0; len >= 0; len--) {      mvaddchnstr( row+len, col, buffer, wid );      buffer += wid;   }   refresh( );}/* * Name:    shadow_area * Purpose: draw a shadow around an area * Author:  Jason Hood * Date:    October 20, 1999 * 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  i;int  j;int  alen;   if (g_display.shadow) {      alen = len;      adjust_area( &wid, &len, &row, &col, &w );      if (w > 0) {         for (i = len - 1; i > 0; i--) {            move( row+i, col+wid-w );            for (j = w; j >= 1; j--)               addch( (inch( ) & A_CHARTEXT) | pc_chars | tde_color_table[8] );         }      }      if (alen < len) {         col += g_display.shadow_width;         wid -= g_display.shadow_width + w;         row += len - 1;         /* hlight_line( col, row, wid, 8 ); */         move( row, col );         while (--wid >= 0)            addch( (inch( ) & A_CHARTEXT) | pc_chars | tde_color_table[8] );      }      refresh( );   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -