public void TableView_ColorsTest_ColorGetter() { var tv = SetUpMiniTable(); tv.Style.ExpandLastColumn = false; tv.Style.InvertSelectedCellFirstCharacter = true; // width exactly matches the max col widths tv.Bounds = new Rect(0, 0, 5, 4); // Create a style for column B var bStyle = tv.Style.GetOrCreateColumnStyle(tv.Table.Columns ["B"]); // when B is 2 use the custom highlight colour ColorScheme cellHighlight = new ColorScheme() { Normal = Attribute.Make(Color.BrightCyan, Color.DarkGray) }; bStyle.ColorGetter = (a) => Convert.ToInt32(a.CellValue) == 2 ? cellHighlight : null; tv.Redraw(tv.Bounds); string expected = @" ┌─┬─┐ │A│B│ ├─┼─┤ │1│2│ "; GraphViewTests.AssertDriverContentsAre(expected, output); string expectedColors = @" 00000 00000 00000 01020 "; var invertedNormalColor = Application.Driver.MakeAttribute(tv.ColorScheme.Normal.Background, tv.ColorScheme.Normal.Foreground); GraphViewTests.AssertDriverColorsAre(expectedColors, new Attribute [] { // 0 tv.ColorScheme.Normal, // 1 invertedNormalColor, // 2 cellHighlight.Normal }); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); }
public void TestTreeViewColor() { var tv = new TreeView { Width = 20, Height = 10 }; var n1 = new TreeNode("normal"); var n1_1 = new TreeNode("pink"); var n1_2 = new TreeNode("normal"); n1.Children.Add(n1_1); n1.Children.Add(n1_2); var n2 = new TreeNode("pink"); tv.AddObject(n1); tv.AddObject(n2); tv.Expand(n1); var pink = new Attribute(Color.Magenta, Color.Black); var hotpink = new Attribute(Color.BrightMagenta, Color.Black); tv.ColorScheme = new ColorScheme(); tv.Redraw(tv.Bounds); // Normal drawing of the tree view GraphViewTests.AssertDriverContentsAre( @"├-normal │ ├─pink │ └─normal └─pink ", output); // Should all be the same color GraphViewTests.AssertDriverColorsAre( @"00000000 00000000 0000000000 000000 ", new [] { tv.ColorScheme.Normal, pink }); // create a new color scheme var pinkScheme = new ColorScheme { Normal = pink, Focus = hotpink }; // and a delegate that uses the pink color scheme // for nodes "pink" tv.ColorGetter = (n) => n.Text.Equals("pink") ? pinkScheme : null; // redraw now that the custom color // delegate is registered tv.Redraw(tv.Bounds); // Same text GraphViewTests.AssertDriverContentsAre( @"├-normal │ ├─pink │ └─normal └─pink ", output); // but now the item (only not lines) appear // in pink when they are the word "pink" GraphViewTests.AssertDriverColorsAre( @"00000000 00001111 0000000000 001111 ", new [] { tv.ColorScheme.Normal, pink }); }