/// <summary> /// - Processes a character event into a Action that occurs while in the OscParam state. /// Events in this state will: /// 1. Trigger the OSC action associated with the param on an OscTerminator /// 2. If we see a ESC, enter the OscTermination state. We'll wait for one /// more character before we dispatch the string. /// 3. Ignore OscInvalid characters. /// 4. Collect everything else into the OscString /// </summary> /// <param name="ch"></param> private void EventOSCString(byte ch) { if (ASCIIChars.IsOSCTerminator(ch)) { // 出现了OSC结束符,那么进入Ground状态 this.ActionOSCDispatch(ch); this.EnterGround(); } else if (ASCIIChars.IsEscape(ch)) { // OSC状态下出现了ESC字符,那么有两种情况会出现: // 1. ESC后面有ST字符,说明是OSC状态结束了 // 2. ESC后面没有ST字符,说明是ESC状态 // 所以这里定义一个OSCTermination状态来处理这两种状态 this.EnterOSCTermination(); } else if (ASCIIChars.IsOSCIndicator(ch)) { // OSC非法字符,忽略 this.ActionIgnore(ch); } else { // 剩下的就是OSC的有效字符,收集 this.oscString.Append((char)ch); } }
/// <summary> /// 解析终端字节流 /// </summary> /// <param name="bytes">要解析的字节流</param> public void ProcessCharacters(byte[] bytes) { int length = bytes.Length; for (int i = 0; i < length; i++) { byte ch = bytes[i]; // 在OSCString的状态下,ESC转义字符可以用作OSC状态的结束符,所以在这里不进入ESC状态 if (ASCIIChars.IsEscape(ch) && this.state != VTStates.OSCString) { this.EnterEscape(); } else { switch (this.state) { case VTStates.Ground: { this.EventGround(ch); break; } case VTStates.Escape: { this.EventEscape(ch); break; } case VTStates.EscapeIntermediate: { this.EventEscapeIntermediate(ch); break; } case VTStates.OSCParam: { this.EventOSCParam(ch); break; } case VTStates.OSCString: { this.EventOSCString(ch); break; } case VTStates.OSCTermination: { this.EventOSCTermination(ch); break; } case VTStates.CSIEntry: { this.EventCSIEntry(ch); break; } case VTStates.CSIIntermediate: { this.EventCSIIntermediate(ch); break; } case VTStates.CSIIgnore: { this.EventCSIIgnore(ch); break; } case VTStates.CSIParam: { this.EventCSIParam(ch); break; } case VTStates.DCSEntry: { this.EventDCSEntry(ch); break; } case VTStates.DCSIgnore: { this.EventDCSIgnore(ch); break; } case VTStates.DCSIntermediate: { this.EventDCSIntermediate(ch); break; } case VTStates.DCSParam: { this.EventDCSParam(ch); break; } case VTStates.DCSPassthrough: { this.EventDCSPassThrough(ch); break; } case VTStates.Vt52Param: { this.EventVt52Param(ch); break; } } } } }