Example #1
0
void *thr01_func (void *arg) {
	gettimeofday (&tv0, NULL);
	while (1) {
		if (paused) { usleep (10000); continue; }
		gettimeofday (&tvc, NULL);
		if (!show_help_once) {
			if ((tvc.tv_sec - tv0.tv_sec) < 5) {
				cx_prev = getcurx (window);
				cy_prev = getcury (window);
				mvcur (cy_prev, cx_prev, 2, 2);
				chrono_help ();
				mvcur (2, getcurx (window), cy_prev, cx_prev);
				fflush (stdout);
			}
			else {
				show_help_once = 1;
				cx_prev = getcurx (window);
				cy_prev = getcury (window);
				mvcur (cy_prev, cx_prev, 2, 2);
				int cnt;
				for (cnt = 0; cnt < getmaxx(window); cnt++)
					fputc (' ', stdout);
				mvcur (2, getmaxx(window)-1, cy_prev, cx_prev);
				fflush (stdout);
			}
		}
		tvdiff (&tv0, &tvc, &tvd);
		seconds = tvd.tv_sec;
		if (pause_time) seconds -= pause_time;
		days = seconds / 60 / 60 / 24;
		if (days)
			seconds -= days * 60 * 60 * 24;
		hours = seconds / 60 / 60;
		if (hours)
			seconds -= hours * 60 * 60;
		minutes = seconds / 60;
		if (minutes)
			seconds -= minutes * 60;
		if (days)
			sprintf (chrono_str, "\r%d day%s %02d:%02d:%02d:%03d", days, (days > 1)?"s":"", 
				hours, minutes, seconds, (int)tvd.tv_usec / 1000);
		else
			sprintf (chrono_str, "\r%02d:%02d:%02d:%03d", hours, minutes, seconds, (int)tvd.tv_usec / 1000);
		printf ("%s", chrono_str);
		fflush (stdout);
		usleep (10000);
	}
	return NULL;
}
Example #2
0
static void
gnt_menu_draw(GntWidget *widget)
{
	GntMenu *menu = GNT_MENU(widget);
	GList *iter;
	chtype type;
	guint i;

	if (menu->type == GNT_MENU_TOPLEVEL) {
		wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_HIGHLIGHT));
		werase(widget->window);

		for (i = 0, iter = menu->list; iter; iter = iter->next, i++) {
			GntMenuItem *item = GNT_MENU_ITEM(iter->data);
			if (!gnt_menuitem_is_visible(item))
				continue;
			type = ' ';
			if (item->callback || item->submenu)
				type |= gnt_color_pair(GNT_COLOR_HIGHLIGHT);
			else
				type |= gnt_color_pair(GNT_COLOR_DISABLED);
			if (i == menu->selected)
				type |= A_REVERSE;
			item->priv.x = getcurx(widget->window) + widget->priv.x;
			item->priv.y = getcury(widget->window) + widget->priv.y + 1;
			wbkgdset(widget->window, type);
			wprintw(widget->window, " %s   ", C_(item->text));
		}
	} else {
		org_draw(widget);
	}

	GNTDEBUG;
}
Example #3
0
/*
  window.cursor.y
  return the row number of the cursor

  Stack:
  1: the instance table
  2: the accessed key
*/
int		lui_window_get_cursor_y(lua_State *L)
{
    PANEL		*p = check_window(L, 1);

    lua_pushinteger(L, getcury(panel_window(p)));
    return 1;
}
Example #4
0
void
win_page_down(ProfWin *window)
{
    int rows = getmaxy(stdscr);
    int y = getcury(window->layout->win);
    int page_space = rows - 4;
    int *page_start = &(window->layout->y_pos);

    *page_start += page_space;

    // only got half a screen, show full screen
    if ((y - (*page_start)) < page_space)
        *page_start = y - page_space;

    // went past end, show full screen
    else if (*page_start >= y)
        *page_start = y - page_space - 1;

    window->layout->paged = 1;
    win_update_virtual(window);

    // switch off page if last line and space line visible
    if ((y) - *page_start == page_space) {
        window->layout->paged = 0;
    }
}
Example #5
0
static void
dlg_raise_window(WINDOW *win)
{
    touchwin(win);
    wmove(win, getcury(win), getcurx(win));
    wnoutrefresh(win);
    doupdate();
}
Example #6
0
unsigned char FunctionMenu(struct words_info *words)
{
    unsigned int i, j;
_refresh:
    clear();
    border('|', '|', '-', '-', '+', '+', '+', '+');
    _mvchgrectat(1, 1, getmaxy(stdscr) - 2, getmaxx(stdscr) - 2, 0, clr_obkg, NULL);
    attron(COLOR_PAIR(clr_ottl));
    mvaddstr(1, (getmaxx(stdscr) - 16) / 2, "Words - 学习方式");
    attroff(COLOR_PAIR(clr_ottl));
    i = (getmaxy(stdscr) - 6) / 4;
    j = (getmaxx(stdscr) - 12 ) / 2;
    attron(COLOR_PAIR(clr_oopt) | A_BOLD);
    mvaddstr(2 + (getmaxy(stdscr) - 6 - 2 * i) / 2, j, "[↑]记默模式");
    mvaddstr(getcury(stdscr) + 1 + i, (getmaxx(stdscr) - 24) / 3, "[←]认知模式");
    mvaddstr(getcury(stdscr), ((getmaxx(stdscr) - 24) / 3) * 2 + 12, "[→]检测模式");
    mvaddstr(getcury(stdscr) + 1 + i, j, "[↓]进入设置");
    attroff(COLOR_PAIR(clr_oopt));
    i = (getmaxx(stdscr) - 36) / 4;
    attron(COLOR_PAIR(clr_otip));
    mvaddstr(getcury(stdscr), j - i - 12, "[输入]单词表");
    mvaddstr(getcury(stdscr), j + i + 12, "[返回]返回");
    attroff(COLOR_PAIR(clr_otip) | A_BOLD);
    refresh();
_getkey:
    switch (getch()) {
    case KEY_UP:
        return 2;
    case KEY_DOWN:
        return 4;
    case KEY_LEFT:
        return 1;
    case KEY_RIGHT:
        return 3;
    case '\n':
        return 5;
    case 033:
        return 0;
    case KEY_RESIZE:
        goto _refresh;
    default:
        goto _getkey;
    }
    return 0;
}
Example #7
0
void game_update(void) {
    int ch = wgetch(main_window);
    while (ch != ERR) {
        switch (ch) {
            case 'q': running = false; break;
            case 'h': wmove(main_window, getcury(main_window), getcurx(main_window)-2); break;
            case 'j': wmove(main_window, getcury(main_window)+1, getcurx(main_window)); break;
            case 'k': wmove(main_window, getcury(main_window)-1, getcurx(main_window)); break;
            case 'l': wmove(main_window, getcury(main_window), getcurx(main_window)+2); break;
            case 'c': matrix_change(); break;
            case 'C': matrix_init(); break;
            case 'i': if (game_delay - DELAY_STEP > DELAY_MIN) game_delay -= DELAY_STEP; panel_draw(); break;
            case 'd': if (game_delay + DELAY_STEP < DELAY_MAX) game_delay += DELAY_STEP; panel_draw(); break;
            case 'p': stat = !stat; break;
        }
        ch = wgetch(main_window);
    }
}
Example #8
0
void
win_sub_newline_lazy(WINDOW *win)
{
    int curx = getcurx(win);
    if (curx > 0) {
        int cury = getcury(win);
        wmove(win, cury+1, 0);
    }
}
Example #9
0
void printrightw(WINDOW *win, const char *fmt, ...) {
	va_list ap;
	char buf[BUFSIZ];

	va_start(ap, fmt);
	vsnprintf(buf, BUFSIZ, fmt, ap);
	va_end(ap);

	mvwprintw(win, getcury(win), getmaxx(win) - 1 - strlen(buf), "%s", buf);
}
Example #10
0
void
win_printline_nowrap(WINDOW *win, char *msg)
{
    int maxx = getmaxx(win);
    int cury = getcury(win);

    waddnstr(win, msg, maxx);

    wmove(win, cury+1, 0);
}
Example #11
0
void cWidget::print(string sMsg)
{
	box(m_Window, '+', '+');
	int nX = getcurx(m_Window);
	int nY = getcury(m_Window);
	mvwprintw(m_Window, ++nY, 2, "%s", sMsg.c_str());
	wrefresh(m_Window);
	refresh();

}
Example #12
0
static void
tui_mld_erase_entire_line (const struct match_list_displayer *displayer)
{
  WINDOW *w = TUI_CMD_WIN->generic.handle;
  int cur_y = getcury (w);

  wmove (w, cur_y, 0);
  wclrtoeol (w);
  wmove (w, cur_y, 0);
}
Example #13
0
void game_step(void) {
    int x = getcurx(main_window);
    int y = getcury(main_window);
    wmove(panel_window, 0, 0);
    matrix_update();
    gettimeofday(&now, NULL);
    int time = game_delay - (now.tv_usec - before.tv_usec)/1000.0;
    if (time > 0) delay_output(time);
    gettimeofday(&before, NULL);
    wmove(main_window, y, x);
}
Example #14
0
void console::debug(std::string str) {
	int row = getcury(this -> debug_window);
	row++;
	if (row > 3) {
		this -> clearWindow(this -> debug_window);
		row = 1;
	}

	mvwprintw(this -> debug_window, row, 1, str.c_str());
	wrefresh(this -> debug_window);
}
Example #15
0
/*
 * Suspend/Resume
 */
static errr Term_xtra_gcu_alive(int v)
{
   /* Suspend */
   if (!v)
   {
      /* Go to normal keymap mode */
      keymap_norm();

      /* Restore modes */
      nocbreak();
      echo();
      nl();

      /* Hack -- make sure the cursor is visible */
      Term_xtra(TERM_XTRA_SHAPE, 1);

      /* Flush the curses buffer */
      (void)refresh();

#ifdef SPECIAL_BSD
      /* this moves curses to bottom right corner */
      mvcur(curscr->cury, curscr->curx, LINES - 1, 0);
#else
      /* this moves curses to bottom right corner */
      mvcur(getcury(curscr), getcurx(curscr), LINES - 1, 0);
#endif

      /* Exit curses */
      endwin();

      /* Flush the output */
      (void)fflush(stdout);
   }

   /* Resume */
   else
   {
      /* Refresh */
      /* (void)touchwin(curscr); */
      /* (void)wrefresh(curscr); */

      /* Restore the settings */
      cbreak();
      noecho();
      nonl();

      /* Go to angband keymap mode */
      keymap_game();
   }

   /* Success */
   return (0);
}
Example #16
0
void show_single(int y, int x, cell_t** field, size_t length, bool anonymous){
    int start_x = getcurx(stdscr);
    int start_y = getcury(stdscr);
    move(y, x);

    for(int i=0; i<length; i++){
        for (int j=0; j<length; j++){
            draw_cell(y+j, x+i*2, (field[i])[j], anonymous);
        }
    }
    move(start_y, start_x);
}
Example #17
0
void
win_move_to_end(ProfWin *window)
{
    window->paged = 0;

    int rows = getmaxy(stdscr);
    int y = getcury(window->win);
    int size = rows - 3;

    window->y_pos = y - (size - 1);
    if (window->y_pos < 0) {
        window->y_pos = 0;
    }
}
Example #18
0
void board_draw(void) {
    int i, j;
    int x = getcurx(main_window);
    int y = getcury(main_window);
    for (i = 0; i < ROWS; i++)
        for (j = 0; j < COLS; j++) {
            wmove(main_window, i, j*2);
            if (matrix[i][j]) waddch(main_window, 'X');
            else {
                waddch(main_window, ' ');
                waddch(main_window, '.');
            }
        }
    wmove(main_window, y, x);
    wrefresh(main_window);
}
Example #19
0
/*
 * returns currsor x position
 */
static int ncurses_redraw_input_line(CHAR_T *text) {
#ifdef HAVE_LIBASPELL
	char *aspell_line = NULL;
#endif
	int i, stop, cur_posx = 0;
	int attr = A_NORMAL;
	const int linelen = xwcslen(text);
	int promptlen = getcurx(input);
	int width = input->_maxx + 1 - promptlen;
	int y = getcury(input);

#ifdef HAVE_LIBASPELL
	if (spell_checker) {
		aspell_line = xmalloc(linelen + 1);
		spellcheck(text, aspell_line);
	}
#endif
	stop = linelen < width+line_start ? linelen : width + line_start;
	for (i = line_start; i < stop; i++) {
		if (line_index == i) {
			cur_posx = getcurx(input);
		}
#ifdef HAVE_LIBASPELL
		if (aspell_line && aspell_line[i] == ASPELLCHAR && text[i] != ' ') /* jesli b³êdny to wy¶wietlamy podkre¶lony */
			attr = A_UNDERLINE;
		else
			attr = A_NORMAL;
#endif
		print_char(input, text[i], attr);
	}
	if (line_index >= i) {
		cur_posx = getcurx(input);
	}
#ifdef HAVE_LIBASPELL
	xfree(aspell_line);
#endif

	if (width>2) {
		wattrset(input, color_pair(COLOR_BLACK, COLOR_BLACK) | A_BOLD);
		if (line_start > 0)
			mvwaddch(input, y, promptlen, '<');
		if (linelen && linelen - line_start > width)
			mvwaddch(input, y, input->_maxx, '>');
	}
	wattrset(input, A_NORMAL);
	return cur_posx;
}
Example #20
0
void
ui_current_page_off(void)
{
    ProfWin *current = wins_get_current();
    current->paged = 0;

    int rows = getmaxy(stdscr);
    int y = getcury(current->win);
    int size = rows - 3;

    current->y_pos = y - (size - 1);
    if (current->y_pos < 0) {
        current->y_pos = 0;
    }

    wins_refresh_current();
}
Example #21
0
void
win_sub_print(WINDOW *win, char *msg, gboolean newline, gboolean wrap, int indent)
{
    int maxx = getmaxx(win);
    int curx = getcurx(win);
    int cury = getcury(win);

    if (wrap) {
        _win_print_wrapped(win, msg, 1, indent);
    } else {
        waddnstr(win, msg, maxx - curx);
    }

    if (newline) {
        wmove(win, cury+1, 0);
    }
}
Example #22
0
File: run.c Project: ryo/netbsd-src
static WINDOW *
show_cmd(const char *scmd, struct winsize *win)
{
	int n, m;
	WINDOW *actionwin;
	int nrow;

	wclear(stdscr);
	clearok(stdscr, 1);
	touchwin(stdscr);
	refresh();

	mvaddstr(0, 4, msg_string(MSG_Status));
	standout();
	addstr(msg_string(MSG_Running));
	standend();
	mvaddstr(1, 4, msg_string(MSG_Command));
	standout();
	printw("%s", scmd);
	standend();
	addstr("\n\n");
	for (n = win->ws_col; (m = min(n, 30)) > 0; n -= m)
		addstr( "------------------------------" + 30 - m);
	refresh();

	nrow = getcury(stdscr) + 1;

	actionwin = subwin(stdscr, win->ws_row - nrow, win->ws_col, nrow, 0);
	if (actionwin == NULL) {
		fprintf(stderr, "sysinst: failed to allocate output window.\n");
		exit(1);
	}
	scrollok(actionwin, TRUE);
	if (has_colors()) {
		wbkgd(actionwin, getbkgd(stdscr));
		wattrset(actionwin, getattrs(stdscr));
	}

	wmove(actionwin, 0, 0);
	wrefresh(actionwin);

	return actionwin;
}
Example #23
0
void
win_page_up(ProfWin *window)
{
    int rows = getmaxy(stdscr);
    int y = getcury(window->layout->win);
    int page_space = rows - 4;
    int *page_start = &(window->layout->y_pos);

    *page_start -= page_space;

    // went past beginning, show first page
    if (*page_start < 0)
        *page_start = 0;

    window->layout->paged = 1;
    win_update_virtual(window);

    // switch off page if last line and space line visible
    if ((y) - *page_start == page_space) {
        window->layout->paged = 0;
    }
}
Example #24
0
void
tui_puts (const char *string)
{
  static int tui_skip_line = -1;
  char c;
  WINDOW *w;

  w = TUI_CMD_WIN->generic.handle;
  while ((c = *string++) != 0)
    {
      /* Catch annotation and discard them.  We need two \032 and
         discard until a \n is seen.  */
      if (c == '\032')
        {
          tui_skip_line++;
        }
      else if (tui_skip_line != 1)
        {
          tui_skip_line = -1;
	  /* Expand TABs, since ncurses on MS-Windows doesn't.  */
	  if (c == '\t')
	    {
	      int col;

	      col = getcurx (w);
	      do
		{
		  waddch (w, ' ');
		  col++;
		} while ((col % 8) != 0);
	    }
	  else
	    waddch (w, c);
        }
      else if (c == '\n')
        tui_skip_line = -1;
    }
  TUI_CMD_WIN->detail.command_info.start_line = getcury (w);
}
Example #25
0
/*
 * Nuke the "curses" system
 */
static void Term_nuke_gcu(term *t)
{
   term_data *td = (term_data *)(t->data);

   /* Delete this window */
   delwin(td->win);

   /* Count nuke's, handle last */
   if (--active != 0) return;

   /* Hack -- make sure the cursor is visible */
   Term_xtra(TERM_XTRA_SHAPE, 1);

#ifdef A_COLOR
  /* Reset colors to defaults */
  start_color();
#endif

#ifdef SPECIAL_BSD
   /* This moves curses to bottom right corner */
   mvcur(curscr->cury, curscr->curx, LINES - 1, 0);
#else
   /* This moves curses to bottom right corner */
   mvcur(getcury(curscr), getcurx(curscr), LINES - 1, 0);
#endif

   /* Flush the curses buffer */
   (void)refresh();

   /* Exit curses */
   endwin();

   /* Flush the output */
   (void)fflush(stdout);

   /* Normal keymap */
   keymap_norm();
}
Example #26
0
/*#DOC*/
int view_moveCursor(View v, int dx, int dy)
{
	int w, h;
	if (NULL == v) return ERR;
	w = view_w(v);
	h = view_h(v);
	dx += getcurx(view_win(v));
	dy += getcury(view_win(v));
	while (dx < 0) {
		/* Si el destino x es negativo,
		** 'wrappeamos' al otro lado */
		dy -= 1;
		dx += w;
	}
	while (dx > w) {
		/* Igual para el lado derecho de la pantalla */
		dy += 1;
		dx -= w;
	}
	if (dy < 0) dy = 0;
	if (dy > h) dy = h;
	return wmove(view_win(v), dy, dx);
}
Example #27
0
void
win_sub_page_down(ProfWin *window)
{

    if (window->layout->type == LAYOUT_SPLIT) {
        int rows = getmaxy(stdscr);
        int page_space = rows - 4;
        ProfLayoutSplit *split_layout = (ProfLayoutSplit*)window->layout;
        int sub_y = getcury(split_layout->subwin);
        int *sub_y_pos = &(split_layout->sub_y_pos);

        *sub_y_pos += page_space;

        // only got half a screen, show full screen
        if ((sub_y- (*sub_y_pos)) < page_space)
            *sub_y_pos = sub_y - page_space;

        // went past end, show full screen
        else if (*sub_y_pos >= sub_y)
            *sub_y_pos = sub_y - page_space - 1;

        win_update_virtual(window);
    }
}
Example #28
0
/** This is edit mode
  * @param fileName file name example zxc.pac
  * @param authorName author information including name and email
  * address
  * @param mapDescription the description of map
  * @param rows number of rows
  * @param cols number of columns
  * @param mapArray the map
  */
void editMode(char * fileName, char * authorName, char * mapDescription, int * rows, int * cols, char * mapArray){
	int quit = 0;
	int * quitP = &quit;
	while(quit == 0){
		noecho();
		int c = getch();
		if (c == KEY_RIGHT) {
			move(getcury(stdscr), getcurx(stdscr) + 1);
		} else if (c == KEY_LEFT) {
			move(getcury(stdscr), getcurx(stdscr) - 1);
		} else if (c == KEY_UP) {
			move(getcury(stdscr) - 1, getcurx(stdscr));
		} else if (c == KEY_DOWN) {
			move(getcury(stdscr) + 1, getcurx(stdscr));
		}else if (c == ':') {
			(void)fullCommandMode(fileName, authorName,mapDescription, rows, cols, mapArray, quitP);
		}

		if(c == '\n'){
			move(getcury(stdscr) + 1, 0);
		}
		
		if(getcury(stdscr) > 4 && getcury(stdscr) <= 4 + rows[0] && getcurx(stdscr) < cols[0]){
			int currentRow;
			int currentCol;
			getyx(stdscr, currentRow, currentCol);
			currentRow = currentRow - 5;
			//	printw("rows: %d, col: %d \n",currentRow, currentCol );
			if (c == 'q' || c == 'Q') {
				mapArray[cols[0] * currentRow + currentCol] = 'q';
				addch(ACS_ULCORNER);
			} else if (c == 'w' || c == 'x') {
				mapArray[cols[0] * currentRow + currentCol] = 'w';
				addch(ACS_HLINE);
			} else if (c == 'e' || c == 'E') {
				mapArray[cols[0] * currentRow + currentCol] = 'e';
				addch(ACS_URCORNER);
			} else if (c == 'a' || c == 'd') {
				mapArray[cols[0] * currentRow + currentCol] = 'a';
				addch(ACS_VLINE);
			} else if (c == 'z' || c == 'Z') {
				mapArray[cols[0] * currentRow + currentCol] = 'z';
				addch(ACS_LLCORNER);
			} else if (c == 'c' || c == 'C') {
				mapArray[cols[0] * currentRow + currentCol] = 'c';
				addch(ACS_LRCORNER);
			} else if (c == 'W'){
				mapArray[cols[0] * currentRow + currentCol] = 'W';
				addch(ACS_TTEE);
			} else if (c == 'D'){
				mapArray[cols[0] * currentRow + currentCol] = 'D';
				addch(ACS_RTEE);
			} else if (c == 'X'){
				mapArray[cols[0] * currentRow + currentCol] = 'X';
				addch(ACS_BTEE);
			} else if(c == 'A'){
				mapArray[cols[0] * currentRow + currentCol] = 'A';
				addch(ACS_LTEE);
			} else if (c == 's') {
				mapArray[cols[0] * currentRow + currentCol] = 's';
				addch(ACS_BULLET);
			} else if (c == 'S') {
				mapArray[cols[0] * currentRow + currentCol] = 'S';
				addch(ACS_DIAMOND);
			} else if (c == 'g' || c == 'G') {
				mapArray[cols[0] * currentRow + currentCol] = 'g';
				addch(ACS_CKBOARD);
			} else if (c == 'p' || c == 'P') {
				mapArray[cols[0] * currentRow + currentCol] = 'p';
				addch(ACS_PI);
			} else if (c == 'f' || c == 'F') {
				mapArray[cols[0] * currentRow + currentCol] = 'f';
				addch(ACS_STERLING);
			} else if (c == ' ') {
				mapArray[cols[0] * currentRow + currentCol] = ' ';
				addch(' ');
			}
		}		
	}
}
Example #29
0
void WriteWords(struct words_info *words)
{
  unsigned char refresh, confirm, menu = 0, gotonext;
  unsigned char *input = NULL;
  unsigned int pos = 0, i, j, wrong;
  int key;
  struct words_p *p = words->p;
  if (words->order < 5)
    words->p = words->f;
  else
    words->order -= 10;
  do {
    p->tmp = 0; p = p->next;
  } while (p != words->p);
_restart:
  pos = 0; confirm = 0;
  free(input);
  input = calloc(sizeof(char), strlen(words->p->word) + 1);
  memset(input, ' ', strlen(words->p->word));
  curs_set(1);
_refresh:
  refresh = 1;
  clear();
  border('|', '|', '-', '-', '+', '+', '+', '+');
  _mvchgrectat(1, 1, getmaxy(stdscr) - 2, getmaxx(stdscr) - 2, 0, clr_wbkg, NULL);
  attron(COLOR_PAIR(clr_wttl)/* | A_BOLD*/);
  mvaddstr(1, (getmaxx(stdscr) - 16) / 2, "Words - 记默模式");
  attroff(COLOR_PAIR(clr_wttl)/* | A_BOLD*/);
  j = (getmaxy(stdscr) - 5) / 3;
  attron(COLOR_PAIR(clr_wmn));
  mvaddstr(2 + j, 4, words->p->mean);
  attroff(COLOR_PAIR(clr_wmn));
  move(getmaxy(stdscr) - j - 2, 4);
_input:
  move(getcury(stdscr), 4);
  for (i = 0, wrong = 0; i < strlen(words->p->word); i++)
    if (*(input + i) != *(words->p->word + i))
      wrong++, addch(*(input + i) | COLOR_PAIR(clr_winw) | A_BOLD);
    else
      addch(*(input + i) | COLOR_PAIR(clr_winr) | A_BOLD);
  if (!wrong)
    if (!refresh) goto _refresh; else goto _next;
  else if (confirm) goto _next;
  if (menu) {
    i = (getmaxx(stdscr) - 32) / 4;
    attron(COLOR_PAIR(menu == 1 ? clr_wmcu : clr_wmop) | A_BOLD);
    mvaddstr(2 + (getmaxy(stdscr) - 3) / 2, 1 + (getmaxx(stdscr) - 2 * i - 32) / 2, "[上一单词]");
    attroff(COLOR_PAIR(menu == 1 ? clr_wmcu : clr_wmop));
    attron(COLOR_PAIR(menu == 2 ? clr_wmcu : clr_wmop));
    mvaddstr(getcury(stdscr), getcurx(stdscr) + i, "[提示字母]");
    attroff(COLOR_PAIR(menu == 2 ? clr_wmcu : clr_wmop));
    attron(COLOR_PAIR(menu == 3 ? clr_wmcu : clr_wmop));
    mvaddstr(getcury(stdscr), getcurx(stdscr) + i, "[下一单词]");
    attroff(COLOR_PAIR(menu == 3 ? clr_wmcu : clr_wmop) | A_BOLD);
  }
  move(getmaxy(stdscr) - j - 2, 4 + pos);
  refresh();
  refresh = 0;
_getch:
  key = getch();
  if (menu)
    switch (key) {
    case KEY_LEFT:
      menu -= menu != 1;
      goto _refresh;
    case KEY_RIGHT:
      menu += menu != 3;
      goto _refresh;
    case KEY_DOWN:
    case 033:
      menu = 0;
    case KEY_RESIZE:
      goto _refresh;
    case '\n':
      switch (menu) {
      case 1:
        menu = 0; gotonext = 0;
        goto _goto;
      case 2:
        *(input + pos) = *(words->p->word + pos);
        pos += pos + 1 != strlen(words->p->word);
        goto _input;
      case 3:
        menu = 0; gotonext = 1;
        goto _goto;
      }
    default:
      goto _getch;
    }
  switch (key) {
  case KEY_RIGHT:
    pos += pos + 1 != strlen(words->p->word);
    goto _input;
  case KEY_UP:
    menu = 2;
    goto _refresh;
  case KEY_DOWN:
    goto _restart;
  case 033:
    curs_set(0);
    return;
  case '\t':
    *(input + pos) = *(words->p->word + pos);
    pos += pos + 1 != strlen(words->p->word);
    goto _input;
  case '\n':
    confirm = 1;
  case KEY_RESIZE:
    goto _refresh;
  case KEY_DC:
  case KEY_BACKSPACE:
  case 127:
    //*(input + pos/* - 1*/) = ' ';
  case KEY_LEFT:
    pos -= pos != 0;
    goto _input;
  default:
    if (key < 0 || key > 127) goto _getch;
    *(input + pos) = (char)key;
    if (pos + 1 < strlen(words->p->word))
      pos++;
    goto _input;
  };
_next:
  menu = 0;
  curs_set(0);
  attron(COLOR_PAIR(clr_wmsg) | A_BOLD);
  if (!wrong)
    mvaddstr(getmaxy(stdscr) - 2, (getmaxx(stdscr) - 29) / 2, "正确! 按任意键继续下一单词...");
  else
    mvaddstr(getmaxy(stdscr) - 2, (getmaxx(stdscr) - 35) / 2, "错误! [输入]下一单词/[返回]继续输入");
  attroff(COLOR_PAIR(clr_wmsg) | A_BOLD);
  refresh();
_getkey:
  switch (getch()) {
  case 033:
    if (wrong) {
      confirm = 0;
      curs_set(1);
      goto _refresh;
    } else break;
  case KEY_RESIZE:
    goto _refresh;
  case -1:
    goto _getkey;
  case '\n':
    if (wrong) break;
  default:
    if (wrong) goto _getkey;
  }
  if (words->order == 1)
    words->p = words->p->next;
  else if (words->order == -1)
    words->p = words->p->prev;
  if (words->p != words->f)
    goto _restart;
  free(input);
  return;
_goto:
  if (words->order == 1)
    words->p = (gotonext ? words->p->next : words->p->prev);
  else if (words->order == -1)
    words->p = (gotonext ? words->p->prev : words->p->next);
  if (gotonext) {
    if (words->p == words->f)
      words->p = words->f->prev;
  } else {
    if (words->p == words->f->prev)
      words->p = words->f;
  }
  goto _restart;
}
Example #30
0
/*
 * Display a temporary window listing the keystroke-commands we recognize.
 */
void
help_edit_field(void)
{
    int x0 = 4;
    int y0 = 2;
    int y1 = 0;
    int y2 = 0;
    int wide = COLS - ((x0 + 1) * 2);
    int high = LINES - ((y0 + 1) * 2);
    WINDOW *help = newwin(high, wide, y0, x0);
    WINDOW *data = newpad(2 + SIZEOF(commands), wide - 4);
    unsigned n;
    int ch = ERR;

    begin_popup();

    keypad(help, TRUE);
    keypad(data, TRUE);
    waddstr(data, "Defined form edit/traversal keys:\n");
    for (n = 0; n < SIZEOF(commands); ++n) {
	const char *name;
#ifdef NCURSES_VERSION
	if ((name = form_request_name(commands[n].result)) == 0)
#endif
	    name = commands[n].help;
	wprintw(data, "%s -- %s\n",
		keyname(commands[n].code),
		name != 0 ? name : commands[n].help);
    }
    waddstr(data, "Arrow keys move within a field as you would expect.");
    y2 = getcury(data);

    do {
	switch (ch) {
	case KEY_HOME:
	    y1 = 0;
	    break;
	case KEY_END:
	    y1 = y2;
	    break;
	case KEY_PREVIOUS:
	case KEY_PPAGE:
	    if (y1 > 0) {
		y1 -= high / 2;
		if (y1 < 0)
		    y1 = 0;
	    } else {
		beep();
	    }
	    break;
	case KEY_NEXT:
	case KEY_NPAGE:
	    if (y1 < y2) {
		y1 += high / 2;
		if (y1 >= y2)
		    y1 = y2;
	    } else {
		beep();
	    }
	    break;
	case CTRL('P'):
	case KEY_UP:
	    if (y1 > 0)
		--y1;
	    else
		beep();
	    break;
	case CTRL('N'):
	case KEY_DOWN:
	    if (y1 < y2)
		++y1;
	    else
		beep();
	    break;
	default:
	    beep();
	    break;
	case ERR:
	    break;
	}
	werase(help);
	box(help, 0, 0);
	wnoutrefresh(help);
	pnoutrefresh(data, y1, 0, y0 + 1, x0 + 1, high, wide);
	doupdate();
    } while ((ch = wgetch(data)) != ERR && ch != QUIT && ch != ESCAPE);
    werase(help);
    wrefresh(help);
    delwin(help);
    delwin(data);

    end_popup();
}