public static TerminalSequence ConsumeNextSequence(XTermInputBuffer stream) { stream.PushState(); var next = stream.Read(); TerminalSequence sequence = null; switch (next) { case '\u001b': // ESC sequence = ConsumeEscapeSequence(stream); break; case '\u008f': // SS3 sequence = ConsumeSS3Sequence(stream); break; default: break; } if (sequence == null) { sequence = new CharacterSequence { Character = next }; stream.Commit(); } return(sequence); }
private static TerminalSequence ConsumeEscapeSequence(XTermInputBuffer stream) { stream.PushState(); var next = stream.Read(); switch (next) { case '[': return(ConsumeCSI(stream)); case ']': return(ConsumeOSC(stream)); case '#': return(ConsumeCharacterSize(stream)); case ' ': return(ConsumeCompliance(stream)); case '%': return(ConsumeUnicode(stream)); case '(': case ')': case '*': case '+': case '-': case '.': case '/': return(ConsumeCharacterSet(next, stream)); case 'Y': var vt52mc = new Vt52MoveCursorSequence { Row = stream.Read() - 37, Column = stream.Read() - 37 }; stream.Commit(); //System.Diagnostics.Debug.WriteLine(vt52mc.ToString()); return(vt52mc); default: var esc = new EscapeSequence { Command = next.ToString() }; stream.Commit(); //System.Diagnostics.Debug.WriteLine(esc.ToString()); return(esc); } }
private static TerminalSequence ConsumeCSI(XTermInputBuffer stream) { stream.PushState(); bool atStart = true; bool isQuery = false; bool isSend = false; bool isBang = false; char?modifier = null; int currentParameter = -1; List <int> Parameters = new List <int>(); List <TerminalSequence> ProcesFirst = new List <TerminalSequence>(); while (true) { var next = stream.Read(); if (atStart && next == '?') { isQuery = true; } else if (atStart && next == '>') { isSend = true; } else if (atStart && next == '!') { isBang = true; } else if (next == ';') { if (currentParameter == -1) { currentParameter = 0; atStart = false; //throw new EscapeSequenceException("Invalid position for ';' in CSI", stream.Stacked); } Parameters.Add(currentParameter); currentParameter = -1; } else if (char.IsDigit(next)) { atStart = false; if (currentParameter == -1) { currentParameter = Convert.ToInt32(next - '0'); } else { currentParameter = (currentParameter * 10) + Convert.ToInt32(next - '0'); } } else if (next == '$' || next == '"' || next == ' ') { if (modifier.HasValue) { throw new EscapeSequenceException("There appears to be two modifiers in a row", stream.Stacked); } if (currentParameter != -1) { Parameters.Add(currentParameter); currentParameter = -1; } modifier = next; } else if (next == '\b' || next == '\r' || next == '\u000B') { // Trash chars that have to be processed before this sequence ProcesFirst.Add( new CharacterSequence { Character = next } ); } else { if (currentParameter != -1) { Parameters.Add(currentParameter); currentParameter = -1; } var csi = new CsiSequence { Parameters = Parameters, IsQuery = isQuery, IsSend = isSend, IsBang = isBang, Command = (modifier.HasValue ? modifier.Value.ToString() : "") + next.ToString(), ProcessFirst = ProcesFirst.Count > 0 ? ProcesFirst : null }; stream.Commit(); //System.Diagnostics.Debug.WriteLine(csi.ToString()); return(csi); } } }
private static TerminalSequence ConsumeOSC(XTermInputBuffer stream) { stream.PushState(); string command = ""; bool readingCommand = false; bool atStart = true; bool isQuery = false; bool isSend = false; bool isBang = false; char? modifier = null; int currentParameter = -1; List <int> Parameters = new List <int>(); while (!stream.AtEnd) { var next = stream.Read(); if (readingCommand) { if (next == 0x07 || next == 0x9C) // BEL or ST { var osc = new OscSequence { Parameters = Parameters, IsQuery = isQuery, IsSend = isSend, IsBang = isBang, Command = command }; stream.Commit(); //System.Diagnostics.Debug.WriteLine(osc.ToString()); return(osc); } else { command += next; } } else { if (atStart && next == '?') { isQuery = true; } else if (atStart && next == '>') { isSend = true; } else if (atStart && next == '!') { isBang = true; } else if (next == ';') { if (currentParameter == -1) { throw new EscapeSequenceException("Invalid position for ';' in OSC", stream.Stacked); } Parameters.Add(currentParameter); currentParameter = -1; } else if (char.IsDigit(next)) { atStart = false; if (currentParameter == -1) { currentParameter = Convert.ToInt32(next - '0'); } else { currentParameter = (currentParameter * 10) + Convert.ToInt32(next - '0'); } } else if (next == '$' || next == '"' || next == ' ') { if (modifier.HasValue) { throw new EscapeSequenceException("There appears to be two modifiers in a row", stream.Stacked); } if (currentParameter != -1) { Parameters.Add(currentParameter); currentParameter = -1; } modifier = next; } else { if (currentParameter != -1) { Parameters.Add(currentParameter); currentParameter = -1; } command += next; readingCommand = true; } } } stream.PopState(); return(null); }