public void TestAsyncDataGridBasic() { var items = new List <Item>(); for (var i = 0; i < 100; i++) { items.Add(new Item() { Bar = "Bar" + i, Foo = "Foo" + i, }); } var app = new CliTestHarness(TestContext, 80, 20, true) { }; var dataGrid = new ListGrid <Item>(new ListGridOptions <Item>() { DataSource = new SlowList <Item>(items), Columns = new List <ListGridColumnDefinition <Item> >() { new ListGridColumnDefinition <Item>() { Header = "Foo".ToGreen(), Width = .5, Type = GridValueType.Percentage, Formatter = (item) => new Label() { Text = item.Foo.ToConsoleString() } }, new ListGridColumnDefinition <Item>() { Header = "Bar".ToRed(), Width = .5, Type = GridValueType.Percentage, Formatter = (item) => new Label() { Text = item.Bar.ToConsoleString() } } } }); app.QueueAction(async() => { var selectionLabel = app.LayoutRoot.Add(new Label() { Text = "DEFAULT".ToConsoleString(), Height = 1 }).CenterHorizontally(); selectionLabel.Text = $"SelectedRowIndex: {dataGrid.SelectedRowIndex}, SelectedCellIndex: {dataGrid.SelectedColumnIndex}".ToConsoleString(); dataGrid.SelectionChanged.SubscribeForLifetime(() => { selectionLabel.Text = $"SelectedRowIndex: {dataGrid.SelectedRowIndex}, SelectedCellIndex: {dataGrid.SelectedColumnIndex}".ToConsoleString(); }, dataGrid); app.LayoutRoot.Add(dataGrid).Fill(padding: new Thickness(0, 0, 1, 0)); await app.PaintAndRecordKeyFrameAsync(); await Task.Delay(125); await app.PaintAndRecordKeyFrameAsync(); app.Stop(); }); app.Start().Wait(); app.AssertThisTestMatchesLKG(); }
public void DrawLines() { var bitmap = new ConsoleBitmap(80, 30); var centerX = bitmap.Width / 2; var centerY = bitmap.Height / 2; var app = new CliTestHarness(TestContext, bitmap.Width, bitmap.Height, true); app.InvokeNextCycle(async() => { app.LayoutRoot.Add(new BitmapControl() { Bitmap = bitmap }).Fill(); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Gray), centerX, centerY, 0, centerY / 2); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Red), centerX, centerY, 0, 0); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Yellow), centerX, centerY, centerX / 2, 0); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Green), centerX, centerY, centerX, 0); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Magenta), centerX, centerY, (int)(bitmap.Width * .75), 0); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Cyan), centerX, centerY, bitmap.Width - 1, 0); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Gray), centerX, centerY, bitmap.Width - 1, centerY / 2); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.White), centerX, centerY, 0, bitmap.Height / 2); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Blue), centerX, centerY, bitmap.Width - 1, bitmap.Height / 2); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Gray), centerX, centerY, 0, (int)(bitmap.Height * .75)); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Red), centerX, centerY, 0, bitmap.Height - 1); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Yellow), centerX, centerY, centerX / 2, bitmap.Height - 1); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Green), centerX, centerY, centerX, bitmap.Height - 1); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Magenta), centerX, centerY, (int)(bitmap.Width * .75), bitmap.Height - 1); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Cyan), centerX, centerY, bitmap.Width - 1, bitmap.Height - 1); await app.RequestPaintAsync(); app.RecordKeyFrame(); bitmap.DrawLine(new ConsoleCharacter('X', ConsoleColor.Gray), centerX, centerY, bitmap.Width - 1, (int)(bitmap.Height * .75)); await app.RequestPaintAsync(); app.RecordKeyFrame(); app.Stop(); }); app.Start().Wait(); app.AssertThisTestMatchesLKG(); }
public static async Task Test(int w, int h, TestContext testContext, Func <CliTestHarness, SpaceTimePanel, Task> test) { Exception stEx = null; var app = new CliTestHarness(testContext, w, h, true); app.SecondsBetweenKeyframes = DefaultTimeIncrement.TotalSeconds; app.InvokeNextCycle(async() => { var d = new TaskCompletionSource <bool>(); var spaceTimePanel = app.LayoutRoot.Add(new SpaceTimePanel(app.LayoutRoot.Width, app.LayoutRoot.Height)); spaceTimePanel.SpaceTime.Increment = DefaultTimeIncrement; var stTask = spaceTimePanel.SpaceTime.Start(); var justUpdated = false; spaceTimePanel.AfterUpdate.SubscribeForLifetime(() => justUpdated = true, app); app.AfterPaint.SubscribeForLifetime(() => { if (justUpdated) { app.RecordKeyFrame(); justUpdated = false; } }, app); spaceTimePanel.SpaceTime.InvokeNextCycle(async() => { spaceTimePanel.RealTimeViewing.Enabled = false; try { await test(app, spaceTimePanel); } catch (Exception ex) { stEx = ex; } await app.Paint(); d.SetResult(true); }); await d.Task; try { await stTask; }catch (Exception exc) { spaceTimePanel.SpaceTime.Stop(); d.SetResult(true); stEx = exc; } await spaceTimePanel.SpaceTime.YieldAsync(); await app.PaintAndRecordKeyFrameAsync(); spaceTimePanel.SpaceTime.Stop(); await app.PaintAndRecordKeyFrameAsync(); app.Stop(); }); await app.Start(); if (stEx != null) { app.Abandon(); Assert.Fail(stEx.ToString()); } else { app.PromoteToLKG(); } }
public void GridLayoutEndToEnd() { var app = new CliTestHarness(this.TestContext, 80, 20, true); var gridLayout = app.LayoutRoot.Add(new GridLayout(new GridLayoutOptions() { Columns = new List <GridColumnDefinition>() { new GridColumnDefinition() { Width = 5, Type = GridValueType.Pixels }, new GridColumnDefinition() { Width = 2, Type = GridValueType.RemainderValue }, new GridColumnDefinition() { Width = 2, Type = GridValueType.RemainderValue }, }, Rows = new List <GridRowDefinition>() { new GridRowDefinition() { Height = 1, Type = GridValueType.Pixels }, new GridRowDefinition() { Height = 2, Type = GridValueType.RemainderValue }, new GridRowDefinition() { Height = 1, Type = GridValueType.Pixels }, } })).Fill(); var colorWheel = new List <ConsoleColor>() { ConsoleColor.Red, ConsoleColor.DarkRed, ConsoleColor.Red, ConsoleColor.Black, ConsoleColor.White, ConsoleColor.Black, ConsoleColor.Green, ConsoleColor.DarkGreen, ConsoleColor.Green }; var colorIndex = 0; for (var y = 0; y < gridLayout.NumRows; y++) { for (var x = 0; x < gridLayout.NumColumns; x++) { gridLayout.Add(new ConsoleControl() { Background = colorWheel[colorIndex], }, x, y); colorIndex = colorIndex == colorWheel.Count - 1 ? 0 : colorIndex + 1; } } app.QueueAction(async() => { await app.Paint().AsAwaitable(); app.RecordKeyFrame(); app.Stop(); }); app.Start().Wait(); app.AssertThisTestMatchesLKG(); }
public void DrawLinesReverse() { var bitmap = new ConsoleBitmap(80, 30); var centerX = bitmap.Width / 2; var centerY = bitmap.Height / 2; var app = new CliTestHarness(TestContext, bitmap.Width, bitmap.Height, true); app.QueueAction(async() => { app.LayoutRoot.Add(new BitmapControl() { Bitmap = bitmap }).Fill(); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Gray); bitmap.DrawLine(0, centerY / 2, centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Red); bitmap.DrawLine(0, 0, centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Yellow); bitmap.DrawLine(centerX / 2, 0, centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Green); bitmap.DrawLine(centerX, centerY, centerX, 0); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Magenta); bitmap.DrawLine((int)(bitmap.Width * .75), 0, centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Cyan); bitmap.DrawLine(bitmap.Width - 1, 0, centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Gray); bitmap.DrawLine(bitmap.Width - 1, centerY / 2, centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.White); bitmap.DrawLine(0, bitmap.Height / 2, centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Blue); bitmap.DrawLine(bitmap.Width - 1, bitmap.Height / 2, centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Gray); bitmap.DrawLine(0, (int)(bitmap.Height * .75), centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Red); bitmap.DrawLine(0, bitmap.Height - 1, centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Yellow); bitmap.DrawLine(centerX / 2, bitmap.Height - 1, centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Green); bitmap.DrawLine(centerX, bitmap.Height - 1, centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Magenta); bitmap.DrawLine((int)(bitmap.Width * .75), bitmap.Height - 1, centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Cyan); bitmap.DrawLine(bitmap.Width - 1, bitmap.Height - 1, centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); bitmap.Pen = new ConsoleCharacter('X', ConsoleColor.Gray); bitmap.DrawLine(bitmap.Width - 1, (int)(bitmap.Height * .75), centerX, centerY); await app.Paint().AsAwaitable(); app.RecordKeyFrame(); app.Stop(); }); app.Start().Wait(); app.AssertThisTestMatchesLKG(); }