TS-11: Autoclear in the Task Shell

- Thanks to Lars Kumbier.
This commit is contained in:
Paul Beckingham 2016-09-04 16:06:17 -04:00
parent 3695e3619e
commit cbb7959833
5 changed files with 36 additions and 7 deletions

View file

@ -18,3 +18,4 @@ suggestions:
David Patrick David Patrick
jonbobbly jonbobbly
hosaka hosaka
Lars Kumbier

View file

@ -4,6 +4,8 @@
(Thanks to Jörg Krause, Ben Boeckel). (Thanks to Jörg Krause, Ben Boeckel).
- TW-1845 Cygwin build fails, missing get_current_dir_name - TW-1845 Cygwin build fails, missing get_current_dir_name
(thanks to hosaka). (thanks to hosaka).
- TS-11 Autoclear in the Task Shell
(thanks to Lars Kumbier).
- TS-24 add review option (m)odify - TS-24 add review option (m)odify
(thanks to David Patrick). (thanks to David Patrick).
- Implemented 'review' command. - Implemented 'review' command.

View file

@ -120,6 +120,13 @@ database, and .taskrc file, Tasksh will not find them unless you set the
TASKDATA and TASKRC environment variables. See 'man taskrc' for more TASKDATA and TASKRC environment variables. See 'man taskrc' for more
details. details.
The review command storeѕ a UDA ('reviewed') and report definition ('_reviewed').
.TP
.B tasksh.autoclear=1
If set to "1", causes each tasksh command to be preceded by a 'clear screen' and
cursor reset. Default is "0".
.SH "CREDITS & COPYRIGHTS" .SH "CREDITS & COPYRIGHTS"
Copyright (C) 2006 \- 2016 P. Beckingham, F. Hernandez. Copyright (C) 2006 \- 2016 P. Beckingham, F. Hernandez.

View file

@ -44,7 +44,7 @@
// tasksh commands. // tasksh commands.
int cmdHelp (); int cmdHelp ();
int cmdDiagnostics (); int cmdDiagnostics ();
int cmdReview (const std::vector <std::string>&); int cmdReview (const std::vector <std::string>&, bool);
int cmdShell (const std::vector <std::string>&); int cmdShell (const std::vector <std::string>&);
std::string promptCompose (); std::string promptCompose ();
std::string findTaskwarrior (); std::string findTaskwarrior ();
@ -99,7 +99,7 @@ const std::string getResponse (const std::string& prompt)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static int commandLoop () static int commandLoop (bool autoClear)
{ {
// Compose the prompt. // Compose the prompt.
std::string prompt = promptCompose (); std::string prompt = promptCompose ();
@ -107,6 +107,10 @@ static int commandLoop ()
// Display prompt, get input. // Display prompt, get input.
std::string command = getResponse (prompt); std::string command = getResponse (prompt);
// Obey Taskwarrior's rc.tasksh.autoclear.
if (autoClear)
std::cout << "\033[2J\033[0;0H";
int status = 0; int status = 0;
if (command != "") if (command != "")
{ {
@ -117,7 +121,7 @@ static int commandLoop ()
else if (closeEnough ("quit", args[0], 3)) status = -1; else if (closeEnough ("quit", args[0], 3)) status = -1;
else if (closeEnough ("help", args[0], 3)) status = cmdHelp (); else if (closeEnough ("help", args[0], 3)) status = cmdHelp ();
else if (closeEnough ("diagnostics", args[0], 3)) status = cmdDiagnostics (); else if (closeEnough ("diagnostics", args[0], 3)) status = cmdDiagnostics ();
else if (closeEnough ("review", args[0], 3)) status = cmdReview (args); else if (closeEnough ("review", args[0], 3)) status = cmdReview (args, autoClear);
else if (closeEnough ("exec", args[0], 3) || else if (closeEnough ("exec", args[0], 3) ||
args[0][0] == '!') status = cmdShell (args); args[0][0] == '!') status = cmdShell (args);
else if (command != "") else if (command != "")
@ -148,8 +152,20 @@ int main (int argc, const char** argv)
{ {
try try
{ {
// Get the Taskwarrior rc.tasksh.autoclear Boolean setting.
bool autoClear = false;
std::string input;
std::string output;
execute ("task", {"_get", "rc.tasksh.autoclear"}, input, output);
output = lowerCase (output);
autoClear = (output == "true\n" ||
output == "1\n" ||
output == "y\n" ||
output == "yes\n" ||
output == "on\n");
welcome (); welcome ();
while ((status = commandLoop ()) == 0) while ((status = commandLoop (autoClear)) == 0)
; ;
} }

View file

@ -175,7 +175,7 @@ static const std::string menu ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static void reviewLoop (const std::vector <std::string>& uuids, unsigned int limit) static void reviewLoop (const std::vector <std::string>& uuids, unsigned int limit, bool autoClear)
{ {
unsigned int reviewed = 0; unsigned int reviewed = 0;
auto total = std::min (static_cast <unsigned int> (uuids.size ()), limit); auto total = std::min (static_cast <unsigned int> (uuids.size ()), limit);
@ -228,6 +228,9 @@ static void reviewLoop (const std::vector <std::string>& uuids, unsigned int lim
// Note that just hitting <Enter> yields an empty command, which does // Note that just hitting <Enter> yields an empty command, which does
// nothing but advance to the next task. // nothing but advance to the next task.
if (autoClear)
std::cout << "\033[2J\033[0;0H";
} }
std::cout << "\n" std::cout << "\n"
@ -236,7 +239,7 @@ static void reviewLoop (const std::vector <std::string>& uuids, unsigned int lim
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int cmdReview (const std::vector <std::string>& args) int cmdReview (const std::vector <std::string>& args, bool autoClear)
{ {
// Is there a specified limit? // Is there a specified limit?
unsigned int limit = 0; unsigned int limit = 0;
@ -284,7 +287,7 @@ int cmdReview (const std::vector <std::string>& args)
// Review the set of UUIDs. // Review the set of UUIDs.
std::vector <std::string> uuids = split (Lexer::trimRight (output, "\n"), '\n'); std::vector <std::string> uuids = split (Lexer::trimRight (output, "\n"), '\n');
reviewLoop (uuids, limit); reviewLoop (uuids, limit, autoClear);
return 0; return 0;
} }