void win_refresh_without_subwin(ProfWin *window) { int cols = getmaxx(stdscr); if ((window->type == WIN_MUC) || (window->type == WIN_CONSOLE)) { int row_start = screen_mainwin_row_start(); int row_end = screen_mainwin_row_end(); pnoutrefresh(window->layout->win, window->layout->y_pos, 0, row_start, 0, row_end, cols-1); } }
static void curses_update(DisplayState *ds, int x, int y, int w, int h) { chtype *line; line = ((chtype *) screen) + y * width; for (h += y; y < h; y ++, line += width) mvwaddchnstr(screenpad, y, 0, line, width); pnoutrefresh(screenpad, py, px, sminy, sminx, smaxy - 1, smaxx - 1); refresh(); }
/* * Update newscr with the given pad then display to the terminal. */ int prefresh(WINDOW *w, int pminr, int pminc, int sminr, int sminc, int smaxr, int smaxc) { int code; code = pnoutrefresh(w, pminr, pminc, sminr, sminc, smaxr, smaxc); if (code == OK) code = doupdate(); return (code); }
/* Updates the Appointment panel */ void apoint_update_panel (int which_pan) { int title_xpos; int bordr = 1; int title_lines = 3; int app_width = win[APP].w - bordr; int app_length = win[APP].h - bordr - title_lines; long date; struct date slctd_date; /* variable inits */ slctd_date = *calendar_get_slctd_day (); title_xpos = win[APP].w - (strlen (_(monthnames[slctd_date.mm - 1])) + 16); if (slctd_date.dd < 10) title_xpos++; date = date2sec (slctd_date, 0, 0); day_write_pad (date, app_width, app_length, hilt); /* Print current date in the top right window corner. */ erase_window_part (win[APP].p, 1, title_lines, win[APP].w - 2, win[APP].h - 2); custom_apply_attr (win[APP].p, ATTR_HIGHEST); mvwprintw (win[APP].p, title_lines, title_xpos, "%s %s %d, %d", calendar_get_pom (date), _(monthnames[slctd_date.mm - 1]), slctd_date.dd, slctd_date.yyyy); custom_remove_attr (win[APP].p, ATTR_HIGHEST); /* Draw the scrollbar if necessary. */ if ((apad.length >= app_length) || (apad.first_onscreen > 0)) { float ratio = ((float) app_length) / ((float) apad.length); int sbar_length = (int) (ratio * app_length); int highend = (int) (ratio * apad.first_onscreen); unsigned hilt_bar = (which_pan == APP) ? 1 : 0; int sbar_top = highend + title_lines + 1; if ((sbar_top + sbar_length) > win[APP].h - 1) sbar_length = win[APP].h - 1 - sbar_top; draw_scrollbar (win[APP].p, sbar_top, win[APP].w - 2, sbar_length, title_lines + 1, win[APP].h - 1, hilt_bar); } wnoutrefresh (win[APP].p); pnoutrefresh (apad.ptrwin, apad.first_onscreen, 0, win[APP].y + title_lines + 1, win[APP].x + bordr, win[APP].y + win[APP].h - 2 * bordr, win[APP].x + win[APP].w - 3 * bordr); }
void win_update_virtual(ProfWin *window) { int rows, cols; getmaxyx(stdscr, rows, cols); if (window->layout->type == LAYOUT_SPLIT) { ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout; if (layout->subwin) { int subwin_cols = 0; if (window->type == WIN_MUC) { subwin_cols = win_occpuants_cols(); } else { subwin_cols = win_roster_cols(); } pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 1, 0, rows-3, (cols-subwin_cols)-1); pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, 1, (cols-subwin_cols), rows-3, cols-1); } else { pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 1, 0, rows-3, cols-1); } } else { pnoutrefresh(window->layout->win, window->layout->y_pos, 0, 1, 0, rows-3, cols-1); } }
prefresh(WINDOW *win, int pminrow, int pmincol, int sminrow, int smincol, int smaxrow, int smaxcol) { T((T_CALLED("prefresh()"))); if (pnoutrefresh(win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol) != ERR && doupdate() != ERR) { returnCode(OK); } returnCode(ERR); }
/* ================== CON_Clear_f ================== */ void CON_Clear_f(void) { if (!curses_on) { CON_Clear_tty(); return; } // Clear the log and the window memset(logbuf, 0, sizeof(logbuf)); werase(logwin); pnoutrefresh(logwin, scrollline, 0, 2, 1, LOG_LINES + 1, LOG_COLS + 1); // Move the cursor back to the input field CON_UpdateCursor(); doupdate(); }
/* ================== CON_Print ================== */ void CON_Print(const char *msg) { int col; bool scroll = (lastline > scrollline && lastline <= scrollline + LOG_LINES); if (!curses_on) { CON_Print_tty(msg); return; } // Print the message in the log window CON_ColorPrint(logwin, msg, qtrue); getyx(logwin, lastline, col); if (col) { lastline++; } if (scroll) { scrollline = lastline - LOG_LINES; if (scrollline < 0) { scrollline = 0; } pnoutrefresh(logwin, scrollline, 0, 2, 1, LOG_LINES + 1, LOG_COLS + 1); } // Add the message to the log buffer if (insert + strlen(msg) >= logbuf + sizeof(logbuf)) { memmove(logbuf, logbuf + sizeof(logbuf) / 2, sizeof(logbuf) / 2); memset(logbuf + sizeof(logbuf) / 2, 0, sizeof(logbuf) / 2); insert -= sizeof(logbuf) / 2; } strcpy(insert, msg); insert += strlen(msg); // Update the scrollbar CON_DrawScrollBar(); // Move the cursor back to the input field CON_UpdateCursor(); doupdate(); }
prefresh(WINDOW *win, int pminrow, int pmincol, int sminrow, int smincol, int smaxrow, int smaxcol) { #if NCURSES_SP_FUNCS SCREEN *sp = _nc_screen_of(win); #endif T((T_CALLED("prefresh()"))); if (pnoutrefresh(win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol) != ERR && NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG) != ERR) { returnCode(OK); } returnCode(ERR); }
static void curses_update(DisplayChangeListener *dcl, int x, int y, int w, int h) { console_ch_t *line; chtype curses_line[width]; line = screen + y * width; for (h += y; y < h; y ++, line += width) { for (x = 0; x < width; x++) { chtype ch = line[x] & 0xff; chtype at = line[x] & ~0xff; if (vga_to_curses[ch]) { ch = vga_to_curses[ch]; } curses_line[x] = ch | at; } mvwaddchnstr(screenpad, y, 0, curses_line, width); } pnoutrefresh(screenpad, py, px, sminy, sminx, smaxy - 1, smaxx - 1); refresh(); }
void LYrefresh( void ) { if ( stdscr != LYwin ) { int y = -1, x = -1; if ( LYcols - ( LYShowScrollbar != 0 ) < x ) x = LYcols - ( LYShowScrollbar != 0 ); wmove( stdscr, y, x ); wnoutrefresh( stdscr ); pnoutrefresh( LYwin, 0, LYshiftWin, 0, 0, LYlines, LYscreenWidth( ) + -1 ); if ( my_subwindow ) { wtouchln( my_subwindow, 0, -1, 1 ); wnoutrefresh( my_subwindow ); } doupdate( ); } else { wrefresh( stdscr ); } return; }
/* Display a scrolling window. */ void wins_scrollwin_display (struct scrollwin *sw) { const int visible_lines = sw->win.h - sw->pad.y - 1; if (sw->total_lines > visible_lines) { float ratio = ((float) visible_lines) / ((float) sw->total_lines); int sbar_length = (int) (ratio * visible_lines); int highend = (int) (ratio * sw->first_visible_line); int sbar_top = highend + sw->pad.y + 1; if ((sbar_top + sbar_length) > sw->win.h - 1) sbar_length = sw->win.h - sbar_top; draw_scrollbar (sw->win.p, sbar_top, sw->win.w + sw->win.x - 2, sbar_length, sw->pad.y + 1, sw->win.h - 1, 1); } wmove (win[STA].p, 0, 0); wnoutrefresh (sw->win.p); pnoutrefresh (sw->pad.p, sw->first_visible_line, 0, sw->pad.y, sw->pad.x, sw->win.h - sw->pad.y + 1, sw->win.w - sw->win.x); wins_doupdate (); }
/* * 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(); }
/* * Display a temporary window, e.g., to display a help-message. */ void popup_msg(WINDOW *parent, const char *const *msg) { int x0 = 4; int y0 = 2; int y1 = 0; int y2 = 0; int wide = getmaxx(parent) - ((x0 + 1) * 2); int high = getmaxy(parent) - ((y0 + 1) * 2); WINDOW *help; WINDOW *data; int n; int width = 0; int length; int last_y; int ch = ERR; for (n = 0; msg[n] != 0; ++n) { int check = (int) strlen(msg[n]); if (width < check) width = check; } length = n; if ((help = newwin(high, wide, y0, x0)) == 0) return; if ((data = newpad(length + 1, width)) == 0) return; begin_popup(); keypad(data, TRUE); for (n = 0; n < length; ++n) { waddstr(data, msg[n]); if ((n + 1) < length) { waddch(data, '\n'); } } y2 = getcury(data); last_y = (y2 - (high - 3)); do { switch (ch) { case KEY_HOME: y1 = 0; break; case KEY_END: y1 = last_y; 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 < last_y) { y1 += high / 2; if (y1 > last_y) y1 = last_y; } else { beep(); } break; case CTRL('P'): case KEY_UP: if (y1 > 0) --y1; else beep(); break; case CTRL('N'): case KEY_DOWN: if (y1 < last_y) ++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(); }
/* ================== CON_Init Initialize the console in curses mode, fall back to tty mode on failure ================== */ void CON_Init(void) { int col; #ifndef _WIN32 // If the process is backgrounded (running non interactively) // then SIGTTIN or SIGTOU is emitted, if not caught, turns into a SIGSTP signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); #endif // Make sure we're on a tty if (isatty(STDIN_FILENO) != 1 || isatty(STDOUT_FILENO) != 1 || isatty(STDERR_FILENO) != 1) { CON_Init_tty(); return; } // Initialize curses and set up the root window if (!curses_on) { SCREEN *test = newterm(NULL, stdout, stdin); if (!test) { CON_Init_tty(); CON_Print_tty("Couldn't initialize curses, falling back to tty\n"); return; } endwin(); delscreen(test); initscr(); cbreak(); noecho(); nonl(); intrflush(stdscr, FALSE); nodelay(stdscr, TRUE); keypad(stdscr, TRUE); wnoutrefresh(stdscr); // Set up colors if (has_colors()) { use_default_colors(); start_color(); init_pair(1, COLOR_BLACK, -1); init_pair(2, COLOR_RED, -1); init_pair(3, COLOR_GREEN, -1); init_pair(4, COLOR_YELLOW, -1); init_pair(5, COLOR_BLUE, -1); init_pair(6, COLOR_CYAN, -1); init_pair(7, COLOR_MAGENTA, -1); init_pair(8, -1, -1); } } // Create the border borderwin = newwin(LOG_LINES + 2, LOG_COLS + 2, 1, 0); CON_SetColor(borderwin, 2); box(borderwin, 0, 0); wnoutrefresh(borderwin); // Create the log window logwin = newpad(MAX_LOG_LINES, LOG_COLS); scrollok(logwin, TRUE); idlok(logwin, TRUE); if (curses_on) CON_ColorPrint(logwin, logbuf, qtrue); getyx(logwin, lastline, col); if (col) lastline++; scrollline = lastline - LOG_LINES; if (scrollline < 0) scrollline = 0; pnoutrefresh(logwin, scrollline, 0, 2, 1, LOG_LINES + 1, LOG_COLS + 1); // Create the scroll bar scrollwin = newwin(LOG_LINES, 1, 2, COLS - 1); CON_DrawScrollBar(); CON_SetColor(stdscr, 3); mvaddch(1, COLS - 1, SCRLBAR_UP); mvaddch(LINES - 2, COLS - 1, SCRLBAR_DOWN); // Create the input field inputwin = newwin(1, COLS - Q_PrintStrlen(PROMPT) - 8, LINES - 1, Q_PrintStrlen(PROMPT) + 8); input_field.widthInChars = COLS - Q_PrintStrlen(PROMPT) - 9; if (curses_on) { if (input_field.cursor < input_field.scroll) input_field.scroll = input_field.cursor; else if (input_field.cursor >= input_field.scroll + input_field.widthInChars) input_field.scroll = input_field.cursor - input_field.widthInChars + 1; CON_ColorPrint(inputwin, input_field.buffer + input_field.scroll, qfalse); } CON_UpdateCursor(); wnoutrefresh(inputwin); // Create the clock clockwin = newwin(1, 8, LINES - 1, 0); CON_UpdateClock(); // Display the title and input prompt move(0, (COLS - Q_PrintStrlen(TITLE)) / 2); CON_ColorPrint(stdscr, TITLE, qtrue); move(LINES - 1, 8); CON_ColorPrint(stdscr, PROMPT, qtrue); wnoutrefresh(stdscr); doupdate(); #ifndef _WIN32 // Catch window resizes signal(SIGWINCH, (void *)CON_Resize); #endif curses_on = qtrue; }
/* ================== CON_Input ================== */ char *CON_Input(void) { int chr, num_chars = 0; static char text[MAX_EDIT_LINE]; static int lasttime = -1; if (!curses_on) return CON_Input_tty(); if (com_ansiColor->modified) { CON_Resize(); com_ansiColor->modified = qfalse; } if (Com_RealTime(NULL) != lasttime) { lasttime = Com_RealTime(NULL); CON_UpdateClock(); num_chars++; } while (1) { chr = getch(); num_chars++; // Special characters switch (chr) { case ERR: if (num_chars > 1) { werase(inputwin); if (input_field.cursor < input_field.scroll) { input_field.scroll = input_field.cursor - INPUT_SCROLL; if (input_field.scroll < 0) input_field.scroll = 0; } else if (input_field.cursor >= input_field.scroll + input_field.widthInChars) input_field.scroll = input_field.cursor - input_field.widthInChars + INPUT_SCROLL; CON_ColorPrint(inputwin, input_field.buffer + input_field.scroll, qfalse); #ifdef _WIN32 wrefresh(inputwin); // If this is not done the cursor moves strangely #else wnoutrefresh(inputwin); #endif CON_UpdateCursor(); doupdate(); } return NULL; case '\n': case '\r': case KEY_ENTER: if (!input_field.buffer[0]) continue; Hist_Add(input_field.buffer); strcpy(text, input_field.buffer); Field_Clear(&input_field); werase(inputwin); wnoutrefresh(inputwin); CON_UpdateCursor(); //doupdate(); Com_Printf(PROMPT "^7%s\n", text); return text; case '\t': case KEY_STAB: Field_AutoComplete(&input_field, PROMPT); input_field.cursor = strlen(input_field.buffer); continue; case '\f': CON_Resize(); continue; case KEY_LEFT: if (input_field.cursor > 0) input_field.cursor--; continue; case KEY_RIGHT: if (input_field.cursor < strlen(input_field.buffer)) input_field.cursor++; continue; case KEY_UP: Q_strncpyz(input_field.buffer, Hist_Prev(), sizeof(input_field.buffer)); input_field.cursor = strlen(input_field.buffer); continue; case KEY_DOWN: Q_strncpyz(input_field.buffer, Hist_Next(input_field.buffer), sizeof(input_field.buffer)); input_field.cursor = strlen(input_field.buffer); continue; case KEY_HOME: input_field.cursor = 0; continue; case KEY_END: input_field.cursor = strlen(input_field.buffer); continue; case KEY_NPAGE: if (lastline > scrollline + LOG_LINES) { scrollline += LOG_SCROLL; if (scrollline + LOG_LINES > lastline) scrollline = lastline - LOG_LINES; pnoutrefresh(logwin, scrollline, 0, 2, 1, LOG_LINES + 1, LOG_COLS + 1); CON_DrawScrollBar(); } continue; case KEY_PPAGE: if (scrollline > 0) { scrollline -= LOG_SCROLL; if (scrollline < 0) scrollline = 0; pnoutrefresh(logwin, scrollline, 0, 2, 1, LOG_LINES + 1, LOG_COLS + 1); CON_DrawScrollBar(); } continue; case '\b': case 127: case KEY_BACKSPACE: if (input_field.cursor <= 0) continue; input_field.cursor--; // Fall through case KEY_DC: if (input_field.cursor < strlen(input_field.buffer)) { memmove(input_field.buffer + input_field.cursor, input_field.buffer + input_field.cursor + 1, strlen(input_field.buffer) - input_field.cursor); } continue; } // Normal characters if (chr >= ' ' && chr < 256 && strlen(input_field.buffer) + 1 < sizeof(input_field.buffer)) { memmove(input_field.buffer + input_field.cursor + 1, input_field.buffer + input_field.cursor, strlen(input_field.buffer) - input_field.cursor); input_field.buffer[input_field.cursor] = chr; input_field.cursor++; } } }
static inline void srefresh(struct wdgt *w) { pnoutrefresh(CWND(w), w->vy, w->vx, w->y, w->x, w->ysize, w->xsize); }
WRAP_API int wrap_pnoutrefresh(WINDOW *win, int py, int px, int sy1, int sx1, int sy2, int sx2) { return pnoutrefresh(win, py, px, sy1, sx1, sy2, sx2); }