コード例 #1
0
        private string WriteAnsi256(Color color, bool foreground)
        {
            var         start = 7;
            var         ansi  = ColorConvert.ToAnsi256(color);
            var         total = start + StringLength((byte)ansi) + 1;
            Span <char> esc   = stackalloc char[total];

            esc[0] = Escape;
            esc[1] = '[';
            esc[2] = foreground ? '3' : '4';
            esc[3] = '8';
            esc[4] = ';';
            esc[5] = '5';
            esc[6] = ';';

            var idx = start;

            var sub = esc.Slice(idx);

            idx   += WriteByte(sub, (byte)ansi);
            sub    = esc.Slice(idx);
            sub[0] = 'm';
            idx++;

            return(esc.Slice(0, idx).ToString());
        }
コード例 #2
0
        private string WriteAnsi16(Color color, bool foreground)
        {
            var start = 2;
            var ansi  = ColorConvert.ToAnsi16(color);

            ansi = foreground ? ansi : ansi + 10;
            var         total = start + StringLength((byte)ansi) + 1;
            Span <char> esc   = stackalloc char[total];

            esc[0] = Escape;
            esc[1] = '[';

            var idx = start;
            var sub = esc.Slice(idx);

            idx   += WriteByte(sub, (byte)ansi);
            sub[0] = 'm';
            idx++;

            return(esc.Slice(0, idx).ToString());
        }