public Decoder(Terminal terminal, Action <byte> responseCallback, IDecoderLogger logger) { this.terminal = terminal; this.responseCallback = responseCallback; this.logger = logger; commands = new Dictionary <char, Action>(); graphicRendition = new GraphicRendition(this); savedGraphicRendition = graphicRendition.Clone(); InitializeCommands(); cursor = new Cursor(this); CharReceivedBlinkDisabledRounds = 1; }
protected override void ProcessCommand(byte _command, String _parameter) { //System.Console.WriteLine ( "ProcessCommand: {0} {1}", (char) _command, _parameter ); switch ((char)_command) { case 'A': OnMoveCursor(Direction.Up, DecodeInt(_parameter, 1)); break; case 'B': OnMoveCursor(Direction.Down, DecodeInt(_parameter, 1)); break; case 'C': OnMoveCursor(Direction.Forward, DecodeInt(_parameter, 1)); break; case 'D': OnMoveCursor(Direction.Backward, DecodeInt(_parameter, 1)); break; case 'E': OnMoveCursorToBeginningOfLineBelow(DecodeInt(_parameter, 1)); break; case 'F': OnMoveCursorToBeginningOfLineAbove(DecodeInt(_parameter, 1)); break; case 'G': OnMoveCursorToColumn(DecodeInt(_parameter, 1) - 1); break; case 'H': case 'f': { int separator = _parameter.IndexOf(';'); if (separator == -1) { OnMoveCursorTo(new Point(0, 0)); } else { String row = _parameter.Substring(0, separator); String column = _parameter.Substring(separator + 1, _parameter.Length - separator - 1); OnMoveCursorTo(new Point(DecodeInt(column, 1) - 1, DecodeInt(row, 1) - 1)); } } break; case 'J': OnClearScreen((ClearDirection)DecodeInt(_parameter, 0)); break; case 'K': OnClearLine((ClearDirection)DecodeInt(_parameter, 0)); break; case 'S': OnScrollPageUpwards(DecodeInt(_parameter, 1)); break; case 'T': OnScrollPageDownwards(DecodeInt(_parameter, 1)); break; case 'm': { String[] commands = _parameter.Split(';'); GraphicRendition[] renditionCommands = new GraphicRendition[commands.Length]; for (int i = 0; i < commands.Length; ++i) { renditionCommands[i] = (GraphicRendition)DecodeInt(commands[i], 0); //System.Console.WriteLine ( "Rendition command: {0} = {1}", commands[i], renditionCommands[i]); } OnSetGraphicRendition(renditionCommands); } break; case 'n': if (_parameter == "6") { Point cursorPosition = OnGetCursorPosition(); cursorPosition.X++; cursorPosition.Y++; String row = cursorPosition.Y.ToString(); String column = cursorPosition.X.ToString(); byte[] output = new byte[2 + row.Length + 1 + column.Length + 1]; int i = 0; output[i++] = EscapeCharacter; output[i++] = LeftBracketCharacter; foreach (char c in row) { output[i++] = (byte)c; } output[i++] = (byte)';'; foreach (char c in column) { output[i++] = (byte)c; } output[i++] = (byte)'R'; OnOutput(output); } break; case 's': OnSaveCursor(); break; case 'u': OnRestoreCursor(); break; case 'l': switch (_parameter) { case "20": // Set line feed mode OnModeChanged(AnsiMode.LineFeed); break; case "?1": // Set cursor key to cursor DECCKM OnModeChanged(AnsiMode.CursorKeyToCursor); break; case "?2": // Set ANSI (versus VT52) DECANM OnModeChanged(AnsiMode.VT52); break; case "?3": // Set number of columns to 80 DECCOLM OnModeChanged(AnsiMode.Columns80); break; case "?4": // Set jump scrolling DECSCLM OnModeChanged(AnsiMode.JumpScrolling); break; case "?5": // Set normal video on screen DECSCNM OnModeChanged(AnsiMode.NormalVideo); break; case "?6": // Set origin to absolute DECOM OnModeChanged(AnsiMode.OriginIsAbsolute); break; case "?7": // Reset auto-wrap mode DECAWM // Disable line wrap OnModeChanged(AnsiMode.DisableLineWrap); break; case "?8": // Reset auto-repeat mode DECARM OnModeChanged(AnsiMode.DisableAutoRepeat); break; case "?9": // Reset interlacing mode DECINLM OnModeChanged(AnsiMode.DisableInterlacing); break; case "?25": OnModeChanged(AnsiMode.HideCursor); break; default: throw new InvalidParameterException(_command, _parameter); } break; case 'h': switch (_parameter) { case "": //Set ANSI (versus VT52) DECANM OnModeChanged(AnsiMode.ANSI); break; case "20": // Set new line mode OnModeChanged(AnsiMode.NewLine); break; case "?1": // Set cursor key to application DECCKM OnModeChanged(AnsiMode.CursorKeyToApplication); break; case "?3": // Set number of columns to 132 DECCOLM OnModeChanged(AnsiMode.Columns132); break; case "?4": // Set smooth scrolling DECSCLM OnModeChanged(AnsiMode.SmoothScrolling); break; case "?5": // Set reverse video on screen DECSCNM OnModeChanged(AnsiMode.ReverseVideo); break; case "?6": // Set origin to relative DECOM OnModeChanged(AnsiMode.OriginIsRelative); break; case "?7": // Set auto-wrap mode DECAWM // Enable line wrap OnModeChanged(AnsiMode.LineWrap); break; case "?8": // Set auto-repeat mode DECARM OnModeChanged(AnsiMode.AutoRepeat); break; case "?9": /// Set interlacing mode OnModeChanged(AnsiMode.Interlacing); break; case "?25": OnModeChanged(AnsiMode.ShowCursor); break; default: throw new InvalidParameterException(_command, _parameter); } break; case '>': // Set numeric keypad mode OnModeChanged(AnsiMode.NumericKeypad); break; case '=': OnModeChanged(AnsiMode.AlternateKeypad); // Set alternate keypad mode (rto: non-numeric, presumably) break; default: throw new InvalidCommandException(_command, _parameter); } }
protected override void ProcessCommand( byte _command, String _parameter ) { //System.Console.WriteLine ( "ProcessCommand: {0} {1}", (char) _command, _parameter ); switch ( (char) _command ) { case 'A': OnMoveCursor( Direction.Up, DecodeInt( _parameter, 1 ) ); break; case 'B': OnMoveCursor( Direction.Down, DecodeInt( _parameter, 1 ) ); break; case 'C': OnMoveCursor( Direction.Forward, DecodeInt( _parameter, 1 ) ); break; case 'D': OnMoveCursor( Direction.Backward, DecodeInt( _parameter, 1 ) ); break; case 'E': OnMoveCursorToBeginningOfLineBelow( DecodeInt( _parameter, 1 ) ); break; case 'F': OnMoveCursorToBeginningOfLineAbove( DecodeInt( _parameter, 1 ) ); break; case 'G': OnMoveCursorToColumn( DecodeInt( _parameter, 1 ) - 1 ); break; case 'H': case 'f': { int separator = _parameter.IndexOf( ';' ); if ( separator == -1 ) { OnMoveCursorTo( new Point( 0, 0 ) ); } else { String row = _parameter.Substring( 0, separator ); String column = _parameter.Substring( separator + 1, _parameter.Length - separator - 1 ); OnMoveCursorTo( new Point( DecodeInt( column, 1 ) - 1, DecodeInt( row, 1 ) - 1 ) ); } } break; case 'J': OnClearScreen( (ClearDirection) DecodeInt( _parameter, 0 ) ); break; case 'K': OnClearLine( (ClearDirection) DecodeInt( _parameter, 0 ) ); break; case 'S': OnScrollPageUpwards( DecodeInt( _parameter, 1 ) ); break; case 'T': OnScrollPageDownwards( DecodeInt( _parameter, 1 ) ); break; case 'm': { String[] commands = _parameter.Split( ';' ); GraphicRendition[] renditionCommands = new GraphicRendition[commands.Length]; for ( int i = 0 ; i < commands.Length ; ++i ) { renditionCommands[i] = (GraphicRendition) DecodeInt( commands[i], 0 ); //System.Console.WriteLine ( "Rendition command: {0} = {1}", commands[i], renditionCommands[i]); } OnSetGraphicRendition( renditionCommands ); } break; case 'n': if ( _parameter == "6" ) { Point cursorPosition = OnGetCursorPosition(); cursorPosition.X++; cursorPosition.Y++; String row = cursorPosition.Y.ToString(); String column = cursorPosition.X.ToString(); byte[] output = new byte[2 + row.Length + 1 + column.Length + 1]; int i = 0; output[i++] = EscapeCharacter; output[i++] = LeftBracketCharacter; foreach ( char c in row ) { output[i++] = (byte) c; } output[i++] = (byte) ';'; foreach ( char c in column ) { output[i++] = (byte) c; } output[i++] = (byte) 'R'; OnOutput( output ); } break; case 's': OnSaveCursor(); break; case 'u': OnRestoreCursor(); break; case 'l': switch ( _parameter ) { case "20": // Set line feed mode OnModeChanged( AnsiMode.LineFeed ); break; case "?1": // Set cursor key to cursor DECCKM OnModeChanged( AnsiMode.CursorKeyToCursor ); break; case "?2": // Set ANSI (versus VT52) DECANM OnModeChanged( AnsiMode.VT52 ); break; case "?3": // Set number of columns to 80 DECCOLM OnModeChanged( AnsiMode.Columns80 ); break; case "?4": // Set jump scrolling DECSCLM OnModeChanged( AnsiMode.JumpScrolling ); break; case "?5": // Set normal video on screen DECSCNM OnModeChanged( AnsiMode.NormalVideo ); break; case "?6": // Set origin to absolute DECOM OnModeChanged( AnsiMode.OriginIsAbsolute ); break; case "?7": // Reset auto-wrap mode DECAWM // Disable line wrap OnModeChanged( AnsiMode.DisableLineWrap ); break; case "?8": // Reset auto-repeat mode DECARM OnModeChanged( AnsiMode.DisableAutoRepeat ); break; case "?9": // Reset interlacing mode DECINLM OnModeChanged( AnsiMode.DisableInterlacing ); break; case "?25": OnModeChanged( AnsiMode.HideCursor ); break; default: throw new InvalidParameterException( _command, _parameter ); } break; case 'h': switch ( _parameter ) { case "": //Set ANSI (versus VT52) DECANM OnModeChanged( AnsiMode.ANSI ); break; case "20": // Set new line mode OnModeChanged( AnsiMode.NewLine ); break; case "?1": // Set cursor key to application DECCKM OnModeChanged( AnsiMode.CursorKeyToApplication ); break; case "?3": // Set number of columns to 132 DECCOLM OnModeChanged( AnsiMode.Columns132 ); break; case "?4": // Set smooth scrolling DECSCLM OnModeChanged( AnsiMode.SmoothScrolling ); break; case "?5": // Set reverse video on screen DECSCNM OnModeChanged( AnsiMode.ReverseVideo ); break; case "?6": // Set origin to relative DECOM OnModeChanged( AnsiMode.OriginIsRelative ); break; case "?7": // Set auto-wrap mode DECAWM // Enable line wrap OnModeChanged( AnsiMode.LineWrap ); break; case "?8": // Set auto-repeat mode DECARM OnModeChanged( AnsiMode.AutoRepeat ); break; case "?9": /// Set interlacing mode OnModeChanged( AnsiMode.Interlacing ); break; case "?25": OnModeChanged( AnsiMode.ShowCursor ); break; default: throw new InvalidParameterException( _command, _parameter ); } break; case '>': // Set numeric keypad mode OnModeChanged( AnsiMode.NumericKeypad ); break; case '=': OnModeChanged( AnsiMode.AlternateKeypad ); // Set alternate keypad mode (rto: non-numeric, presumably) break; default: throw new InvalidCommandException( _command, _parameter ); } }
protected virtual void OnSetGraphicRendition( GraphicRendition[] _commands ) { foreach ( IAnsiDecoderClient client in m_listeners ) { client.SetGraphicRendition( this, _commands ); } }
protected override void ProcessCommandCSI(byte _command, String _parameter) { //System.Console.WriteLine ( "ProcessCommand: {0} {1}", (char) _command, _parameter ); switch ((char)_command) { case 'A': // CSI Ps A Cursor Up Ps Times (default = 1) (CUU). OnMoveCursor(Direction.Up, DecodeInt(_parameter, 1), false); break; case 'B': // CSI Ps B Cursor Down Ps Times (default = 1) (CUD). OnMoveCursor(Direction.Down, DecodeInt(_parameter, 1), false); break; case 'C': // CSI Ps C Cursor Forward Ps Times(default = 1)(CUF). OnMoveCursor(Direction.Forward, DecodeInt(_parameter, 1), false); break; case 'D': // CSI Ps D Cursor Backward Ps Times (default = 1) (CUB). OnMoveCursor(Direction.Backward, DecodeInt(_parameter, 1), false); break; case 'E': // CSI Ps E Cursor Next Line Ps Times (default = 1) (CNL). OnMoveCursorToBeginningOfLineBelow(DecodeInt(_parameter, 1), false); break; case 'F': // CSI Ps F Cursor Preceding Line Ps Times (default = 1) (CPL). OnMoveCursorToBeginningOfLineAbove(DecodeInt(_parameter, 1), false); break; case 'G': // CSI Ps G Cursor Character Absolute [column] (default = [row,1]) (CHA). OnMoveCursorToColumn(DecodeInt(_parameter, 1) - 1); break; case 'H': //CSI Ps ; Ps H - Cursor Position[row; column] (default = [1, 1])(CUP). case 'f': { int separator = _parameter.IndexOf(';'); if (separator == -1) { OnMoveCursorTo(new Point(0, 0)); } else { String row = _parameter.Substring(0, separator); String column = _parameter.Substring(separator + 1, _parameter.Length - separator - 1); OnMoveCursorTo(new Point(DecodeInt(column, 1) - 1, DecodeInt(row, 1) - 1)); } } break; case 'I': // CSI Ps I Cursor Forward Tabulation Ps tab stops (default = 1) (CHT). break; case 'J': // CSI Ps J Erase in Display(ED), VT100. // Ps = 0->Erase Below(default). // Ps = 1->Erase Above. // Ps = 2->Erase All. // Ps = 3->Erase Saved Lines(xterm). OnClearScreen((ClearDirection)DecodeInt(_parameter, 0)); break; case 'K': // CSI Ps K Erase in Line(EL), VT100. // Ps = 0->Erase to Right(default). // Ps = 1->Erase to Left. // Ps = 2->Erase All. OnClearLine((ClearDirection)DecodeInt(_parameter, 0)); break; case 'M': // CSI Ps M Delete Ps Line(s) (default = 1) (DL). break; case 'S': // CSI Ps S Scroll up Ps lines (default = 1) (SU), VT420, ECMA-48. OnScrollPageUpwards(DecodeInt(_parameter, 1)); break; case 'T': // CSI Ps T Scroll down Ps lines (default = 1) (SD), VT420. OnScrollPageDownwards(DecodeInt(_parameter, 1)); break; case 'c': // CSI Ps c Send Device Attributes (Primary DA). DoCSI_PrimaryDA(_parameter); break; case 'h': // CSI ? Pm h - DEC Private Mode Set(DECSET). DoCSI_DECSET(_command, _parameter); break; case 'g': // CSI Ps g Tab Clear (TBC). switch (_parameter) { case "": case "0": ClearTab(false); break; case "3": ClearTab(true); break; } break; case 'l': // CSI ? Pm l - DEC Private Mode Reset(DECRST). DoCSI_DECRST(_command, _parameter); break; case 'm': // CSI Pm m Character Attributes (SGR). { String[] commands = _parameter.Split(';'); GraphicRendition[] renditionCommands = new GraphicRendition[commands.Length]; for (int i = 0; i < commands.Length; ++i) { renditionCommands[i] = (GraphicRendition)DecodeInt(commands[i], 0); //System.Console.WriteLine ( "Rendition command: {0} = {1}", commands[i], renditionCommands[i]); } OnSetGraphicRendition(renditionCommands); } break; case 'n': // CSI Ps n Device Status Report (DSR). DoCSI_DSR(_parameter); break; case 'r': // CSI Ps ; Ps r Set Scrolling Region [top;bottom] (default = full size of window) (DECSTBM), VT100. // CSI ? Pm r Restore DEC Private Mode Values.The value of Ps previously saved is restored.Ps values are the same as for DECSET. // CSI Pt; Pl; Pb ; Pr; Ps $ r Change Attributes in Rectangular Area(DECCARA), VT400 and up. Pt; Pl; Pb; Pr denotes the rectangle. Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7. break; case 's': // CSI s Save cursor, available only when DECLRMM is disabled (SCOSC, also ANSI.SYS). OnSaveCursor(); break; case 't': // Window manipulation EWMH DoCSI_WindowManipulation(_parameter); break; case 'u': // CSI u Restore cursor (SCORC, also ANSI.SYS). OnRestoreCursor(); break; case '>': // Set numeric keypad mode OnModeChanged(AnsiMode.NumericKeypad); break; case '=': OnModeChanged(AnsiMode.AlternateKeypad); // Set alternate keypad mode (rto: non-numeric, presumably) break; // Unknowns case '(': case 'j': case '\\': case ']': default: Debug.WriteLine("Unimplemented CSI: Command=" + _command + " Param=" + _parameter); break; } }
void IAnsiDecoderClient.SetGraphicRendition ( IAnsiDecoder _sender, GraphicRendition[] _commands ) { }