/// gets a user-inputted string until return is entered /// will use getChar to process characters one by one so that individual /// key handlers can be created std::string getInputString(teasafe::TeaSafe &theBfs, std::string const &workingPath) { std::string toReturn(""); // disable echo and prevent need to press enter for getchar flush setupTerminal(); int cursorPos(0); while(1) { char c = getchar(); if((int)c == 10) { // enter std::cout<<std::endl; break; } if((int)c == 127 || (int)c == 8) { // delete / backspace handleBackspace(cursorPos, toReturn); } else if((int)c == 9) { // tab handleTabKey(theBfs, workingPath, cursorPos, toReturn); } else { // print out char to screen and push into string vector std::cout<<c; ++cursorPos; toReturn.push_back(c); } } return toReturn; }
//============================================================================== bool CodeEditorComponent::keyPressed (const KeyPress& key) { if (! TextEditorKeyMapper<CodeEditorComponent>::invokeKeyFunction (*this, key)) { if (key == KeyPress::tabKey || key.getTextCharacter() == '\t') handleTabKey(); else if (key == KeyPress::returnKey) handleReturnKey(); else if (key == KeyPress::escapeKey) handleEscapeKey(); else if (key == KeyPress ('[', ModifierKeys::commandModifier, 0)) unindentSelection(); else if (key == KeyPress (']', ModifierKeys::commandModifier, 0)) indentSelection(); else if (key.getTextCharacter() >= ' ') insertTextAtCaret (String::charToString (key.getTextCharacter())); else return false; } pimpl->handleUpdateNowIfNeeded(); return true; }