/// <summary> /// Creates a styled piece of text. /// </summary> /// <param name="foreColor">The foreground color to use.</param> /// <param name="backColor">The background color to use.</param> /// <param name="decorations">The decorations to be applied to the text.</param> /// <param name="text">The text to be styled.</param> /// <param name="reset">Whether to reset the console to default styling before and after printing the text.</param> /// <exception cref="ArgumentNullException"><paramref name="foreColor"/> or <paramref name="backColor"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException"><paramref name="decorations"/> is not a valid enum.</exception> public FabulousText(IColor foreColor, IColor backColor, TextDecoration decorations, string?text, bool reset = false) { ForegroundColor = foreColor ?? throw new ArgumentNullException(nameof(foreColor)); BackgroundColor = backColor ?? throw new ArgumentNullException(nameof(backColor)); if (!decorations.IsValid()) { throw new ArgumentException($"The { nameof(TextDecoration) } provided must be a valid enum.", nameof(decorations)); } Decorations = decorations; ConsoleReset = reset; Text = text ?? string.Empty; }
public static IEnumerable <ConsoleStyle> GetAnsiStyles(this TextDecoration decorations) { if (!decorations.IsValid()) { throw new ArgumentException($"The { nameof(TextDecoration) } provided must be a valid enum.", nameof(decorations)); } var result = new List <ConsoleStyle>(); var validDecorations = decorations.GetFlags().Where(d => d != TextDecoration.None); foreach (var decoration in validDecorations) { result.Add(_decorations[decoration]); } return(result); }