mirror of
https://github.com/GothenburgBitFactory/taskshell.git
synced 2025-07-07 20:06:42 +02:00
Prompt
- 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:
parent
d77766b400
commit
a18d8cc579
3 changed files with 39 additions and 23 deletions
|
@ -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)
|
||||
combined += (i ? " " : "")
|
||||
+ (pretty
|
||||
? Color::colorize (" " + contexts[i] + " ", contextColors[i % NUM_COLORS])
|
||||
: contexts[i]);
|
||||
{
|
||||
if (pretty)
|
||||
{
|
||||
combined += (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;
|
||||
}
|
||||
|
|
37
src/main.cpp
37
src/main.cpp
|
@ -84,26 +84,29 @@ static int commandLoop (std::vector <std::string>& contexts)
|
|||
}
|
||||
#endif
|
||||
|
||||
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 );
|
||||
else if (closeEnough ("diagnostics", args[0], 3)) status = cmdDiagnostics (args );
|
||||
else if (closeEnough ("context", args[0], 3)) status = cmdContext (args, contexts);
|
||||
else if (closeEnough ("clear", args[0], 3)) status = cmdClear ( contexts);
|
||||
else if (closeEnough ("leave", args[0], 3)) status = cmdLeave ( contexts);
|
||||
else if (command != "")
|
||||
if (command != "")
|
||||
{
|
||||
command = "task " + composeContexts (contexts) + " " + command;
|
||||
std::cout << "[task " << command << "]\n";
|
||||
system (command.c_str ());
|
||||
std::vector <std::string> args;
|
||||
split (args, command, ' ');
|
||||
|
||||
// Deliberately ignoreѕ taskwarrior exit status, otherwise empty filters
|
||||
// cause the shell to terminate.
|
||||
// Dispatch command
|
||||
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 );
|
||||
else if (closeEnough ("diagnostics", args[0], 3)) status = cmdDiagnostics (args );
|
||||
else if (closeEnough ("context", args[0], 3)) status = cmdContext (args, contexts);
|
||||
else if (closeEnough ("clear", args[0], 3)) status = cmdClear ( contexts);
|
||||
else if (closeEnough ("leave", args[0], 3)) status = cmdLeave ( contexts);
|
||||
else if (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;
|
||||
|
|
|
@ -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> ";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue