114 int main(
int argc,
char** argv)
133 keypad(stdscr, TRUE);
140 const int TITLE_WIN_HEIGHT = 6;
141 const int TITLE_WIN_WIDTH = COLS;
142 const int TITLE_WIN_BEGIN_Y = 0;
143 const int TITLE_WIN_BEGIN_X = 0;
144 WINDOW* title_win = newwin(TITLE_WIN_HEIGHT, TITLE_WIN_WIDTH, TITLE_WIN_BEGIN_Y, TITLE_WIN_BEGIN_X);
148 const int CONTEXT_WIN_HEIGHT = 5;
149 const int CONTEXT_WIN_WIDTH = COLS;
150 const int CONTEXT_WIN_BEGIN_Y = TITLE_WIN_BEGIN_Y + TITLE_WIN_HEIGHT + 1;
151 const int CONTEXT_WIN_BEGIN_X = 0;
152 WINDOW* context_win = newwin(CONTEXT_WIN_HEIGHT, CONTEXT_WIN_WIDTH, CONTEXT_WIN_BEGIN_Y, CONTEXT_WIN_BEGIN_X);
156 const int FUNCTION_WIN_HEIGHT = atoi(
suggestions.c_str()) + 2;
157 const int FUNCTION_WIN_WIDTH = 4;
158 const int FUNCTION_WIN_BEGIN_Y = CONTEXT_WIN_BEGIN_Y + CONTEXT_WIN_HEIGHT + 1;
159 const int FUNCTION_WIN_BEGIN_X = 0;
160 WINDOW* function_win = newwin(FUNCTION_WIN_HEIGHT, FUNCTION_WIN_WIDTH, FUNCTION_WIN_BEGIN_Y, FUNCTION_WIN_BEGIN_X);
163 mvprintw(LINES - 1, 0,
"Press F12 to quit.");
167 std::vector<std::string> words;
168 unsigned int c =
' ';
170 size_t size = words.size();
171 if ((KEY_F0 < c) && (c <= KEY_F(size)) && (c - KEY_F0 <= size)) {
175 std::string message =
"Last selected word: " + words[c - KEY_F0 - 1];
176 mvprintw(LINES - 3, 0, message.c_str());
188 buffer << static_cast<char>(c);
197 CONTEXT_WIN_BEGIN_Y + CONTEXT_WIN_HEIGHT + 1,
198 FUNCTION_WIN_BEGIN_X + FUNCTION_WIN_WIDTH + 1 );
201 }
while( c != KEY_F(12) );
205 delwin(function_win);
216 mvwprintw( win, 1, 1, str.c_str() );
221 void drawMsgWin( WINDOW* win, std::vector<std::string> words )
227 std::vector<std::string>::const_iterator j = words.begin();
228 while( j != words.end() ) {
229 mvwprintw( win, i, 1, j->c_str() );
241 for (
int i = 1; i <= atoi(
suggestions.c_str()); i++) {
242 std::stringstream ss;
244 mvwprintw(win, i, 1, ss.str().c_str());
250 const int starty,
int startx)
252 static std::list< std::vector<std::string> > previousSuggestions;
253 static std::vector< WINDOW* > windows;
256 for (std::vector< WINDOW* >::iterator winit = windows.begin();
257 winit != windows.end();
269 std::vector< std::string > marker;
270 for (
int i = 0; i < atoi(
suggestions.c_str()); i++) {
271 marker.push_back(
"|");
273 previousSuggestions.insert(previousSuggestions.begin(), marker);
276 previousSuggestions.insert(previousSuggestions.begin(), words);
278 for (std::list< std::vector<std::string> >::const_iterator listit = previousSuggestions.begin();
279 (listit != previousSuggestions.end() && startx < COLS);
282 int height = listit->size() + 2;
285 WINDOW* win = newwin(height, width, starty, startx);
290 for (std::vector<std::string>::const_iterator strit = listit->begin();
291 strit != listit->end();
294 mvwprintw(win, line, 1, strit->c_str());
299 windows.push_back(win);
307 for (std::vector< std::string >::const_iterator it =
suggestions.begin();
310 if (it->size() > result) {
319 int topBottomBorder = (LINES/8);
320 int borderWinHeight = 15;
321 int borderWinWidth = 70;
322 int sideBorder = (COLS - borderWinWidth) / 2;
323 WINDOW* borderWin = newwin(borderWinHeight, borderWinWidth, topBottomBorder, sideBorder);
324 WINDOW* disclaimerWin = newwin(borderWinHeight-2, borderWinWidth-2, topBottomBorder+1, sideBorder+1);
325 box(borderWin, 0, 0);
327 wprintw(disclaimerWin,
330 "This program is intended as a demonstration of Presage ONLY.\n" 332 "The Presage project aims to provide an intelligent predictive\n" 333 "text entry platform.\n" 335 "Its intent is NOT to provide a predictive text entry user interface.\n" 336 "Think of Presage as the predictive backend that sits behind a\n" 337 "shiny user interface and does all the predictive heavy lifting.\n" 339 mvwprintw(disclaimerWin, (borderWinHeight-2)-1, 1,
"Press any key to continue...");
340 wrefresh(disclaimerWin);
344 delwin(disclaimerWin);
354 box(title_win, 0, 0);
355 mvwprintw(title_win, 1, 1,
"Presage Demo ", VERSION);
356 mvwprintw(title_win, 2, 1,
"Copyright (C) Matteo Vescovi");
357 mvwprintw(title_win, 3, 1,
"This is free software; see the source for copying conditions. There is NO");
358 mvwprintw(title_win, 4, 1,
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
367 const char*
const short_options =
"c:s:hv";
369 const struct option long_options[] = {
370 {
"config", required_argument, 0,
'c' },
371 {
"suggestions", required_argument, 0,
's' },
372 {
"help", no_argument, 0,
'h' },
373 {
"version", no_argument, 0,
'v' },
378 next_option = getopt_long( argc, argv,
379 short_options, long_options, NULL );
381 switch( next_option ) {
406 }
while( next_option != -1 );
412 <<
"Copyright (C) 2004 Matteo Vescovi." <<
std::endl 413 <<
"This is free software; see the source for copying conditions. There is NO" <<
std::endl 414 <<
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE," <<
std::endl 415 <<
"to the extent permitted by law." <<
std::endl;
422 <<
"Begin typing. presage will attempt to predict the desired word." <<
std::endl 423 <<
"After each keystroke, presage will return a number of predictions." <<
std::endl 424 <<
"If the desired word appears in the prediction list, select it by pressing the" <<
std::endl 425 <<
"corresponding function key." <<
std::endl 427 <<
" -c, --config CONFIG use config file CONFIG" <<
std::endl 428 <<
" -s, --suggestions N set prediction size to N suggestions" <<
std::endl 429 <<
" -h, --help display this help and exit" <<
std::endl 430 <<
" -v, --version output version information and exit" <<
std::endl 432 <<
"Direct your bug reports to: " << PACKAGE_BUGREPORT <<
std::endl;
std::string config(const std::string variable) const
Gets the value of specified configuration variable.
std::string get_past_stream() const
size_t getGreatestSuggestionLength(std::vector< std::string > suggestions)
std::vector< std::string > predict()
Obtain a prediction.
void draw_context_win(WINDOW *, std::string)
void draw_function_keys(WINDOW *)
PresageDemoCallback(std::stringstream &buffer)
std::stringstream & m_buffer
void draw_title_win(WINDOW *)
void parseCommandLineArgs(int argc, char **argv)
const char PROGRAM_NAME[]
int main(int argc, char **argv)
bool context_change() const
Returns true if a context change occured.
std::string get_future_stream() const
void draw_previous_suggestions(std::vector< std::string >, bool, const int, int)
Presage, the intelligent predictive text entry platform.
void drawMsgWin(WINDOW *win, std::vector< std::string > words)
std::string context() const
Returns the text entered so far.
std::string completion(std::string str)
Request presage to return the completion string for the given predicted token.
const Logger< _charT, _Traits > & endl(const Logger< _charT, _Traits > &lgr)