static void test_winsdelln(WINDOW *win) { STATUS st; int n; init_status(win, &st); do { (void) wattrset(win, st.attr | COLOR_PAIR(st.pair)); switch (st.ch) { case 'i': for (n = 0; n < st.count; ++n) winsertln(win); break; case 'd': for (n = 0; n < st.count; ++n) wdeleteln(win); break; case 'I': winsdelln(win, st.count); break; case 'D': winsdelln(win, -st.count); break; case 'f': fill_window(win); reshow_status(win, &st); break; case 'w': do_subwindow(win, &st, test_winsdelln); break; case 'q': return; default: update_status(win, &st); break; } } while ((st.ch = wgetch(win)) != ERR); }
void ncurses_backlog_display(window_t *w) { ncurses_window_t *n = w->priv_data; int y, n_rows, idx; backlog_line_t *bl; werase(n->window); if (n->backlog->len <= 0) return; calc_window_dimension(w); /* draw text */ if (n->index == EKG_NCURSES_BACKLOG_END) { /* display from end of backlog */ w->more = n->more_lines = n->cleared = 0; for (y = n->height, idx = n->backlog->len - 1; idx >= 0 && y > 0; idx--) { y -= ncurses_get_backlog_height(w, bl, idx); ncurses_backlog_display_line(w, y, bl); } if (y>0 && !(config_text_bottomalign && (!w->floating || config_text_bottomalign == 2))) { wmove(n->window, n->margin_top, 0); winsdelln(n->window, -y); } } else { /* display from line */ idx = n->index; for (y = - n->first_row; idx < n->backlog->len && y < n->height; idx++) { n_rows = ncurses_get_backlog_height(w, bl, idx); ncurses_backlog_display_line(w, y, bl); y += n_rows; } /* count 'more' */ if (n->more_lines && (n->backlog->len - idx < n->more_lines)) { n->more_lines = n->backlog->len - idx; if ((0 == n->more_lines) && (y >= n->height)) n->more_lines = 1; } if ((!n->cleared && (!(idx < n->backlog->len) && (y <= n->height))) || ( n->cleared && !(y < n->height))) { ncurses_backlog_seek_end(n); ncurses_backlog_display(w); } } }
static TACommandVerdict winsdelln_cmd(TAThread thread,TAInputStream stream) { WINDOW *win; int n; int res; win = readPointer(&stream); n = readInt(&stream); START_TARGET_OPERATION(thread); res = winsdelln(win,n); END_TARGET_OPERATION(thread); writeInt(thread, res); sendResponse(thread); return taDefaultVerdict; }
/* Scroll the given window up/down n lines. */ int wscrl(WINDOW *win, int n) { short curx, cury; bool savimmed, savsync; #ifdef DEBUG if (outf) if (win == stdscr) fprintf(outf, "scroll(stdscr, %d)\n", n); else if (win == curscr) fprintf(outf, "scroll(curscr, %d)\n", n); else fprintf(outf, "scroll(%x, %d)\n", win, n); #endif /* DEBUG */ if (!win->_scroll || (win->_flags & _ISPAD)) return (ERR); savimmed = win->_immed; savsync = win->_sync; win->_immed = win->_sync = FALSE; curx = win->_curx; cury = win->_cury; if (cury >= win->_tmarg && cury <= win->_bmarg) win->_cury = win->_tmarg; else win->_cury = 0; (void) winsdelln(win, -n); win->_curx = curx; win->_cury = cury; win->_sync = savsync; if (win->_sync) wsyncup(win); return ((win->_immed = savimmed) ? wrefresh(win) : OK); }
void tdu_interface_expand (int levels, int redraw) { node_s *n; long scrolllines; n = find_node_numbered(root_node, cursor_line); if (!n) return; scrolllines = expand_tree(n, levels); if (!scrolllines) return; if (!redraw && (levels > 1)) redraw = 1; if (redraw) { display_nodes(cursor_line - start_line, visible_lines - (cursor_line - start_line), root_node, cursor_line, cursor_line); tdu_interface_refresh(); } else { long maxlines = visible_lines - (cursor_line - start_line); if (scrolllines >= maxlines - 1) { display_nodes(cursor_line - start_line, visible_lines - (cursor_line - start_line), root_node, cursor_line, cursor_line); } else { tdu_interface_refresh(); winsdelln(main_window, scrolllines); display_nodes(cursor_line - start_line, scrolllines + 1, root_node, cursor_line, cursor_line); } tdu_interface_refresh(); } }
void tdu_interface_collapse (int redraw) { node_s *n; long scrolllines; n = find_node_numbered(root_node, cursor_line); if (!n) return; scrolllines = collapse_tree(n); if (!scrolllines) return; if (redraw) { display_nodes(cursor_line - start_line, visible_lines - (cursor_line - start_line), root_node, cursor_line, cursor_line); tdu_interface_refresh(); } else { long maxlines = visible_lines - (cursor_line - start_line); if (scrolllines >= maxlines - 1) { display_nodes(cursor_line - start_line, visible_lines - (cursor_line - start_line), root_node, cursor_line, cursor_line); } else { tdu_interface_refresh(); winsdelln(main_window, -scrolllines); display_nodes(cursor_line - start_line, 1, root_node, cursor_line, cursor_line); display_nodes(visible_lines - scrolllines, scrolllines, root_node, cursor_line + maxlines - scrolllines, cursor_line); } tdu_interface_refresh(); } }
/* * wscrl -- * Scroll a window n lines - up if n is positive, down if n is negative. */ int wscrl(WINDOW *win, int nlines) { int oy, ox; #ifdef DEBUG __CTRACE(__CTRACE_WINDOW, "wscrl: (%p) lines=%d\n", win, nlines); #endif if (!(win->flags & __SCROLLOK)) return (ERR); if (!nlines) return (OK); getyx(win, oy, ox); #ifdef DEBUG __CTRACE(__CTRACE_WINDOW, "wscrl: y=%d\n", oy); #endif if (oy < win->scr_t || oy > win->scr_b) /* Outside scrolling region */ wmove(win, 0, 0); else /* Inside scrolling region */ wmove(win, win->scr_t, 0); winsdelln(win, 0 - nlines); wmove(win, oy, ox); if (win == curscr) { __cputchar('\n'); if (!__NONL) win->curx = 0; #ifdef DEBUG __CTRACE(__CTRACE_WINDOW, "scroll: win == curscr\n"); #endif } return (OK); }
void outputTest(WINDOW *win) { WINDOW *win1; char Buffer[80]; chtype ch; int by, bx; nl(); wclear(win); mvwaddstr(win, 1, 1, "You should now have a screen in the upper " "left corner, and this text should have wrapped"); waddstr(win,"\nThis text should be down\n"); waddstr(win, "and broken into two here ^"); Continue(win); wclear(win); wattron(win, A_BOLD); mvwaddstr(win, 1, 1, "A new window will appear with this text in it"); mvwaddstr(win, 8, 1, "Press any key to continue"); wrefresh(win); wgetch(win); getbegyx(win, by, bx); if (LINES < 24 || COLS < 75) { mvwaddstr(win, 5, 1, "Some tests have been skipped as they require a"); mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS"); Continue(win); } else { win1 = newwin(10, 50, 14, 25); if (win1 == NULL) { endwin(); return; } #ifdef A_COLOR if (has_colors()) { init_pair(3, COLOR_BLUE, COLOR_WHITE); wbkgd(win1, COLOR_PAIR(3)); } else #endif wbkgd(win1, A_NORMAL); wclear(win1); mvwaddstr(win1, 5, 1, "This text should appear; using overlay option"); copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE); box(win1, ACS_VLINE, ACS_HLINE); wmove(win1, 8, 26); wrefresh(win1); wgetch(win1); wclear(win1); wattron(win1, A_BLINK); mvwaddstr(win1, 4, 1, "This blinking text should appear in only the second window"); wattroff(win1, A_BLINK); mvwin(win1, by, bx); overlay(win, win1); mvwin(win1, 14, 25); wmove(win1, 8, 26); wrefresh(win1); wgetch(win1); delwin(win1); } clear(); wclear(win); wrefresh(win); mvwaddstr(win, 6, 2, "This line shouldn't appear"); mvwaddstr(win, 4, 2, "Only half of the next line is visible"); mvwaddstr(win, 5, 2, "Only half of the next line is visible"); wmove(win, 6, 1); wclrtobot(win); wmove(win, 5, 20); wclrtoeol(win); mvwaddstr(win, 8, 2, "This line also shouldn't appear"); wmove(win, 8, 1); winsdelln(win, -1); Continue(win); wmove(win, 5, 9); ch = winch(win); wclear(win); wmove(win, 6, 2); waddstr(win, "The next char should be l: "); winsch(win, ch); Continue(win); mvwinsstr(win, 6, 2, "A1B2C3D4E5"); Continue(win); wmove(win, 5, 1); winsdelln(win, 1); mvwaddstr(win, 5, 2, "The lines below should have moved down"); Continue(win); wclear(win); wmove(win, 2, 2); wprintw(win, "This is a formatted string in a window: %d %s\n", 42, "is it"); mvwaddstr(win, 10, 1, "Enter a string: "); wrefresh(win); echo(); wscanw(win, "%s", Buffer); printw("This is a formatted string in stdscr: %d %s\n", 42, "is it"); mvaddstr(10, 1, "Enter a string: "); scanw("%s", Buffer); wclear(win); curs_set(2); mvwaddstr(win, 1, 1, "The cursor should be in high-visibility mode"); Continue(win); wclear(win); curs_set(0); mvwaddstr(win, 1, 1, "The cursor should have disappeared"); Continue(win); wclear(win); curs_set(1); mvwaddstr(win, 1, 1, "The cursor should be normal"); Continue(win); #ifdef A_COLOR if (has_colors()) { wclear(win); mvwaddstr(win, 1, 1, "Colors should change after you press a key"); Continue(win); init_pair(1, COLOR_RED, COLOR_WHITE); wrefresh(win); } #endif werase(win); mvwaddstr(win, 1, 1, "Information About Your Terminal"); mvwaddstr(win, 3, 1, termname()); mvwaddstr(win, 4, 1, longname()); if (termattrs() & A_BLINK) mvwaddstr(win, 5, 1, "This terminal claims to support blinking."); else mvwaddstr(win, 5, 1, "This terminal does NOT support blinking."); mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16); wrefresh(win); mvwinnstr(win, 7, 5, Buffer, 18); mvaddstr(LINES - 2, 10, Buffer); refresh(); Continue(win); }
NCURSES_EXPORT(int) (insertln) (void) { T((T_CALLED("insertln()"))); returnCode(winsdelln(stdscr,1)); }
int scrollback_do(int window_nr, buffer *pbuf, int *winnrs, char *header) { int rc = 0; char *find = NULL; char fullscreen = scrollback_fullscreen_default; NEWWIN *mywin1 = NULL, *mywin2 = NULL; int nlines, ncols; compute_text_dimensions(&nlines, &ncols, fullscreen); int offset = max(0, pbuf -> curpos - nlines); /* FIXME: aantal regels laten afhangen van lengte */ char redraw = 2; int line_offset = 0; char show_winnr = default_sb_showwinnr; mybool_t case_insensitive = re_case_insensitive; buffer cur_lb; int loop = 0; memset(&cur_lb, 0x00, sizeof(cur_lb)); for(loop=0; loop<pbuf -> curpos; loop++) { if ((pbuf -> be)[loop].Bline == NULL) continue; cur_lb.be = myrealloc(cur_lb.be, (cur_lb.curpos + 1) * sizeof(buffered_entry)); cur_lb.be[cur_lb.curpos].pi = (pbuf -> be)[loop].pi; if ((pbuf -> be)[loop].pi != NULL && (!IS_MARKERLINE((pbuf -> be)[loop].pi)) && (pbuf -> be)[loop].pi -> cdef.term_emul != TERM_IGNORE) { color_offset_in_line *cmatches; int n_cmatches; cur_lb.be[cur_lb.curpos].Bline = emulate_terminal((pbuf -> be)[loop].Bline, &cmatches, &n_cmatches); myfree(cmatches); } else cur_lb.be[cur_lb.curpos].Bline = strdup((pbuf -> be)[loop].Bline); cur_lb.be[cur_lb.curpos].ts = (pbuf -> be)[loop].ts; cur_lb.curpos++; } LOG("---\n"); if (global_highlight_str) { find = mystrdup(global_highlight_str); } create_scrollback_windows(&mywin1, &mywin2, nlines, ncols, fullscreen); for(;;) { int c, uc; if (redraw == 2) { int index = 0; int lines_used = 0; if (mywin1) { ui_inverse_on(mywin1); mvwprintw(mywin1 -> win, nlines + 1, 1, "%s - %d buffered lines", shorten_filename(header, max(24, ncols - 24)), cur_lb.curpos); ui_inverse_off(mywin1); if (!no_linewrap) ui_inverse_on(mywin1); mvwprintw(mywin1 -> win, nlines + 1, ncols - 8, "LINEWRAP"); if (!no_linewrap) ui_inverse_off(mywin1); } werase(mywin2 -> win); if (!no_linewrap && line_offset > 0) { int temp_line_offset = line_offset; int n_chars_to_display_left = strlen((cur_lb.be)[offset].Bline) - temp_line_offset; while(lines_used < nlines && n_chars_to_display_left > 0) { scrollback_displayline(winnrs?winnrs[offset]:window_nr, mywin2, &cur_lb, offset, lines_used, temp_line_offset, 1, show_winnr); temp_line_offset += ncols; n_chars_to_display_left -= ncols; lines_used++; } index++; } for(;(offset + index) < cur_lb.curpos && lines_used < nlines;) { int lines_needed = get_lines_needed((cur_lb.be)[offset + index].Bline, ncols); if (no_linewrap || lines_needed == 1) { scrollback_displayline(winnrs?winnrs[offset + index]:window_nr, mywin2, &cur_lb, offset + index, lines_used, no_linewrap?line_offset:0, no_linewrap, show_winnr); lines_used++; } else { int cur_line_offset = 0; while(lines_used < nlines && lines_needed > 0) { scrollback_displayline(winnrs?winnrs[offset + index]:window_nr, mywin2, &cur_lb, offset + index, lines_used, cur_line_offset, 1, show_winnr); cur_line_offset += ncols; lines_used++; lines_needed--; } } index++; } redraw = 1; } if (redraw == 1) { mydoupdate(); redraw = 0; } c = wait_for_keypress(HELP_SCROLLBACK_HELP, 0, NULL, 1); uc = toupper(c); if (c == 'q' || c == abort_key || c == KEY_CLOSE || c == KEY_EXIT) { break; } else if (c == 'Q' || c == -1) /* Q: close whole stack of scrollbackwindows, -1: something got closed */ { rc = -1; break; } else if (c == 20 && winnrs != NULL) /* ^t */ { show_winnr = 1 - show_winnr; redraw = 2; } else if (c == 'x') { send_to_clipboard(pbuf); } else if (c == 'Y') { no_linewrap = !no_linewrap; redraw = 2; line_offset = 0; } else if (c == KEY_F(9) || c == 23) /* ^w */ { fullscreen = ! fullscreen; compute_text_dimensions(&nlines, &ncols, fullscreen); create_scrollback_windows(&mywin1, &mywin2, nlines, ncols, fullscreen); redraw = 2; } else if (c == 't') { statistics_menu(); } else if ((c == KEY_LEFT || c == KEY_BACKSPACE) && no_linewrap) { if (line_offset > 0) line_offset--; redraw = 2; } else if (c == KEY_SLEFT && no_linewrap) { if (line_offset >= (ncols / 2)) line_offset -= (ncols / 2); else line_offset = 0; redraw = 2; } else if (c == KEY_SRIGHT && no_linewrap) { line_offset += (ncols / 2); redraw = 2; } else if (c == KEY_BEG && no_linewrap) { if (line_offset) { line_offset = 0; redraw = 2; } } else if (c == KEY_BTAB) { if (line_offset >= 4) line_offset -= 4; else line_offset = 0; redraw = 2; } else if (c == KEY_RIGHT && no_linewrap) { line_offset++; redraw = 2; } else if ((c == KEY_UP || c == 'y' || c == 25 || /* ^y */ c == 'k' || /* c == 11 || */ /* ^k */ c == 16) /* ^p */ && (offset > 0 || (!no_linewrap && line_offset > 0))) { if (no_linewrap) { offset--; } else if (line_offset > 0) { line_offset = max(0, line_offset - ncols); } else { offset--; line_offset = (get_lines_needed((cur_lb.be)[offset].Bline, ncols) - 1) * ncols; } wmove(mywin2 -> win, 0, 0); winsdelln(mywin2 -> win, 1); scrollback_displayline(winnrs?winnrs[offset]:window_nr, mywin2, &cur_lb, offset, 0, line_offset, no_linewrap, show_winnr); redraw = 1; } else if ((c == KEY_DOWN || c == 'e' || c == 5 || /* ^e */ c == 'j' || c == 14 || /* ^n */ c == 13 || c == KEY_ENTER) && offset < (cur_lb.curpos - 1)) { if (no_linewrap) { offset++; } else if (strlen((cur_lb.be)[offset].Bline) > (line_offset + ncols)) { line_offset += ncols; } else if (offset < (cur_lb.curpos - 1)) { if (strlen((cur_lb.be)[offset].Bline) > (line_offset + ncols)) line_offset += ncols; else { line_offset = 0; offset++; } } redraw = 2; } else if ((c == KEY_NPAGE || c == 'f' || c == 6 || /* ^f */ c == ('V' - 65 + 1) || /* ^v */ c == ' ' || c == 'z' || c == 'u' || c == ('U' - 65 + 1)) /* ^u */ && offset < (cur_lb.curpos - 1)) { if (no_linewrap) { offset += nlines; if (offset >= cur_lb.curpos) offset = cur_lb.curpos - 1; } else { int n_lines_to_move = nlines; while(n_lines_to_move > 0 && offset < (cur_lb.curpos)) { if (line_offset > 0) { if (line_offset + ncols >= strlen((cur_lb.be)[offset].Bline)) { line_offset = 0; offset++; n_lines_to_move--; } else { line_offset += ncols; n_lines_to_move--; } } else { n_lines_to_move -= get_lines_needed((cur_lb.be)[offset].Bline, ncols); offset++; } } if (n_lines_to_move < 0) line_offset = (-n_lines_to_move) * ncols; } redraw = 2; } else if ((c == KEY_PPAGE || c == 'b' || c == 2 || /* ^b */ c == 'w' || c == 'd' || c == 4) /* ^d */ && offset > 0) { if (no_linewrap) { offset -= nlines; if (offset < 0) offset = 0; } else { int n_lines_to_move = nlines; if (line_offset) n_lines_to_move -= line_offset / ncols; while(n_lines_to_move > 0 && offset > 0) { offset--; n_lines_to_move -= get_lines_needed((cur_lb.be)[offset].Bline, ncols); if (n_lines_to_move < 0) { line_offset = (get_lines_needed((cur_lb.be)[offset].Bline, ncols) + n_lines_to_move) * ncols; } } } redraw = 2; } else if ((c == KEY_HOME || c == 'g' || c == '<' || c == KEY_SBEG) && offset > 0) { line_offset = offset = 0; redraw = 2; } else if ((c == KEY_END || c == 'G' || c == '>' || c == KEY_SEND) && offset < (cur_lb. curpos - 1)) { offset = cur_lb. curpos - 1; redraw = 2; } else if (uc == 'R' || c == ('R' - 65 + 1) || c == ('L' - 65 + 1) || c == KEY_REFRESH) { redraw = 2; } else if (c == ('K' - 65 + 1) || c == KEY_MARK) { scrollback_find_popup(&find, &case_insensitive); if (find) { int rc; regfree(&global_highlight_re); myfree(global_highlight_str); global_highlight_str = NULL; if ((rc = regcomp(&global_highlight_re, find, (case_insensitive == MY_TRUE?REG_ICASE:0) | REG_EXTENDED))) { regexp_error_popup(rc, &global_highlight_re); myfree(find); } else { global_highlight_str = find; } redraw = 2; /* force redraw */ } } else if (c == 'f' || c == '/' || c == '?' || c == KEY_FIND || c == KEY_SFIND) { char direction = (c == '?' || c == KEY_SFIND) ? -1 : 1; scrollback_find_popup(&find, &case_insensitive); if (find) { if (scrollback_search_new_window) { if (scrollback_search_to_new_window(&cur_lb, header, find, case_insensitive) == -1) { /* cascaded close */ rc = -1; break; } } else { int new_f_index; redraw = 2; /* force redraw */ regfree(&global_highlight_re); myfree(global_highlight_str); global_highlight_str = NULL; new_f_index = find_string(&cur_lb, find, 0, direction, case_insensitive); if (new_f_index == -1) { wrong_key(); } else { offset = new_f_index; line_offset = 0; } } } } else if (uc == 'N' || c == KEY_NEXT || c == KEY_PREVIOUS || c == KEY_SNEXT) { if (find != NULL) { char direction = (c == 'n' || c == KEY_NEXT) ? 1 : -1; int start_offset = offset + direction; int new_f_index = find_string(&cur_lb, find, start_offset, direction, case_insensitive); if (new_f_index == -1) { wrong_key(); } else { redraw = 2; /* force redraw */ offset = new_f_index; line_offset = 0; } } else { wrong_key(); } } else if (c == 's' || c == KEY_SAVE) { scrollback_savefile(&cur_lb); redraw = 2; /* force redraw */ } else if (c == 'h') { show_help(HELP_SCROLLBACK_HELP); } else if (c == 'c') { toggle_colors(); redraw = 2; /* force redraw */ } else if (c == 'i') { info(); } else if (c == 'T') { statistics_menu(); } else if (c == 20) { toggle_subwindow_nr(); redraw = 2; /* force redraw */ } else { wrong_key(); } } delete_popup(mywin2); if (mywin1) delete_popup(mywin1); myfree(find); delete_be_in_buffer(&cur_lb); return rc; }
int sc_insertLines(int lines) { return (winsdelln(stdscr, lines) != ERR); }
int sc_deleteLines(int lines) { return (winsdelln(stdscr, -lines) != ERR); }
NCURSES_EXPORT(int) (winsertln) (WINDOW * z) { T((T_CALLED("winsertln(%p)"), (const void *)z)); returnCode(winsdelln(z,1)); }
int insdelln(int n) { PDC_LOG(("insdelln() - called\n")); return winsdelln(stdscr, n); }
NCURSES_EXPORT(int) (insdelln) (int z) { T((T_CALLED("insdelln(%d)"), z)); returnCode(winsdelln(stdscr,z)); }
int insertln(void) { return (winsdelln(stdscr, 1)); }
int winsertln(WINDOW *w) { return (winsdelln(w, 1)); }
int wdeleteln(WINDOW *w) { return (winsdelln(w, -1)); }
int insdelln(int n) { return (winsdelln(stdscr, n)); }
int deleteln(void) { return (winsdelln(stdscr, -1)); }
EIF_INTEGER c_ecurses_winsdelln(EIF_POINTER w, EIF_INTEGER n) { return winsdelln ( ((WINDOW *) w), (int) n) ; };
NCURSES_EXPORT(int) (deleteln) (void) { T((T_CALLED("deleteln()"))); returnCode(winsdelln(stdscr,-1)); }