static bool save_window_vline(FILE *file, WINDOW *left, WINDOW *right, int y, char *buf, size_t bufsize) { int read1 = mvwinnstr(left, y, 0, buf, bufsize); int read2 = read1 == ERR ? ERR : mvwinnstr(right, y, 0, buf + read1 + 1, bufsize - read1 - 1); if (read2 == ERR) return false; buf[read1] = '|'; return fprintf(file, "%s\n", buf) == read1 + 1 + read2 + 1; }
static bool save_window_line(FILE *file, WINDOW *win, int y, char *buf, size_t bufsize) { int read = mvwinnstr(win, y, 0, buf, bufsize); return read == ERR ? false : fprintf(file, "%s\n", buf) == read + 1; }
static void draw_view_line_search_result(struct view *view, unsigned int lineno) { size_t bufsize = view->width * 4; char *buf = malloc(bufsize); regmatch_t pmatch[1]; regoff_t bufpos = 0; if (!buf || mvwinnstr(view->win, lineno, 0, buf, bufsize) == ERR) { free(buf); return; } while (bufpos < bufsize && !regexec(view->regex, buf + bufpos, ARRAY_SIZE(pmatch), pmatch, 0)) { regoff_t start = pmatch[0].rm_so; regoff_t end = pmatch[0].rm_eo; if (start == -1 || end <= 0 || end <= start) continue; mvwchgat(view->win, lineno, utf8_width_of(buf, bufpos + start, -1), utf8_width_of(buf + bufpos + start, end - start, -1), get_view_attr(view, LINE_SEARCH_RESULT), get_view_color(view, LINE_SEARCH_RESULT), NULL); bufpos += end; } free(buf); }
double NWindowEditDegrees::getValueDouble () { char buf[200]; char *endptr; mvwinnstr (getWriteWindow (), 0, 0, buf, 199); char *p = buf; double tval = 0; while (*p != '\0') { double v = strtod (p, &endptr); switch (*endptr) { case 'd': case '\0': case ' ': tval += v; break; case 'm': case '\'': tval += v / 60.0; break; case 's': case '"': tval += v / 3600.0; break; default: return tval; } p = endptr; if (*p != '\0') p++; } return tval; }
static void draw_view_line_search_result(struct view *view, unsigned int lineno) { size_t bufsize = view->width * 4; char *buf = malloc(bufsize); regmatch_t pmatch[1]; int i; if (!buf || mvwinnstr(view->win, lineno, 0, buf, bufsize) == ERR || regexec(view->regex, buf, ARRAY_SIZE(pmatch), pmatch, 0)) { free(buf); return; } for (i = 0; i < ARRAY_SIZE(pmatch); i++) { regoff_t start = pmatch[i].rm_so; if (start == -1) continue; mvwchgat(view->win, lineno, utf8_width_of(buf, start, -1), utf8_width_of(buf + start, pmatch[i].rm_eo - start, -1), get_view_attr(view, LINE_SEARCH_RESULT), get_view_color(view, LINE_SEARCH_RESULT), NULL); } free(buf); }
static bool save_window_line(FILE *file, WINDOW *win, int y, char *buf, size_t bufsize) { int read = mvwinnstr(win, y, 0, buf, bufsize); const char *out = read == ERR ? "" : string_trim_end(buf); return read == ERR ? false : fprintf(file, "%s\n", out) == strlen(out) + 1; }
bool NWindowEditBool::getValueBool () { char buf[200]; mvwinnstr (getWriteWindow (), 0, 0, buf, 199); if (dt & RTS2_DT_ONOFF) return strncasecmp (buf, "on", 2) ? false : true; else return strncasecmp (buf, "true", 4) ? false : true; }
double NWindowEditDigits::getValueDouble () { char buf[200]; char *endptr; mvwinnstr (getWriteWindow (), 0, 0, buf, 199); double tval = strtod (buf, &endptr); if (*endptr != '\0' && *endptr != ' ') { // log error; return 0; } return tval; }
int NWindowEditIntegers::getValueInteger () { char buf[200]; char *endptr; mvwinnstr (getWriteWindow (), 0, 0, buf, 199); int tval = strtol (buf, &endptr, hex ? 0 : 10); if (*endptr != '\0' && *endptr != ' ') { // log error; return 0; } return tval; }
char *get_user_input(ui_t *ui) { char *msg = malloc(MAX_BUFF); int msg_len = 0, c, px, py; wmove(ui->prompt, 1, 4); wrefresh(ui->prompt); while (c = getch()) switch (c) { case KEY_MOUSE: mvwinnstr(ui->prompt, 1, 4, msg, msg_len); process_mouse_events(ui); show_prompt(ui, msg); break; case KEY_BACKSPACE: if (msg_len > 0) { getyx(ui->prompt, py, px); if (px >= 4) { mvwdelch(ui->prompt, py, px-1); msg_len--; wrefresh(ui->prompt); } } break; case '\n': mvwinnstr(ui->prompt, 1, 4, msg, msg_len); show_prompt(ui, NULL); return msg; default: getyx(ui->prompt, py, px); mvwaddch(ui->prompt, py, px, c); msg_len++; wrefresh(ui->prompt); break; } }
std::string CursedWindow::getContents() { //std::stringstream s; int read; std::string str; const char* tempC; // point the constant char at the buffer tempC = content; // remember where we are in the curses window getyx(contentWindow, cursorY, cursorX); // read from the window into the char buffer read = mvwinnstr(contentWindow, 0, 0, content, 1024); // copy from the char buffer into the string str.reserve(read); str.assign(tempC, read); //return contents.str(); wmove(contentWindow, cursorY, cursorX); return str; }
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); }
static void outputTest(WINDOW *win) { WINDOW *win1; char Buffer[80]; chtype ch; int by, bx; #if !HAVE_TIGETSTR #if HAVE_TGETENT char tc_buffer[4096]; char tc_parsed[4096]; char *area_pointer = tc_parsed; tgetent(tc_buffer, getenv("TERM")); #else #define tgetstr(a,b) 0 #endif #endif /* !HAVE_TIGETSTR */ nl(); wclear(win); MvWAddStr(win, 1, 1, "You should now have a screen in the upper left corner, and this text should have wrapped"); mvwin(win, 2, 1); 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, (chtype) COLOR_PAIR(3)); } else wbkgd(win1, A_NORMAL); #else wbkgd(win1, A_NORMAL); #endif wclear(win1); MvWAddStr(win1, 5, 1, "This text should appear; using overlay option"); copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE); #if defined(PDCURSES) && !defined(XCURSES) box(win1, 0xb3, 0xc4); #else box(win1, ACS_VLINE, ACS_HLINE); #endif 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); wdeleteln(win); 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); #if HAVE_WINSSTR (void) mvwinsstr(win, 6, 2, "A1B2C3D4E5"); Continue(win); #endif wmove(win, 5, 1); winsertln(win); 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); noraw(); echo(); *Buffer = 0; wscanw(win, "%s", Buffer); printw("This is a formatted string in stdscr: %d %s\n", 42, "is it"); MvAddStr(10, 1, "Enter a string: "); *Buffer = 0; scanw("%s", Buffer); if (TIGETSTR("cvvis", "vs") != 0) { wclear(win); curs_set(2); MvWAddStr(win, 1, 1, "The cursor should appear as a block (visible)"); Continue(win); } if (TIGETSTR("civis", "vi") != 0) { wclear(win); curs_set(0); MvWAddStr(win, 1, 1, "The cursor should have disappeared (invisible)"); Continue(win); } if (TIGETSTR("cnorm", "ve") != 0) { wclear(win); curs_set(1); MvWAddStr(win, 1, 1, "The cursor should be an underline (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); #if HAVE_TERMNAME 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 supports blinking."); else MvWAddStr(win, 5, 1, "This terminal does NOT support blinking."); #endif (void) mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16); wrefresh(win); (void) mvwinnstr(win, 7, 5, Buffer, 18); MvAddStr(LINES - 2, 10, Buffer); refresh(); Continue(win); }
int mvinnstr(int y, int x, char *str, int n) { return mvwinnstr(stdscr, y, x, str, n); }