Exemple #1
0
void redraw_all (void)
{
	int min_lines = TITLE_WIN_LINES+SHOW_WIN_LINES+COMMAND_WIN_LINES+3;
	struct winsize ws;
	int	save_col, save_lines;

	/* get the size of the terminal connected to stdout */
	ioctl(1, TIOCGWINSZ, &ws);
	/*
	 * Do it again because GDB doesn't stop before the first ioctl
	 * call, we want an up-to-date size when we're
	 * single-stepping.
	 */
	if (ioctl(1, TIOCGWINSZ, &ws) == 0) {
		if (ws.ws_row < min_lines)
			ws.ws_row = min_lines;
		if ((ws.ws_row != LINES) || (ws.ws_col != COLS)) {
			wmove (show_win,2,COLS-18);
			wclrtoeol(show_win);
			wrefresh(show_win);
			resizeterm(ws.ws_row, ws.ws_col);
			wresize(title_win, TITLE_WIN_LINES,COLS);
			wresize(show_win, SHOW_WIN_LINES,COLS);
			wresize(command_win, COMMAND_WIN_LINES,COLS);
			wresize(mt_win1, 1,COLS);
			wresize(mt_win2, 1,COLS);
			mvwin(mt_win2, LINES-COMMAND_WIN_LINES-1,0);
			mvwin(command_win, LINES-COMMAND_WIN_LINES,0);
			draw_title_win();
			show_pad_info.display_lines=LINES-TITLE_WIN_LINES-SHOW_WIN_LINES-COMMAND_WIN_LINES-2;
			show_pad_info.display_cols=COLS;
		}
	}
	clearok(title_win, 1);
	clearok(show_win, 1);
	clearok(command_win, 1);
	clearok(mt_win1, 1);
	clearok(mt_win2, 1);
	wrefresh(mt_win1);
	wrefresh(mt_win2);
	refresh_show_pad();
	refresh_show_win();
	refresh_title_win ();
	refresh_command_win ();
}
Exemple #2
0
void init_windows (void)
{
	initscr ();
	tcgetattr(0,&termioInit); /* save initial config */
	termioCurrent = termioInit;
	termioCurrent.c_lflag |= ECHO; /* set echo on */
	tcsetattr(0,TCSANOW,&termioCurrent);

	if (LINES<TITLE_WIN_LINES+SHOW_WIN_LINES+COMMAND_WIN_LINES+3) {
		printf ("Sorry, your terminal screen is too small\n");
		printf ("Error - Can not initialize windows\n");
		exit (1);
	}

	title_win=newwin (TITLE_WIN_LINES,COLS,0,0);
	show_win=newwin (SHOW_WIN_LINES,COLS,TITLE_WIN_LINES,0);
	show_pad=newpad (SHOW_PAD_LINES,SHOW_PAD_COLS);
	mt_win1=newwin (1,COLS,TITLE_WIN_LINES+SHOW_WIN_LINES,0);
	mt_win2=newwin (1,COLS,LINES-COMMAND_WIN_LINES-1,0);
	command_win=newwin (COMMAND_WIN_LINES,COLS,LINES-COMMAND_WIN_LINES,0);

	if (title_win==NULL || show_win==NULL || show_pad==NULL || command_win==NULL) {
		printf ("Error - Not enough memory - Can not initialize windows\n");exit (1);
	}

	draw_title_win();

	setup_show_win();

	scrollok (command_win,TRUE);

	refresh_title_win ();
	refresh_show_win ();
	refresh_show_pad();
	refresh_command_win ();
	wrefresh(mt_win1);
	wrefresh(mt_win2);
}
/** Demo program using curses.
 *
 * This demo displays the text entered in a top windows that stretches
 * across the screen. The current prediction is displayed immediately
 * underneath the text window, at the leftmost position.
 *
 * The previous predictions are displayed in cronological order to the
 * right of the current prediction.
 *
 * Subsequent predictions shifted to the right, so that the current
 * prediction is always on the left hand side.
 * Context switches are marked in some way (either a vertical bar or a
 * box enclosing the other prediction boxes).
 *
 */
int main(int argc, char** argv)
{
    parseCommandLineArgs(argc, argv);

    // magic starts here
    PresageCallback* callback = new PresageDemoCallback(buffer); 
    Presage presage(callback, config);

    // configuration variable may be read and written programmatically
    if (suggestions.empty()) {
	suggestions = presage.config("Presage.Selector.SUGGESTIONS");
    } else {
	presage.config("Presage.Selector.SUGGESTIONS", suggestions);
    }

    // curses 
    initscr();
    noecho();
    cbreak();
    keypad(stdscr, TRUE);
    clear();
    refresh();

    disclaimer();

    // curses title window
    const int TITLE_WIN_HEIGHT  = 6;
    const int TITLE_WIN_WIDTH   = COLS;
    const int TITLE_WIN_BEGIN_Y = 0;
    const int TITLE_WIN_BEGIN_X = 0;
    WINDOW* title_win = newwin(TITLE_WIN_HEIGHT, TITLE_WIN_WIDTH, TITLE_WIN_BEGIN_Y, TITLE_WIN_BEGIN_X);
    draw_title_win(title_win);

    // curses context window
    const int CONTEXT_WIN_HEIGHT  = 5;
    const int CONTEXT_WIN_WIDTH   = COLS;
    const int CONTEXT_WIN_BEGIN_Y = TITLE_WIN_BEGIN_Y + TITLE_WIN_HEIGHT + 1;
    const int CONTEXT_WIN_BEGIN_X = 0;
    WINDOW* context_win = newwin(CONTEXT_WIN_HEIGHT, CONTEXT_WIN_WIDTH, CONTEXT_WIN_BEGIN_Y, CONTEXT_WIN_BEGIN_X);
    draw_context_win(context_win, std::string(""));

    // curses function keys window
    const int FUNCTION_WIN_HEIGHT  = atoi(suggestions.c_str()) + 2;
    const int FUNCTION_WIN_WIDTH   = 4;
    const int FUNCTION_WIN_BEGIN_Y = CONTEXT_WIN_BEGIN_Y + CONTEXT_WIN_HEIGHT + 1;
    const int FUNCTION_WIN_BEGIN_X = 0;
    WINDOW* function_win = newwin(FUNCTION_WIN_HEIGHT, FUNCTION_WIN_WIDTH, FUNCTION_WIN_BEGIN_Y, FUNCTION_WIN_BEGIN_X);
    draw_function_keys(function_win);

    mvprintw(LINES - 1, 0, "Press F12 to quit.");
    refresh();


    std::vector<std::string> words;
    int c = ' ';
    do {
	size_t size = words.size();
	if ((KEY_F0 < c) && (c <= KEY_F(size)) && (c - KEY_F0 <= size)) {
	    // prediction was successful. user pressed the function
	    // key corresponding to desired token. selecting
	    // suggestion.
	    std::string message = "Last selected word: " + words[c - KEY_F0 - 1];
	    mvprintw(LINES - 3, 0, message.c_str());
            clrtoeol();
	    move(LINES, COLS);

	    // update buffer with prediction completion
	    buffer << presage.completion(words[c - KEY_F0 - 1]);
	    // ask presage to predict next token
	    words = presage.predict();

	} else {
	    // prediction unsuccessful. get next character from user
	    // and elaborate a new prediction.
	    buffer << static_cast<char>(c);
	    words = presage.predict();

	    // refresh curses screen
	    refresh();
	}
	draw_context_win(context_win, presage.context());
	draw_previous_suggestions(words,
				  presage.context_change(),
                                  CONTEXT_WIN_BEGIN_Y + CONTEXT_WIN_HEIGHT + 1,
                                  FUNCTION_WIN_BEGIN_X + FUNCTION_WIN_WIDTH + 1 );
        c = getch();

    } while( c != KEY_F(12) );


    delwin(title_win);
    delwin(context_win);
    delwin(function_win);
    endwin();

    return 0;
}