Exemple #1
0
// Move cursor left "delta" chars
void term_left( unsigned delta )
{
  term_ansi( "%uD", delta );  
  term_cx += delta;
}
Exemple #2
0
// Move cursor down "delta" lines
void term_down( unsigned delta )
{
  term_ansi( "%uB", delta );  
  term_cy += delta;
}
Exemple #3
0
// Move cursor right "delta" chars
void term_right( unsigned delta )
{
  term_ansi( "%uC", delta );  
  term_cx -= delta;
}
Exemple #4
0
// Move cursor up "delta" lines
void term_up( unsigned delta )
{
  term_ansi( "%uA", delta );  
  term_cy -= delta;
}
Exemple #5
0
// Move cursor to (x, y)
void term_gotoxy( unsigned x, unsigned y )
{
  term_ansi( "%u;%uH", y, x );
  term_cx = x;
  term_cy = y;
}
Exemple #6
0
// Clear to end of line
void term_clreol()
{
  term_ansi( "K" );
}
Exemple #7
0
// Clear the screen
void term_clrscr()
{
  term_ansi( "2J" );
  term_cx = term_cy = 0;
}
Exemple #8
0
/* ----------------------------------------------------------------------- */
int term_read(int fd, char *buf, unsigned int len) {
  char c;
  int ret;
  static unsigned long remain;
          
  if(remain) {
  check_remain:
    if(len > remain)
      len = remain;
    byte_copy(buf, len, &term_cmdline.s[term_cmdline.len - remain]);
    remain -= len;
    if(!remain) {
      tcsetattr(fd, TCSANOW, &term_tcattr);
      stralloc_zero(&term_cmdline);
    }
    return len;
  }
    
/*  tcsetattr(fd, TCSANOW, &term_tcattr);*/
  term_attr(term_input.fd, 1);
  
  prompt_show();
    
  while((ret = buffer_getc(&term_input, &c)) > 0) {
    switch(c) {
      /* control-c discards the current line */
      case 3:
        stralloc_zero(&term_cmdline);
      /* newline */
      case '\n':
        term_newline();
        remain = term_cmdline.len;
        goto check_remain;
      /* control-a is HOME */
      case 1:
        term_home();
        break;
      /* control-e is END */
      case 5:
        term_end();
        break;
      /* control-d is EOF */
      case 4:
      if(!term_cmdline.len) {
          buffer_puts(term_output, "EOF");
          buffer_putnlflush(term_output);
          ret = 0;
          goto fail;
        }
        break;
      /* do the ANSI codes */
      case '\033':
        term_ansi();
        break;
      /* backspace */
      case 127:
      case '\b':
        term_backspace();
        break;
      /* printable chars */
      case '\t':
        c = ' ';
      default:
        if(term_insert)
          term_insertc(c);
        else
          term_overwritec(c);
        break;
    }
  }
fail:
  return ret;
}