示例#1
0
        public void Write(IEnumerable <Segment> segments)
        {
            lock (_lock)
            {
                var builder = new StringBuilder();
                foreach (var segment in segments)
                {
                    if (segment.IsControlCode)
                    {
                        builder.Append(segment.Text);
                        continue;
                    }

                    var parts = segment.Text.NormalizeNewLines().Split(new[] { '\n' });
                    foreach (var(_, _, last, part) in parts.Enumerate())
                    {
                        if (!string.IsNullOrEmpty(part))
                        {
                            builder.Append(_ansiBuilder.GetAnsi(part, segment.Style));
                        }

                        if (!last)
                        {
                            builder.Append(Environment.NewLine);
                        }
                    }
                }

                if (builder.Length > 0)
                {
                    _out.Write(builder.ToString());
                    _out.Flush();
                }
            }
        }
示例#2
0
        public void Write(Segment segment)
        {
            var parts = segment.Text.NormalizeLineEndings().Split(new[] { '\n' });

            foreach (var(_, _, last, part) in parts.Enumerate())
            {
                if (!string.IsNullOrEmpty(part))
                {
                    _out.Write(_ansiBuilder.GetAnsi(part, segment.Style));
                }

                if (!last)
                {
                    _out.Write(Environment.NewLine);
                }
            }
        }
示例#3
0
        public void Write(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var parts = text.NormalizeLineEndings().Split(new[] { '\n' });

            foreach (var(_, _, last, part) in parts.Enumerate())
            {
                if (!string.IsNullOrEmpty(part))
                {
                    _out.Write(AnsiBuilder.GetAnsi(_system, part, Decoration, Foreground, Background));
                }

                if (!last)
                {
                    _out.Write(Environment.NewLine);
                }
            }
        }
        public void Write(string text, Style style)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            style ??= Style.Plain;

            var parts = text.NormalizeLineEndings().Split(new[] { '\n' });

            foreach (var(_, _, last, part) in parts.Enumerate())
            {
                if (!string.IsNullOrEmpty(part))
                {
                    _out.Write(_ansiBuilder.GetAnsi(part, style));
                }

                if (!last)
                {
                    _out.Write(Environment.NewLine);
                }
            }
        }