Add ability to toggle show-trace from within the repl

This commit is contained in:
Alexander Bantyev 2021-12-28 16:13:07 +03:00
parent 2dc29e0d93
commit a26351da02
No known key found for this signature in database
GPG key ID: E081FF12ADCB4AD5
2 changed files with 16 additions and 1 deletions

View file

@ -2,3 +2,5 @@
* The TOML parser used by `builtins.fromTOML` has been replaced by [a * The TOML parser used by `builtins.fromTOML` has been replaced by [a
more compliant one](https://github.com/ToruNiina/toml11). more compliant one](https://github.com/ToruNiina/toml11).
* Added `:st`/`:show-trace` commands to nix repl, which are used to
set or toggle display of error traces.

View file

@ -430,7 +430,8 @@ bool NixRepl::processLine(string line)
<< " :t <expr> Describe result of evaluation\n" << " :t <expr> Describe result of evaluation\n"
<< " :u <expr> Build derivation, then start nix-shell\n" << " :u <expr> Build derivation, then start nix-shell\n"
<< " :doc <expr> Show documentation of a builtin function\n" << " :doc <expr> Show documentation of a builtin function\n"
<< " :log <expr> Show logs for a derivation\n"; << " :log <expr> Show logs for a derivation\n"
<< " :st [bool] Enable, disable or toggle showing traces for errors\n";
} }
else if (command == ":a" || command == ":add") { else if (command == ":a" || command == ":add") {
@ -572,6 +573,18 @@ bool NixRepl::processLine(string line)
throw Error("value does not have documentation"); throw Error("value does not have documentation");
} }
else if (command == ":st" || command == ":show-trace") {
if (arg == "false" || (arg == "" && loggerSettings.showTrace)) {
std::cout << "not showing error traces\n";
loggerSettings.showTrace = false;
} else if (arg == "true" || (arg == "" && !loggerSettings.showTrace)) {
std::cout << "showing error traces\n";
loggerSettings.showTrace = true;
} else {
throw Error("unexpected argument '%s' to %s", arg, command);
};
}
else if (command != "") else if (command != "")
throw Error("unknown command '%1%'", command); throw Error("unknown command '%1%'", command);