Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for all line colouring #75

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override int VisitScalarValue(ThemedValueFormatterState state, ScalarV
{
if (scalar == null)
throw new ArgumentNullException(nameof(scalar));
return FormatLiteralValue(scalar, state.Output, state.Format);
return FormatLiteralValue(scalar, state.Output, state.Format, state.logEventLevel);
}

protected override int VisitSequenceValue(ThemedValueFormatterState state, SequenceValue sequence)
Expand All @@ -49,23 +49,23 @@ protected override int VisitSequenceValue(ThemedValueFormatterState state, Seque

var count = 0;

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write('[');

var delim = string.Empty;
for (var index = 0; index < sequence.Elements.Count; ++index)
{
if (delim.Length != 0)
{
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write(delim);
}

delim = ", ";
Visit(state, sequence.Elements[index]);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write(']');

return count;
Expand All @@ -77,38 +77,38 @@ protected override int VisitStructureValue(ThemedValueFormatterState state, Stru

if (structure.TypeTag != null)
{
using (ApplyStyle(state.Output, ConsoleThemeStyle.Name, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.Name, ref count, state.logEventLevel))
state.Output.Write(structure.TypeTag);

state.Output.Write(' ');
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write('{');

var delim = string.Empty;
for (var index = 0; index < structure.Properties.Count; ++index)
{
if (delim.Length != 0)
{
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write(delim);
}

delim = ", ";

var property = structure.Properties[index];

using (ApplyStyle(state.Output, ConsoleThemeStyle.Name, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.Name, ref count, state.logEventLevel))
state.Output.Write(property.Name);

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write('=');

count += Visit(state.Nest(), property.Value);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write('}');

return count;
Expand All @@ -118,53 +118,53 @@ protected override int VisitDictionaryValue(ThemedValueFormatterState state, Dic
{
var count = 0;

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write('{');

var delim = string.Empty;
foreach (var element in dictionary.Elements)
{
if (delim.Length != 0)
{
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write(delim);
}

delim = ", ";

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write('[');

using (ApplyStyle(state.Output, ConsoleThemeStyle.String, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.String, ref count, state.logEventLevel))
count += Visit(state.Nest(), element.Key);

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write("]=");

count += Visit(state.Nest(), element.Value);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write('}');

return count;
}

public int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format)
public int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format, LogEventLevel logEventLevel)
{
var value = scalar.Value;
var count = 0;

if (value == null)
{
using (ApplyStyle(output, ConsoleThemeStyle.Null, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Null, ref count, logEventLevel))
output.Write("null");
return count;
}

if (value is string str)
{
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count, logEventLevel))
{
if (format != "l")
JsonValueFormatter.WriteQuotedJsonString(str, output);
Expand All @@ -180,22 +180,22 @@ public int FormatLiteralValue(ScalarValue scalar, TextWriter output, string form
value is decimal || value is byte || value is sbyte || value is short ||
value is ushort || value is float || value is double)
{
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count, logEventLevel))
scalar.Render(output, format, _formatProvider);
return count;
}

if (value is bool b)
{
using (ApplyStyle(output, ConsoleThemeStyle.Boolean, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Boolean, ref count, logEventLevel))
output.Write(b);

return count;
}

if (value is char ch)
{
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count, logEventLevel))
{
output.Write('\'');
output.Write(ch);
Expand All @@ -205,7 +205,7 @@ value is decimal || value is byte || value is sbyte || value is short ||
}
}

using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count, logEventLevel))
scalar.Render(output, format, _formatProvider);

return count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ protected override int VisitScalarValue(ThemedValueFormatterState state, ScalarV

// At the top level, for scalar values, use "display" rendering.
if (state.IsTopLevel)
return _displayFormatter.FormatLiteralValue(scalar, state.Output, state.Format);
return _displayFormatter.FormatLiteralValue(scalar, state.Output, state.Format, state.logEventLevel);

return FormatLiteralValue(scalar, state.Output);
return FormatLiteralValue(scalar, state.Output, state.logEventLevel);
}

protected override int VisitSequenceValue(ThemedValueFormatterState state, SequenceValue sequence)
Expand All @@ -57,23 +57,23 @@ protected override int VisitSequenceValue(ThemedValueFormatterState state, Seque

var count = 0;

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write('[');

var delim = string.Empty;
for (var index = 0; index < sequence.Elements.Count; ++index)
{
if (delim.Length != 0)
{
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write(delim);
}

delim = ", ";
Visit(state.Nest(), sequence.Elements[index]);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write(']');

return count;
Expand All @@ -83,47 +83,47 @@ protected override int VisitStructureValue(ThemedValueFormatterState state, Stru
{
var count = 0;

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write('{');

var delim = string.Empty;
for (var index = 0; index < structure.Properties.Count; ++index)
{
if (delim.Length != 0)
{
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write(delim);
}

delim = ", ";

var property = structure.Properties[index];

using (ApplyStyle(state.Output, ConsoleThemeStyle.Name, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.Name, ref count, state.logEventLevel))
JsonValueFormatter.WriteQuotedJsonString(property.Name, state.Output);

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write(": ");

count += Visit(state.Nest(), property.Value);
}

if (structure.TypeTag != null)
{
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write(delim);

using (ApplyStyle(state.Output, ConsoleThemeStyle.Name, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.Name, ref count, state.logEventLevel))
JsonValueFormatter.WriteQuotedJsonString("$type", state.Output);

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write(": ");

using (ApplyStyle(state.Output, ConsoleThemeStyle.String, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.String, ref count, state.logEventLevel))
JsonValueFormatter.WriteQuotedJsonString(structure.TypeTag, state.Output);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write('}');

return count;
Expand All @@ -133,15 +133,15 @@ protected override int VisitDictionaryValue(ThemedValueFormatterState state, Dic
{
var count = 0;

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write('{');

var delim = string.Empty;
foreach (var element in dictionary.Elements)
{
if (delim.Length != 0)
{
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write(delim);
}

Expand All @@ -153,36 +153,36 @@ protected override int VisitDictionaryValue(ThemedValueFormatterState state, Dic
? ConsoleThemeStyle.String
: ConsoleThemeStyle.Scalar;

using (ApplyStyle(state.Output, style, ref count))
using (ApplyStyle(state.Output, style, ref count, state.logEventLevel))
JsonValueFormatter.WriteQuotedJsonString((element.Key.Value ?? "null").ToString(), state.Output);

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write(": ");

count += Visit(state.Nest(), element.Value);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count, state.logEventLevel))
state.Output.Write('}');

return count;
}

int FormatLiteralValue(ScalarValue scalar, TextWriter output)
int FormatLiteralValue(ScalarValue scalar, TextWriter output, LogEventLevel logEventLevel)
{
var value = scalar.Value;
var count = 0;

if (value == null)
{
using (ApplyStyle(output, ConsoleThemeStyle.Null, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Null, ref count, logEventLevel))
output.Write("null");
return count;
}

if (value is string str)
{
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count, logEventLevel))
JsonValueFormatter.WriteQuotedJsonString(str, output);
return count;
}
Expand All @@ -191,14 +191,14 @@ int FormatLiteralValue(ScalarValue scalar, TextWriter output)
{
if (value is int || value is uint || value is long || value is ulong || value is decimal || value is byte || value is sbyte || value is short || value is ushort)
{
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count, logEventLevel))
output.Write(((IFormattable)value).ToString(null, CultureInfo.InvariantCulture));
return count;
}

if (value is double d)
{
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count, logEventLevel))
{
if (double.IsNaN(d) || double.IsInfinity(d))
JsonValueFormatter.WriteQuotedJsonString(d.ToString(CultureInfo.InvariantCulture), output);
Expand All @@ -210,7 +210,7 @@ int FormatLiteralValue(ScalarValue scalar, TextWriter output)

if (value is float f)
{
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count, logEventLevel))
{
if (double.IsNaN(f) || double.IsInfinity(f))
JsonValueFormatter.WriteQuotedJsonString(f.ToString(CultureInfo.InvariantCulture), output);
Expand All @@ -222,22 +222,22 @@ int FormatLiteralValue(ScalarValue scalar, TextWriter output)

if (value is bool b)
{
using (ApplyStyle(output, ConsoleThemeStyle.Boolean, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Boolean, ref count, logEventLevel))
output.Write(b ? "true" : "false");

return count;
}

if (value is char ch)
{
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count, logEventLevel))
JsonValueFormatter.WriteQuotedJsonString(ch.ToString(), output);
return count;
}

if (value is DateTime || value is DateTimeOffset)
{
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count, logEventLevel))
{
output.Write('"');
output.Write(((IFormattable)value).ToString("O", CultureInfo.InvariantCulture));
Expand All @@ -247,7 +247,7 @@ int FormatLiteralValue(ScalarValue scalar, TextWriter output)
}
}

using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count, logEventLevel))
JsonValueFormatter.WriteQuotedJsonString(value.ToString(), output);

return count;
Expand Down
Loading