Beispiel #1
0
        public void XtermColorIndex()
        {
            var surface = new RenderTest();
            var buffer  = new ConsoleBuffer.Buffer(DefaultColumns, DefaultRows);

            for (var i = 0; i < 256; ++i)
            {
                buffer.AppendString($"\x1b[2J\x1b[H\x1b[38;5;{i}mc");
                surface.OnChar = (c, x, y) =>
                {
                    if (c.Glyph != 'c')
                    {
                        return;
                    }
                    Assert.IsTrue(c.ForegroundXterm256);
                    Assert.AreEqual(i, c.ForegroundXterm256Index);
                };
                buffer.Render(surface);

                buffer.AppendString($"\x1b[2J\x1b[H\x1b[48;5;{i}mc");
                surface.OnChar = (c, x, y) =>
                {
                    if (c.Glyph != 'c')
                    {
                        return;
                    }
                    Assert.IsTrue(c.BackgroundXterm256);
                    Assert.AreEqual(i, c.BackgroundXterm256Index);
                };
                buffer.Render(surface);
            }
        }
Beispiel #2
0
        public Screen(ConsoleBuffer.Buffer buffer)
        {
            this.dpiInfo = VisualTreeHelper.GetDpi(this);
            this.cells   = new VisualCollection(this);
            this.Buffer  = buffer;

            this.cursorBlinkWatch.Start();

            CompositionTarget.Rendering += this.RenderFrame;
            this.MouseEnter             += (sender, args) =>
            {
                args.MouseDevice.OverrideCursor = Cursors.IBeam;
            };
            this.MouseLeave += (sender, args) =>
            {
                args.MouseDevice.OverrideCursor = Cursors.Arrow;
            };
            this.MouseWheel += (sender, args) =>
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    var factor = args.Delta > 0 ? 2 : -2;
                    this.SetFontSize(this.fontSizeEm + factor);
                    args.Handled = true;
                }
            };

            this.SetFontSize(14);
            this.Resize();
        }
Beispiel #3
0
        public void InitializeState()
        {
            var buffer = new ConsoleBuffer.Buffer(DefaultColumns, DefaultRows);

            Assert.AreEqual(DefaultColumns, buffer.Width);
            Assert.AreEqual(DefaultRows, buffer.Height);
            Assert.AreEqual((0, 0), buffer.CursorPosition);
            Assert.IsTrue(buffer.CursorVisible);
            Assert.IsTrue(buffer.CursorBlink);
            Assert.AreEqual(string.Empty, buffer.Title);
            Assert.AreEqual(DefaultRows, buffer.BufferSize);
        }
Beispiel #4
0
        public void MaxBufferSize()
        {
            var buffer = new ConsoleBuffer.Buffer(DefaultColumns, DefaultRows);

            for (var i = 0; i < short.MaxValue; ++i)
            {
                buffer.AppendString($"line {i}\r\n");
            }
            Assert.AreEqual(short.MaxValue, buffer.BufferSize);

            buffer.AppendString($"that's too much, man! -sarah lynn (1984 - 2016)\r\n");
            Assert.AreEqual(short.MaxValue, buffer.BufferSize);
        }
Beispiel #5
0
        public void DefaultColors()
        {
            var buffer = new ConsoleBuffer.Buffer(DefaultColumns, DefaultRows);

            buffer.AppendString("!");
            var surface = new RenderTest();

            surface.OnChar = (c, x, y) =>
            {
                if (x == 0 && y == 0)
                {
                    Assert.AreEqual(ConsoleBuffer.Commands.SetGraphicsRendition.Colors.White, c.BasicForegroundColor);
                    Assert.AreEqual(ConsoleBuffer.Commands.SetGraphicsRendition.Colors.Black, c.BasicBackgroundColor);
                }
            };
            buffer.Render(surface);
        }
Beispiel #6
0
        public void BasicColor()
        {
            var surface = new RenderTest();
            var buffer  = new ConsoleBuffer.Buffer(DefaultColumns, DefaultRows);

            for (var fg = 0; fg < 16; ++fg)
            {
                for (var bg = 0; bg < 16; ++bg)
                {
                    buffer.AppendString("\x1b[2J\x1b[m");
                    buffer.AppendString("\x1b[");
                    if (fg < 8)
                    {
                        buffer.AppendString($"3{fg}");
                    }
                    else
                    {
                        buffer.AppendString($"9{fg - 8}");
                    }
                    if (bg < 8)
                    {
                        buffer.AppendString($";4{bg}m");
                    }
                    else
                    {
                        buffer.AppendString($";10{bg - 8}m");
                    }
                    buffer.AppendString("c\r\n");

                    surface.OnChar = (c, x, y) =>
                    {
                        if (c.Glyph != 'c')
                        {
                            return;
                        }
                        Assert.AreEqual(fg > 7, c.ForegroundBright);
                        Assert.AreEqual(bg > 7, c.BackgroundBright);
                        Assert.AreEqual((ConsoleBuffer.Commands.SetGraphicsRendition.Colors)(fg > 7 ? fg - 8 : fg), c.BasicForegroundColor);
                        Assert.AreEqual((ConsoleBuffer.Commands.SetGraphicsRendition.Colors)(bg > 7 ? bg - 8 : bg), c.BasicBackgroundColor);
                    };

                    buffer.Render(surface);
                }
            }
        }
Beispiel #7
0
        public void BrightForegroundText()
        {
            var buffer = new ConsoleBuffer.Buffer(DefaultColumns, DefaultRows);

            buffer.AppendString("\x1b[1mbb\x1b[22mn\x1b[1mb\x1b[22mnnnn\n");
            var surface = new RenderTest();

            surface.OnChar = (c, x, y) =>
            {
                if (c.Glyph == 'b')
                {
                    Assert.IsTrue(c.ForegroundBright);
                }
                if (c.Glyph == 'n')
                {
                    Assert.IsFalse(c.ForegroundBright);
                }
            };
            buffer.Render(surface);
        }
Beispiel #8
0
        public Screen(ConsoleBuffer.Buffer buffer, Configuration configuration)
        {
            this.dpiInfo  = VisualTreeHelper.GetDpi(this);
            this.children = new VisualCollection(this)
            {
                new DrawingVisual {
                    Offset = new Vector(0, 0)
                }
            };
            this.Buffer = buffer;

            this.cursorBlinkWatch.Start();

            CompositionTarget.Rendering += this.RenderFrame;
            this.MouseEnter             += (sender, args) =>
            {
                args.MouseDevice.OverrideCursor = Cursors.IBeam;

                // handles the case where the user released the mouse button outside the window.
                if (this.selecting && args.LeftButton == MouseButtonState.Released)
                {
                    this.CompleteSelection();
                }
            };
            this.MouseLeave += (sender, args) =>
            {
                args.MouseDevice.OverrideCursor = Cursors.Arrow;
            };
            this.MouseWheel += (sender, args) =>
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    var factor = args.Delta > 0 ? 2 : -2;
                    this.SetFontValues(this.fontSizeEm + factor, this.typeface);
                    args.Handled = true;
                }
            };

            this.MouseLeftButtonDown += (sender, args) =>
            {
                this.selecting      = true;
                this.selectionStart = this.selectionEnd = args.GetPosition(this);
                args.Handled        = true;
            };
            this.MouseLeftButtonUp += (sender, args) =>
            {
                this.selectionEnd = args.GetPosition(this);
                Logger.Verbose($"sel: start:{this.selectionStart}, end:{this.selectionEnd}");
                this.selectionStart = this.selectionEnd = new Point(0, 0);
                this.CompleteSelection();
                args.Handled = true;
            };
            this.MouseMove += (sender, args) =>
            {
                if (this.selecting)
                {
                    this.selectionEnd = args.GetPosition(this);
                    this.shouldRedraw = 1;
                }
            };

            this.SetConfiguration(configuration);
        }