internal void DetachTelnet(TelnetSingletonServer server) { server.DisconnectFromProcessor(); telnets.Remove(server); }
/// <summary> /// Respond to one single input character in Unicode, using the pretend /// virtual Unicode terminal keycodes described in the UnicodeCommand enum. /// To keep things simple, all key input is coerced into single Unicode chars /// even if the actual keypress takes multiple characters to express in its /// native form (i.e. ESC [ A means left-arrow on a VT100 terminal. If /// a telnet is talking via VT100 codes, that ESC [ A will get converted into /// a single UnicdeCommand.LEFTCURSORONE character before being sent here.) /// <br/> /// This method is public because it is also how other mods should send input /// to the terminal if they want some other source to send simulated keystrokes. /// </summary> /// <param name="ch">The character, which might be a UnicodeCommand char</param> /// <param name="whichTelnet">If this came from a telnet session, which one did it come from? /// Set to null in order to say it wasn't from a telnet but was from the interactive GUI</param> /// <param name="doQueuing">true if the keypress should get queued if we're not ready for it /// right now. If false, then the keypress will be ignored if we're not ready for it.</param> public void ProcessOneInputChar(char ch, TelnetSingletonServer whichTelnet, bool doQueuing = true) { // Weird exceptions for multi-char data combos that would have been begun on previous calls to this method: switch (inputExpected) { case ExpectNextChar.RESIZEWIDTH: pendingWidth = ch; inputExpected = ExpectNextChar.RESIZEHEIGHT; return; case ExpectNextChar.RESIZEHEIGHT: int height = ch; shared.Screen.SetSize(height, pendingWidth); inputExpected = ExpectNextChar.NORMAL; return; default: break; } // Printable ASCII section of Unicode - the common vanilla situation // (Idea: Since this is all Unicode anyway, should we allow a wider range to // include multi-language accent characters and so on? Answer: to do so we'd // first need to expand the font pictures in the font image file, so it's a // bigger task than it may first seem.) if (0x0020 <= ch && ch <= 0x007f) { Type(ch, doQueuing); } else { switch(ch) { // A few conversions from UnicodeCommand into those parts of ASCII that it // maps directly into nicely, otherwise just pass it through to SpecialKey(): case (char)UnicodeCommand.DELETELEFT: case (char)8: Type((char)8, doQueuing); break; case (char)UnicodeCommand.STARTNEXTLINE: case '\r': Type('\r', doQueuing); break; case '\t': Type('\t', doQueuing); break; case (char)UnicodeCommand.RESIZESCREEN: inputExpected = ExpectNextChar.RESIZEWIDTH; break; // next expected char is the width. // Finish session: If GUI, then close window. If Telnet, then detatch from the session: case (char)0x0004/*control-D*/: // How users of unix shells are used to doing this. case (char)0x0018/*control-X*/: // How kOS did it in the past in the GUI window. if (shared.Interpreter.IsAtStartOfCommand()) { if (whichTelnet == null) Close(); else whichTelnet.DisconnectFromProcessor(); } break; // User asking for redraw (Unity already requires that we continually redraw the GUI Terminal, so this is only meaningful for telnet): case (char)UnicodeCommand.REQUESTREPAINT: if (whichTelnet != null) { ResizeAndRepaintTelnet(whichTelnet, shared.Screen.ColumnCount, shared.Screen.RowCount, true); } break; // Typical case is to just let SpecialKey do the work: default: SpecialKey(ch, doQueuing); break; } } // else ignore it - unimplemented char. }