diff --git a/AUTHORS b/AUTHORS index 388e6d1..4b8f4bc 100644 --- a/AUTHORS +++ b/AUTHORS @@ -18,3 +18,4 @@ suggestions: David Patrick jonbobbly hosaka + Lars Kumbier diff --git a/ChangeLog b/ChangeLog index 03ada47..585c10a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ (Thanks to Jörg Krause, Ben Boeckel). - TW-1845 Cygwin build fails, missing get_current_dir_name (thanks to hosaka). +- TS-11 Autoclear in the Task Shell + (thanks to Lars Kumbier). - TS-24 add review option (m)odify (thanks to David Patrick). - Implemented 'review' command. diff --git a/doc/man/tasksh.1.in b/doc/man/tasksh.1.in index ea355f3..bd06f83 100644 --- a/doc/man/tasksh.1.in +++ b/doc/man/tasksh.1.in @@ -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 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" Copyright (C) 2006 \- 2016 P. Beckingham, F. Hernandez. diff --git a/src/main.cpp b/src/main.cpp index 5af3a67..82ed079 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,7 +44,7 @@ // tasksh commands. int cmdHelp (); int cmdDiagnostics (); -int cmdReview (const std::vector &); +int cmdReview (const std::vector &, bool); int cmdShell (const std::vector &); std::string promptCompose (); 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. std::string prompt = promptCompose (); @@ -107,6 +107,10 @@ static int commandLoop () // Display prompt, get input. std::string command = getResponse (prompt); + // Obey Taskwarrior's rc.tasksh.autoclear. + if (autoClear) + std::cout << "\033[2J\033[0;0H"; + int status = 0; if (command != "") { @@ -117,7 +121,7 @@ static int commandLoop () else if (closeEnough ("quit", args[0], 3)) status = -1; else if (closeEnough ("help", args[0], 3)) status = cmdHelp (); 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) || args[0][0] == '!') status = cmdShell (args); else if (command != "") @@ -148,8 +152,20 @@ int main (int argc, const char** argv) { 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 (); - while ((status = commandLoop ()) == 0) + while ((status = commandLoop (autoClear)) == 0) ; } diff --git a/src/review.cpp b/src/review.cpp index a13c97c..4649fbd 100644 --- a/src/review.cpp +++ b/src/review.cpp @@ -175,7 +175,7 @@ static const std::string menu () } //////////////////////////////////////////////////////////////////////////////// -static void reviewLoop (const std::vector & uuids, unsigned int limit) +static void reviewLoop (const std::vector & uuids, unsigned int limit, bool autoClear) { unsigned int reviewed = 0; auto total = std::min (static_cast (uuids.size ()), limit); @@ -228,6 +228,9 @@ static void reviewLoop (const std::vector & uuids, unsigned int lim // Note that just hitting yields an empty command, which does // nothing but advance to the next task. + + if (autoClear) + std::cout << "\033[2J\033[0;0H"; } std::cout << "\n" @@ -236,7 +239,7 @@ static void reviewLoop (const std::vector & uuids, unsigned int lim } //////////////////////////////////////////////////////////////////////////////// -int cmdReview (const std::vector & args) +int cmdReview (const std::vector & args, bool autoClear) { // Is there a specified limit? unsigned int limit = 0; @@ -284,7 +287,7 @@ int cmdReview (const std::vector & args) // Review the set of UUIDs. std::vector uuids = split (Lexer::trimRight (output, "\n"), '\n'); - reviewLoop (uuids, limit); + reviewLoop (uuids, limit, autoClear); return 0; }