prompt: Greater C++11 compliance

This commit is contained in:
Paul Beckingham 2017-01-08 14:26:22 -05:00
parent cc2e173d74
commit a2a900d144

View file

@ -29,8 +29,7 @@
#include <string> #include <string>
#include <Color.h> #include <Color.h>
static const char* contextColors[] = static std::vector <std::string> contextColors = {
{
"bold white on red", "bold white on red",
"bold white on blue", "bold white on blue",
"bold white on green", "bold white on green",
@ -40,8 +39,6 @@ static const char* contextColors[] =
"black on white", "black on white",
}; };
#define NUM_COLORS (sizeof (contextColors) / sizeof (contextColors[0]))
static std::vector <std::string> contexts; static std::vector <std::string> contexts;
std::string composeContexts (bool pretty = false); std::string composeContexts (bool pretty = false);
@ -73,21 +70,14 @@ int promptAdd (const std::string& context)
std::string composeContexts (bool pretty /* = false */) std::string composeContexts (bool pretty /* = false */)
{ {
std::string combined; std::string combined;
for (unsigned int i = 0; i < contexts.size (); ++i) for (unsigned int i = 0; i < contexts.size (); i++)
{
if (pretty) if (pretty)
{ combined += (combined != "" ? " " : "")
combined += (i ? " " : "")
+ std::string ("\001") + std::string ("\001")
+ Color::colorize ("\002 " + contexts[i] + " \001", contextColors[i % NUM_COLORS]) + Color::colorize ("\002 " + contexts[i] + " \001", contextColors[i % contextColors.size ()])
+ "\002"; + "\002";
}
else else
{ combined += (combined != "" ? " " : "") + contexts[i];
combined += (i ? " " : "") + contexts[i];
}
}
if (combined != "") if (combined != "")
combined += ' '; combined += ' ';
@ -103,9 +93,9 @@ std::string promptCompose ()
// TODO - The accumulated context, as colored tokens. // TODO - The accumulated context, as colored tokens.
// TODO - sync status // TODO - sync status
// TODO - time // TODO - time
std::string decoration = composeContexts (true); auto decoration = composeContexts (true);
if (decoration.length ()) if (decoration.length ())
return "task " + composeContexts (true) + "> "; return "task " + decoration + "> ";
return "tasksh> "; return "tasksh> ";
} }