示例#1
0
        private int RenderTextToken(TextToken tt, TextWriter output)
        {
            var count = 0;

            using (_theme.Apply(output, RichTextBoxThemeStyle.Text, ref count))
            {
                var text = SpecialCharsEscaping.Apply(tt.Text, ref count);
                output.Write(text);
            }

            return(count);
        }
示例#2
0
        private int RenderValue(RichTextBoxTheme theme, ThemedValueFormatter valueFormatter, LogEventPropertyValue propertyValue, TextWriter output, string format)
        {
            if (_isLiteral && propertyValue is ScalarValue {
                Value : string
            } sv)
            {
                var count = 0;
                using (theme.Apply(output, RichTextBoxThemeStyle.String, ref count))
                {
                    var text = SpecialCharsEscaping.Apply(sv.Value.ToString(), ref count);
                    output.Write(text);
                }

                return(count);
            }

            return(valueFormatter.Format(propertyValue, output, format, _isLiteral));
        }
示例#3
0
        private int RenderPropertyToken(PropertyToken pt, IReadOnlyDictionary <string, LogEventPropertyValue> properties, TextWriter output)
        {
            if (!properties.TryGetValue(pt.PropertyName, out var propertyValue))
            {
                var count = 0;
                using (_theme.Apply(output, RichTextBoxThemeStyle.Invalid, ref count))
                {
                    output.Write(SpecialCharsEscaping.Apply(pt.ToString(), ref count));
                }

                return(count);
            }

            if (!pt.Alignment.HasValue)
            {
                return(RenderValue(_theme, _valueFormatter, propertyValue, output, pt.Format));
            }

            var valueOutput = new StringWriter();

            if (!_theme.CanBuffer)
            {
                return(RenderAlignedPropertyTokenUnbuffered(pt, output, propertyValue));
            }

            var invisibleCount = RenderValue(_theme, _valueFormatter, propertyValue, valueOutput, pt.Format);

            var value = valueOutput.ToString();

            if (value.Length - invisibleCount >= pt.Alignment.Value.Width)
            {
                output.Write(value);
            }
            else
            {
                Padding.Apply(output, value, pt.Alignment.Value.Widen(invisibleCount));
            }

            return(invisibleCount);
        }