Exemplo n.º 1
0
void Console::keyPress( const NEvent& event )
{
  if( event.keyboard.key == KEY_RETURN )
  {
    if( currentCommand_.size() > 0 )
      resolveCommand_();
  }
  else if( event.keyboard.pressed )
  {
    switch ( event.keyboard.key )
    {
      case KEY_BACK:
        if( currentCommand_.size() > 0 && cursorPos_ > 1 )
        {
          cursorPos_--;
          currentCommand_.erase( cursorPos_-1 );
        }
      break;
      case KEY_DELETE:
            if( cursorPos_ <= currentCommand_.size() )
               currentCommand_.erase( cursorPos_-1 );
      break;
      case KEY_UP: setPrevCommand_(); break;

      case KEY_LEFT:
      case KEY_RIGHT: moveCursor_( event.keyboard.key == KEY_LEFT ); break;

      case KEY_DOWN: setNextCommand_(); break;
      case KEY_TAB: tabComplete(); break;
      default: inputChar_( event.keyboard.symbol, event.keyboard.shift ); break;
    }
  }

  _updateCommandRect();
}
Exemplo n.º 2
0
void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) {
	event->ignore();
	if (event->isAccepted()) {
		return;
	}
	event->accept();

	int key = event->key();
	if (key == Qt::Key_Tab) {
		tabComplete();
	}
	else if ((key == Qt::Key_Up) && input_->toPlainText().isEmpty() && !(lastSentMessage_.isEmpty())) {
		beginCorrection();
	}
	else if (key == Qt::Key_Down && isCorrection_ && input_->textCursor().atBlockEnd()) {
		cancelCorrection();
	}
	else if (key == Qt::Key_Down || key == Qt::Key_Up) {
		event->ignore();
	}
	else {
		messageLog_->handleKeyPressEvent(event);
	}
}
Exemplo n.º 3
0
std::string InputReader::getInput() {
    output = "";
    current_char = 0;
    cursor_pos = 0;
    hist_pos = 0;
    tab_pos = 0;
    in_tab_complete = false;
    in_history = false;

    std::cout << this->prompt << std::flush;
    getch();

    bool escaped = false;
    bool arrow_key = false;

    while (current_char != '\n') {
        if (arrow_key) {
            moveCursor(current_char);
            escaped = false;
            arrow_key = false;
        } else if (escaped) {
            if (current_char == '[') {
                arrow_key = true;
            }
        } else {
            if (current_char == 27) {  // esc char for arrow keys
                escaped = true;
            } else if (current_char == '\t') {
                tabComplete();
            } else {
                if (in_history) {
                    output = current_hist_val;
                    in_history = false;

                } else if (in_tab_complete) {
                    output = current_tab_val;
                    in_tab_complete = false;
                }

                if (current_char == 127) {
                    backspace();
                } else {
                    output.insert(output.begin() + (cursor_pos++), current_char);
                    std::cout << current_char << std::flush;
                    showFullText(output);
                }
            }
        }

        getch();
    }

    if (in_history) {
        return current_hist_val;
    }
    if (in_tab_complete) {
        return current_tab_val;
    }

    return output;
}
Exemplo n.º 4
0
void terminalDriver() {
  char commands[NUM_SAVED_COMMANDS][BUFFERSIZE];
  int lengths[NUM_SAVED_COMMANDS];
  int commandNum = 0, viewingNum = 0;

  char curCommand[BUFFERSIZE];
  int commandLength = 0, totalCommands = 0;

  char c;

  int trainSpeeds[80];
  int i;
  for(i=0; i<80; i++) {
    trainSpeeds[i] = 0;
  }
  int train[80];
  for(i=0; i<80; i++) {
    train[i] = -1;
  }

  Create(2, clockDriver);

  outputEscape("[2J[13;100r");
  refreshScreen();
  initializeTrack();
  moveCursor(13, 1);
  Putc(2, '>');
  while(true) {
    c = (char)Getc(2);
    switch(c) {
      case '\r':
	curCommand[commandLength] = '\0';
	strcpy(commands[commandNum], curCommand);
	lengths[commandNum] = commandLength;
	Putc(2, '\r');
	parseCommand(curCommand, trainSpeeds, train);
	commandNum++;
	commandNum %= NUM_SAVED_COMMANDS;
	viewingNum = commandNum;
	commands[commandNum][0] = '\0';
	commandLength = 0;
	if(totalCommands < NUM_SAVED_COMMANDS-1) totalCommands++;
	Putc(2, '>');
	break;
      case '\t':
	if(commandLength > 0) {
	  curCommand[commandLength] = '\0';
	  commandLength = tabComplete(curCommand);
	  outputEscape("[100D[K");
	  printf(">%s", curCommand);
	}
	break;
      case '\x8':
	if(commandLength > 0) {
	  commandLength--;
	  outputEscape("[1D[K");
	}
	break;
      case '\x1B':	//escape
	c = (char)Getc(2);
	c = (char)Getc(2);
	if(c == 'A') {
	  if(commandNum == viewingNum) {
	    curCommand[commandLength] = '\0';
	    strcpy(commands[commandNum], curCommand);
	    lengths[commandNum] = commandLength;
	  }
	  if(viewingNum != ((commandNum + NUM_SAVED_COMMANDS - totalCommands) 
					% NUM_SAVED_COMMANDS)) {
	    viewingNum += NUM_SAVED_COMMANDS - 1;
	    viewingNum %= NUM_SAVED_COMMANDS;
	    strcpy(curCommand, commands[viewingNum]);
	    commandLength = lengths[viewingNum];
	    outputEscape("[100D[K");
	    printf(">%s", curCommand);
	  }
	}else if(c == 'B') {
	  if(viewingNum != commandNum) {
	    viewingNum += 1;
	    viewingNum %= NUM_SAVED_COMMANDS;
	    strcpy(curCommand, commands[viewingNum]);
	    commandLength = lengths[viewingNum];
	    outputEscape("[100D[K");
	    printf(">%s", curCommand);
	  }
	}
	break;
      default:
	if(commandLength < BUFFERSIZE - 1) {
          curCommand[commandLength++] = c;
          Putc(2, c);
	}
        break;
    }
  }
}