Review: Added framework

- Added 'review' command, which does nothing.
- Removed 'context' command, which now passes to Taskwarrior.
- Removed 'leave' command.
- Removed 'clear' command.
This commit is contained in:
Paul Beckingham 2015-05-23 22:42:03 -04:00
parent d485f9440a
commit 7f712d0926
4 changed files with 83 additions and 89 deletions

View file

@ -3,10 +3,10 @@ include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src
${TASKSH_INCLUDE_DIRS})
set (tasksh_SRCS context.cpp
diag.cpp
set (tasksh_SRCS diag.cpp
help.cpp
prompt.cpp
review.cpp
Color.cpp Color.h
Path.cpp Path.h
File.cpp File.h

View file

@ -45,18 +45,15 @@
// tasksh commands.
int cmdHelp (const std::vector <std::string>&);
int cmdDiagnostics (const std::vector <std::string>&);
int cmdContext (const std::vector <std::string>&, std::vector <std::string>&);
int cmdClear (std::vector <std::string>&);
int cmdLeave (std::vector <std::string>&);
std::string composePrompt (std::vector <std::string>&);
std::string composeContexts (std::vector <std::string>&, bool pretty = false);
int cmdReview (const std::vector <std::string>&);
std::string promptCompose ();
std::string findTaskwarrior ();
////////////////////////////////////////////////////////////////////////////////
static int commandLoop (std::vector <std::string>& contexts)
static int commandLoop ()
{
// Compose the prompt.
std::string prompt = composePrompt (contexts);
std::string prompt = promptCompose ();
// Display prompt, get input.
#ifdef HAVE_READLINE
@ -90,18 +87,16 @@ static int commandLoop (std::vector <std::string>& contexts)
std::vector <std::string> args;
split (args, command, ' ');
// Dispatch command
// 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 (closeEnough ("help", args[0], 3)) status = cmdHelp (args);
else if (closeEnough ("diagnostics", args[0], 3)) status = cmdDiagnostics (args);
else if (closeEnough ("review", args[0], 3)) status = cmdReview (args);
else if (command != "")
{
command = "task " + composeContexts (contexts) + command;
std::cout << "[task " << command << "]\n";
command = "task " + command;
std::cout << "[" << command << "]\n";
system (command.c_str ());
// Deliberately ignoreѕ taskwarrior exit status, otherwise empty filters
@ -126,8 +121,7 @@ int main (int argc, const char** argv)
{
try
{
std::vector <std::string> contexts;
while ((status = commandLoop (contexts)) == 0)
while ((status = commandLoop ()) == 0)
;
}

View file

@ -27,20 +27,85 @@
#include <cmake.h>
#include <vector>
#include <string>
#include <Color.h>
std::string composeContexts (std::vector <std::string>&, bool plain = true);
static const char* contextColors[] =
{
"bold white on red",
"bold white on blue",
"bold white on green",
"bold white on magenta",
"black on cyan",
"black on yellow",
"black on white",
};
#define NUM_COLORS (sizeof (contextColors) / sizeof (contextColors[0]))
static std::vector <std::string> contexts;
std::string composeContexts (bool pretty = false);
////////////////////////////////////////////////////////////////////////////////
std::string composePrompt (std::vector <std::string>& contexts)
int promptClear ()
{
contexts.clear ();
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int promptRemove ()
{
if (contexts.size ())
contexts.pop_back ();
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int promptAdd (const std::string& context)
{
contexts.push_back (context);
return 0;
}
////////////////////////////////////////////////////////////////////////////////
std::string composeContexts (bool pretty /* = false */)
{
std::string combined;
for (int i = 0; i < contexts.size (); ++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;
}
////////////////////////////////////////////////////////////////////////////////
std::string promptCompose ()
{
// TODO The prompt may be composed of different elements:
// TODO - The configurable text
// TODO - The accumulated context, as colored tokens.
// TODO - sync status
// TODO - time
std::string decoration = composeContexts (contexts, true);
std::string decoration = composeContexts (true);
if (decoration.length ())
return "task " + composeContexts (contexts, true) + "> ";
return "task " + composeContexts (true) + "> ";
return "task> ";
}

View file

@ -25,78 +25,13 @@
////////////////////////////////////////////////////////////////////////////////
#include <cmake.h>
#include <iostream> // TODO Remove.
#include <vector>
#include <string>
#include <Color.h>
static const char* contextColors[] =
{
"bold white on red",
"bold white on blue",
"bold white on green",
"bold white on magenta",
"black on cyan",
"black on yellow",
"black on white",
};
#define NUM_COLORS (sizeof (contextColors) / sizeof (contextColors[0]))
////////////////////////////////////////////////////////////////////////////////
int cmdClear (std::vector <std::string>& contexts)
int cmdReview (const std::vector <std::string>& args)
{
contexts.clear ();
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int cmdLeave (std::vector <std::string>& contexts)
{
if (contexts.size ())
contexts.pop_back ();
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int cmdContext (
const std::vector <std::string>& args,
std::vector <std::string>& contexts)
{
// TODO Verify context not already in use.
if (args.size () > 1)
contexts.push_back (args[1]);
return 0;
}
////////////////////////////////////////////////////////////////////////////////
std::string composeContexts (
std::vector <std::string>& contexts,
bool pretty /* = false */)
{
std::string combined;
for (int i = 0; i < contexts.size (); ++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;
}
////////////////////////////////////////////////////////////////////////////////