Example #1
0
        public void Append(string text)
        {
            var        lastLine            = lines.Count > 0 ? lines[lines.Count - 1] : null;
            SimpleText lastNonSentinelLine = null;

            if (SquashDuplicateLines)
            {
                lastNonSentinelLine = lines.Count > 1 ? lines[lines.Count - 2] : null;
            }
            var newLines = text.Split('\n');

            for (int i = 0; i < newLines.Length; i++)
            {
                var l = newLines[i];
                if (SquashDuplicateLines)
                {
                    if (lastNonSentinelLine != null && lastNonSentinelLine.Text == l)
                    {
                        lastNonSentinelLine.Components.Get <ThemedTextView.TextLineMultiplicity>().Multiplicity++;
                        lastNonSentinelLine.Invalidate();
                        //TODO: invalidate window only if it isn't docked
                        (GetRoot() as WindowWidget)?.Window.Invalidate();
                        continue;
                    }
                }
                if (lastLine != null)
                {
                    lastLine.Text += l;
                    if (SquashDuplicateLines)
                    {
                        lastNonSentinelLine = lastLine;
                    }
                    lastLine = null;
                }
                else
                {
                    var line = new ThemedSimpleText(l)
                    {
                        TrimWhitespaces = TrimWhitespaces
                    };
                    line.TextProcessor += ProcessTextLine;
                    line.Components.Add(new TextLineMultiplicity());
                    lines.Add(line);
                    Behaviour.Content.AddNode(line);
                }
            }
        }