Beispiel #1
0
        public void TestRecordVideoBasic()
        {
            ConsoleBitmap bitmap = new ConsoleBitmap(4, 2), redBitmap = null, greenBitmap = null, magentaPixelBitmap = null;

            using (var sharedStream = new MemoryStream())
            {
                var bitmapVideoWriter = new ConsoleBitmapVideoWriter(s => sharedStream.Write(Encoding.Default.GetBytes(s)));

                bitmap = new ConsoleBitmap(4, 2);
                bitmap.Fill(ConsoleCharacter.RedBG());
                redBitmap = bitmapVideoWriter.WriteFrame(bitmap).Clone();
                bitmap.Fill(ConsoleCharacter.GreenBG());
                greenBitmap = bitmapVideoWriter.WriteFrame(bitmap).Clone();
                bitmap.DrawPoint(ConsoleCharacter.MagentaBG(), 0, 0);
                magentaPixelBitmap = bitmapVideoWriter.WriteFrame(bitmap).Clone();
                bitmapVideoWriter.Finish();

                sharedStream.Position = 0; // rewind the stream to the beginning to read it back

                // create a reader and make sure we can read each frame back exactly as they were written
                var bitmapVideoReader = new ConsoleBitmapStreamReader(sharedStream);
                Assert.AreEqual(redBitmap, bitmapVideoReader.ReadFrame().CurrentBitmap);
                Assert.AreEqual(greenBitmap, bitmapVideoReader.ReadFrame().CurrentBitmap);
                Assert.AreEqual(magentaPixelBitmap, bitmapVideoReader.ReadFrame().CurrentBitmap);
                Assert.IsNull(bitmapVideoReader.ReadFrame().CurrentFrame);
            }
        }
Beispiel #2
0
        public void TestPlaybackEndToEnd()
        {
            var app = new CliTestHarness(this.TestContext, 80, 30);

            app.InvokeNextCycle(async() =>
            {
                int w    = 10, h = 1;
                var temp = Path.GetTempFileName();
                using (var stream = File.OpenWrite(temp))
                {
                    var writer = new ConsoleBitmapVideoWriter(s => stream.Write(Encoding.Default.GetBytes(s)));
                    var bitmap = new ConsoleBitmap(w, h);

                    for (var i = 0; i < bitmap.Width; i++)
                    {
                        bitmap.Fill(new ConsoleCharacter(' '));
                        bitmap.DrawPoint(new ConsoleCharacter(' ', backgroundColor: ConsoleColor.Red), i, 0);
                        writer.WriteFrame(bitmap, true, TimeSpan.FromSeconds(.1 * i));
                    }
                    writer.Finish();
                }

                var player = app.LayoutRoot.Add(new ConsoleBitmapPlayer()).Fill();
                Assert.IsFalse(player.Width == 0);
                Assert.IsFalse(player.Height == 0);
                player.Load(File.OpenRead(temp));

                var playStarted = false;
                player.SubscribeForLifetime(nameof(player.State), () =>
                {
                    if (player.State == PlayerState.Playing)
                    {
                        playStarted = true;
                    }
                    else if (player.State == PlayerState.Stopped && playStarted)
                    {
                        app.Stop();
                    }
                }, app);

                await Task.Delay(100);
                await app.SendKey(new ConsoleKeyInfo('p', ConsoleKey.P, false, false, false));
            });

            app.Start().Wait();
            Thread.Sleep(100);
            app.AssertThisTestMatchesLKGFirstAndLastFrame();
        }
Beispiel #3
0
        /// <summary>
        /// Paints the divider
        /// </summary>
        /// <param name="context">the bitmap target</param>
        protected override void OnPaint(ConsoleBitmap context)
        {
            var c = Orientation == Orientation.Vertical ? '|' : '-';

            context.Fill(new ConsoleCharacter(c, Foreground, Background));
        }