aboutsummaryrefslogtreecommitdiff
path: root/src/nix/repl.cc
diff options
context:
space:
mode:
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 b46f7015f..d5661f7b7 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;
@@ -649,25 +642,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: {
@@ -703,7 +696,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 << "; ";
}
@@ -729,7 +722,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 << " ";
}
@@ -741,16 +734,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:
@@ -758,7 +751,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;
}