Skip to content

Commit

Permalink
Use ansicolor.hh in nix repl rather than duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Jun 17, 2020
1 parent ccbea82 commit 6403508
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/libutil/ansicolor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ namespace nix {
#define ANSI_GREEN "\e[32;1m"
#define ANSI_YELLOW "\e[33;1m"
#define ANSI_BLUE "\e[34;1m"
#define ANSI_MAGENTA "\e[35m;1m"
#define ANSI_CYAN "\e[36m;1m"

}
33 changes: 13 additions & 20 deletions src/nix/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern "C" {
}
#endif

#include "ansicolor.hh"
#include "shared.hh"
#include "eval.hh"
#include "eval-inline.hh"
Expand All @@ -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;
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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 << "; ";
}
Expand All @@ -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 << " ";
}
Expand All @@ -737,24 +730,24 @@ 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:
str << v.fpoint;
break;

default:
str << ESC_RED "«unknown»" ESC_END;
str << ANSI_RED "«unknown»" ANSI_NORMAL;
break;
}

Expand Down

0 comments on commit 6403508

Please sign in to comment.