public void KeyPress(char keyChar) { if (ctrlModifier == true) { if (keyChar == '\n') { //Store input in recall buffer, clear input, and invoke command handler. textBuffer.Write(textBuffer.activeInput.input + "\n"); var s = textBuffer.activeInput.input; textBuffer.activeInput.input = ""; textBuffer.outputScrollPoint = 0; textBuffer.activeInput.cursor = 0; textBuffer.activeInput.scroll = 0; commandRecallBuffer.Add(s); recallBufferPlace = commandRecallBuffer.Count; OnCommand(s); } } else { if (keyChar == (char)System.Windows.Forms.Keys.Enter) { //Newline. Hack, since underlying display doesn't handle layout. var newPosition = (int)System.Math.Ceiling((float)(textBuffer.activeInput.cursor + 1) / displayWidth) * displayWidth; if (textBuffer.activeInput.cursor < textBuffer.activeInput.input.Length) { textBuffer.activeInput.input = textBuffer.activeInput.input.Insert(textBuffer.activeInput.cursor, new String(' ', newPosition - textBuffer.activeInput.cursor)); } else { textBuffer.activeInput.input += new String(' ', newPosition - textBuffer.activeInput.cursor); } textBuffer.activeInput.cursor = newPosition; } else if (keyChar == (char)System.Windows.Forms.Keys.Tab) { //Tab. Convertted to spaces immediately. var newPosition = (int)System.Math.Ceiling((float)(textBuffer.activeInput.cursor + 1) / 4) * 4; if (textBuffer.activeInput.cursor < textBuffer.activeInput.input.Length) { textBuffer.activeInput.input = textBuffer.activeInput.input.Insert(textBuffer.activeInput.cursor, new String(' ', newPosition - textBuffer.activeInput.cursor)); } else { textBuffer.activeInput.input += new String(' ', newPosition - textBuffer.activeInput.cursor); } textBuffer.activeInput.cursor = newPosition; } else if (keyChar == (char)System.Windows.Forms.Keys.Back) { //Backspace. if (textBuffer.activeInput.cursor > 0) { var front = textBuffer.activeInput.cursor - 1; var sofar = textBuffer.activeInput.input.Substring(0, front); var back = textBuffer.activeInput.input.Length - textBuffer.activeInput.cursor; if (back > 0) { sofar += textBuffer.activeInput.input.Substring(textBuffer.activeInput.cursor, back); } textBuffer.activeInput.input = sofar; textBuffer.activeInput.cursor -= 1; } } else { //If we made it here, the key must be an ordinary key. if (textBuffer.activeInput.cursor < textBuffer.activeInput.input.Length) { textBuffer.activeInput.input = textBuffer.activeInput.input.Insert(textBuffer.activeInput.cursor, new String(keyChar, 1)); } else { textBuffer.activeInput.input += keyChar; } textBuffer.activeInput.cursor += 1; } } }
public void Write(String s) { Buffer.Write(s); }