void eingabe_loesch_anzeigen(void) { char vname[25], nname[25], bestaetigung[2]; curs_set(1); wclear(seingabe); mvwaddstr(seingabe, 2, 2, "* Eintrag löschen"); mvwaddstr(seingabe, 2+2, 2, "- Vorname: "); wrefresh(seingabe); wgetnstr(seingabe, vname, 24); mvwaddstr(seingabe, 2+3, 2, "- Nachname: "); wrefresh(seingabe); wgetnstr(seingabe, nname, 24); mvwaddstr(seingabe, 2+4, 2, "- Wirklich löschen? "); wrefresh(seingabe); wgetnstr(seingabe, bestaetigung, 1); if (strcasecmp("j", bestaetigung) == 0) { snprintf( aenderungs_eintrag.vname, sizeof(aenderungs_eintrag.vname), "%s", vname ); snprintf( aenderungs_eintrag.nname, sizeof(aenderungs_eintrag.nname), "%s", nname ); } curs_set(0); }
void eingabe_hinzuf_anzeigen(void) { char vname[25], nname[25], tag[3], monat[3], jahr[5]; curs_set(1); wclear(seingabe); mvwaddstr(seingabe, 2, 2, "* Eintrag hinzufügen"); mvwaddstr(seingabe, 2+2, 2, "+ Vorname: "); wrefresh(seingabe); wgetnstr(seingabe, vname, 24); mvwaddstr(seingabe, 2+3, 2, "+ Nachname: "); wrefresh(seingabe); wgetnstr(seingabe, nname, 24); mvwaddstr(seingabe, 2+4, 2, "+ Datum: - - "); mvwgetnstr(seingabe, 2+4, 11, tag, 2); mvwgetnstr(seingabe, 2+4, 14, monat, 2); mvwgetnstr(seingabe, 2+4, 17, jahr, 4); if (strlen(vname) > 0 && strlen(nname) > 0 && strlen(tag) > 0 && strlen(monat) > 0 && strlen(jahr) > 0) { strcpy(aenderungs_eintrag.vname, vname); strcpy(aenderungs_eintrag.nname, nname); aenderungs_eintrag.sdatum.tag = atoi(tag); aenderungs_eintrag.sdatum.monat = atoi(monat); aenderungs_eintrag.sdatum.jahr = atoi(jahr); } curs_set(0); }
void display_input_add_event(int is_single) { char text[PHRASES_CHARS_LENGTH], day[3], month[3], year[5], hour[3], minute[3], repeat_cycle[5]; curs_set(1); wclear(wsinput); if (is_single == 1) { mvwaddstr(wsinput, 0, 0, "* "); waddstr(wsinput, phrases_data.input_single_event); } else { mvwaddstr(wsinput, 0, 0, "* "); waddstr(wsinput, phrases_data.input_repeating_event); } mvwaddstr(wsinput, 2, 0, "+ "); waddstr(wsinput, phrases_data.input_text); waddstr(wsinput, ": "); wrefresh(wsinput); wgetnstr(wsinput, text, PHRASES_CHARS_LENGTH-1); mvwaddstr(wsinput, 4, 0, "+ "); waddstr(wsinput, phrases_data.input_date); waddstr(wsinput, ": - - "); mvwgetnstr(wsinput, 4, strlen(phrases_data.input_date)+4, day, 2); mvwgetnstr(wsinput, 4, strlen(phrases_data.input_date)+7, month, 2); mvwgetnstr(wsinput, 4, strlen(phrases_data.input_date)+10, year, 4); mvwaddstr(wsinput, 5, 0, "+ "); waddstr(wsinput, phrases_data.input_time); waddstr(wsinput, ": - "); mvwgetnstr(wsinput, 5, strlen(phrases_data.input_time)+4, hour, 2); mvwgetnstr(wsinput, 5, strlen(phrases_data.input_time)+7, minute, 2); if (is_single == 0) { mvwaddstr(wsinput, 7, 0, "+ "); waddstr(wsinput, phrases_data.input_repeat_cycle); waddstr(wsinput, ": "); wgetnstr(wsinput, repeat_cycle, 4); } if (strlen(text) > 0 && strlen(day) > 0 && strlen(month) > 0 && strlen(year) > 0) { strcpy(entry_to_change.text, text); entry_to_change.date.day = atoi(day); entry_to_change.date.month = atoi(month); entry_to_change.date.year = atoi(year); entry_to_change.time.hour = atoi(hour); entry_to_change.time.minute = atoi(minute); entry_to_change.is_birthday = 0; entry_to_change.repeat_cycle = atoi(repeat_cycle); } curs_set(0); }
void login_ncurses::input_account(char *account) { WINDOW *login_win = NULL; int row = 0, col = 0; setlocale(LC_ALL,""); // must before the first init initscr(); cbreak(); int height = 6; int width = 30; int starty = (LINES - height) / 2; int startx = (COLS - width) / 2; refresh(); login_win = create_newwin(height, width, starty, startx); getmaxyx(login_win, row, col); mvwprintw(login_win, row/2, (col - 9 - 16)/2, "account: "); wrefresh(login_win); wattron(login_win, A_BOLD); wgetnstr(login_win, account, 31); wattroff(login_win, A_BOLD); destroy_win(login_win); refresh(); endwin(); }
static int popup_window(char const *message, int original_value, bool ignore) { int message_width = MESSAGE_WIDTH + (int) strlen(message); int ret = 0; char string[7] = {0}; char *end = NULL; WINDOW *popup = newwin(MESSAGE_HEIGHT, message_width, (LINES - MESSAGE_HEIGHT) / 2, (COLS - message_width) / 2); box(popup, 0, 0); echo(); mvwaddstr(popup, 2, 1, message); if (ignore) { wgetch(popup); } else { wgetnstr(popup, string, 6); string[6] = '\0'; ret = (int) strtol(string, &end, 16); if (*end || !strlen(string)) { ret = original_value; } } noecho(); delwin(popup); return ret; }
void window::get_str_from_win(WINDOW* _win,string& _out) { char buf[1024]; memset(buf,'\0',sizeof(buf)); wgetnstr(_win,buf,sizeof(buf)); _out = buf; }
/* * Get a string from the user. This is a fancy version which will size * the maximum length of the line based on the amount of space remaining * on the current line in the ncurses window. */ value caml_curses_wgetstr(value mlwindow) { CAMLparam1(mlwindow); CAMLlocal1(result); WINDOW *window = window_of_ml(mlwindow); char *buffer = NULL; int cury, curx; int maxy, maxx; int len; /* Get the window extents to determine a line length */ getyx(window, cury, curx); getmaxyx(window, maxy, maxx); len = maxx - curx - 1; /* Allocate a buffer to store the results in. */ buffer = malloc(len + 1); if(buffer == NULL) { CAMLreturn(copy_string("")); } /* Get the line input */ wgetnstr(window, buffer, len); /* Return the character read */ result = copy_string(buffer); free(buffer); CAMLreturn(result); }
int bwx_input( char *prompt, char *buffer ) { int y,x,my,mx; #if INTENSIVE_DEBUG prn_xprintf( stdout, "<INP>" ); #endif prn_xprintf( stdout, prompt ); getyx(stdscr,y,x); echo(); wgetnstr(stdscr, buffer, MAXREADLINESIZE); noecho(); getmaxyx(stdscr,my,mx); /* printf("%d %d",my,mx);*/ if(y+1==my)scroll(stdscr); /* So this is an extreeeeemely ugly kludge to work around some bug/feature/wart in ncurses FIXME I should replace it with getch/addch in a loop */ /* prn_xprintf( stdout, "\n" );*/ /* let _outtext catch up */ * prn_getcol( stdout ) = 1; /* reset column */ return TRUE; }
char *cgetlnq(char strg[], int n) { int i; if (initialized==0) init_lconio(); if (n > 253) n = 253; curs_set(1); timeout(-1); echo(); wgetnstr(conio_scr,strg,n); noecho(); timeout(0); curs_set(0); cprintf("\n\r"); for (i=0; i<n; i++) { if ((strg[i] == '\n') || (strg[i] == 0)) { strg[i] = 0; break; } } strg[n] = 0; return strg; }
void cgets(char *s, int maxsize) { if (!initialized) initconio(); echo(); wgetnstr(win, s, maxsize); noecho(); }
void login_ncurses::input_name(char *name) { WINDOW *login_win = NULL; int row = 0, col = 0; initscr(); /* Start curses mode */ cbreak(); int height = 6; int width = 30; int starty = (LINES - height) / 2; int startx = (COLS - width) / 2; refresh(); login_win = create_newwin(height, width, starty, startx); getmaxyx(login_win, row, col); mvwprintw(login_win, row/2, (col - 9 - 16)/2, "new player name: "); wrefresh(login_win); wattron(login_win, A_BOLD); wgetnstr(login_win, name, sizeof(name) - 1); wattroff(login_win, A_BOLD); destroy_win(login_win); refresh(); endwin(); }
void chat_window::get_str_to_win(WINDOW *_win, std::string &_msg) { char buf[BUF_SIZE]; memset(buf, '\0', sizeof(buf)); wgetnstr(_win, buf, sizeof(buf)); _msg = buf; }
std::string CursesInput::prompt(const std::string & text, unsigned int maxLen, const std::string & suffix) { std::vector<std::string> msgBuf = split(text, '\n'); unsigned int width = maxLen + (suffix.empty() ? 0 : suffix.size() + 2); for(auto & s : msgBuf) width = (s.size() > width ? s.size() : width); width = (width > maxLen ? width : maxLen) + 4; int msgHeight = msgBuf.size(); int height = 3 + msgHeight; char result[maxLen+1]; std::memset(result, 0, maxLen + 1); myRenderer->startWindow(myRenderer->width() / 2 - width / 2, myRenderer->height() / 2 - height / 2, width, height); echo(); cbreak(); curs_set(1); timeout(-1); wborder(myRenderer->win(), 0,0,0,0,0,0,0,0); int yoff = 1; for(auto & s : msgBuf) myRenderer->drawText(2, yoff++, s); if (!suffix.empty()) myRenderer->drawText(maxLen + 4, msgHeight+1, suffix); myRenderer->refresh(); wmove(myRenderer->win(), msgHeight+1, 2); wgetnstr(myRenderer->win(), result, maxLen); reset(0); timeout(0); myRenderer->endWindow(); return result; }
/* * mvwgetnstr -- * Get a string (of maximum n) characters from the given window starting * at (y, x). */ int mvwgetnstr(WINDOW *win, int y, int x, char *str, int n) { if (wmove(win, y, x) == ERR) return ERR; return wgetnstr(win, str, n); }
void get_string(char *string) { int len; wgetnstr(stdscr, string, MAX_STRING); len = strlen(string); if (len > 0 && string[len - 1] == '\n') string[len - 1] = '\0'; }
void update_cd() { FILE *tracks_fp; char track_name[MAX_STRING]; int len; int track = 1; int screen_line = 1; WINDOW *box_window_ptr; WINDOW *sub_window_ptr; clear_all_screen(); mvprintw(PROMPT_LINE, 0, "Re-entering tracks for CD. "); if(!get_confirm()) return; move(PROMPT_LINE, 0); clrtoeol(); remove_tracks(); mvprintw(MESSAGE_LINE, 0, "Enter a blank line to finish"); tracks_fp = fopen(tracks_file, "a"); box_window_ptr = subwin(stdscr, BOXED_LINES + 2, BOXED_ROWS + 2, BOX_LINE_POS - 1, BOX_ROW_POS - 1); if(!box_window_ptr) return; box(box_window_ptr, ACS_VLINE, ACS_HLINE); sub_window_ptr = subwin(stdscr, BOXED_LINES, BOXED_ROWS, BOX_LINE_POS, BOX_ROW_POS); if(!sub_window_ptr) return; scrollok(sub_window_ptr, TRUE); werase(sub_window_ptr); touchwin(stdscr); do { mvwprintw(sub_window_ptr, screen_line++, BOX_ROW_POS + 2, "Track %d: ", track); clrtoeol(); refresh(); wgetnstr(sub_window_ptr, track_name, MAX_STRING); len = strlen(track_name); if(len > 0 && track_name[len - 1] == '\n') track_name[len - 1] = '\0'; if(*track_name) fprintf(tracks_fp, "%s,%d,%s\n", current_cat, track, track_name); track++; if(screen_line > BOXED_LINES - 1) { /* time to start scrolling */ scroll(sub_window_ptr); screen_line--; } } while(*track_name); delwin(sub_window_ptr); fclose(tracks_fp); }
int getstr(char *str) { int code; code = wgetnstr(stdscr, str, -1); return (code); }
int getnstr(char *str, int n) { int code; code = wgetnstr(stdscr, str, n); return (code); }
int wgetstr(WINDOW *w, char *str) { int code; code = wgetnstr(w, str, -1); return (code); }
vwscanw(WINDOW *win, NCURSES_CONST char *fmt, va_list argp) { char buf[BUFSIZ]; if (wgetnstr(win, buf, (int) sizeof(buf) - 1) == ERR) return (ERR); return (vsscanf(buf, fmt, argp)); }
char* cgets(char* buf) { init_screen(); echo(); wgetnstr(_working_window, buf + 2, buf[0]); wrefresh(_working_window); noecho(); buf[1] = strlen(buf + 2); return buf + 2; }
static void readstr(WINDOW *w, char *buf, size_t buflen) { echo(); curs_set(1); wgetnstr(w, buf, buflen); curs_set(0); noecho(); }
int gui_ask(char *question, char *answer) { gui_draw_question(question); echo(); wgetnstr(bar_window->win, answer, 512); noecho(); gui_draw_bar(); return strlen(answer); }
int mvwgetnstr(WINDOW *win, int y, int x, char *str, int n) { PDC_LOG(("mvwgetnstr() - called\n")); if (wmove(win, y, x) == ERR) return ERR; return wgetnstr(win, str, n); }
int mvgetnstr(int y, int x, char *str, int n) { PDC_LOG(("mvgetnstr() - called\n")); if (move(y, x) == ERR) return ERR; return wgetnstr(stdscr, str, n); }
int mvgetnstr(int y, int x, char *str, int n) { int code; if ((code = wmove(stdscr, y, x)) == OK) code = wgetnstr(stdscr, str, n); return (code); }
int mvwgetnstr(WINDOW *w, int y, int x, char *str, int n) { int code; if ((code = wmove(w, y, x)) == OK) code = wgetnstr(w, str, n); return (code); }
int vwscanw(WINDOW *win, const char *fmt, va_list varglist) { char scanbuf[256]; PDC_LOG(("vwscanw() - called\n")); if (wgetnstr(win, scanbuf, 255) == ERR) return ERR; return vsscanf(scanbuf, fmt, varglist); }
static int internal_getnstr(lua_State *L, WINDOW **w, int n){ char s[n+1]; if(wgetnstr(*w, s, n) == ERR){ lua_pushnil(L); lua_pushstring(L, "wgetnstr() returned an error"); return 2; } lua_pushstring(L, s); return 1; }
void display_input_add_birthday_event(void) { char first_name[PHRASES_CHARS_LENGTH/2], last_name[128], day[3], month[3], year[5]; curs_set(1); wclear(wsinput); mvwaddstr(wsinput, 0, 0, "* "); waddstr(wsinput, phrases_data.input_birthday_event); mvwaddstr(wsinput, 2, 0, "+ "); waddstr(wsinput, phrases_data.input_first_name); waddstr(wsinput, ": "); wrefresh(wsinput); wgetnstr(wsinput, first_name, 127); mvwaddstr(wsinput, 4, 0, "+ "); waddstr(wsinput, phrases_data.input_last_name); waddstr(wsinput, ": "); wrefresh(wsinput); wgetnstr(wsinput, last_name, 127); mvwaddstr(wsinput, 6, 0, "+ "); waddstr(wsinput, phrases_data.input_date); waddstr(wsinput, ": - - "); mvwgetnstr(wsinput, 6, strlen(phrases_data.input_date)+4, day, 2); mvwgetnstr(wsinput, 6, strlen(phrases_data.input_date)+7, month, 2); mvwgetnstr(wsinput, 6, strlen(phrases_data.input_date)+10, year, 4); if (strlen(first_name) > 0 && strlen(last_name) > 0 && strlen(day) > 0 && strlen(month) > 0 && strlen(year) > 0) { strcpy(entry_to_change.text, first_name); strcat(entry_to_change.text, " "); strcat(entry_to_change.text, last_name); entry_to_change.date.day = atoi(day); entry_to_change.date.month = atoi(month); entry_to_change.date.year = atoi(year); entry_to_change.time.hour = 0; entry_to_change.time.minute = 0; entry_to_change.is_birthday = 1; entry_to_change.repeat_cycle = 0; } curs_set(0); }