public void NormalPath() { var fg = ConsoleColor.Green; var bg = ConsoleColor.DarkGray; var colors = new ColorPair(_console, fg, bg); // ensure that initial color state is preserved Assert.IsTrue(colors.OriginalBackground == _console.BackgroundColor); Assert.IsTrue(colors.OriginalForeground == _console.ForegroundColor); Assert.IsTrue(colors.Foreground == fg); Assert.IsTrue(colors.Background == bg); // ensure that the colors are applied colors.ApplyColors(); Assert.IsTrue(_console.BackgroundColor == bg); Assert.IsTrue(_console.ForegroundColor == fg); // ensure that the colors are reset colors.ResetColors(); Assert.IsTrue(_console.BackgroundColor == origBG); Assert.IsTrue(_console.ForegroundColor == origFG); Assert.IsTrue(colors.Foreground == fg); Assert.IsTrue(colors.Background == bg); }
public void Execute(IWriteTextCmdlet cmdLet) { if (_originalColors == null) { _originalColors = new ColorPair(); } ColorPair group = new ColorPair(cmdLet.ForegroundColor, cmdLet.BackgroundColor); var blocks = GetTextValues(cmdLet); var colors = GetColorGroups(cmdLet); var useNewLine = !this.NoNewLine; var lastPos = blocks.Length - 1; for (var i = 0; i < blocks.Length; i++) { var colGroup = i < colors.Length ? colors[i] : null; if (colGroup != null) { group = _colors.GetColor(colGroup, cmdLet.ForegroundColor, cmdLet.BackgroundColor); } if (i == lastPos && useNewLine) { _writer.WriteLine(blocks[i], group); } else { _writer.Write(blocks[i], group); } } if (this.NoColorReset) { group.ApplyColors(); } if (this.ForceColorReset) { _originalColors.ResetColors(); } }
public void MissingBackColor() { ConsoleColor?fg = ConsoleColor.Yellow; ConsoleColor?bg = null; var colors = new ColorPair(_console, fg, bg); Assert.IsFalse(colors.Background.HasValue); // ensure that the colors are applied colors.ApplyColors(); Assert.IsTrue(_console.BackgroundColor == origBG); Assert.IsTrue(_console.ForegroundColor == fg); // ensure that the colors are reset colors.ResetColors(); Assert.IsTrue(_console.BackgroundColor == origBG); Assert.IsTrue(_console.ForegroundColor == origFG); Assert.IsTrue(colors.Foreground == fg); Assert.IsTrue(colors.Background == bg); }