Fix #12091: Error message with TERM=dumb is missing info

This commit is contained in:
yujiri8 2022-10-20 10:57:57 +00:00 committed by GitHub
parent a4eb221b9e
commit a99d465f62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 19 deletions

View File

@ -429,25 +429,23 @@ pub const AllErrors = struct {
try stderr.print(" ({d} times)\n", .{src.count});
}
ttyconf.setColor(stderr, .Reset);
if (ttyconf != .no_color) {
if (src.source_line) |line| {
for (line) |b| switch (b) {
'\t' => try stderr.writeByte(' '),
else => try stderr.writeByte(b),
};
try stderr.writeByte('\n');
// TODO basic unicode code point monospace width
const before_caret = src.span.main - src.span.start;
// -1 since span.main includes the caret
const after_caret = src.span.end - src.span.main -| 1;
try stderr.writeByteNTimes(' ', src.column - before_caret);
ttyconf.setColor(stderr, .Green);
try stderr.writeByteNTimes('~', before_caret);
try stderr.writeByte('^');
try stderr.writeByteNTimes('~', after_caret);
try stderr.writeByte('\n');
ttyconf.setColor(stderr, .Reset);
}
if (src.source_line) |line| {
for (line) |b| switch (b) {
'\t' => try stderr.writeByte(' '),
else => try stderr.writeByte(b),
};
try stderr.writeByte('\n');
// TODO basic unicode code point monospace width
const before_caret = src.span.main - src.span.start;
// -1 since span.main includes the caret
const after_caret = src.span.end - src.span.main -| 1;
try stderr.writeByteNTimes(' ', src.column - before_caret);
ttyconf.setColor(stderr, .Green);
try stderr.writeByteNTimes('~', before_caret);
try stderr.writeByte('^');
try stderr.writeByteNTimes('~', after_caret);
try stderr.writeByte('\n');
ttyconf.setColor(stderr, .Reset);
}
for (src.notes) |note| {
try note.renderToWriter(ttyconf, stderr, "note", .Cyan, indent);

View File

@ -1662,6 +1662,7 @@ pub const TestContext = struct {
var msg: Compilation.AllErrors.Message = actual_error;
msg.src.src_path = case_msg.src.src_path;
msg.src.notes = &.{};
msg.src.source_line = null;
var fib = std.io.fixedBufferStream(&buf);
try msg.renderToWriter(.no_color, fib.writer(), "error", .Red, 0);
var it = std.mem.split(u8, fib.getWritten(), "error: ");