diff options
-rw-r--r-- | src/logger.zig | 45 | ||||
-rw-r--r-- | src/string_immutable.zig | 21 |
2 files changed, 51 insertions, 15 deletions
diff --git a/src/logger.zig b/src/logger.zig index caa701bf1..87b9c9c73 100644 --- a/src/logger.zig +++ b/src/logger.zig @@ -224,27 +224,42 @@ pub const Data = struct { const before_segment = line_text[0..location_in_line_text]; try to.writeAll(before_segment); - if (is_colored) { try to.writeAll(color_name); } - var end_of_segment: usize = 1; - // extremely naive: we should really use IsIdentifierContinue || isIdentifierStart here - var rest_of_line = line_text[location_in_line_text..]; - while (end_of_segment < rest_of_line.len) : (end_of_segment += 1) { - if (!switch (rest_of_line[end_of_segment]) { - 'A'...'Z', 'a'...'z', '0'...'9', '_', '$', '(', ')' => true, - else => false, - }) break; - } - - try to.writeAll(rest_of_line[0..end_of_segment]); - if (is_colored) { + const rest_of_line = line_text[location_in_line_text..]; + + if (rest_of_line.len > 0) { + var end_of_segment: usize = 1; + var iter = strings.CodepointIterator{ .bytes = rest_of_line, .i = 1 }; + // extremely naive: we should really use IsIdentifierContinue || isIdentifierStart here + + // highlight until we reach the next matching + switch (line_text[location_in_line_text]) { + '\'' => { + end_of_segment = iter.scanUntilQuotedValueOrEOF('\''); + }, + '"' => { + end_of_segment = iter.scanUntilQuotedValueOrEOF('"'); + }, + '<' => { + end_of_segment = iter.scanUntilQuotedValueOrEOF('>'); + }, + '`' => { + end_of_segment = iter.scanUntilQuotedValueOrEOF('`'); + }, + else => {}, + } + try to.writeAll(rest_of_line[0..end_of_segment]); + if (is_colored) { + try to.writeAll("\x1b[0m"); + } + + try to.writeAll(rest_of_line[end_of_segment..]); + } else if (is_colored) { try to.writeAll("\x1b[0m"); } - - try to.writeAll(rest_of_line[end_of_segment..]); } else { try to.writeAll(line_text); } diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 83719571b..564a4f94d 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -679,6 +679,27 @@ pub const CodepointIterator = struct { } } + pub fn scanUntilQuotedValueOrEOF(iter: *CodepointIterator, comptime quote: CodePoint) usize { + @setRuntimeSafety(false); + + while (iter.c > -1) { + if (!switch (iter.nextCodepoint()) { + quote => false, + '\\' => brk: { + if (iter.nextCodepoint() == quote) { + continue; + } + break :brk true; + }, + else => true, + }) { + return iter.i + 1; + } + } + + return iter.i; + } + pub fn nextCodepoint(it: *CodepointIterator) CodePoint { const slice = it.nextCodepointSlice(); it.width = @intCast(u3, slice.len); |