int main (int argc, char **argv) { int quit = 0; #if defined(__GLIBC__) setup_signal_handlers (); #endif /* command line/config options */ verify_global_config (argc, argv); parse_conf_file (&argc, &argv); parse_cmd_line (argc, argv); /* initialize storage */ init_storage (); /* setup to use the current locale */ set_locale (); #ifdef HAVE_LIBGEOIP init_geoip (); #endif /* init logger */ logger = init_log (); /* init parsing spinner */ parsing_spinner = new_gspinner (); parsing_spinner->process = &logger->process; /* outputting to stdout */ if (conf.output_html) { ui_spinner_create (parsing_spinner); goto out; } /* init curses */ set_input_opts (); if (conf.no_color || has_colors () == FALSE) { conf.color_scheme = NO_COLOR; conf.no_color = 1; } else { start_color (); } init_colors (); init_windows (&header_win, &main_win); set_curses_spinner (parsing_spinner); /* configuration dialog */ if (isatty (STDIN_FILENO) && (conf.log_format == NULL || conf.load_conf_dlg)) { refresh (); quit = verify_format (logger, parsing_spinner); } /* straight parsing */ else { ui_spinner_create (parsing_spinner); } out: /* main processing event */ time (&start_proc); if (conf.load_from_disk) set_general_stats (); else if (!quit && parse_log (&logger, NULL, -1)) FATAL ("Error while processing file"); logger->offset = logger->process; /* no valid entries to process from the log */ if ((logger->process == 0) || (logger->process == logger->invalid)) FATAL ("Nothing valid to process."); /* init reverse lookup thread */ gdns_init (); parse_initial_sort (); allocate_holder (); end_spinner (); time (&end_proc); /* stdout */ if (conf.output_html) { /* CSV */ if (conf.output_format && strcmp ("csv", conf.output_format) == 0) output_csv (logger, holder); /* JSON */ else if (conf.output_format && strcmp ("json", conf.output_format) == 0) output_json (logger, holder); /* HTML */ else output_html (logger, holder); } /* curses */ else { allocate_data (); if (!conf.skip_term_resolver) gdns_thread_create (); render_screens (); get_keys (); attroff (COLOR_PAIR (COL_WHITE)); /* restore tty modes and reset * terminal into non-visual mode */ endwin (); } /* clean */ house_keeping (); return EXIT_SUCCESS; }
/* ================== 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) || !isatty(STDOUT_FILENO)) { 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); } // Prevent bad libraries from messing up the console fclose(stderr); } // 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; }
/* return values: * * 1 message should be postponed * 0 normal exit * -1 abort message */ int mutt_compose_menu (HEADER *msg, /* structure for new message */ char *fcc, /* where to save a copy of the message */ size_t fcclen, HEADER *cur, /* current message */ int flags) { char helpstr[LONG_STRING]; char buf[LONG_STRING]; char fname[_POSIX_PATH_MAX]; MUTTMENU *menu; ATTACHPTR **idx = NULL; short idxlen = 0; short idxmax = 0; int i, close = 0; int r = -1; /* return value */ int op = 0; int loop = 1; int fccSet = 0; /* has the user edited the Fcc: field ? */ CONTEXT *ctx = NULL, *this = NULL; /* Sort, SortAux could be changed in mutt_index_menu() */ int oldSort, oldSortAux; struct stat st; mutt_attach_init (msg->content); idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1); menu = mutt_new_menu (MENU_COMPOSE); menu->offset = HDR_ATTACH; menu->max = idxlen; menu->make_entry = snd_entry; menu->tag = mutt_tag_attach; menu->data = idx; menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp); while (loop) { switch (op = mutt_menuLoop (menu)) { case OP_REDRAW: draw_envelope (msg, fcc); menu->offset = HDR_ATTACH; menu->pagelen = LINES - HDR_ATTACH - 2; break; case OP_COMPOSE_EDIT_FROM: menu->redraw = edit_address_list (HDR_FROM, &msg->env->from); mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_TO: menu->redraw = edit_address_list (HDR_TO, &msg->env->to); if (option (OPTCRYPTOPPORTUNISTICENCRYPT)) { crypt_opportunistic_encrypt (msg); redraw_crypt_lines (msg); } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_BCC: menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc); if (option (OPTCRYPTOPPORTUNISTICENCRYPT)) { crypt_opportunistic_encrypt (msg); redraw_crypt_lines (msg); } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_CC: menu->redraw = edit_address_list (HDR_CC, &msg->env->cc); if (option (OPTCRYPTOPPORTUNISTICENCRYPT)) { crypt_opportunistic_encrypt (msg); redraw_crypt_lines (msg); } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_SUBJECT: if (msg->env->subject) strfcpy (buf, msg->env->subject, sizeof (buf)); else buf[0] = 0; if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) { mutt_str_replace (&msg->env->subject, buf); move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth); if (msg->env->subject) mutt_paddstr (W, msg->env->subject); else clrtoeol(); } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_REPLY_TO: menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to); mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_FCC: strfcpy (buf, fcc, sizeof (buf)); if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) { strfcpy (fcc, buf, fcclen); mutt_pretty_mailbox (fcc, fcclen); move (HDR_FCC, HDR_XOFFSET + SidebarWidth); mutt_paddstr (W, fcc); fccSet = 1; } MAYBE_REDRAW (menu->redraw); mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_MESSAGE: if (Editor && (mutt_strcmp ("builtin", Editor) != 0) && !option (OPTEDITHDRS)) { mutt_edit_file (Editor, msg->content->filename); mutt_update_encoding (msg->content); menu->redraw = REDRAW_FULL; mutt_message_hook (NULL, msg, M_SEND2HOOK); break; } /* fall through */ case OP_COMPOSE_EDIT_HEADERS: if (mutt_strcmp ("builtin", Editor) != 0 && (op == OP_COMPOSE_EDIT_HEADERS || (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) { char *tag = NULL, *err = NULL; mutt_env_to_local (msg->env); mutt_edit_headers (NONULL (Editor), msg->content->filename, msg, fcc, fcclen); if (mutt_env_to_intl (msg->env, &tag, &err)) { mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err); FREE (&err); } if (option (OPTCRYPTOPPORTUNISTICENCRYPT)) crypt_opportunistic_encrypt (msg); } else { /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the attachment list could change if the user invokes ~v to edit the message with headers, in which we need to execute the code below to regenerate the index array */ mutt_builtin_editor (msg->content->filename, msg, cur); } mutt_update_encoding (msg->content); /* attachments may have been added */ if (idxlen && idx[idxlen - 1]->content->next) { for (i = 0; i < idxlen; i++) { FREE (&idx[i]->tree); FREE (&idx[i]); } idxlen = 0; idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1); menu->data = idx; menu->max = idxlen; } menu->redraw = REDRAW_FULL; mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_ATTACH_KEY: if (!(WithCrypto & APPLICATION_PGP)) break; if (idxlen == idxmax) { safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5)); menu->data = idx; } idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL) { update_idx (menu, idx, idxlen++); menu->redraw |= REDRAW_INDEX; } else FREE (&idx[idxlen]); menu->redraw |= REDRAW_STATUS; if (option(OPTNEEDREDRAW)) { menu->redraw = REDRAW_FULL; unset_option(OPTNEEDREDRAW); } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_ATTACH_FILE: { char *prompt, **files; int error, numfiles; fname[0] = 0; prompt = _("Attach file"); numfiles = 0; files = NULL; if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files, &numfiles) == -1 || *fname == '\0') break; if (idxlen + numfiles >= idxmax) { safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles)); menu->data = idx; } error = 0; if (numfiles > 1) mutt_message _("Attaching selected files..."); for (i = 0; i < numfiles; i++) { char *att = files[i]; idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); idx[idxlen]->unowned = 1; idx[idxlen]->content = mutt_make_file_attach (att); if (idx[idxlen]->content != NULL) update_idx (menu, idx, idxlen++); else { error = 1; mutt_error (_("Unable to attach %s!"), att); FREE (&idx[idxlen]); } } FREE (&files); if (!error) mutt_clear_error (); menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_ATTACH_MESSAGE: { char *prompt; HEADER *h; fname[0] = 0; prompt = _("Open mailbox to attach message from"); if (Context) { strfcpy (fname, NONULL (Context->path), sizeof (fname)); mutt_pretty_mailbox (fname, sizeof (fname)); } if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0]) break; mutt_expand_path (fname, sizeof (fname)); #ifdef USE_IMAP if (!mx_is_imap (fname)) #endif #ifdef USE_POP if (!mx_is_pop (fname)) #endif /* check to make sure the file exists and is readable */ if (access (fname, R_OK) == -1) { mutt_perror (fname); break; } menu->redraw = REDRAW_FULL; ctx = mx_open_mailbox (fname, M_READONLY, NULL); if (ctx == NULL) { mutt_error (_("Unable to open mailbox %s"), fname); break; } if (!ctx->msgcount) { mx_close_mailbox (ctx, NULL); FREE (&ctx); mutt_error _("No messages in that folder."); break; } this = Context; /* remember current folder and sort methods*/ oldSort = Sort; oldSortAux = SortAux; Context = ctx; set_option(OPTATTACHMSG); mutt_message _("Tag the messages you want to attach!"); close = mutt_index_menu (); unset_option(OPTATTACHMSG); if (!Context) { /* go back to the folder we started from */ Context = this; /* Restore old $sort and $sort_aux */ Sort = oldSort; SortAux = oldSortAux; menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; break; } if (idxlen + Context->tagged >= idxmax) { safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + Context->tagged)); menu->data = idx; } for (i = 0; i < Context->msgcount; i++) { h = Context->hdrs[i]; if (h->tagged) { idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); idx[idxlen]->content = mutt_make_message_attach (Context, h, 1); if (idx[idxlen]->content != NULL) update_idx (menu, idx, idxlen++); else { mutt_error _("Unable to attach!"); FREE (&idx[idxlen]); } } } menu->redraw |= REDRAW_FULL; if (close == OP_QUIT) mx_close_mailbox (Context, NULL); else mx_fastclose_mailbox (Context); FREE (&Context); /* go back to the folder we started from */ Context = this; /* Restore old $sort and $sort_aux */ Sort = oldSort; SortAux = oldSortAux; } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_DELETE: CHECK_COUNT; if (idx[menu->current]->unowned) idx[menu->current]->content->unlink = 0; if (delete_attachment (menu, &idxlen, menu->current) == -1) break; mutt_update_tree (idx, idxlen); if (idxlen) { if (menu->current > idxlen - 1) menu->current = idxlen - 1; } else menu->current = 0; if (menu->current == 0) msg->content = idx[0]->content; menu->redraw |= REDRAW_STATUS; mutt_message_hook (NULL, msg, M_SEND2HOOK); break; #define CURRENT idx[menu->current]->content case OP_COMPOSE_TOGGLE_RECODE: { CHECK_COUNT; if (!mutt_is_text_part (CURRENT)) { mutt_error (_("Recoding only affects text attachments.")); break; } CURRENT->noconv = !CURRENT->noconv; if (CURRENT->noconv) mutt_message (_("The current attachment won't be converted.")); else mutt_message (_("The current attachment will be converted.")); menu->redraw = REDRAW_CURRENT; mutt_message_hook (NULL, msg, M_SEND2HOOK); break; } #undef CURRENT case OP_COMPOSE_EDIT_DESCRIPTION: CHECK_COUNT; strfcpy (buf, idx[menu->current]->content->description ? idx[menu->current]->content->description : "", sizeof (buf)); /* header names should not be translated */ if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) { mutt_str_replace (&idx[menu->current]->content->description, buf); menu->redraw = REDRAW_CURRENT; } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_UPDATE_ENCODING: CHECK_COUNT; if (menu->tagprefix) { BODY *top; for (top = msg->content; top; top = top->next) { if (top->tagged) mutt_update_encoding (top); } menu->redraw = REDRAW_FULL; } else { mutt_update_encoding(idx[menu->current]->content); menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_TOGGLE_DISPOSITION: /* toggle the content-disposition between inline/attachment */ idx[menu->current]->content->disposition = (idx[menu->current]->content->disposition == DISPINLINE) ? DISPATTACH : DISPINLINE; menu->redraw = REDRAW_CURRENT; break; case OP_EDIT_TYPE: CHECK_COUNT; { mutt_edit_content_type (NULL, idx[menu->current]->content, NULL); /* this may have been a change to text/something */ mutt_update_encoding (idx[menu->current]->content); menu->redraw = REDRAW_CURRENT; } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_ENCODING: CHECK_COUNT; strfcpy (buf, ENCODING (idx[menu->current]->content->encoding), sizeof (buf)); if (mutt_get_field ("Content-Transfer-Encoding: ", buf, sizeof (buf), 0) == 0 && buf[0]) { if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) { idx[menu->current]->content->encoding = i; menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; mutt_clear_error(); } else mutt_error _("Invalid encoding."); } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_SEND_MESSAGE: /* Note: We don't invoke send2-hook here, since we want to leave * users an opportunity to change settings from the ":" prompt. */ if(check_attachments(idx, idxlen) != 0) { menu->redraw = REDRAW_FULL; break; } #ifdef MIXMASTER if (msg->chain && mix_check_message (msg) != 0) break; #endif if (!fccSet && *fcc) { if ((i = query_quadoption (OPT_COPY, _("Save a copy of this message?"))) == -1) break; else if (i == M_NO) *fcc = 0; } loop = 0; r = 0; break; case OP_COMPOSE_EDIT_FILE: CHECK_COUNT; mutt_edit_file (NONULL(Editor), idx[menu->current]->content->filename); mutt_update_encoding (idx[menu->current]->content); menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_TOGGLE_UNLINK: CHECK_COUNT; idx[menu->current]->content->unlink = !idx[menu->current]->content->unlink; #if 0 /* OPTRESOLVE is otherwise ignored on this menu. * Where's the bug? */ if (option (OPTRESOLVE) && menu->current + 1 < menu->max) menu->current++; # endif menu->redraw = REDRAW_INDEX; /* No send2hook since this doesn't change the message. */ break; case OP_COMPOSE_GET_ATTACHMENT: CHECK_COUNT; if(menu->tagprefix) { BODY *top; for(top = msg->content; top; top = top->next) { if(top->tagged) mutt_get_tmp_attachment(top); } menu->redraw = REDRAW_FULL; } else if (mutt_get_tmp_attachment(idx[menu->current]->content) == 0) menu->redraw = REDRAW_CURRENT; /* No send2hook since this doesn't change the message. */ break; case OP_COMPOSE_RENAME_FILE: CHECK_COUNT; strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname)); mutt_pretty_mailbox (fname, sizeof (fname)); if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE) == 0 && fname[0]) { if (stat(idx[menu->current]->content->filename, &st) == -1) { /* L10N: "stat" is a system call. Do "man 2 stat" for more information. */ mutt_error (_("Can't stat %s: %s"), fname, strerror (errno)); break; } mutt_expand_path (fname, sizeof (fname)); if(mutt_rename_file (idx[menu->current]->content->filename, fname)) break; mutt_str_replace (&idx[menu->current]->content->filename, fname); menu->redraw = REDRAW_CURRENT; if(idx[menu->current]->content->stamp >= st.st_mtime) mutt_stamp_attachment(idx[menu->current]->content); } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_NEW_MIME: { char type[STRING]; char *p; int itype; FILE *fp; CLEARLINE (LINES-1); fname[0] = 0; if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE) != 0 || !fname[0]) continue; mutt_expand_path (fname, sizeof (fname)); /* Call to lookup_mime_type () ? maybe later */ type[0] = 0; if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0 || !type[0]) continue; if (!(p = strchr (type, '/'))) { mutt_error _("Content-Type is of the form base/sub"); continue; } *p++ = 0; if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) { mutt_error (_("Unknown Content-Type %s"), type); continue; } if (idxlen == idxmax) { safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5)); menu->data = idx; } idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); /* Touch the file */ if (!(fp = safe_fopen (fname, "w"))) { mutt_error (_("Can't create file %s"), fname); FREE (&idx[idxlen]); continue; } safe_fclose (&fp); if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) { mutt_error _("What we have here is a failure to make an attachment"); continue; } update_idx (menu, idx, idxlen++); idx[menu->current]->content->type = itype; mutt_str_replace (&idx[menu->current]->content->subtype, p); idx[menu->current]->content->unlink = 1; menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; if (mutt_compose_attachment (idx[menu->current]->content)) { mutt_update_encoding (idx[menu->current]->content); menu->redraw = REDRAW_FULL; } } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_MIME: CHECK_COUNT; if (mutt_edit_attachment (idx[menu->current]->content)) { mutt_update_encoding (idx[menu->current]->content); menu->redraw = REDRAW_FULL; } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_VIEW_ATTACH: case OP_DISPLAY_HEADERS: CHECK_COUNT; mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen, NULL, 0); menu->redraw = REDRAW_FULL; /* no send2hook, since this doesn't modify the message */ break; case OP_SAVE: CHECK_COUNT; mutt_save_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, NULL, menu); MAYBE_REDRAW (menu->redraw); /* no send2hook, since this doesn't modify the message */ break; case OP_PRINT: CHECK_COUNT; mutt_print_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content); /* no send2hook, since this doesn't modify the message */ break; case OP_PIPE: case OP_FILTER: CHECK_COUNT; mutt_pipe_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, op == OP_FILTER); if (op == OP_FILTER) /* cte might have changed */ menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT; menu->redraw |= REDRAW_STATUS; mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_EXIT: if ((i = query_quadoption (OPT_POSTPONE, _("Postpone this message?"))) == M_NO) { for (i = 0; i < idxlen; i++) if (idx[i]->unowned) idx[i]->content->unlink = 0; if (!(flags & M_COMPOSE_NOFREEHEADER)) { while (idxlen-- > 0) { /* avoid freeing other attachments */ idx[idxlen]->content->next = NULL; idx[idxlen]->content->parts = NULL; mutt_free_body (&idx[idxlen]->content); FREE (&idx[idxlen]->tree); FREE (&idx[idxlen]); } FREE (&idx); idxlen = 0; idxmax = 0; } r = -1; loop = 0; break; } else if (i == -1) break; /* abort */ /* fall through to postpone! */ case OP_COMPOSE_POSTPONE_MESSAGE: if(check_attachments(idx, idxlen) != 0) { menu->redraw = REDRAW_FULL; break; } loop = 0; r = 1; break; case OP_COMPOSE_ISPELL: endwin (); snprintf (buf, sizeof (buf), "%s -x %s", NONULL(Ispell), msg->content->filename); if (mutt_system (buf) == -1) mutt_error (_("Error running \"%s\"!"), buf); else { mutt_update_encoding (msg->content); menu->redraw |= REDRAW_STATUS; } break; case OP_COMPOSE_WRITE_MESSAGE: fname[0] = '\0'; if (Context) { strfcpy (fname, NONULL (Context->path), sizeof (fname)); mutt_pretty_mailbox (fname, sizeof (fname)); } if (idxlen) msg->content = idx[0]->content; if (mutt_enter_fname (_("Write message to mailbox"), fname, sizeof (fname), &menu->redraw, 1) != -1 && fname[0]) { mutt_message (_("Writing message to %s ..."), fname); mutt_expand_path (fname, sizeof (fname)); if (msg->content->next) msg->content = mutt_make_multipart (msg->content); if (mutt_write_fcc (fname, msg, NULL, 0, NULL) < 0) msg->content = mutt_remove_multipart (msg->content); else mutt_message _("Message written."); } break; case OP_COMPOSE_PGP_MENU: if (!(WithCrypto & APPLICATION_PGP)) break; if ((WithCrypto & APPLICATION_SMIME) && (msg->security & APPLICATION_SMIME)) { if (msg->security & (ENCRYPT | SIGN)) { if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "), M_YES) != M_YES) { mutt_clear_error (); break; } msg->security &= ~(ENCRYPT | SIGN); } msg->security &= ~APPLICATION_SMIME; msg->security |= APPLICATION_PGP; crypt_opportunistic_encrypt (msg); redraw_crypt_lines (msg); } msg->security = crypt_pgp_send_menu (msg, &menu->redraw); redraw_crypt_lines (msg); mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_FORGET_PASSPHRASE: crypt_forget_passphrase (); break; case OP_COMPOSE_SMIME_MENU: if (!(WithCrypto & APPLICATION_SMIME)) break; if ((WithCrypto & APPLICATION_PGP) && (msg->security & APPLICATION_PGP)) { if (msg->security & (ENCRYPT | SIGN)) { if (mutt_yesorno (_("PGP already selected. Clear & continue ? "), M_YES) != M_YES) { mutt_clear_error (); break; } msg->security &= ~(ENCRYPT | SIGN); } msg->security &= ~APPLICATION_PGP; msg->security |= APPLICATION_SMIME; crypt_opportunistic_encrypt (msg); redraw_crypt_lines (msg); } msg->security = crypt_smime_send_menu(msg, &menu->redraw); redraw_crypt_lines (msg); mutt_message_hook (NULL, msg, M_SEND2HOOK); break; #ifdef MIXMASTER case OP_COMPOSE_MIX: mix_make_chain (&msg->chain, &menu->redraw); mutt_message_hook (NULL, msg, M_SEND2HOOK); break; #endif } /* Draw formatted compose status line */ if (menu->redraw & REDRAW_STATUS) { compose_status_line (buf, sizeof (buf), 0, menu, NONULL(ComposeFormat)); move(option (OPTSTATUSONTOP) ? 0 : LINES-2, 0); SETCOLOR (MT_COLOR_STATUS); mutt_paddstr (COLS, buf); NORMAL_COLOR; menu->redraw &= ~REDRAW_STATUS; } } mutt_menuDestroy (&menu); if (idxlen) { msg->content = idx[0]->content; for (i = 0; i < idxlen; i++) { idx[i]->content->aptr = NULL; FREE (&idx[i]->tree); FREE (&idx[i]); } } else msg->content = NULL; FREE (&idx); return (r); }
int main() { int ch, x, y; char fname[80]; FILE *fp; bool entering_metadata = false; char to_delete; char existing; initscr(); cbreak(); noecho(); nonl(); intrflush(stdscr, false); keypad(stdscr, true); /* Enable arrow keys. */ getmaxyx(stdscr, ROW, COL); move(0,0); start_color(); /* Yay colors! */ init_pair(1, COLOR_RED, COLOR_WHITE); // attron(COLOR_PAIR(1)); // printw("rows: %d, columns: %d\n", ROW, COL); char** contents = new_string_table(ROW, COL); char* blank_row = (char*)malloc(COL*sizeof(char)); for (int i=0; i<COL; i++) { blank_row[i] = ' '; } getyx(stdscr, y, x); while (true) { ch = getch(); switch (ch) { case KEY_LEFT: x -= 1; break; case KEY_RIGHT: x += 1; break; case KEY_UP: y -= 1; break; case KEY_DOWN: y += 1; break; case BACKSPACE: /* KEY_BACKSPACE wasn't working. */ --x; move(y, x); to_delete = inch(); attron(COLOR_PAIR(1)); addch(to_delete); attroff(COLOR_PAIR(1)); break; case KEY_DC: //attron(COLOR_PAIR(1)); addch('X'); //attroff(COLOR_PAIR(1)); break; case ESC: ch = getch(); switch (ch) { case ESC: /* Press ESC twice to exit. */ endwin(); free(blank_row); delete_string_table(contents, ROW); return 0; break; case 'w': move(ROW-1, 0); printw("Enter a file name (up to 80 characters): "); echo(); if (getnstr(fname, 80) == ERR) { perror("Something went wrong reading the file name you gave."); } noecho(); fp = fopen(fname, "w"); if (fp == NULL) { perror("Cannot open file"); } contents_to_file(contents, fp, ROW, COL); fclose(fp); move(ROW-1, 0); printw(blank_row); break; default: break; } break; default: existing = contents[y][x]; //printw("%d", (int)existing); if (existing == '\0') { addch(ch); ensureposition(&y, &x); contents[y][x] = ch; ++x; } //getyx(stdscr, y, x); break; } ensureposition(&y, &x); move(y, x); } }
int main() { ITEM **my_items; int c; MENU *my_menu; int n_choices, i; ITEM *cur_item; /* Initialize curses */ initscr(); start_color(); cbreak(); noecho(); keypad(stdscr, TRUE); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_MAGENTA, COLOR_BLACK); /* Initialize items */ n_choices = ARRAY_SIZE(choices); my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); for(i = 0; i < n_choices; ++i) { my_items[i] = new_item(choices[i], choices[i]); /* Set the user pointer */ set_item_userptr(my_items[i], func); } my_items[n_choices] = (ITEM *)NULL; /* Create menu */ my_menu = new_menu((ITEM **)my_items); /* Post the menu */ mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected"); mvprintw(LINES - 2, 0, "Up and Down arrow keys to naviage (F1 to Exit)"); post_menu(my_menu); refresh(); while((c = getch()) != KEY_F(1)) { switch(c) { case KEY_DOWN: menu_driver(my_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(my_menu, REQ_UP_ITEM); break; case 10: /* Enter */ { ITEM *cur; void (*p)(char *); cur = current_item(my_menu); p = item_userptr(cur); p((char *)item_name(cur)); pos_menu_cursor(my_menu); break; } break; } } unpost_menu(my_menu); for(i = 0; i < n_choices; ++i) free_item(my_items[i]); free_menu(my_menu); endwin(); }
void display_end(void) { endwin(); }
/* * Display a dialog box with a list of options that can be turned on or off * in the style of radiolist (only one option turned on at a time). */ int dialog_checklist(const char *title, const char *prompt, int height, int width, int list_height, int item_no, const char *const *items) { int i, x, y, box_x, box_y; int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status; WINDOW *dialog, *list; /* Allocate space for storing item on/off status */ if ((status = malloc(sizeof(int) * item_no)) == NULL) { endwin(); fprintf(stderr, "\nCan't allocate memory in dialog_checklist().\n"); exit(-1); } /* Initializes status */ for (i = 0; i < item_no; i++) { status[i] = !strcasecmp(items[i * 3 + 2], "on"); if ((!choice && status[i]) || !strcasecmp(items[i * 3 + 2], "selected")) choice = i + 1; } if (choice) choice--; max_choice = MIN(list_height, item_no); /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); wattrset(dialog, border_attr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dialog_attr); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, width - 2, 1, 3); list_width = width - 6; box_y = height - list_height - 5; box_x = (width - list_width) / 2 - 1; /* create new window for the list */ list = subwin(dialog, list_height, list_width, y + box_y + 1, x + box_x + 1); keypad(list, TRUE); /* draw a box around the list items */ draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2, menubox_border_attr, menubox_attr); /* Find length of longest item in order to center checklist */ check_x = 0; for (i = 0; i < item_no; i++) check_x = MAX(check_x, +strlen(items[i * 3 + 1]) + 4); check_x = (list_width - check_x) / 2; item_x = check_x + 4; if (choice >= list_height) { scroll = choice - list_height + 1; choice -= scroll; } /* Print the list */ for (i = 0; i < max_choice; i++) { print_item(list, items[(scroll + i) * 3 + 1], status[i + scroll], i, i == choice); } print_arrows(dialog, choice, item_no, scroll, box_y, box_x + check_x + 5, list_height); print_buttons(dialog, height, width, 0); wnoutrefresh(dialog); wnoutrefresh(list); doupdate(); while (key != ESC) { key = wgetch(dialog); for (i = 0; i < max_choice; i++) if (toupper(key) == toupper(items[(scroll + i) * 3 + 1][0])) break; if (i < max_choice || key == KEY_UP || key == KEY_DOWN || key == '+' || key == '-') { if (key == KEY_UP || key == '-') { if (!choice) { if (!scroll) continue; /* Scroll list down */ if (list_height > 1) { /* De-highlight current first item */ print_item(list, items[scroll * 3 + 1], status[scroll], 0, FALSE); scrollok(list, TRUE); wscrl(list, -1); scrollok(list, FALSE); } scroll--; print_item(list, items[scroll * 3 + 1], status[scroll], 0, TRUE); print_arrows(dialog, choice, item_no, scroll, box_y, box_x + check_x + 5, list_height); wnoutrefresh(dialog); wrefresh(list); continue; /* wait for another key press */ } else i = choice - 1; } else if (key == KEY_DOWN || key == '+') { if (choice == max_choice - 1) { if (scroll + choice >= item_no - 1) continue; /* Scroll list up */ if (list_height > 1) { /* De-highlight current last item before scrolling up */ print_item(list, items[(scroll + max_choice - 1) * 3 + 1], status[scroll + max_choice - 1], max_choice - 1, FALSE); scrollok(list, TRUE); wscrl(list, 1); scrollok(list, FALSE); } scroll++; print_item(list, items[(scroll + max_choice - 1) * 3 + 1], status[scroll + max_choice - 1], max_choice - 1, TRUE); print_arrows(dialog, choice, item_no, scroll, box_y, box_x + check_x + 5, list_height); wnoutrefresh(dialog); wrefresh(list); continue; /* wait for another key press */ } else i = choice + 1; } if (i != choice) { /* De-highlight current item */ print_item(list, items[(scroll + choice) * 3 + 1], status[scroll + choice], choice, FALSE); /* Highlight new item */ choice = i; print_item(list, items[(scroll + choice) * 3 + 1], status[scroll + choice], choice, TRUE); wnoutrefresh(dialog); wrefresh(list); } continue; /* wait for another key press */ } switch (key) { case 'H': case 'h': case '?': fprintf(stderr, "%s", items[(scroll + choice) * 3]); delwin(dialog); free(status); return 1; case TAB: case KEY_LEFT: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(dialog); break; case 'S': case 's': case ' ': case '\n': if (!button) { if (!status[scroll + choice]) { for (i = 0; i < item_no; i++) status[i] = 0; status[scroll + choice] = 1; for (i = 0; i < max_choice; i++) print_item(list, items[(scroll + i) * 3 + 1], status[scroll + i], i, i == choice); } wnoutrefresh(dialog); wrefresh(list); for (i = 0; i < item_no; i++) if (status[i]) fprintf(stderr, "%s", items[i * 3]); } else fprintf(stderr, "%s", items[(scroll + choice) * 3]); delwin(dialog); free(status); return button; case 'X': case 'x': key = ESC; case ESC: break; } /* Now, update everything... */ doupdate(); } delwin(dialog); free(status); return -1; /* ESC pressed */ }
int main() { int ch; char body = '='; int MaxX, MaxY; int curx, cury, oldx, oldy, randX, randY; randX = randY = -1; int FOOD = 0; int GAME = 1; int snk_len = 1; snk = (struct snake *)malloc(sizeof(struct snake)); snk->next = NULL; initscr(); /* Start curses mode */ curs_set(0); raw(); /* Line buffering disabled */ noecho(); /* Don't echo() while we do getch */ keypad(stdscr, TRUE); /* We get F1, F2 etc.. */ getmaxyx(stdscr, MaxX, MaxY); curx = MaxX/2; cury = MaxY/2-6; //curx = 10; //cury = 10; snk->x = curx; snk->y = cury; mvprintw(curx, cury, "%c",body); while(1) { ch = wgetch(stdscr); oldx = snk->x; oldy = snk->y; switch(ch) { case KEY_UP: temp = snk; prev = NULL; while(temp->next) { temp->x = temp->next->x; temp->y = temp->next->y; prev = temp; temp = temp->next; } if ( temp->x > 0 ) { // if (!prev || (prev->x != temp->x-1 && prev->y != temp->y)) // { curx--; temp->x = temp->x - 1; // } } else GAME = 0; break; case KEY_DOWN: temp = snk; prev = NULL; while(temp->next) { temp->x = temp->next->x; temp->y = temp->next->y; prev = temp; temp = temp->next; } if ( temp->x < MaxX-1 ) { // if (!prev || (prev->x != temp->x+1 && prev->y != temp->y)) // { curx++; temp->x = temp->x + 1; // } } else GAME = 0; break; case KEY_RIGHT: temp = snk; prev = NULL; while(temp->next) { temp->x = temp->next->x; temp->y = temp->next->y; prev = temp; temp = temp->next; } if ( temp->y < MaxY-1 ) { // if (!prev || (prev->y != temp->y+1 && prev->x != temp->x)) // { cury++; temp->y = temp->y + 1; // } } else GAME = 0; break; case KEY_LEFT: temp = snk; prev = NULL; while(temp->next) { temp->x = temp->next->x; temp->y = temp->next->y; prev = temp; temp = temp->next; } if ( temp->y > 0 ) { // if (!prev || (prev->y != temp->y+1 && prev->x != temp->x)) // { cury--; temp->y = temp->y - 1; // } } else GAME = 0; break; default: break; } if ( ch == 'Q' || ch == 'q' ) break; temp = snk; while(temp->next) { if ( temp->x == curx && temp->y == cury ) { GAME = 0; break; } temp = temp->next; } if ( GAME == 0 ) { start_color(); init_pair(1, COLOR_RED, COLOR_BLACK); attron(COLOR_PAIR(1)); mvprintw(MaxX/2, MaxY/2-6, "GAME OVER"); while(1) { ch = wgetch(stdscr); if ( ch == 'q' || ch == 'Q' ) break; } break; } mvprintw(oldx, oldy, " "); temp = snk; while(temp) { mvprintw(temp->x, temp->y, "="); temp = temp->next; } if ( curx == randX && cury == randY ) { snk_len++; temp = (struct snake *)malloc(sizeof(struct snake)); temp->x = oldx; temp->y = oldy; temp->next = snk; snk = temp; FOOD = 0; } if (!FOOD) { srand ( time(NULL) ); randX = rand()%MaxX; srand ( time(NULL) ); randY = rand()%MaxY; mvprintw(randX, randY, "$"); FOOD = 1; } } refresh(); /* Print it on to the real screen */ endwin(); /* End curses mode */ while(snk) { temp = snk; snk = snk->next; temp->next = NULL; free(temp); } return 0; }
int main() { //cria um objeto da classe Jogo Jogo j; j.iniciaJogo(); //inicia o jogo apenas montando o cenario int op=0; int tecla=0; //apresenta o menu while(op!=3){ cout << "--------------------------------" << endl; cout << "(1) Jogar ; " << endl; cout << "(2) Testar ; " << endl; cout << "(3) Sair." << endl; cout << "--------------------------------" << endl; cout << "Informe uma opcao:" << endl; cin >> op; switch (op) { //operacao JOGAR case 1: //apresenta os comandos validos do jogo cout << "Movimentos validos <cima> <baixo> <esquerda> e <direita>" << endl; cout << "Para sair do jogo pressione <ESC>" << endl << endl; //apresenta a tela atual j.mostrarTelaAtual(); do { initscr(); keypad(stdscr, true); tecla= getch(); endwin(); cout << tecla << endl; //joga de acordo com a tecla apertada switch (tecla) { case 72: //move o bloco para cima j.jogar('C'); break; case 80: //move o bloco para baixo j.jogar('B'); break; case 77: //move o bloco para a direita j.jogar('D'); break; case 75: //move o bloco para a esquerdas j.jogar('E'); break; } //passa de fase verificando a vitoria a cada nivel if (j.getFaseAtual()<7){ if (j.verificaVitoria()) { j.passarFase(); } else if (j.verificaDerrota()){ j.reiniciaJogo(); } } //faz a funcao ate que a tecla <esc> seja pressionada } while (tecla != 27); break; //operacao TESTAR case 2: //testa o jogo com os movimentos passados no final do arquivo da fase for (int i=0 ; i<7 ; i++){ j.testarJogo(); cout << "pressione uma tecla para continuar" << endl; tecla=getch(); if (j.getFaseAtual()<7) j.passarFase(); } cout << "teste do jogo completo." << endl; break; //sai do jogo case 3: break;//exit(0); } } return 0; }
static void tstp(int dummy GCC_UNUSED) { sigset_t mask, omask; sigaction_t act, oact; #ifdef SIGTTOU int sigttou_blocked; #endif T(("tstp() called")); /* * The user may have changed the prog_mode tty bits, so save them. * * But first try to detect whether we still are in the foreground * process group - if not, an interactive shell may already have * taken ownership of the tty and modified the settings when our * parent was stopped before us, and we would likely pick up the * settings already modified by the shell. */ if (SP != 0 && !SP->_endwin) /* don't do this if we're not in curses */ #if HAVE_TCGETPGRP if (tcgetpgrp(STDIN_FILENO) == getpgrp()) #endif def_prog_mode(); /* * Block window change and timer signals. The latter * is because applications use timers to decide when * to repaint the screen. */ (void) sigemptyset(&mask); (void) sigaddset(&mask, SIGALRM); #if USE_SIGWINCH (void) sigaddset(&mask, SIGWINCH); #endif (void) sigprocmask(SIG_BLOCK, &mask, &omask); #ifdef SIGTTOU sigttou_blocked = sigismember(&omask, SIGTTOU); if (!sigttou_blocked) { (void) sigemptyset(&mask); (void) sigaddset(&mask, SIGTTOU); (void) sigprocmask(SIG_BLOCK, &mask, NULL); } #endif /* * End window mode, which also resets the terminal state to the * original (pre-curses) modes. */ endwin(); /* Unblock SIGTSTP. */ (void) sigemptyset(&mask); (void) sigaddset(&mask, SIGTSTP); #ifdef SIGTTOU if (!sigttou_blocked) { /* Unblock this too if it wasn't blocked on entry */ (void) sigaddset(&mask, SIGTTOU); } #endif (void) sigprocmask(SIG_UNBLOCK, &mask, NULL); /* Now we want to resend SIGSTP to this process and suspend it */ act.sa_handler = SIG_DFL; sigemptyset(&act.sa_mask); act.sa_flags = 0; #ifdef SA_RESTART act.sa_flags |= SA_RESTART; #endif /* SA_RESTART */ sigaction(SIGTSTP, &act, &oact); kill(getpid(), SIGTSTP); /* Process gets suspended...time passes...process resumes */ T(("SIGCONT received")); sigaction(SIGTSTP, &oact, NULL); flushinp(); /* * If the user modified the tty state while suspended, he wants * those changes to stick. So save the new "default" terminal state. */ def_shell_mode(); /* * This relies on the fact that doupdate() will restore the * program-mode tty state, and issue enter_ca_mode if need be. */ doupdate(); /* Reset the signals. */ (void) sigprocmask(SIG_SETMASK, &omask, NULL); }
int main() { initscr(); struct player { char *name; unsigned short age; unsigned short health; unsigned int level; unsigned short location; unsigned short active; unsigned short inventory[50]; }; char input[25] = ""; struct player *main_character = NULL; main_character = malloc(sizeof(struct player)); main_character -> level = 1; main_character -> location = 0; main_character -> health = 100; main_character -> active = 1; for (unsigned short i = 0; i < 50; i++) { main_character -> inventory[i] = 0; } main_character -> name = malloc(sizeof(char) * 15); printw("What is your name? (Maximum of 15 characters)\n"); getstr(main_character -> name); refresh(); printw("Welcome, %s\n", main_character -> name); refresh(); while (main_character -> active == 1) { if (main_character -> location == 0) { printw("You are in a dark room. There is a door to the north.\n"); refresh(); scanw("%s", &input); if (strncmp(input, "north", 5) == 0 || strncmp(input, "n", 1) == 0) { printw("You walk through the doorway.\n"); refresh(); main_character -> location = 1; } if (strncmp(input, "exit", 4) == 0 || strncmp(input, "quit", 4) == 0) { printw("Exiting game..."); refresh(); main_character -> active = 0; } } if (main_character -> location == 1) { printw("You are now in a hallway. There is a light to the west.\n"); refresh(); scanw("%s", &input); if (strncmp(input, "west", 4) == 0 || strncmp(input, "w", 1) == 0) { printw("You are free.\n"); refresh(); main_character -> active = 0; } } } printw("Game over. Press any key to quit.\n"); refresh(); getch(); endwin(); return 0; }
//退出屏幕函数 void exit_graphics(void) { endwin(); }
/* * This function gets called just * before we go back home to the shell. Put all of * the terminal parameters back. */ void ttclose (void) { endwin (); tcsetattr (0, TCSANOW, &oldtty); }
static void die(int onsig) { signal(onsig, SIG_IGN); endwin(); exit(0); }
void Draft::makeBoard(Team *arr, vector<NodeData*>& a, int teams) { int sY = 8, sX = 0, w = 14, h = 4, ch, j = 0, z = 0; string tName; WINDOW *board[BOARD_SIZE]; //timer + players + menu + roster + titles + title + teams(2) //ar[34] arr[33] ar[32] ar[31] arr[20-29] ar[30] ar[0-19] initscr(); //start curses cbreak(); //line buffer off keypad(stdscr, TRUE); //to use f1 printw("Press cntr+c to exit"); //print refresh(); //output board[TITLE] = createWin(4, 100, 1, 0); //title wattron(board[TITLE], A_BOLD); mvwprintw(board[TITLE], 1, 10, "John Zoeller Draft"); //print T wrefresh(board[TITLE]); //output board[34] = createWin(4, 40, 1, 101); //timer wattron(board[34], A_BOLD); mvwprintw(board[34], 1, 1, "ROUND"); //print time wrefresh(board[34]); //output for(int k = 0; k < 10; k++){ //team names board[k + 20] = createWin(3, 14, 5, (sX + (w * k))); wattron(board[k + 20], A_BOLD); if(arr[k].getUser()){ tName = to_string(arr[k].getPosition()) + " " + arr[k].getName(); wattron(board[k + 20], A_UNDERLINE); } else tName = to_string(k + 1) + " Auto"; mvwprintw(board[k + 20], 1, 1, tName.c_str()); wrefresh(board[k + 20]); } for(int i = 0; i < 10; i++) board[i] = createWin(h, w, (sY + (h * j)), (sX + (w * i))); j++; for(int a = 19; a >= 10; a--){ board[a] = createWin(h, w, (sY + (h * j)), (sX + (w * z))); z++; } int dims[] = { 22, 45, 16, 0 }; makeWindow("PLAYERS", dims, PLAYERS_AVAILABLE); board[33] = createWin(22, 45, 16, 0); //players wattron(board[33], A_BOLD); mvwprintw(board[33], 1, 1, "PLAYERS"); //print title wattroff(board[33], A_BOLD); wrefresh(board[33]); //output board[32] = createWin(10, 45, 16, 46); //menu wattron(board[32], A_BOLD); mvwprintw(board[32], 1, 1, "MENU"); //print title wattroff(board[32], A_BOLD); wrefresh(board[32]); //output board[31] = createWin(22, 45, 16, 92); //roster wattron(board[31], A_BOLD); mvwprintw(board[31], 1, 1, "MY ROSTER"); //print title wattroff(board[31], A_BOLD); wrefresh(board[31]); //output while((ch = getch()) != KEY_F(1)){ //drafting startDraft(arr, a, teams, board); } for(int i = 0; i < 35; i++){ //delete windows if(board[i] != NULL) destroy_win(board[i]); } endwin(); }
void con_done() { delwin(conio_scr); endwin(); }
bool game::opening_screen() { std::map<std::string, WORLDPTR> worlds; if (world_generator) { world_generator->set_active_world(NULL); worlds = world_generator->get_all_worlds(); } WINDOW *w_background = newwin(TERMY, TERMX, 0, 0); werase(w_background); wrefresh(w_background); // main window should also expand to use available display space. // expanding to evenly use up half of extra space, for now. int extra_w = ((TERMX - FULL_SCREEN_WIDTH) / 2) - 1; int extra_h = ((TERMY - FULL_SCREEN_HEIGHT) / 2) - 1; extra_w = (extra_w > 0 ? extra_w : 0); extra_h = (extra_h > 0 ? extra_h : 0); const int total_w = FULL_SCREEN_WIDTH + extra_w; const int total_h = FULL_SCREEN_HEIGHT + extra_h; // position of window within main display const int x0 = (TERMX - total_w) / 2; const int y0 = (TERMY - total_h) / 2; WINDOW *w_open = newwin(total_h, total_w, y0, x0); const int iMenuOffsetX = 2; int iMenuOffsetY = total_h - 3; std::vector<std::string> vSubItems; vSubItems.push_back(pgettext("Main Menu|New Game", "<C>ustom Character")); vSubItems.push_back(pgettext("Main Menu|New Game", "<P>reset Character")); vSubItems.push_back(pgettext("Main Menu|New Game", "<R>andom Character")); vSubItems.push_back(pgettext("Main Menu|New Game", "Play <N>ow!")); std::vector<std::string> vWorldSubItems; vWorldSubItems.push_back(pgettext("Main Menu|World", "<C>reate World")); vWorldSubItems.push_back(pgettext("Main Menu|World", "<D>elete World")); vWorldSubItems.push_back(pgettext("Main Menu|World", "<R>eset World")); print_menu(w_open, 0, iMenuOffsetX, iMenuOffsetY); std::vector<std::string> savegames, templates; dirent *dp; DIR *dir; dir = opendir("save"); if (!dir){ #if (defined _WIN32 || defined __WIN32__) mkdir("save"); #else mkdir("save", 0777); #endif dir = opendir("save"); } if (!dir) { dbg(D_ERROR) << "game:opening_screen: Unable to make save directory."; debugmsg("Could not make './save' directory"); endwin(); exit(1); } closedir(dir); dir = opendir("data"); while ((dp = readdir(dir))) { std::string tmp = dp->d_name; if (tmp.find(".template") != std::string::npos) { templates.push_back(tmp.substr(0, tmp.find(".template"))); } } closedir(dir); int sel1 = 1, sel2 = 1, sel3 = 1, layer = 1; InputEvent input; int chInput; bool start = false; // Load MOTD and store it in a string // Only load it once, it shouldn't change for the duration of the application being open static std::vector<std::string> motd; if (motd.empty()) { std::ifstream motd_file; motd_file.open("data/motd"); if (!motd_file.is_open()) { motd.push_back(_("No message today.")); } else { while (!motd_file.eof()) { std::string tmp; getline(motd_file, tmp); if (!tmp.length() || tmp[0] != '#') { motd.push_back(tmp); } } } } // Load Credits and store it in a string // Only load it once, it shouldn't change for the duration of the application being open static std::vector<std::string> credits; if (credits.empty()) { std::ifstream credits_file; credits_file.open("data/credits"); if (!credits_file.is_open()) { credits.push_back(_("No message today.")); } else { while (!credits_file.eof()) { std::string tmp; getline(credits_file, tmp); if (!tmp.length() || tmp[0] != '#') { credits.push_back(tmp); } } } } u = player(); while(!start) { if (layer == 1) { print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY, (sel1 == 0 || sel1 == 7) ? false : true); if (sel1 == 0) { // Print the MOTD. for (int i = 0; i < motd.size() && i < 16; i++) { mvwprintz(w_open, i + 6, 8 + extra_w / 2, c_ltred, motd[i].c_str()); } wrefresh(w_open); refresh(); } else if (sel1 == 7) { // Print the Credits. for (int i = 0; i < credits.size() && i < 16; i++) { mvwprintz(w_open, i + 6, 8 + extra_w / 2, c_ltred, credits[i].c_str()); } wrefresh(w_open); refresh(); } chInput = getch(); if (chInput == 'm' || chInput == 'M') { // MOTD sel1 = 0; chInput = '\n'; } else if (chInput == 'n' || chInput == 'N') { // New Game sel1 = 1; chInput = '\n'; } else if (chInput == 'a' || chInput == 'A') { // Load Game sel1 = 2; chInput = '\n'; } else if (chInput == 'w' || chInput == 'W') { // World sel1 = 3; chInput = '\n'; } else if (chInput == 's' || chInput == 'S') { // Special Game sel1 = 4; chInput = '\n'; } else if (chInput == 'o' || chInput == 'O') { // Options sel1 = 5; chInput = '\n'; } else if (chInput == 'e' || chInput == 'E' || chInput == '?') { // Help sel1 = 6; chInput = '\n'; } else if (chInput == 'c' || chInput == 'C') { // Credits sel1 = 7; chInput = '\n'; } else if (chInput == 'q' || chInput == 'Q' || chInput == KEY_ESCAPE) { // Quit sel1 = 8; chInput = '\n'; } if (chInput == KEY_LEFT || chInput == 'h') { if (sel1 > 0) { sel1--; } else { sel1 = 8; } } else if (chInput == KEY_RIGHT || chInput == 'l') { if (sel1 < 8) { sel1++; } else { sel1 = 0; } } else if ((chInput == KEY_UP || chInput == 'k' || chInput == '\n') && sel1 > 0 && sel1 != 7) { if (sel1 == 5) { show_options(); } else if (sel1 == 6) { display_help(); } else if (sel1 == 8) { uquit = QUIT_MENU; delwin(w_open); delwin(w_background); return false; } else { sel2 = 0; layer = 2; print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY, (sel1 == 0 || sel1 == 7) ? false : true); } } } else if (layer == 2) { if (sel1 == 1) { // New Character print_menu_items(w_open, vSubItems, sel2, iMenuOffsetY - 2, iMenuOffsetX); wrefresh(w_open); refresh(); chInput = getch(); if (chInput == 'c' || chInput == 'C') { sel2 = 0; chInput = '\n' ; } else if (chInput == 'p' || chInput == 'P') { sel2 = 1; chInput = '\n'; } else if (chInput == 'r' || chInput == 'R') { sel2 = 2; chInput = '\n'; } else if (chInput == 'n' || chInput == 'N') { sel2 = 3; chInput = '\n'; } if (chInput == KEY_LEFT || chInput == 'h') { sel2--; if (sel2 < 0) { sel2 = vSubItems.size() - 1; } } if (chInput == KEY_RIGHT || chInput == 'l') { sel2++; if (sel2 >= vSubItems.size()) { sel2 = 0; } } else if (chInput == KEY_DOWN || chInput == 'j' || chInput == KEY_ESCAPE) { layer = 1; sel1 = 1; } if (chInput == KEY_UP || chInput == 'k' || chInput == '\n') { if (sel2 == 0 || sel2 == 2 || sel2 == 3) { setup(); if (!u.create((sel2 == 0) ? PLTYPE_CUSTOM : ((sel2 == 2) ? PLTYPE_RANDOM : PLTYPE_NOW))) { u = player(); delwin(w_open); return (opening_screen()); } // Pick a world, supressing prompts if it's "play now" mode. WORLDPTR world = world_generator->pick_world( sel2 != 3 ); if (!world) { u = player(); delwin(w_open); return opening_screen(); } else { world_generator->set_active_world(world); } werase(w_background); wrefresh(w_background); load_artifacts(world->world_path + "/artifacts.gsav", itypes); MAPBUFFER.load(world->world_name); start_game(world->world_name); start = true; } else if (sel2 == 1) { layer = 3; sel3 = 0; } } } else if (sel1 == 2) { // Load Character if (world_generator->all_worldnames.empty()) { mvwprintz(w_open, iMenuOffsetY - 2, 15 + iMenuOffsetX + extra_w / 2, c_red, _("No Worlds found!")); } else { for (int i = 0; i < world_generator->all_worldnames.size(); ++i) { int line = iMenuOffsetY - 2 - i; std::string world_name = world_generator->all_worldnames[i]; int savegames_count = world_generator->all_worlds[world_name]->world_saves.size(); mvwprintz(w_open, line, 15 + iMenuOffsetX + extra_w / 2, (sel2 == i ? h_white : c_white), "%s (%d)", world_name.c_str(), savegames_count); } } wrefresh(w_open); refresh(); input = get_input(); if (world_generator->all_worldnames.empty() && (input == DirectionS || input == Confirm)) { layer = 1; } else if (input == DirectionS) { if (sel2 > 0) { sel2--; } else { sel2 = world_generator->all_worldnames.size() - 1; } } else if (input == DirectionN) { if (sel2 < world_generator->all_worldnames.size() - 1) { sel2++; } else { sel2 = 0; } } else if (input == DirectionW || input == Cancel) { layer = 1; } if (input == DirectionE || input == Confirm) { if (sel2 >= 0 && sel2 < world_generator->all_worldnames.size()) { layer = 3; sel3 = 0; } } } else if (sel1 == 3) { // World Menu // Show options for Create, Destroy, Reset worlds. // Create world goes directly to Make World screen. // Reset and Destroy ask for world to modify. // Reset empties world of everything but options, then makes new world within it. // Destroy asks for confirmation, then destroys everything in world and then removes world folder. // only show reset / destroy world if there is at least one valid world existing! int world_subs_to_display = (world_generator->all_worldnames.size() > 0)? vWorldSubItems.size(): 1; std::vector<std::string> world_subs; int xoffset = 25 + iMenuOffsetX + extra_w / 2; int yoffset = iMenuOffsetY - 2; int xlen = 0; for (int i = 0; i < world_subs_to_display; ++i) { world_subs.push_back(vWorldSubItems[i]); xlen += vWorldSubItems[i].size() + 2; // Open and close brackets added } xlen += world_subs.size() - 1; if (world_subs.size() > 1) { xoffset -= 6; } print_menu_items(w_open, world_subs, sel2, yoffset, xoffset - (xlen / 4)); wrefresh(w_open); refresh(); input = get_input(); if (input == DirectionW) { if (sel2 > 0) { --sel2; } else { sel2 = world_subs_to_display - 1; } } else if (input == DirectionE) { if (sel2 < world_subs_to_display - 1) { ++sel2; } else { sel2 = 0; } } else if (input == DirectionS || input == Cancel) { layer = 1; } if (input == DirectionN || input == Confirm) { if (sel2 == 0) { // Create world // Open up world creation screen! if (world_generator->make_new_world()) { return opening_screen(); } else { layer = 1; } } else if (sel2 == 1 || sel2 == 2) { // Delete World | Reset World layer = 3; sel3 = 0; } } } else if (sel1 == 4) { // Special game std::vector<std::string> special_names; int xoffset = 32 + iMenuOffsetX + extra_w / 2; int yoffset = iMenuOffsetY - 2; int xlen = 0; for (int i = 1; i < NUM_SPECIAL_GAMES; i++) { std::string spec_name = special_game_name(special_game_id(i)); special_names.push_back(spec_name); xlen += spec_name.size() + 2; } xlen += special_names.size() - 1; print_menu_items(w_open, special_names, sel2, yoffset, xoffset - (xlen / 4)); wrefresh(w_open); refresh(); input = get_input(); if (input == DirectionW) { if (sel2 > 0) { sel2--; } else { sel2 = NUM_SPECIAL_GAMES - 2; } } else if (input == DirectionE) { if (sel2 < NUM_SPECIAL_GAMES - 2) { sel2++; } else { sel2 = 0; } } else if (input == DirectionS || input == Cancel) { layer = 1; } if (input == DirectionN || input == Confirm) { if (sel2 >= 0 && sel2 < NUM_SPECIAL_GAMES - 1) { delete gamemode; gamemode = get_special_game( special_game_id(sel2 + 1) ); // check world WORLDPTR world = world_generator->make_new_world(special_game_id(sel2 + 1)); if (world) { world_generator->set_active_world(world); setup(); } if (world == NULL || !gamemode->init()) { delete gamemode; gamemode = new special_game; u = player(); delwin(w_open); return (opening_screen()); } load_artifacts(world->world_path + "/artifacts.gsav", itypes); start = true; } } } } else if (layer == 3) { if (sel1 == 2) { // Load Game savegames = world_generator->all_worlds[world_generator->all_worldnames[sel2]]->world_saves; if (savegames.empty()) { mvwprintz(w_open, iMenuOffsetY - 2, 19 + 19 + iMenuOffsetX + extra_w / 2, c_red, _("No save games found!")); } else { for (int i = 0; i < savegames.size(); i++) { int line = iMenuOffsetY - 2 - i; mvwprintz(w_open, line, 19 + 19 + iMenuOffsetX + extra_w / 2, (sel3 == i ? h_white : c_white), base64_decode(savegames[i]).c_str()); } } wrefresh(w_open); refresh(); input = get_input(); if (savegames.size() == 0 && (input == DirectionS || input == Confirm)) { layer = 2; } else if (input == DirectionS) { if (sel3 > 0) { sel3--; } else { sel3 = savegames.size() - 1; } } else if (input == DirectionN) { if (sel3 < savegames.size() - 1) { sel3++; } else { sel3 = 0; } } else if (input == DirectionW || input == Cancel) { layer = 2; sel3 = 0; print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY); } if (input == DirectionE || input == Confirm) { if (sel3 >= 0 && sel3 < savegames.size()) { werase(w_background); wrefresh(w_background); WORLDPTR world = world_generator->all_worlds[world_generator->all_worldnames[sel2]]; world_generator->set_active_world(world); load_artifacts(world->world_path + "/artifacts.gsav", itypes); MAPBUFFER.load(world->world_name); setup(); load(world->world_name, savegames[sel3]); start = true; } } } else if (sel1 == 3) { // Show world names int i = 0; for (std::vector<std::string>::iterator it = world_generator->all_worldnames.begin(); it != world_generator->all_worldnames.end(); ++it) { int savegames_count = world_generator->all_worlds[*it]->world_saves.size(); int line = iMenuOffsetY - 4 - i; mvwprintz(w_open, line, 26 + iMenuOffsetX + extra_w / 2, (sel3 == i ? h_white : c_white), "%s (%d)", (*it).c_str(), savegames_count); ++i; } wrefresh(w_open); refresh(); input = get_input(); if (input == DirectionS) { if (sel3 > 0) { --sel3; } else { sel3 = world_generator->all_worldnames.size() - 1; } } else if (input == DirectionN) { if (sel3 < world_generator->all_worldnames.size() - 1) { ++sel3; } else { sel3 = 0; } } else if (input == DirectionW || input == Cancel) { layer = 2; print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY); } if (input == DirectionE || input == Confirm) { if (sel3 >= 0 && sel3 < world_generator->all_worldnames.size()) { bool query_yes = false; bool do_delete = false; if (sel2 == 1) { // Delete World if (query_yn(_("Delete the world and all saves?"))) { query_yes = true; do_delete = true; } } else if (sel2 == 2) { // Reset World if (query_yn(_("Remove all saves and regenerate world?"))) { query_yes = true; do_delete = false; } } if (query_yes) { delete_world(world_generator->all_worldnames[sel3], do_delete); savegames.clear(); MAPBUFFER.reset(); MAPBUFFER.make_volatile(); overmap_buffer.clear(); layer = 2; if (do_delete) { // delete world and all contents world_generator->remove_world(world_generator->all_worldnames[sel3]); } else { // clear out everything but worldoptions from this world world_generator->all_worlds[world_generator->all_worldnames[sel3]]->world_saves.clear(); } if (world_generator->all_worldnames.size() == 0) { sel2 = 0; // reset to create world selection } } else { // hacky resolution to the issue of persisting world names on the screen return opening_screen(); } } print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY); } } else { // Character Templates if (templates.size() == 0) { mvwprintz(w_open, iMenuOffsetY - 4, iMenuOffsetX + 20 + extra_w / 2, c_red, _("No templates found!")); } else { for (int i = 0; i < templates.size(); i++) { int line = iMenuOffsetY - 4 - i; mvwprintz(w_open, line, 20 + iMenuOffsetX + extra_w / 2, (sel3 == i ? h_white : c_white), templates[i].c_str()); } } wrefresh(w_open); refresh(); input = get_input(); if (input == DirectionS) { if (sel3 > 0) { sel3--; } else { sel3 = templates.size() - 1; } } else if (templates.size() == 0 && (input == DirectionN || input == Confirm)) { sel1 = 1; layer = 2; print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY); } else if (input == DirectionN) { if (sel3 < templates.size() - 1) { sel3++; } else { sel3 = 0; } } else if (input == DirectionW || input == Cancel || templates.size() == 0) { sel1 = 1; layer = 2; print_menu(w_open, sel1, iMenuOffsetX, iMenuOffsetY); } else if (input == DirectionE || input == Confirm) { setup(); if (!u.create(PLTYPE_TEMPLATE, templates[sel3])) { u = player(); delwin(w_open); return (opening_screen()); } // check world WORLDPTR world = world_generator->pick_world(); if (!world) { u = player(); delwin(w_open); return (opening_screen()); } else { world_generator->set_active_world(world); } werase(w_background); wrefresh(w_background); std::string artfilename = world_generator->active_world->world_path + "/artifacts.gsav"; load_artifacts(artfilename, itypes); MAPBUFFER.load(world_generator->active_world->world_name); start_game(world_generator->active_world->world_name); start = true; } } } } delwin(w_open); delwin(w_background); if (start == false) { uquit = QUIT_MENU; } else { refresh_all(); draw(); } return start; }
/** Curses window finalization. */ static void tty_restore(void) { if (!b_interactive) return; endwin(); }
~DisplayManager() { endwin(); }
void get_command(void) { char com[255]; int text_width, text_startx; allocated_block_t *allocated_block = NULL; int i = 0; int count = 0; WINDOW *command_win = NULL; List allocated_blocks = NULL; ListIterator results_i; if (params.commandline && !params.command) { printf("Configure won't work with commandline mode.\n"); printf("Please remove the -c from the commandline.\n"); bg_configure_ba_fini(); exit(0); } if (working_cluster_rec) { char *cluster_name = slurm_get_cluster_name(); if (strcmp(working_cluster_rec->name, cluster_name)) { xfree(cluster_name); endwin(); printf("To use the configure option you must be on the " "cluster the configure is for.\nCross cluster " "support doesn't exist today.\nSorry for the " "inconvenince.\n"); bg_configure_ba_fini(); exit(0); } xfree(cluster_name); } /* make sure we don't get any noisy debug */ ba_configure_set_ba_debug_flags(0); bg_configure_ba_setup_wires(); color_count = 0; allocated_blocks = list_create(_destroy_allocated_block); if (params.commandline) { snprintf(com, sizeof(com), "%s", params.command); goto run_command; } else { text_width = text_win->_maxx; text_startx = text_win->_begx; command_win = newwin(3, text_width - 1, LINES - 4, text_startx + 1); curs_set(1); echo(); } while (strcmp(com, "quit")) { clear_window(grid_win); print_grid(); clear_window(text_win); box(text_win, 0, 0); box(grid_win, 0, 0); if (!params.no_header) _print_header_command(); if (error_string != NULL) { i = 0; while (error_string[i] != '\0') { if (error_string[i] == '\n') { main_ycord++; main_xcord=1; i++; } mvwprintw(text_win, main_ycord, main_xcord, "%c", error_string[i++]); main_xcord++; } main_ycord++; main_xcord = 1; memset(error_string, 0, 255); } results_i = list_iterator_create(allocated_blocks); count = list_count(allocated_blocks) - (LINES-(main_ycord+5)); if (count<0) count=0; i=0; while ((allocated_block = list_next(results_i)) != NULL) { if (i >= count) _print_text_command(allocated_block); i++; } list_iterator_destroy(results_i); wnoutrefresh(text_win); wnoutrefresh(grid_win); doupdate(); clear_window(command_win); box(command_win, 0, 0); mvwprintw(command_win, 0, 3, "Input Command: (type quit to change view, " "exit to exit)"); wmove(command_win, 1, 1); wgetstr(command_win, com); if (!strcmp(com, "exit")) { endwin(); if (allocated_blocks) list_destroy(allocated_blocks); bg_configure_ba_fini(); exit(0); } run_command: if (!strcmp(com, "quit") || !strcmp(com, "\\q")) { break; } else if (!strncasecmp(com, "layout", 6)) { _set_layout(com); } else if (!strncasecmp(com, "basepartition", 13)) { _set_base_part_cnt(com); } else if (!strncasecmp(com, "nodecard", 8)) { _set_nodecard_cnt(com); } else if (!strncasecmp(com, "resolve", 7) || !strncasecmp(com, "r ", 2)) { _resolve(com); } else if (!strncasecmp(com, "resume", 6)) { mvwprintw(text_win, main_ycord, main_xcord, "%s", com); } else if (!strncasecmp(com, "drain", 5)) { mvwprintw(text_win, main_ycord, main_xcord, "%s", com); } else if (!strncasecmp(com, "alldown", 7)) { _change_state_all_bps(com, NODE_STATE_DOWN); } else if (!strncasecmp(com, "down", 4)) { _change_state_bps(com, NODE_STATE_DOWN); } else if (!strncasecmp(com, "allup", 5)) { _change_state_all_bps(com, NODE_STATE_IDLE); } else if (!strncasecmp(com, "up", 2)) { _change_state_bps(com, NODE_STATE_IDLE); } else if (!strncasecmp(com, "remove", 6) || !strncasecmp(com, "delete", 6) || !strncasecmp(com, "drop", 4)) { _remove_allocation(com, allocated_blocks); } else if (!strncasecmp(com, "create", 6)) { _create_allocation(com, allocated_blocks); } else if (!strncasecmp(com, "copy", 4) || !strncasecmp(com, "c ", 2) || !strncasecmp(com, "c\0", 2)) { _copy_allocation(com, allocated_blocks); } else if (!strncasecmp(com, "save", 4)) { _save_allocation(com, allocated_blocks); } else if (!strncasecmp(com, "load", 4)) { _load_configuration(com, allocated_blocks); } else if (!strncasecmp(com, "clear all", 9) || !strncasecmp(com, "clear", 5)) { list_flush(allocated_blocks); } else { memset(error_string, 0, 255); sprintf(error_string, "Unknown command '%s'",com); } if (params.commandline) { bg_configure_ba_fini(); exit(1); } } if (allocated_blocks) list_destroy(allocated_blocks); params.display = 0; noecho(); clear_window(text_win); main_xcord = 1; main_ycord = 1; curs_set(0); print_date(); get_job(); return; }
int main() { long double zoom = 1; long double zoom_factor = 1.25; long double shift_x = -11; long double shift_y = 0; // if you have a larger terminal... // should get curses window size int width = 50; int height = 20; int c = 0; short color; initscr(); noecho(); cbreak(); keypad(stdscr,TRUE); color = COLORS >= 256; if (color) { start_color(); init_color(0,62*0,0,0); init_color(1,62*1,0,0); init_color(2,62*2,0,0); init_color(3,62*3,0,0); init_color(4,62*4,0,0); init_color(5,62*5,0,0); init_color(6,62*6,0,0); init_color(7,62*7,0,0); init_color(8,62*8,0,0); init_color(9,62*9,0,0); init_color(10,62*10,0,0); init_color(11,62*11,0,0); init_color(12,62*12,0,0); init_color(13,62*13,0,0); init_color(14,62*14,0,0); init_color(15,62*15,0,0); init_pair(0,0,0); init_pair(1,1,0); init_pair(2,2,0); init_pair(3,3,0); init_pair(4,4,0); init_pair(5,5,0); init_pair(6,6,0); init_pair(7,7,0); init_pair(8,8,0); init_pair(9,9,0); init_pair(10,10,0); init_pair(11,11,0); init_pair(12,12,0); init_pair(13,13,0); init_pair(14,14,0); init_pair(15,15,0); } do { if (c == 'x' || c == 'X' || c == 'q' || c == 'Q') { break; } else if (c == '+') { zoom *= zoom_factor; shift_x *= zoom_factor; shift_y *= zoom_factor; } else if (c == '-') { zoom /= zoom_factor; shift_x /= zoom_factor; shift_y /= zoom_factor; } else if (c == KEY_UP) { shift_y--; } else if (c == KEY_DOWN) { shift_y++; } else if (c == KEY_LEFT) { shift_x--; } else if (c == KEY_RIGHT) { shift_x++; } getmaxyx(stdscr,height,width); if (zoom < 1) zoom = 1; render(color,zoom,shift_x,shift_y,width/2,height/2); refresh(); c = getch(); } while(c); endwin(); return 0; }
static void _exit_cb(void) { // clean up ncurses so terminal is not left in funky state endwin(); }
int main() { ITEM **my_items; int c; MENU *my_menu; int n_choices, i; ITEM *cur_item; /* Initialize curses */ initscr(); start_color(); cbreak(); noecho(); keypad(stdscr, TRUE); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_MAGENTA, COLOR_BLACK); /* Initialize items */ n_choices = ARRAY_SIZE(choices); my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); for(i = 0; i < n_choices; ++i) my_items[i] = new_item(choices[i], choices[i]); my_items[n_choices] = (ITEM *)NULL; item_opts_off(my_items[3], O_SELECTABLE); item_opts_off(my_items[6], O_SELECTABLE); /* Create menu */ my_menu = new_menu((ITEM **)my_items); /* Set fore ground and back ground of the menu */ set_menu_fore(my_menu, COLOR_PAIR(1) | A_REVERSE); set_menu_back(my_menu, COLOR_PAIR(2)); set_menu_grey(my_menu, COLOR_PAIR(3)); /* Post the menu */ mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected"); mvprintw(LINES - 2, 0, "Up and Down arrow keys to naviage (F1 to Exit)"); post_menu(my_menu); refresh(); while((c = getch()) != KEY_F(1)) { switch(c) { case KEY_DOWN: menu_driver(my_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(my_menu, REQ_UP_ITEM); break; case 10: /* Enter */ move(20, 0); clrtoeol(); mvprintw(20, 0, "Item selected is : %s", item_name(current_item(my_menu))); pos_menu_cursor(my_menu); break; } } unpost_menu(my_menu); for(i = 0; i < n_choices; ++i) free_item(my_items[i]); free_menu(my_menu); endwin(); }
void back_to_normal(void) { echo(); curs_set(1); endwin(); }
int main(int ac, char *av[]) { /* set up curses */ initscr(); // init curses crmode(); // disable required \r after each key press noecho(); // don't print out the character the key is bound to clear(); int c; /* user input */ pthread_t maker; int i = 0; int column = COLS/2; ammo = MAXROCKET+10; escaped = 0; pthread_create(&maker, NULL, setupUFO, NULL); pthread_mutex_init(&mx, NULL); pthread_mutex_init(&scr_mx, NULL); pthread_mutex_init(&esc_mx, NULL); pthread_mutex_init(&rckt_mx, NULL); pthread_mutex_init(&ufo_mx, NULL); struct propset launchSite = { "|", COLS, LINES-3, 0, 0}; displayInfo(); moveHorizontal(&launchSite, column); while(1) { displayInfo(); if (ammo < 0 || escaped >= 3) { break; } c = getchar(); if ( c == 'Q' || c == 'q' ) { // Q quits the program break; } if ( c == ' ' ) { // check if space button was pressed int k = i % MAXROCKET; buildRocket(k, column); i++; pthread_mutex_lock(&mx); ammo--; pthread_mutex_unlock(&mx); /* refresh info */ displayInfo(); } if ( c == ',') { if (column > 0) { column--; moveHorizontal(&launchSite, column); } } if ( c == '.') { if (column+1 < COLS-1) { column++; moveHorizontal(&launchSite, column); } } } pthread_cancel(maker); endwin(); return 0; }
void mtr_curses_close(void) { printw("\n"); endwin(); }
main() { int i; CHTYPE ch; menu ostate; /* Setup GL environment */ (void) GLenvsetup(); /* Read in chart of accounts file into array, charttab. ** This array will be queried to validate account numbers. */ (void)CHload(); /* ** Initialize curses environment */ if (ERR == initscr() ) { fprintf(stderr, "JSedit: cannot initialize curses\n"); JEinthand(); } /* Function key translation */ keypad(stdscr, TRUE); /* let the program echo characters */ noecho(); /* do not return after linefeed */ nonl(); /* ** Create and initialize windows */ menuline=newwin(1,80,0,0); leaveok(menuline,TRUE); wattrset(menuline, A_COLOR(A_BRIGHTWHITE,A_BLUE) ); wclear(menuline); prompt=newwin(3,35,16,22); leaveok(prompt,TRUE); wclear(prompt); message = newwin(1,80,22,0); leaveok(message,TRUE); wclear(message); wrefresh(stdscr); /* ** Display initial menu */ ostate=quit; state=start; strcpy(filename,""); strcpy(filetmp,""); fileopened=JEFALSE; filechgd=JEFALSE; while( state!=quit ) { if (ostate != state) { wclear(prompt); wrefresh(prompt); wclear(message); wrefresh(message); JSdspmenu(state); ostate = state; strcpy(filetmp,filename); } ch=getch(); switch(state) { case start: state = JMstart(ch); break; case file: state = JMfile(ch); break; case edit: state = JMedit(ch); break; default: fprintf(stderr,"JSedit: unknown state\n"); JEinthand(); break; } } /* Close curses */ endwin(); /* Restore working directory */ chdir(cwdstr); } /* end of main */
static void close_io(struct holder *holder) { endwin(); snd_pcm_close(holder->alsa_handle); sf_close(holder->infile); }
//Close curses and the program void cleanup(int param) { endwin(); exit(0); }
static void get_keys (void) { int search; int c, quit = 1, scrll, offset, ok_mouse; int *scroll_ptr, *offset_ptr; int exp_size = DASH_EXPANDED - DASH_NON_DATA; MEVENT event; char buf[LINE_BUFFER]; FILE *fp = NULL; unsigned long long size1 = 0, size2 = 0; if (!logger->piping) size1 = file_size (conf.ifile); while (quit) { c = wgetch (stdscr); switch (c) { case 'q': /* quit */ if (!scrolling.expanded) { quit = 0; break; } collapse_current_module (); break; case KEY_F (1): case '?': case 'h': load_help_popup (main_win); render_screens (); break; case 49: /* 1 */ /* reset expanded module */ set_module_to (&scrolling, VISITORS); break; case 50: /* 2 */ /* reset expanded module */ set_module_to (&scrolling, REQUESTS); break; case 51: /* 3 */ /* reset expanded module */ set_module_to (&scrolling, REQUESTS_STATIC); break; case 52: /* 4 */ /* reset expanded module */ set_module_to (&scrolling, NOT_FOUND); break; case 53: /* 5 */ /* reset expanded module */ set_module_to (&scrolling, HOSTS); break; case 54: /* 6 */ /* reset expanded module */ set_module_to (&scrolling, OS); break; case 55: /* 7 */ /* reset expanded module */ set_module_to (&scrolling, BROWSERS); break; case 56: /* 8 */ /* reset expanded module */ set_module_to (&scrolling, REFERRERS); break; case 57: /* 9 */ /* reset expanded module */ set_module_to (&scrolling, REFERRING_SITES); break; case 48: /* 0 */ /* reset expanded module */ set_module_to (&scrolling, KEYPHRASES); break; case 33: /* Shift+1 */ /* reset expanded module */ #ifdef HAVE_LIBGEOIP set_module_to (&scrolling, GEO_LOCATION); #else set_module_to (&scrolling, STATUS_CODES); #endif break; #ifdef HAVE_LIBGEOIP case 64: /* Shift+2 */ /* reset expanded module */ set_module_to (&scrolling, STATUS_CODES); break; #endif case 9: /* TAB */ /* reset expanded module */ collapse_current_module (); scrolling.current++; if (scrolling.current == TOTAL_MODULES) scrolling.current = 0; render_screens (); break; case 353: /* Shift TAB */ /* reset expanded module */ collapse_current_module (); if (scrolling.current == 0) scrolling.current = TOTAL_MODULES - 1; else scrolling.current--; render_screens (); break; case 'g': /* g = top */ if (!scrolling.expanded) scrolling.dash = 0; else { scrolling.module[scrolling.current].scroll = 0; scrolling.module[scrolling.current].offset = 0; } display_content (main_win, logger, dash, &scrolling); break; case 'G': /* G = down */ if (!scrolling.expanded) scrolling.dash = dash->total_alloc - real_size_y; else { scrll = offset = 0; scrll = dash->module[scrolling.current].idx_data - 1; if (scrll >= exp_size && scrll >= offset + exp_size) offset = scrll < exp_size - 1 ? 0 : scrll - exp_size + 1; scrolling.module[scrolling.current].scroll = scrll; scrolling.module[scrolling.current].offset = offset; } display_content (main_win, logger, dash, &scrolling); break; /* expand dashboard module */ case KEY_RIGHT: case 0x0a: case 0x0d: case 32: /* ENTER */ case 79: /* o */ case 111: /* O */ case KEY_ENTER: if (scrolling.expanded && scrolling.current == HOSTS) { /* make sure we have a valid IP */ int sel = scrolling.module[scrolling.current].scroll; if (!invalid_ipaddr (dash->module[HOSTS].data[sel].data)) load_agent_list (main_win, dash->module[HOSTS].data[sel].data); break; } if (scrolling.expanded) break; reset_scroll_offsets (&scrolling); scrolling.expanded = 1; free_holder_by_module (&holder, scrolling.current); free_dashboard (dash); allocate_holder_by_module (scrolling.current); allocate_data (); display_content (main_win, logger, dash, &scrolling); break; case KEY_DOWN: /* scroll main dashboard */ if ((scrolling.dash + real_size_y) < (unsigned) dash->total_alloc) { scrolling.dash++; display_content (main_win, logger, dash, &scrolling); } break; case KEY_MOUSE: /* handles mouse events */ ok_mouse = getmouse (&event); if (conf.mouse_support && ok_mouse == OK) { if (event.bstate & BUTTON1_CLICKED) { /* ignore header/footer clicks */ if (event.y < MAX_HEIGHT_HEADER || event.y == LINES - 1) break; if (set_module_from_mouse_event (&scrolling, dash, event.y)) break; reset_scroll_offsets (&scrolling); scrolling.expanded = 1; free_holder_by_module (&holder, scrolling.current); free_dashboard (dash); allocate_holder_by_module (scrolling.current); allocate_data (); render_screens (); } } break; case 106: /* j - DOWN expanded module */ scroll_ptr = &scrolling.module[scrolling.current].scroll; offset_ptr = &scrolling.module[scrolling.current].offset; if (!scrolling.expanded) break; if (*scroll_ptr >= dash->module[scrolling.current].idx_data - 1) break; ++(*scroll_ptr); if (*scroll_ptr >= exp_size && *scroll_ptr >= *offset_ptr + exp_size) ++(*offset_ptr); display_content (main_win, logger, dash, &scrolling); break; /* scroll up main_win */ case KEY_UP: if (scrolling.dash > 0) { scrolling.dash--; display_content (main_win, logger, dash, &scrolling); } break; case 2: /* ^ b - page up */ case 339: /* ^ PG UP */ scroll_ptr = &scrolling.module[scrolling.current].scroll; offset_ptr = &scrolling.module[scrolling.current].offset; if (!scrolling.expanded) break; /* decrease scroll and offset by exp_size */ *scroll_ptr -= exp_size; if (*scroll_ptr < 0) *scroll_ptr = 0; if (*scroll_ptr < *offset_ptr) *offset_ptr -= exp_size; if (*offset_ptr <= 0) *offset_ptr = 0; display_content (main_win, logger, dash, &scrolling); break; case 6: /* ^ f - page down */ case 338: /* ^ PG DOWN */ scroll_ptr = &scrolling.module[scrolling.current].scroll; offset_ptr = &scrolling.module[scrolling.current].offset; if (!scrolling.expanded) break; *scroll_ptr += exp_size; if (*scroll_ptr >= dash->module[scrolling.current].idx_data - 1) *scroll_ptr = dash->module[scrolling.current].idx_data - 1; if (*scroll_ptr >= exp_size && *scroll_ptr >= *offset_ptr + exp_size) *offset_ptr += exp_size; if (*offset_ptr + exp_size >= dash->module[scrolling.current].idx_data - 1) *offset_ptr = dash->module[scrolling.current].idx_data - exp_size; if (*scroll_ptr < exp_size - 1) *offset_ptr = 0; display_content (main_win, logger, dash, &scrolling); break; case 107: /* k - UP expanded module */ scroll_ptr = &scrolling.module[scrolling.current].scroll; offset_ptr = &scrolling.module[scrolling.current].offset; if (!scrolling.expanded) break; if (*scroll_ptr <= 0) break; --(*scroll_ptr); if (*scroll_ptr < *offset_ptr) --(*offset_ptr); display_content (main_win, logger, dash, &scrolling); break; case 'n': pthread_mutex_lock (&gdns_thread.mutex); search = perform_next_find (holder, &scrolling); pthread_mutex_unlock (&gdns_thread.mutex); if (search == 0) { free_dashboard (dash); allocate_data (); render_screens (); } break; case '/': if (render_find_dialog (main_win, &scrolling)) break; pthread_mutex_lock (&gdns_thread.mutex); search = perform_next_find (holder, &scrolling); pthread_mutex_unlock (&gdns_thread.mutex); if (search == 0) { free_dashboard (dash); allocate_data (); render_screens (); } break; case 99: /* c */ if (conf.no_color) break; load_schemes_win (main_win); free_dashboard (dash); allocate_data (); render_screens (); break; case 115: /* s */ load_sort_win (main_win, scrolling.current, &module_sort[scrolling.current]); pthread_mutex_lock (&gdns_thread.mutex); free_holder (&holder); pthread_cond_broadcast (&gdns_thread.not_empty); pthread_mutex_unlock (&gdns_thread.mutex); free_dashboard (dash); allocate_holder (); allocate_data (); render_screens (); break; case 269: case KEY_RESIZE: endwin (); refresh (); werase (header_win); werase (main_win); werase (stdscr); term_size (main_win); refresh (); render_screens (); break; default: if (logger->piping) break; size2 = file_size (conf.ifile); /* file has changed */ if (size2 != size1) { if (!(fp = fopen (conf.ifile, "r"))) FATAL ("Unable to read log file %s.", strerror (errno)); if (!fseeko (fp, size1, SEEK_SET)) while (fgets (buf, LINE_BUFFER, fp) != NULL) parse_log (&logger, buf, -1); fclose (fp); size1 = size2; pthread_mutex_lock (&gdns_thread.mutex); free_holder (&holder); pthread_cond_broadcast (&gdns_thread.not_empty); pthread_mutex_unlock (&gdns_thread.mutex); free_dashboard (dash); allocate_holder (); allocate_data (); term_size (main_win); render_screens (); usleep (200000); /* 0.2 seconds */ } break; } } }