Interactive - stub

- Added stub code for the interactive version of task.
This commit is contained in:
Paul Beckingham 2009-06-06 17:41:24 -04:00
parent e9c45aab85
commit bc13f0be48
4 changed files with 82 additions and 3 deletions

View file

@ -36,6 +36,10 @@
#include "i18n.h"
#include "../auto.h"
#ifdef HAVE_LIBNCURSES
#include <ncurses.h>
#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
}
////////////////////////////////////////////////////////////////////////////////