Merge pull request #10208 from 9999years/print-strings-directly

`:print` strings directly in `nix repl`
This commit is contained in:
Robert Hensing 2024-03-11 10:02:09 +01:00 committed by GitHub
commit 3539172fd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -542,6 +542,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
<< " :l, :load <path> Load Nix expression and add it to scope\n"
<< " :lf, :load-flake <ref> Load Nix flake and add it to scope\n"
<< " :p, :print <expr> Evaluate and print expression recursively\n"
<< " Strings are printed directly, without escaping.\n"
<< " :q, :quit Exit nix-repl\n"
<< " :r, :reload Reload all files\n"
<< " :sh <expr> Build dependencies of derivation, then start\n"
@ -749,7 +750,11 @@ ProcessLineResult NixRepl::processLine(std::string line)
else if (command == ":p" || command == ":print") {
Value v;
evalString(arg, v);
printValue(std::cout, v);
if (v.type() == nString) {
std::cout << v.string_view();
} else {
printValue(std::cout, v);
}
std::cout << std::endl;
}