Beispiel #1
0
        private static void JumpCursor(CaptureCollection captures, ConsoleOutputLayer outputLayer)
        {
            int x = 0, y = 0;

            if (captures.Count > 0 && !String.IsNullOrEmpty(captures[0].Value))
            {
                Int32.TryParse(captures[0].Value, out x);
            }
            if (captures.Count > 1 && !String.IsNullOrEmpty(captures[1].Value))
            {
                Int32.TryParse(captures[1].Value, out y);
            }

            outputLayer.SetCursorPosition(x, y);
        }
Beispiel #2
0
        public static void WriteWithAnsiEscapeCode(string value, ConsoleOutputLayer outputLayer)
        {
            var match = Regex.Match(value, "\x1B\\x5B(((?<value>[0-9]+);)*(?<value>[0-9]+))?(?<type>.)");

            if (match.Success)
            {
                outputLayer.Write(value.Substring(0, match.Index));

                while (match != null && match.Success)
                {
                    var valueGroup = match.Groups["value"];
                    var typeGroup  = match.Groups["type"];

                    switch (typeGroup.Value)
                    {
                    case "H":
                    case "f":
                        JumpCursor(valueGroup.Captures, outputLayer);
                        break;

                    case "A":
                        JumpCursor(valueGroup.Captures, 1, outputLayer);
                        break;

                    case "B":
                        JumpCursor(valueGroup.Captures, 3, outputLayer);
                        break;

                    case "C":
                        JumpCursor(valueGroup.Captures, 2, outputLayer);
                        break;

                    case "D":
                        JumpCursor(valueGroup.Captures, 0, outputLayer);
                        break;

                    case "s":
                        curX = outputLayer.CursorLeft;
                        curY = outputLayer.CursorTop;
                        break;

                    case "u":
                        outputLayer.CursorLeft = curX;
                        outputLayer.CursorTop  = curY;
                        break;

                    case "J":
                        outputLayer.Clear();
                        outputLayer.SetCursorPosition(0, 0);
                        break;

                    case "K":
                        ClearLine(valueGroup.Captures, outputLayer);
                        break;

                    case "m":
                        UpdateGraphicMode(valueGroup.Captures, outputLayer);
                        break;
                    }

                    var startIndex = match.Index + match.Length;
                    match = match.NextMatch();
                    var endIndex = match.Success ? match.Index : value.Length;

                    outputLayer.Write(value.Substring(startIndex, endIndex - startIndex));
                }
            }
            else
            {
                outputLayer.Write(value);
            }
        }