do_postwar() { int rc, in_postwar_read, in_postwar = 1; int openflags, newmsgs; struct readnewstruct rns; char msgbuf[80], ans[4]; while(in_postwar) { bbs_set_mode(M_POSTWAR); rc = (GenericPost(0)); bbs_set_mode(M_POSTWAR); in_postwar_read = 1; while(in_postwar_read) { move(t_lines-1,0); clrtoeol(); getdata(t_lines-1, 0, "Post again, Read new posts, Exit PostWar Mode? [R]: ", ans, sizeof(ans), DOECHO, 0); switch (*ans) { case 'e': case 'E': in_postwar = in_postwar_read = 0; break; case 'p': case 'P': in_postwar_read = 0; break; default: { clear(); CloseBoard(); newmsgs = OpenBoard(&openflags, 1, NULL); if (newmsgs > 0) { rns.nummsgs = newmsgs; rns.numread = 0; rns.openflags = openflags; rns.dispflags = NEW_SKIP; rns.thread = NULL; bbs_enum_headers(10, 0, 1, NewPostReadfn, &rns); } else { sprintf(msgbuf, "No New Posts on %s\n", currboard); move(t_lines/2, t_columns/2-10); prints(msgbuf); } } } } } return rc; }
void MenuEscape::handleInput(int in) { const int maxUiSelection = 3; move(selection + 2, 0); clrtoeol(); if(in == KEY_ESCAPE){ closeThisMenu(); } else if(in == Key::interact || in == '\n'){ switch (selection) { case 0: closeThisMenu(); break; case 1: openMenu(new MenuControls()); break; case 2: openMenu(new MenuSettings()); break; case 3: if(Settings::autoSave && menuTime > Settings::autoSaveDelay){ closeAllMenus(); } else { openMenu(new MenuYesNo("Do you want to save '" + menuGame->currentWorld->name + "' ?", menuGame->saveAnswer, true)); } break; default: break; } }else if(in == Key::uiUp){ selection--; if (selection < 0) { selection = maxUiSelection; } }else if(in == Key::uiDown){ selection++; if (selection > maxUiSelection) { selection = 0; } } }
static void IgnorePage(int infile) { static time_t last; time_t now = time((time_t *) 0); if (now != last) { last = now; move(LINES - 1, 0); (void) standout(); PRINTW("---line %d ...skipping", infile); (void) standend(); PRINTW(" "); clrtoeol(); refresh(); } }
/* * *_memory(stats) - print "Memory: " followed by the memory summary string */ void i_memory(int *stats) { if (screen_length > y_mem || !smart_terminal) { char memory_buffer[MAX_COLS]; move(y_mem, 0); clrtoeol(); addstrp("Memory: "); /* format and print the memory summary */ summary_format(memory_buffer, sizeof(memory_buffer), stats, memory_names); addstrp(memory_buffer); putn(); } }
void i_header(char *text) { if (header_status == Yes && (screen_length > y_header || !smart_terminal)) { if (!smart_terminal) { putn(); if (fputs(text, stdout) == EOF) exit(1); putn(); } else { move(y_header, 0); clrtoeol(); addstrp(text); } } }
/* "valid" string. */ wchar_t prompt_char(int row, int col, const char *promptstr, const char *valid) { wchar_t *w_prompt, *w_valid=NULL, ch; int code; w_prompt = mbstowcs_alloc(promptstr); /* if w_promptstr == NULL ?? .... */ /* Print the prompt. */ mvaddwstr(row, col, w_prompt); clrtoeol(); refresh(); if ( valid != NULL ) { w_valid = mbstowcs_alloc(valid); } /* Read characters... */ while ((code = get_wch(&ch)) != ERR) { /* If it's not a valid one, beep and get another one. */ /* if (index(valid, c) == NULL) { */ if ( valid != NULL ) { if (wcsrchr(w_valid, ch) == NULL) { /* CHANGED !! */ beep(); continue; } /* Add the character to the screen, and return it. */ AddCh((chtype) ch); refresh(); } goto _exit; } _exit: free(w_prompt); refresh(); if (valid != NULL ) { free(w_valid); w_valid= NULL ; return (ch); /* to avoid compiler warning */ } else { return '\0' ; } }
// print updated interactive control value void Responder::print_interactive_msg(std::string msg) { if(msg != "") { // move cursor back to beginning of line int y, x; getyx(_window, y, x); if (x > 0) { move(y, 0); clrtoeol(); } print_msg(msg); move(y, 0); } }
/* Draw the board, the help, and the two wordlists at the end of a * round. Returns zero if the end of screen was reached before the end * of the wordlist. */ int doendgameoutput(int y, int x, int offset, int highlighted) { int f = TRUE; drawgridletters(highlighted); movetowords(TRUE); listwords("Your words:", getfound(), 0); if (!ego) f = listwords("Other words that were present:", getfindable(), offset); move(y, x); if (!offset && f) addline("^D: quit &: new game ?: find word"); else addline("^D: quit &: new game ?: find word -+: scroll"); clrtoeol(); return f; }
int ifcmd(const char *cmd, const char *args) { int scale; if (prefix(cmd, "scale")) { if ((scale = get_scale(args)) != -1) curscale = scale; else { move(CMDLINE, 0); clrtoeol(); addstr("what scale? "); addstr(get_helplist()); } } return (1); }
void WDL_CursesEditor::draw_message(const char *str) { int l=strlen(str); if (l > COLS-2) l=COLS-2; if (str[0]) { attrset(m_color_message); bkgdset(m_color_message); } mvaddnstr(LINES-(m_bottom_margin>1?2:1),0,str,l); clrtoeol(); if (str[0]) { attrset(0); bkgdset(0); } }
/* * get_line: * Reads the next line up to '\n' or EOF. Multiple spaces are * compressed to one space; a space is inserted before a ',' */ char * get_line(void) { size_t pos; int c, oy, ox; WINDOW *oscr; oscr = stdscr; stdscr = Msgwin; getyx(stdscr, oy, ox); refresh(); /* loop reading in the string, and put it in a temporary buffer */ for (pos = 0; (c = readchar()) != '\n'; clrtoeol(), refresh()) { if (c == -1) continue; if (c == ' ' && (pos == 0 || linebuf[pos - 1] == ' ')) continue; if (c == erasechar()) { if (pos > 0) { int i; pos--; for (i = strlen(unctrl(linebuf[pos])); i; i--) addch('\b'); } continue; } if (c == killchar()) { pos = 0; move(oy, ox); continue; } if (pos >= LINESIZE - 1 || !(isalnum(c) || c == ' ')) { beep(); continue; } if (islower(c)) c = toupper(c); linebuf[pos++] = c; addstr(unctrl(c)); Mpos++; } while (pos < sizeof(linebuf)) linebuf[pos++] = '\0'; stdscr = oscr; return (linebuf); }
void drawpos() { file_t *file; file = files[current]; attron(COLOR_PAIR(3)); attron(A_BOLD); mvprintw(0, 55, "C: %d L: %d/%d (%d%%)", file->cursor_x+1, file->cursor_y+1, file->line_count, file->cursor_y*100/file->line_count); clrtoeol(); attron(COLOR_PAIR(2)); attroff(A_BOLD); }
int main() { WINDOW *menu_win; int highlight = 1; int choice = 0; int c; initscr(); clear(); noecho(); cbreak(); startx = (80 - WIDTH) / 2; starty = (24 - HEIGHT) / 2; menu_win = newwin(HEIGHT, WIDTH, starty, startx); keypad(menu_win, TRUE); mvprintw(0, 0, "Use arrow keys to go up and down, Press enter to select a choice"); refresh(); print_menu(menu_win, highlight); while (1) { c = wgetch(menu_win); switch(c) { case KEY_UP: if (highlight == 1) highlight = n_choices; else --highlight; break; case KEY_DOWN: if (highlight == n_choices) highlight = 1; else ++highlight; break; case 10: choice = highlight; break; default: mvprintw(24, 0, "Character pressed is = %3d Hopefully it can be...", c); refresh(); break; } print_menu(menu_win, highlight); if (choice != 0) break; } mvprintw(23, 0, "You chose choice %d width choice string %s\n", choice, choices[choice - 1]); clrtoeol(); refresh(); endwin(); return 0; }
int main() { int rows; int cols; char input[5]; int tall; int wide; initscr(); //initalize ncurses getmaxyx(stdscr, rows, cols); //get size of screen //Move to position, and print mvprintw(2, 3, "Enter the height: "); getstr(input); //get string from user, store in input tall = (int)strtol(input, NULL, 10); move(2,0); //move to beginning of line clrtoeol(); //clear line mvprintw(2, 3, "Enter the width: "); getstr(input); wide = (int)strtol(input, NULL, 10); erase(); //clear entire screen printRec(2,3,tall,wide); getch(); printRec(6,7,tall,wide); getch(); printRec(12,23,tall,wide); getch(); /* Pause for input. This really does nothing. It's just hear so you can see the screen before the program exits. Hit any key to continue*/ printMsg("End of program. Push any key to quit."); getch(); /* Important. Don't forget to do this: */ endwin(); //deinitalize ncurses return 0; }
void init(mcu_t* const state) { uint8_t size_ok = 0; initscr(); cbreak(); noecho(); keypad(stdscr, TRUE); curs_set(0); while(!size_ok) { getmaxyx(stdscr, message_y, message_x); if(message_y < 40 || message_x < 80) { clear(); mvprintw(message_y - 1, 0, "Please increase your terminal window size to accommodate the UI."); refresh(); getch(); } else size_ok = 1; } sfr_x = 0; sfr_y = 0; gpram_x = 26; gpram_y = 15; misc_x = 0; misc_y = 15; message_x = 0; move(message_y, message_x); clrtoeol(); refresh(); message_y -= 1; sfr_draw(); gpram_draw(); misc_draw(); mvprintw(message_y, message_x, "Welcome to MULE. Press ESC followed by r to run, or : to enter a command."); refresh(); while(getch() != 27) ; get_cmd(state); return; }
/* * getguess: * Get another guess */ void getguess(void) { int i; int ch, uch; bool correct; leaveok(stdscr, FALSE); for (;;) { move(PROMPTY, PROMPTX + sizeof("Guess: ")); refresh(); ch = readch(); if (isalpha(ch)) { if (isupper(ch)) ch = tolower(ch); if (Guessed[ch - 'a']) mvprintw(MESGY, MESGX, "Already guessed '%c'", ch); else break; } else if (ch == CTRL('D')) die(0); else mvprintw(MESGY, MESGX, "Not a valid guess: '%s'", unctrl(ch)); } leaveok(stdscr, TRUE); move(MESGY, MESGX); clrtoeol(); Guessed[ch - 'a'] = TRUE; correct = FALSE; uch = toupper(ch); for (i = 0; Word[i] != '\0'; i++) { if (Word[i] == ch) { Known[i] = ch; correct = TRUE; } else if (Word[i] == uch) { Known[i] = uch; correct = TRUE; } } if (!correct) Errors++; }
/* * get_line: * Reads the next line up to '\n' or EOF. Multiple spaces are * compressed to one space; a space is inserted before a ',' */ char * get_line(void) { size_t pos; int c, oy, ox; WINDOW *oscr; oscr = stdscr; stdscr = Msgwin; getyx(stdscr, oy, ox); refresh(); /* loop reading in the string, and put it in a temporary buffer */ for (pos = 0; (c = readchar()) != '\n'; clrtoeol(), refresh()) { if (c == erasechar()) { /* process erase character */ if (pos > 0) { int i; pos--; for (i = strlen(unctrl(linebuf[pos])); i; i--) addch('\b'); } continue; } else if (c == killchar()) { /* process kill * character */ pos = 0; move(oy, ox); continue; } else if (pos == 0 && c == ' ') continue; if (pos >= LINESIZE - 1 || !(isprint(c) || c == ' ')) putchar(CTRL('G')); else { if (islower(c)) c = toupper(c); linebuf[pos++] = c; addstr(unctrl(c)); Mpos++; } } linebuf[pos] = '\0'; stdscr = oscr; return (linebuf); }
void WDL_CursesEditor::draw_status_state() { // always show this? if (m_bottom_margin>0) { char statusstr[512]; snprintf(statusstr,sizeof(statusstr),"Line %d/%d, Col %d [%s%s]%s",m_curs_y+1,m_text.GetSize(),m_curs_x,s_overwrite?"OVR":"INS","",m_clean_undopos == m_undoStack_pos ? "" :"M"); attrset(m_color_statustext); bkgdset(m_color_statustext); mvaddstr(LINES-1,COLS-28,statusstr); clrtoeol(); attrset(0); bkgdset(0); } }
void i_process(int line, char *thisline, int hl) { /* make sure we are on the correct line */ move(y_procs + line, 0); /* truncate the line to conform to our current screen width */ thisline[display_width] = '\0'; /* write the line out */ if (hl && smart_terminal) standoutp(); addstrp(thisline); if (hl && smart_terminal) standendp(); putn(); clrtoeol(); }
void press (void) { int c; extern int showansi; int tmpansi; tmpansi = showansi; showansi = 1; saveline (t_lines-1, 0); move (t_lines-1, 0); clrtoeol (); prints ("[37;40m[0m [33m°´ÈÎÒâ¼ü¼ÌÐø ...[37;40m[0m"); refresh (); read (0, &c, sizeof (int)); move (t_lines-1, 0); saveline (t_lines-1, 1); showansi = tmpansi; }
// prepare screen buffer to display one line of text CCW_PROTO void ccw_prepare_line(CCW_CTX *ctx) { move(ctx->line, 0); if ( ctx->line+1 < CCW_STOP_LINE) { // simply append ctx->line ++; } else { // scroll screen buffer region_scroll_up(CCW_INIT_LINE, CCW_STOP_LINE - CCW_INIT_LINE); move(ctx->line-1, 0); // XXX after resize, we may need to scroll more than once. } clrtoeol(); }
static int a_multi_search_num(char init, a_menu_session_t *sess) { char buf[STRLEN - sizeof(MULTI_SEARCH_PROMPT) -1] = ""; buf[0] = init; move(b_lines, 0); clrtoeol(); outs(MULTI_SEARCH_PROMPT); sess->z_indexes[0] = sess->z_indexes[1] = 0; if (vgetstr(buf, sizeof(buf), VGET_DEFAULT, buf) < 1) return 0; a_parse_zindexes(buf, sess); if (!sess->z_indexes[1]) return sess->z_indexes[0]; return 0; }
void i_loadave(pid_t mpid, double *avenrun) { if (screen_length > 1 || !smart_terminal) { int i; move(0, 0); clrtoeol(); addstrp("load averages"); /* mpid == -1 implies this system doesn't have an _mpid */ if (mpid != -1) printwp("last pid: %5ld; ", (long) mpid); for (i = 0; i < 3; i++) printwp("%c %5.2f", i == 0 ? ':' : ',', avenrun[i]); } }
void printChatLog(chatLog cl, int currentLine){ while(cl != NULL){ if(currentLine > - 1){ move(cl -> lineNumber - 1, 0); clrtoeol(); char* buf = cl -> lineOfText; if(cl -> person){ printw("Friend: %s", cl -> lineOfText); } else{ printw("You: %s", cl -> lineOfText); } } cl = cl -> next; currentLine--; } return; }
void nlisterr(struct nlist namelist[]) { int i, n; n = 0; clear(); mvprintw(2, 10, "systat: nlist: can't find following symbols:"); for (i = 0; namelist[i].n_name != NULL && *namelist[i].n_name != '\0'; i++) if (namelist[i].n_value == 0) mvprintw(2 + ++n, 10, "%s", namelist[i].n_name); move(CMDLINE, 0); clrtoeol(); refresh(); endwin(); exit(1); }
/// \brief Show and handle commands inputed by : /// \return void void command(){ char cmd[MAX_BOARD_SIZE*MAX_BOARD_SIZE*4]; echo(); //curs_set(1); move(0,0); clrtoeol(); attron(A_STANDOUT); mvprintw(0,MENU_POSITION_X,":"); attroff(A_STANDOUT); int arg=NA,arg2=NA; scanw("%s %d %d",cmd,&arg,&arg2);cmd[15]='\0'; noecho(); //curs_set(0); if(strcmp(cmd,"r")==0||strcmp(cmd,"read")==0){ c_readBoard(arg); }else if(strcmp(cmd,"s")==0||strcmp(cmd,"save")==0){ c_saveBoard(arg,true); }else if(strcmp(cmd,"s!")==0||strcmp(cmd,"saveto")==0){ c_saveBoard(arg,false); }else if(strcmp(cmd,"q")==0||strcmp(cmd,"quit")==0){ c_tryQuit(); }else if(strcmp(cmd,"w")==0||strcmp(cmd,"write")==0){ c_writeBoardToDisk(NA,true); }else if(strcmp(cmd,"wb")==0||strcmp(cmd,"writeboard")==0){ if(NA==arg){ c_warning("Librazy don't know which board should be saved"); }else{ c_writeBoardToDisk(arg,true); } }else if(strcmp(cmd,"wq")==0||strcmp(cmd,"writequit")==0){ if(c_writeBoardToDisk(NA,true))c_forceQuit(); }else if(strcmp(cmd,"q!")==0||strcmp(cmd,"quit!")==0){ c_forceQuit(); }else if(strcmp(cmd,"o")==0||strcmp(cmd,"open")==0){ c_readFromDisk(arg,true); }else if(strcmp(cmd,"boom")==0){ c_boom(arg,arg2); }else{ char str[1000]; sprintf(str,"Librazy don't know how to %s,\nresume game now",cmd); str[99]='\0'; c_warning(str); } }
int get_line(char *buf, int size) { char *cp, *end; int c = EOF; extern int interactive; cp = buf; end = buf + size - 1; /* save room for the '\0' */ while (cp < end && (c = getchar()) != EOF && c != '\n' && c != '\r') { *cp++ = c; if (interactive) { switch (c) { case 0x0c: /* ^L */ wrefresh(curscr); cp--; continue; case 0x15: /* ^U */ case 0x18: /* ^X */ while (cp > buf) { cp--; addch('\b'); } clrtoeol(); break; case '\b': case 0x7f: /* DEL */ if (cp == buf + 1) { cp--; continue; } cp -= 2; addch('\b'); c = ' '; /* FALLTHROUGH */ default: addch(c); } refresh(); } } *cp = '\0'; return(c != EOF); }
void getmove() { int i, c; c = 0; for (;;) { i = checkmove(c); switch (i) { case -1: if (movokay(mvlim)) { move(20, 0); for (i = 0; i < mvlim; i++) if (h[i]) wrhit(g[i]); nexturn(); if (*offopp == 15) cturn *= -2; return; } case -4: case 0: refresh(); if (i != 0 && i != -4) break; mvaddstr(20, 0, *Colorptr); if (i == -4) addstr(" must make "); else addstr(" can only make "); printw("%d move%s.\n", mvlim, mvlim > 1 ? "s":""); break; case -3: if (quit()) return; } move(cturn == -1 ? 18 : 19, 39); clrtoeol(); c = -1; } }
/* * Show text in the status line */ void screen_message(const char *format,...) { char msg[BUFSIZ]; va_list ap; int y, x; getyx(stdscr, y, x); move(0, 0); va_start(ap, format); vsprintf(msg, format, ap); va_end(ap); addstr(msg); clrtoeol(); move(y, x); refresh(); }
void global_help(char *args) { int col, len; struct mode *p; char *name, *prev; move(CMDLINE, col = 0); name = prev = NULL; for (p = modes; p->c_name; p++) { if ((name = shortname(args, p->c_name)) == NULL) continue; if (name && prev && strcmp(name, prev) == 0) { free(name); name = NULL; continue; } len = strlen(name); if (col + len > COLS) break; addstr(name); col += len + 1; if (col + 1 < COLS) addch(' '); if (prev) free(prev); prev = name; name = NULL; } if (col == 0 && args) { standout(); if ((int)strlen(args) < COLS - 25) printw("help: no matches for `%s.*'", args); else printw("help: no matches"); standend(); } clrtoeol(); if (name) free(name); if (prev) free(prev); }