public Terminal( TerminalOpenEvent terminalOpen = null, ConsoleOutEvent onConsoleOutEvent = null ) { var chr = CharacterParser.Create(); var ansi = new AnsiParserEvents() { Input = (characters) => Debug.Write(new string(characters)) }; _ansiParser = new AnsiParser(events: ansi, utf8: chr.TryParseUtf8); var vt = new VTParserEvents() { EscapeSequence = _ansiParser.OnEscapeSequence, ControlSequence = _ansiParser.OnControlSequenceCommand, Execute = _ansiParser.OnExecute, OsCommand = _ansiParser.OnOsCommand, Print = _ansiParser.OnPrint }; _vtParser = new VTParser(events: vt, utf8: chr.TryParseUtf8, ascii: chr.TryParseAscii); onConsoleOutEvent?.Subscribe(OnConsoleOut); terminalOpen?.Publish(new TerminalOpenEventData( @"C:\windows\system32\cmd.exe", "", null, null )); }
public static void AnsiParser_Print_ConfigureCharSet_ShiftIn_ShiftOut() { const string Case = "Hello 😁 world a "; const string SpecialCase = "H\n┌┌⎺ 😁 ┬⎺⎼┌\r ▒ "; var sb = new StringBuilder(); var ix = 0; var current = Case; var events = new AnsiParserEvents() { Input = (characters) => { sb.Append(new string(characters)); ix = (ix + characters.Length) % Case.Length; } }; var chars = CharacterParser.Create(); var sut = new AnsiParser(events: events, utf8: chars.TryParseUtf8); sut.OnPrint(Case); sut.OnPrint(Case); Assert.Equal(current + current, sb.ToString()); // SET G0 sut.OnEscapeSequence(EscapeCommand.ConfigureSpecialCharSet, new[] { (byte)'(' }); sb.Clear(); ix = 0; current = SpecialCase; sut.OnPrint(Case); sut.OnPrint(Case); Assert.Equal(current + current, sb.ToString()); // Shift sut.OnExecute(ControlCode.ShiftOut); sb.Clear(); ix = 0; current = Case; sut.OnPrint(Case); sut.OnPrint(Case); Assert.Equal(current + current, sb.ToString()); // Reset G0 and Shift sut.OnEscapeSequence(EscapeCommand.ConfigureAsciiCharSet, new[] { (byte)'(' }); sut.OnExecute(ControlCode.ShiftIn); sb.Clear(); ix = 0; current = Case; sut.OnPrint(Case); sut.OnPrint(Case); Assert.Equal(current + current, sb.ToString()); }
private static void Osc(AnsiParser sut, OsCommand command, params string[] args) { var arr = new ReadOnlyMemory <byte> [args.Length]; for (var i = 0; i < args.Length; i++) { arr[i] = Encoding.UTF8.GetBytes(args[i]); } sut.OnOsCommand(command, arr.AsSpan()); }
internal static void AnsiParser_ControlSequence_InsertBlank(ControlSequenceCommand command, long[] param) { var dispatched = 0; var events = new AnsiParserEvents { InsertBlank = (count) => { ++dispatched; Assert.Equal(param.AsSpan().Optional(0).GetValueOrDefault(1), count); } }; var sut = new AnsiParser(events: events); sut.OnControlSequenceCommand(command, default, param);
public static void AnsiParser_Execute_SingleCharacterIntroducer() { var dispatched = 0; var events = new AnsiParserEvents { IdentifyTerminal = () => { dispatched++; } }; var sut = new AnsiParser(events: events); sut.OnExecute(ControlCode.SingleCharacterIntroducer); Assert.Equal(1, dispatched); }
public static void AnsiParser_Execute_HorizontalTabulationSet() { var dispatched = 0; var events = new AnsiParserEvents { SetHorizontalTabStop = () => { dispatched++; } }; var sut = new AnsiParser(events: events); sut.OnExecute(ControlCode.HorizontalTabulationSet); Assert.Equal(1, dispatched); }
public static void AnsiParser_Execute_Bell() { var dispatched = 0; var events = new AnsiParserEvents { Bell = () => { dispatched++; } }; var sut = new AnsiParser(events: events); sut.OnExecute(ControlCode.Bell); Assert.Equal(1, dispatched); }
public static void AnsiParser_Execute_CarriageReturn() { var dispatched = 0; var events = new AnsiParserEvents { CarriageReturn = () => { dispatched++; } }; var sut = new AnsiParser(events: events); sut.OnExecute(ControlCode.CarriageReturn); Assert.Equal(1, dispatched); }
internal static void AnsiParser_EscapeSequence_UnsetKeypadApplicationMode() { var dispatched = 0; var events = new AnsiParserEvents { UnsetKeypadApplicationMode = () => { ++dispatched; } }; var sut = new AnsiParser(events: events); sut.OnEscapeSequence(EscapeCommand.UnsetKeypadApplicationMode, default); Assert.Equal(1, dispatched); }
internal static void AnsiParser_EscapeSequence_IdentifyTerminal() { var dispatched = 0; var events = new AnsiParserEvents { IdentifyTerminal = () => { ++dispatched; } }; var sut = new AnsiParser(events: events); sut.OnEscapeSequence(EscapeCommand.IdentifyTerminal, default); Assert.Equal(1, dispatched); }
internal static void AnsiParser_EscapeSequence_RestoreCursorPosition() { var dispatched = 0; var events = new AnsiParserEvents { RestoreCursorPosition = () => { ++dispatched; } }; var sut = new AnsiParser(events: events); sut.OnEscapeSequence(EscapeCommand.RestoreCursorPosition, default); Assert.Equal(1, dispatched); }
internal static void AnsiParser_EscapeSequence_LineFeed() { var dispatched = 0; var events = new AnsiParserEvents { LineFeed = () => { ++dispatched; } }; var sut = new AnsiParser(events: events); sut.OnEscapeSequence(EscapeCommand.LineFeed, default); Assert.Equal(1, dispatched); }
internal static void AnsiParser_EscapeSequence_ReverseIndex() { var dispatched = 0; var events = new AnsiParserEvents { ReverseIndex = () => { ++dispatched; } }; var sut = new AnsiParser(events: events); sut.OnEscapeSequence(EscapeCommand.ReverseIndex, default); Assert.Equal(1, dispatched); }
internal static void AnsiParser_OsCommand_ResetColor_Special(OsCommand command, NamedColor expectedIndex) { var dispatched = 0; var events = new AnsiParserEvents { ResetColor = (index) => { ++dispatched; Assert.Equal(expectedIndex, index); } }; var sut = new AnsiParser(events: events); Osc(sut, command); Assert.Equal(1, dispatched); }
public static void AnsiParser_Execute_HorizontalTabulation() { var dispatched = 0; var events = new AnsiParserEvents { PutTab = (count) => { dispatched++; Assert.Equal(1, count); } }; var sut = new AnsiParser(events: events); sut.OnExecute(ControlCode.HorizontalTabulation); Assert.Equal(1, dispatched); }
internal static void AnsiParser_OsCommand_ResetColor_All() { var expected = new HashSet <NamedColor>(Enumerable.Range(0, 257).Select(x => (NamedColor)x)); var events = new AnsiParserEvents { ResetColor = (index) => { Assert.Contains(index, expected); expected.Remove(index); } }; var sut = new AnsiParser(events: events); Osc(sut, OsCommand.ResetColor); Assert.Empty(expected); }
public static void AnsiParser_Execute_FormFeed() { var dispatched = 0; var events = new AnsiParserEvents { LineFeed = () => { dispatched++; } }; var sut = new AnsiParser(events: events); sut.OnExecute(ControlCode.FormFeed); sut.OnExecute(ControlCode.VerticalTabulation); sut.OnExecute(ControlCode.LineFeed); Assert.Equal(3, dispatched); }
public static void AnsiParser_OsCommand_SetWindowTitle() { var dispatched = 0; var events = new AnsiParserEvents { SetTitle = (characters) => { dispatched++; Assert.Equal("Hello 😁 world", new string(characters)); } }; var chars = CharacterParser.Create(); var sut = new AnsiParser(events: events, chars.TryParseUtf8); Osc(sut, OsCommand.SetWindowTitle, "Hello 😁 world"); Osc(sut, OsCommand.SetWindowIconAndTitle, "Hello 😁 world"); Assert.Equal(2, dispatched); }
internal static void AnsiParser_OsCommand_SetCursorStyle( CursorStyle expectedStyle, params string[] param ) { var dispatched = 0; var events = new AnsiParserEvents { SetCursor = (style) => { ++dispatched; Assert.Equal(expectedStyle, style); } }; var sut = new AnsiParser(events: events); Osc(sut, OsCommand.SetCursorStyle, param); Assert.Equal(1, dispatched); }
internal static void AnsiParser_OsCommand_SetColor( int expectedCount, NamedColor expectedIndex, int expectedR, int expectedG, int expectedB, OsCommand command, params string[] param ) { var dispatched = 0; var events = new AnsiParserEvents { SetColor = (NamedColor index, in Color color) => { dispatched++; Assert.Equal(expectedIndex, index); Assert.Equal(Color.FromArgb(expectedR, expectedG, expectedB), color); } }; var sut = new AnsiParser(events: events); Osc(sut, command, param); Assert.Equal(expectedCount, dispatched); }
internal static void AnsiParser_EscapeSequence_NextLine() { var crDispatched = 0; var lfDispatched = 0; var events = new AnsiParserEvents { CarriageReturn = () => { ++crDispatched; }, LineFeed = () => { ++lfDispatched; } }; var sut = new AnsiParser(events: events); sut.OnEscapeSequence(EscapeCommand.NextLine, default); Assert.Equal(1, crDispatched); Assert.Equal(1, lfDispatched); }
internal static void AnsiParser_OsCommand_SetClipboard() { const string Case = "Hello 😁 world"; var dispatched = 0; var events = new AnsiParserEvents { SetClipboard = (characters) => { ++dispatched; Assert.Equal(Case, new string(characters)); } }; var chars = CharacterParser.Create(); var sut = new AnsiParser(events: events, utf8: chars.TryParseUtf8); var param = Convert.ToBase64String(Encoding.UTF8.GetBytes(Case)); Osc(sut, OsCommand.SetClipboard, "", param); Assert.Equal(1, dispatched); }
internal static void AnsiParser_OsCommand_ResetColor_Values() { var expected = new HashSet <NamedColor> { NamedColor.Black, NamedColor.Red, NamedColor.Green, NamedColor.Yellow, NamedColor.Blue }; var events = new AnsiParserEvents { ResetColor = (index) => { Assert.Contains(index, expected); expected.Remove(index); } }; var sut = new AnsiParser(events: events); Osc(sut, OsCommand.ResetColor, "0", "1", "2", "3", "4"); Assert.Empty(expected); }