public void SetupTests() { _console = Substitute.For <IConsole>(); _writer = Substitute.For <IConsoleWriter>(); _noNewLine = new SwitchParameter(false); _noColorReset = new SwitchParameter(false); _forceColorReset = new SwitchParameter(false); _cmdlet = Substitute.For <IWriteTextCmdlet>(); _cmdlet.NoNewLine.Returns(_noNewLine); _cmdlet.NoColorReset.Returns(_noColorReset); _cmdlet.ForceColorReset.Returns(_forceColorReset); }
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 string[] GetTextValues(IWriteTextCmdlet cmdLet) { return(GetValues(cmdLet.TextBlocks, cmdLet.Text, cmdLet.TextSplit)); }
public string[] GetColorGroups(IWriteTextCmdlet cmdLet) { return(GetValues(cmdLet.ColorGroups, cmdLet.ColorGroup, ",")); }