Beispiel #1
0
        public static async Task Content(string title, string[] content, int?delay = null,
                                         int?lineDelay = null, ConsoleColor?contentColor = null, ConsoleColor?boxColor = null,
                                         ICollection <Accent>?accents = null)
        {
            var original = Console.ForegroundColor;

            Console.ForegroundColor = boxColor ?? original;

            accents ??= new List <Accent>();
            accents.Add(new Accent('*', ConsoleColor.White));

            var boxWriter = new TypeWriter(1, 0, contentColor: boxColor, accents: accents);
            var writer    = new TypeWriter(delay, lineDelay, contentColor: contentColor, accents: accents);

            var width = Math.Min(Offset + Math.Max(title.Length, content.Max(x => x.Length)),
                                 Console.BufferWidth - Offset - 2);
            var middle = Repeat(Blocks[Horizontal], width);

            // Header
            await boxWriter.WriteLine($"*{Blocks[TopLeft]}{middle}{Blocks[TopRight]}*");

            await boxWriter.WriteLine(
                $"*{Blocks[Vertical]}* {title}{Repeat(' ', width - title.Length - Offset)} *{Blocks[Vertical]}*");

            await boxWriter.WriteLine($"*{Blocks[Left]}{Repeat(Blocks[Horizontal], width)}{Blocks[Right]}*");

            // Content
            foreach (var line in content)
            {
                await Write(line);
            }
            await boxWriter.WriteLine(
                $"*{Blocks[BottomLeft]}{Repeat(Blocks[Horizontal], width)}{Blocks[BottomRight]}*");

            Console.ForegroundColor = original;

            async Task Write(string input)
            {
                var lines = Split(input, width - Offset).Select(x =>
                                                                $"*{Blocks[Vertical]}* {x}{Repeat(' ', width - CountNonAccents(x, accents) - Offset)} *{Blocks[Vertical]}*");
                await writer.WriteAllLines(lines, delay, 0);
            }
        }
Beispiel #2
0
        public static async Task Box(string text, int delay = 100, ConsoleColor?textColor        = null,
                                     ConsoleColor?boxColor  = null, ICollection <Accent>?accents = null)
        {
            var original = Console.ForegroundColor;

            Console.ForegroundColor = boxColor ?? original;

            accents ??= new List <Accent>();
            accents.Add(new Accent('*', boxColor ?? original));

            var boxWriter = new TypeWriter(delay, 0, contentColor: boxColor, accents: accents);
            var writer    = new TypeWriter(delay, contentColor: textColor, accents: accents);
            var middle    = Repeat(Blocks[Horizontal], CountNonAccents(text, accents) + Offset);

            await boxWriter.WriteLine($"{Blocks[TopLeft]}{middle}{Blocks[TopRight]}");

            await writer.WriteLine($"*{Blocks[Vertical]}* {text} *{Blocks[Vertical]}*");

            await boxWriter.WriteLine($"{Blocks[BottomLeft]}{middle}{Blocks[BottomRight]}");

            Console.ForegroundColor = original;
        }