aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-17 18:47:52 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-17 18:47:52 +0100
commitf76d86676c93ef2e510110a54f3caab763e4f87c (patch)
tree11aab20fa3f89d05da535ea5d2615ec9eb1c5fc2
parentfcb3768728047e9df1f456bf6a426687b8560d0b (diff)
downloadpaludis-f76d86676c93ef2e510110a54f3caab763e4f87c.tar.gz
paludis-f76d86676c93ef2e510110a54f3caab763e4f87c.tar.xz
cave --colour yes|no|auto
Fixes: ticket:950
-rw-r--r--src/clients/cave/cave.cc8
-rw-r--r--src/clients/cave/command_line.cc8
-rw-r--r--src/clients/cave/command_line.hh2
-rw-r--r--src/clients/cave/format_user_config.cc80
-rw-r--r--src/clients/cave/format_user_config.hh2
5 files changed, 66 insertions, 34 deletions
diff --git a/src/clients/cave/cave.cc b/src/clients/cave/cave.cc
index 13ff28c..b7f55ed 100644
--- a/src/clients/cave/cave.cc
+++ b/src/clients/cave/cave.cc
@@ -33,6 +33,7 @@
#include "command_factory.hh"
#include "command_line.hh"
+#include "format_user_config.hh"
using namespace paludis;
using std::endl;
@@ -85,8 +86,15 @@ int main(int argc, char * argv[])
cave_var = cave_var + " --" + cmdline.a_environment.long_name() + " " + cmdline.a_environment.argument();
if (cmdline.a_log_level.specified())
cave_var = cave_var + " --" + cmdline.a_log_level.long_name() + " " + cmdline.a_log_level.argument();
+ if (cmdline.a_colour.specified())
+ cave_var = cave_var + " --" + cmdline.a_colour.long_name() + " " + cmdline.a_colour.argument();
setenv("CAVE", cave_var.c_str(), 1);
+ if (cmdline.a_colour.argument() == "yes")
+ cave::set_want_colours(true);
+ else if (cmdline.a_colour.argument() == "no")
+ cave::set_want_colours(false);
+
Log::get_instance()->set_program_name(argv[0]);
Log::get_instance()->set_log_level(cmdline.a_log_level.option());
std::shared_ptr<Environment> env(EnvironmentFactory::get_instance()->create(cmdline.a_environment.argument()));
diff --git a/src/clients/cave/command_line.cc b/src/clients/cave/command_line.cc
index 1025513..ffa0367 100644
--- a/src/clients/cave/command_line.cc
+++ b/src/clients/cave/command_line.cc
@@ -28,6 +28,14 @@ CaveCommandLine::CaveCommandLine() :
a_environment(&g_global_options, "environment", 'E',
"Environment specification (class:suffix, both parts optional)"),
a_log_level(&g_global_options, "log-level", '\0'),
+ a_colour(&g_global_options, "colour", 'c',
+ "Specify whether to use colour",
+ args::EnumArg::EnumArgOptions
+ ("auto", 'a', "Yes if stdout is connected to a terminal")
+ ("yes", 'y', "Yes")
+ ("no", 'n', "No"),
+ "auto"),
+ a_color(&a_colour, "color", true),
a_help(&g_global_options, "help", 'h', "display help message", false),
a_version(&g_global_options, "version", 'v', "display version information", false)
{
diff --git a/src/clients/cave/command_line.hh b/src/clients/cave/command_line.hh
index 1869afb..e18fbcf 100644
--- a/src/clients/cave/command_line.hh
+++ b/src/clients/cave/command_line.hh
@@ -48,6 +48,8 @@ namespace paludis
args::ArgsGroup g_global_options;
args::StringArg a_environment;
args::LogLevelArg a_log_level;
+ args::EnumArg a_colour;
+ args::AliasArg a_color;
args::SwitchArg a_help;
args::SwitchArg a_version;
diff --git a/src/clients/cave/format_user_config.cc b/src/clients/cave/format_user_config.cc
index 9d9b420..5f591f5 100644
--- a/src/clients/cave/format_user_config.cc
+++ b/src/clients/cave/format_user_config.cc
@@ -31,45 +31,57 @@
using namespace paludis;
using namespace cave;
-std::string
-user_config_file_presets(
- const KeyValueConfigFile & k,
- const std::string & s)
+namespace
{
- static std::map<std::string, std::string> colours{
- { "red", "\033[0;31m" },
- { "bold_red", "\033[1;31m" },
- { "green", "\033[0;32m" },
- { "bold_green", "\033[1;32m" },
- { "yellow", "\033[0;33m" },
- { "bold_yellow", "\033[1;33m" },
- { "blue", "\033[0;34m" },
- { "bold_blue", "\033[1;34m" },
- { "pink", "\033[0;35m" },
- { "bold_pink", "\033[1;35m" },
- { "normal", "\033[0;0m" },
- { "bold_normal", "\033[1m" }
- };
-
static bool want_colours(::isatty(STDOUT_FILENO));
+}
- if (0 == s.compare(0, 8, "colours/"))
- {
- auto i(colours.find(s.substr(8)));
- if (i == colours.end())
- return "";
- else
- return i->second;
- }
- else
+void
+paludis::cave::set_want_colours(const bool v)
+{
+ want_colours = v;
+}
+
+namespace
+{
+ std::string
+ user_config_file_presets(
+ const KeyValueConfigFile & k,
+ const std::string & s)
{
- auto i(colours.find(s));
- if (i == colours.end())
- return "";
- else if (want_colours)
- return k.get("colours/" + s);
+ static std::map<std::string, std::string> colours{
+ { "red", "\033[0;31m" },
+ { "bold_red", "\033[1;31m" },
+ { "green", "\033[0;32m" },
+ { "bold_green", "\033[1;32m" },
+ { "yellow", "\033[0;33m" },
+ { "bold_yellow", "\033[1;33m" },
+ { "blue", "\033[0;34m" },
+ { "bold_blue", "\033[1;34m" },
+ { "pink", "\033[0;35m" },
+ { "bold_pink", "\033[1;35m" },
+ { "normal", "\033[0;0m" },
+ { "bold_normal", "\033[1m" }
+ };
+
+ if (0 == s.compare(0, 8, "colours/"))
+ {
+ auto i(colours.find(s.substr(8)));
+ if (i == colours.end())
+ return "";
+ else
+ return i->second;
+ }
else
- return k.get("colourless/" + s);
+ {
+ auto i(colours.find(s));
+ if (i == colours.end())
+ return "";
+ else if (want_colours)
+ return k.get("colours/" + s);
+ else
+ return k.get("colourless/" + s);
+ }
}
}
diff --git a/src/clients/cave/format_user_config.hh b/src/clients/cave/format_user_config.hh
index bf2bf93..dc682cf 100644
--- a/src/clients/cave/format_user_config.hh
+++ b/src/clients/cave/format_user_config.hh
@@ -32,6 +32,8 @@ namespace paludis
{
namespace cave
{
+ void set_want_colours(const bool v);
+
class FormatUserConfigFile :
private Pimp<FormatUserConfigFile>,
public Singleton<FormatUserConfigFile>