diff --git a/i18n/strings.en-US b/i18n/strings.en-US index ea3f19e4e..b511b7501 100644 --- a/i18n/strings.en-US +++ b/i18n/strings.en-US @@ -18,7 +18,7 @@ 105 Inverted sequence range high-low 106 ID Range too large 107 Not a sequence. - +108 Interactive task is only available when built with ncurses support. # 2xx Commands 200 active diff --git a/src/Context.cpp b/src/Context.cpp index c44d13480..dd15ca926 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -36,6 +36,10 @@ #include "i18n.h" #include "../auto.h" +#ifdef HAVE_LIBNCURSES +#include +#endif + //////////////////////////////////////////////////////////////////////////////// Context::Context () : config () @@ -181,6 +185,8 @@ int Context::run () //////////////////////////////////////////////////////////////////////////////// int Context::interactive () { +#ifdef HAVE_LIBNCURSES + // TODO init ncurses // TODO create worker thread // TODO create refresh thread @@ -189,8 +195,76 @@ int Context::interactive () // TODO join worker thread // TODO take down ncurses - throw std::string ("unimplemented Context::interactive"); +// throw std::string ("unimplemented Context::interactive"); + + // Fake interactive teaser... + WINDOW* w = initscr (); + int width = w->_maxx + 1; + int height = w->_maxy + 1; + + (void) nonl (); + (void) cbreak (); + + start_color (); + init_pair (1, COLOR_WHITE, COLOR_BLUE); + init_pair (2, COLOR_WHITE, COLOR_RED); + init_pair (3, COLOR_CYAN, COLOR_BLUE); + + // Process commands. + std::string command = ""; + int c; + while (command != "quit") + { + // Render title. + std::string title = "task 2.0.0"; + while ((int) title.length () < width) + title += " "; + + bkgdset (COLOR_PAIR (1)); + mvprintw (0, 0, title.c_str ()); + + bkgdset (COLOR_PAIR (2)); + int line = height / 2; + mvprintw (line, width / 2 - 14, " I n t e r a c t i v e t a s k "); + mvprintw (line + 1, width / 2 - 14, " Coming in version 2.0.0 "); + + std::string footer = "Press 'q' to quit."; + while ((int) footer.length () < width) + footer = " " + footer; + + bkgdset (COLOR_PAIR (3)); + mvprintw (height - 1, 0, footer.c_str ()); + + move (1, 0); + refresh (); + + if ((c = getch ()) != ERR) + { + // 'Esc' and 'Enter' clear the accumulated commands. + // TODO Looks like \n is not preserved by getch. + if (c == 033 || c == '\n') + { + command = ""; + } + + else if (c == 'q') + { + command = "quit"; + break; + } + } + } + + endwin (); return 0; + +#else + + throw stringtable (INTERACTIVE_NO_NCURSES, + "Interactive task is only available when built with ncurses " + "support."); + +#endif } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/i18n.h b/src/i18n.h index 06d1cd117..eebdcad13 100644 --- a/src/i18n.h +++ b/src/i18n.h @@ -40,6 +40,8 @@ #define SEQUENCE_RANGE_MAX 106 #define SEQUENCE_NOT_A_SEQUENCE 107 +#define INTERACTIVE_NO_NCURSES 108 + // 2xx Commands #define CMD_ACTIVE 200 #define CMD_ADD 201 diff --git a/src/task.cpp b/src/task.cpp index 7dd33a9af..bdf6d18eb 100644 --- a/src/task.cpp +++ b/src/task.cpp @@ -302,7 +302,10 @@ int main (int argc, char** argv) try { context.initialize (argc, argv); - /* return */ context.run (); + if (context.args[0].find ("itask") != std::string::npos) + /* return */ context.interactive (); + else + /* return */ context.run (); // start OBSOLETE TDB tdb;