aboutsummaryrefslogtreecommitdiff
path: root/src/nix/repl.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-17 15:13:00 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-17 15:13:00 +0000
commit6403508f5a2fcf073b2a0d4e5fcf5f5ebb890384 (patch)
tree84cfb3bf0c6c7a514a77c80da0bae711bf16055d /src/nix/repl.cc
parentccbea8255cf52413938d994a69222fd953b08659 (diff)
Use `ansicolor.hh` in `nix repl` rather than duplicates
Diffstat (limited to 'src/nix/repl.cc')
-rw-r--r--src/nix/repl.cc33
1 files changed, 13 insertions, 20 deletions
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index 4bcaaeebf..617d49614 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -19,6 +19,7 @@ extern "C" {
}
#endif
+#include "ansicolor.hh"
#include "shared.hh"
#include "eval.hh"
#include "eval-inline.hh"
@@ -37,14 +38,6 @@ extern "C" {
namespace nix {
-#define ESC_RED "\033[31m"
-#define ESC_GRE "\033[32m"
-#define ESC_YEL "\033[33m"
-#define ESC_BLU "\033[34;1m"
-#define ESC_MAG "\033[35m"
-#define ESC_CYA "\033[36m"
-#define ESC_END "\033[0m"
-
struct NixRepl : gc
{
string curDir;
@@ -645,25 +638,25 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
switch (v.type) {
case tInt:
- str << ESC_CYA << v.integer << ESC_END;
+ str << ANSI_CYAN << v.integer << ANSI_NORMAL;
break;
case tBool:
- str << ESC_CYA << (v.boolean ? "true" : "false") << ESC_END;
+ str << ANSI_CYAN << (v.boolean ? "true" : "false") << ANSI_NORMAL;
break;
case tString:
- str << ESC_YEL;
+ str << ANSI_YELLOW;
printStringValue(str, v.string.s);
- str << ESC_END;
+ str << ANSI_NORMAL;
break;
case tPath:
- str << ESC_GRE << v.path << ESC_END; // !!! escaping?
+ str << ANSI_GREEN << v.path << ANSI_NORMAL; // !!! escaping?
break;
case tNull:
- str << ESC_CYA "null" ESC_END;
+ str << ANSI_CYAN "null" ANSI_NORMAL;
break;
case tAttrs: {
@@ -699,7 +692,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
try {
printValue(str, *i.second, maxDepth - 1, seen);
} catch (AssertionError & e) {
- str << ESC_RED "«error: " << e.msg() << "»" ESC_END;
+ str << ANSI_RED "«error: " << e.msg() << "»" ANSI_NORMAL;
}
str << "; ";
}
@@ -725,7 +718,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
try {
printValue(str, *v.listElems()[n], maxDepth - 1, seen);
} catch (AssertionError & e) {
- str << ESC_RED "«error: " << e.msg() << "»" ESC_END;
+ str << ANSI_RED "«error: " << e.msg() << "»" ANSI_NORMAL;
}
str << " ";
}
@@ -737,16 +730,16 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
case tLambda: {
std::ostringstream s;
s << v.lambda.fun->pos;
- str << ESC_BLU "«lambda @ " << filterANSIEscapes(s.str()) << "»" ESC_END;
+ str << ANSI_BLUE "«lambda @ " << filterANSIEscapes(s.str()) << "»" ANSI_NORMAL;
break;
}
case tPrimOp:
- str << ESC_MAG "«primop»" ESC_END;
+ str << ANSI_MAGENTA "«primop»" ANSI_NORMAL;
break;
case tPrimOpApp:
- str << ESC_BLU "«primop-app»" ESC_END;
+ str << ANSI_BLUE "«primop-app»" ANSI_NORMAL;
break;
case tFloat:
@@ -754,7 +747,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
break;
default:
- str << ESC_RED "«unknown»" ESC_END;
+ str << ANSI_RED "«unknown»" ANSI_NORMAL;
break;
}