- Fixed crash bug by properly indexing color list.
- Added \001 and \002 readline markers, although it doesn't seem to help much.
This commit is contained in:
Paul Beckingham 2014-12-21 18:55:31 -05:00
parent d77766b400
commit a18d8cc579
3 changed files with 39 additions and 23 deletions

View file

@ -41,7 +41,7 @@ static const char* contextColors[] =
"black on white",
};
#define NUM_COLORS (sizeof contextColors)
#define NUM_COLORS (sizeof (contextColors) / sizeof (contextColors[0]))
////////////////////////////////////////////////////////////////////////////////
int cmdClear (std::vector <std::string>& contexts)
@ -78,10 +78,23 @@ std::string composeContexts (
{
std::string combined;
for (int i = 0; i < contexts.size (); ++i)
{
if (pretty)
{
combined += (i ? " " : "")
+ (pretty
? Color::colorize (" " + contexts[i] + " ", contextColors[i % NUM_COLORS])
: contexts[i]);
+ std::string ("\001")
+ Color::colorize ("\002 " + contexts[i] + " \001", contextColors[i % NUM_COLORS])
+ "\002";
}
else
{
combined += (i ? " " : "") + contexts[i];
}
}
if (combined != "")
combined += ' ';
return combined;
}

View file

@ -84,11 +84,13 @@ static int commandLoop (std::vector <std::string>& contexts)
}
#endif
int status = 0;
if (command != "")
{
std::vector <std::string> args;
split (args, command, ' ');
// Dispatch command
int status = 0;
if (closeEnough ("exit", args[0], 3)) status = -1;
else if (closeEnough ("quit", args[0], 3)) status = -1;
else if (closeEnough ("help", args[0], 3)) status = cmdHelp (args );
@ -98,13 +100,14 @@ static int commandLoop (std::vector <std::string>& contexts)
else if (closeEnough ("leave", args[0], 3)) status = cmdLeave ( contexts);
else if (command != "")
{
command = "task " + composeContexts (contexts) + " " + command;
command = "task " + composeContexts (contexts) + command;
std::cout << "[task " << command << "]\n";
system (command.c_str ());
// Deliberately ignoreѕ taskwarrior exit status, otherwise empty filters
// cause the shell to terminate.
}
}
return status;
}

View file

@ -40,7 +40,7 @@ std::string composePrompt (std::vector <std::string>& contexts)
// TODO - time
std::string decoration = composeContexts (contexts, true);
if (decoration.length ())
return "task " + composeContexts (contexts, true) + " > ";
return "task " + composeContexts (contexts, true) + "> ";
return "task> ";
}