newline-as-prefix; no final newline in output.

This commit is contained in:
Ben Burdette 2020-06-03 14:47:00 -06:00
parent 156d4f8bc8
commit f97576c5d9

View file

@ -57,20 +57,20 @@ void printCodeLines(std::ostream &out, const string &prefix, const NixCode &nixC
{
// previous line of code.
if (nixCode.prevLineOfCode.has_value()) {
out << fmt("%1% %|2$5d|| %3%",
out << std::endl
<< fmt("%1% %|2$5d|| %3%",
prefix,
(nixCode.errPos.line - 1),
*nixCode.prevLineOfCode)
<< std::endl;
*nixCode.prevLineOfCode);
}
if (nixCode.errLineOfCode.has_value()) {
// line of code containing the error.
out << fmt("%1% %|2$5d|| %3%",
out << std::endl
<< fmt("%1% %|2$5d|| %3%",
prefix,
(nixCode.errPos.line),
*nixCode.errLineOfCode)
<< std::endl;
*nixCode.errLineOfCode);
// error arrows for the column range.
if (nixCode.errPos.column > 0) {
int start = nixCode.errPos.column;
@ -81,20 +81,21 @@ void printCodeLines(std::ostream &out, const string &prefix, const NixCode &nixC
std::string arrows("^");
out << fmt("%1% |%2%" ANSI_RED "%3%" ANSI_NORMAL,
out << std::endl
<< fmt("%1% |%2%" ANSI_RED "%3%" ANSI_NORMAL,
prefix,
spaces,
arrows) << std::endl;
arrows);
}
}
// next line of code.
if (nixCode.nextLineOfCode.has_value()) {
out << fmt("%1% %|2$5d|| %3%",
out << std::endl
<< fmt("%1% %|2$5d|| %3%",
prefix,
(nixCode.errPos.line + 1),
*nixCode.nextLineOfCode)
<< std::endl;
*nixCode.nextLineOfCode);
}
}
@ -167,46 +168,50 @@ std::ostream& operator<<(std::ostream &out, const ErrorInfo &einfo)
levelString,
einfo.name,
dashes,
einfo.programName.value_or(""))
<< std::endl;
einfo.programName.value_or(""));
else
out << fmt("%1%%2%" ANSI_BLUE " -----%3% %4%" ANSI_NORMAL,
prefix,
levelString,
dashes,
einfo.programName.value_or(""))
<< std::endl;
einfo.programName.value_or(""));
// filename, line, column.
bool nl = false; // intersperse newline between sections.
if (einfo.nixCode.has_value()) {
if (einfo.nixCode->errPos.file != "") {
out << fmt("%1%in file: " ANSI_BLUE "%2% %3%" ANSI_NORMAL,
// filename, line, column.
out << std::endl << fmt("%1%in file: " ANSI_BLUE "%2% %3%" ANSI_NORMAL,
prefix,
einfo.nixCode->errPos.file,
showErrPos(einfo.nixCode->errPos)) << std::endl;
out << prefix << std::endl;
showErrPos(einfo.nixCode->errPos));
} else {
out << fmt("%1%from command line argument", prefix) << std::endl;
out << prefix << std::endl;
out << std::endl << fmt("%1%from command line argument", prefix);
}
nl = true;
}
// description
if (einfo.description != "") {
out << prefix << einfo.description << std::endl;
out << prefix << std::endl;
if (nl)
out << std::endl << prefix;
out << std::endl << prefix << einfo.description;
nl = true;
}
// lines of code.
if (einfo.nixCode.has_value() && einfo.nixCode->errLineOfCode.has_value()) {
if (nl)
out << std::endl << prefix;
printCodeLines(out, prefix, *einfo.nixCode);
out << prefix << std::endl;
nl = true;
}
// hint
if (einfo.hint.has_value()) {
out << prefix << *einfo.hint << std::endl;
out << prefix << std::endl;
if (nl)
out << std::endl << prefix;
out << std::endl << prefix << *einfo.hint;
nl = true;
}
return out;