35
35
#include < libsolidity/interface/CompilerStack.h>
36
36
#include < libsolidity/interface/StandardCompiler.h>
37
37
#include < liblangutil/SourceReferenceFormatter.h>
38
+ #include < liblangutil/SourceReferenceFormatterHuman.h>
38
39
#include < libsolidity/interface/GasEstimator.h>
39
40
#include < libsolidity/interface/AssemblyStack.h>
40
41
46
47
#include < libdevcore/CommonIO.h>
47
48
#include < libdevcore/JSON.h>
48
49
50
+ #include < memory>
51
+
49
52
#include < boost/filesystem.hpp>
50
53
#include < boost/filesystem/operations.hpp>
51
54
#include < boost/algorithm/string.hpp>
@@ -134,6 +137,9 @@ static string const g_strStrictAssembly = "strict-assembly";
134
137
static string const g_strPrettyJson = " pretty-json" ;
135
138
static string const g_strVersion = " version" ;
136
139
static string const g_strIgnoreMissingFiles = " ignore-missing" ;
140
+ static string const g_strColor = " color" ;
141
+ static string const g_strNoColor = " no-color" ;
142
+ static string const g_strNewReporter = " new-reporter" ;
137
143
138
144
static string const g_argAbi = g_strAbi;
139
145
static string const g_argPrettyJson = g_strPrettyJson;
@@ -169,6 +175,9 @@ static string const g_argStrictAssembly = g_strStrictAssembly;
169
175
static string const g_argVersion = g_strVersion;
170
176
static string const g_stdinFileName = g_stdinFileNameStr;
171
177
static string const g_argIgnoreMissingFiles = g_strIgnoreMissingFiles;
178
+ static string const g_argColor = g_strColor;
179
+ static string const g_argNoColor = g_strNoColor;
180
+ static string const g_argNewReporter = g_strNewReporter;
172
181
173
182
// / Possible arguments to for --combined-json
174
183
static set<string> const g_combinedJsonArgs
@@ -652,6 +661,9 @@ Allowed options)",
652
661
po::value<string>()->value_name (" path(s)" ),
653
662
" Allow a given path for imports. A list of paths can be supplied by separating them with a comma."
654
663
)
664
+ (g_argColor.c_str (), " Force colored output." )
665
+ (g_argNoColor.c_str (), " Explicitly disable colored output, disabling terminal auto-detection." )
666
+ (g_argNewReporter.c_str (), " Enables new diagnostics reporter." )
655
667
(g_argIgnoreMissingFiles.c_str (), " Ignore missing files." );
656
668
po::options_description outputComponents (" Output Components" );
657
669
outputComponents.add_options ()
@@ -691,6 +703,14 @@ Allowed options)",
691
703
return false ;
692
704
}
693
705
706
+ if (m_args.count (g_argColor) && m_args.count (g_argNoColor))
707
+ {
708
+ serr () << " Option " << g_argColor << " and " << g_argNoColor << " are mutualy exclusive." << endl;
709
+ return false ;
710
+ }
711
+
712
+ m_coloredOutput = !m_args.count (g_argNoColor) && (isatty (STDERR_FILENO) || m_args.count (g_argColor));
713
+
694
714
if (m_args.count (g_argHelp) || (isatty (fileno (stdin)) && _argc == 1 ))
695
715
{
696
716
sout () << desc;
@@ -858,7 +878,11 @@ bool CommandLineInterface::processInput()
858
878
859
879
m_compiler.reset (new CompilerStack (fileReader));
860
880
861
- SourceReferenceFormatter formatter (serr (false ));
881
+ unique_ptr<SourceReferenceFormatter> formatter;
882
+ if (m_args.count (g_argNewReporter))
883
+ formatter = make_unique<SourceReferenceFormatterHuman>(serr (false ), m_coloredOutput);
884
+ else
885
+ formatter = make_unique<SourceReferenceFormatter>(serr (false ));
862
886
863
887
try
864
888
{
@@ -881,7 +905,7 @@ bool CommandLineInterface::processInput()
881
905
for (auto const & error: m_compiler->errors ())
882
906
{
883
907
g_hasOutput = true ;
884
- formatter. printExceptionInformation (
908
+ formatter-> printExceptionInformation (
885
909
*error,
886
910
(error->type () == Error::Type::Warning) ? " Warning" : " Error"
887
911
);
@@ -893,7 +917,7 @@ bool CommandLineInterface::processInput()
893
917
catch (CompilerError const & _exception)
894
918
{
895
919
g_hasOutput = true ;
896
- formatter. printExceptionInformation (_exception, " Compiler error" );
920
+ formatter-> printExceptionInformation (_exception, " Compiler error" );
897
921
return false ;
898
922
}
899
923
catch (InternalCompilerError const & _exception)
@@ -915,7 +939,7 @@ bool CommandLineInterface::processInput()
915
939
else
916
940
{
917
941
g_hasOutput = true ;
918
- formatter. printExceptionInformation (_error, _error.typeName ());
942
+ formatter-> printExceptionInformation (_error, _error.typeName ());
919
943
}
920
944
921
945
return false ;
@@ -1221,12 +1245,16 @@ bool CommandLineInterface::assemble(
1221
1245
for (auto const & sourceAndStack: assemblyStacks)
1222
1246
{
1223
1247
auto const & stack = sourceAndStack.second ;
1224
- SourceReferenceFormatter formatter (serr (false ));
1248
+ unique_ptr<SourceReferenceFormatter> formatter;
1249
+ if (m_args.count (g_argNewReporter))
1250
+ formatter = make_unique<SourceReferenceFormatterHuman>(serr (false ), m_coloredOutput);
1251
+ else
1252
+ formatter = make_unique<SourceReferenceFormatter>(serr (false ));
1225
1253
1226
1254
for (auto const & error: stack.errors ())
1227
1255
{
1228
1256
g_hasOutput = true ;
1229
- formatter. printExceptionInformation (
1257
+ formatter-> printExceptionInformation (
1230
1258
*error,
1231
1259
(error->type () == Error::Type::Warning) ? " Warning" : " Error"
1232
1260
);
0 commit comments