From 8d4bf0e3ead74ce80e9ef02fb9768ea650200fe8 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Mon, 12 Feb 2018 15:17:41 +0000 Subject: [PATCH] endwin: separate curses from the message --- attach.c | 12 +++++------ commands.c | 10 +++++----- curs_lib.c | 27 ++++++++++--------------- init.c | 13 ++++++------ main.c | 54 +++++++++++++++++++++++--------------------------- mutt_curses.h | 2 +- muttlib.c | 2 +- ncrypt/crypt.c | 16 ++++++++++----- ncrypt/pgp.c | 2 +- ncrypt/smime.c | 8 ++++---- recvattach.c | 4 ++-- remailer.c | 3 +-- 12 files changed, 74 insertions(+), 79 deletions(-) diff --git a/attach.c b/attach.c index 6e1f46ed6d8..5fd7b18730b 100644 --- a/attach.c +++ b/attach.c @@ -133,7 +133,7 @@ int mutt_compose_attachment(struct Body *a) { int r; - mutt_endwin(NULL); + mutt_endwin(); r = mutt_system(command); if (r == -1) mutt_error(_("Error running \"%s\"!"), command); @@ -266,7 +266,7 @@ int mutt_edit_attachment(struct Body *a) } else { - mutt_endwin(NULL); + mutt_endwin(); if (mutt_system(command) == -1) { mutt_error(_("Error running \"%s\"!"), command); @@ -474,7 +474,7 @@ int mutt_view_attachment(FILE *fp, struct Body *a, int flag, struct Header *hdr, int tempfd = -1, pagerfd = -1; if (!use_pager) - mutt_endwin(NULL); + mutt_endwin(); if (use_pager || use_pipe) { @@ -659,7 +659,7 @@ int mutt_pipe_attachment(FILE *fp, struct Body *b, const char *path, char *outfi } } - mutt_endwin(NULL); + mutt_endwin(); if (fp) { @@ -1021,7 +1021,7 @@ int mutt_print_attachment(FILE *fp, struct Body *a) mutt_str_strfcpy(command, entry->printcommand, sizeof(command)); piped = rfc1524_expand_command(a, newfile, type, command, sizeof(command)); - mutt_endwin(NULL); + mutt_endwin(); /* interactive program */ if (piped) @@ -1095,7 +1095,7 @@ int mutt_print_attachment(FILE *fp, struct Body *a) mutt_debug(2, "successfully opened %s read-only\n", newfile); - mutt_endwin(NULL); + mutt_endwin(); thepid = mutt_create_filter(NONULL(PrintCommand), &fpout, NULL, NULL); if (thepid < 0) { diff --git a/commands.c b/commands.c index b4cb941841c..8e3dea84282 100644 --- a/commands.c +++ b/commands.c @@ -228,7 +228,7 @@ int mutt_display_message(struct Header *cur) { int r; - mutt_endwin(NULL); + mutt_endwin(); snprintf(buf, sizeof(buf), "%s %s", NONULL(Pager), tempfile); r = mutt_system(buf); if (r == -1) @@ -401,7 +401,7 @@ static int pipe_message(struct Header *h, char *cmd, int decode, int print, if (h->security & ENCRYPT && !crypt_valid_passphrase(h->security)) return 1; } - mutt_endwin(NULL); + mutt_endwin(); thepid = mutt_create_filter(cmd, &fpout, NULL, NULL); if (thepid < 0) @@ -444,7 +444,7 @@ static int pipe_message(struct Header *h, char *cmd, int decode, int print, continue; mutt_message_hook(Context, Context->hdrs[i], MUTT_MESSAGEHOOK); - mutt_endwin(NULL); + mutt_endwin(); thepid = mutt_create_filter(cmd, &fpout, NULL, NULL); if (thepid < 0) { @@ -464,7 +464,7 @@ static int pipe_message(struct Header *h, char *cmd, int decode, int print, } else { - mutt_endwin(NULL); + mutt_endwin(); thepid = mutt_create_filter(cmd, &fpout, NULL, NULL); if (thepid < 0) { @@ -613,7 +613,7 @@ void mutt_shell_escape(void) if (buf[0]) { mutt_window_clearline(MuttMessageWindow, 0); - mutt_endwin(NULL); + mutt_endwin(); fflush(stdout); int rc = mutt_system(buf); if (rc == -1) diff --git a/curs_lib.c b/curs_lib.c index c1a3f245ea6..ab1b053f29d 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -224,7 +224,7 @@ void mutt_edit_file(const char *editor, const char *data) { char cmd[LONG_STRING]; - mutt_endwin(NULL); + mutt_endwin(); mutt_expand_file_fmt(cmd, sizeof(cmd), editor, data); if (mutt_system(cmd) != 0) { @@ -802,24 +802,17 @@ void mutt_show_error(void) mutt_window_clrtoeol(MuttMessageWindow); } -void mutt_endwin(const char *msg) +void mutt_endwin(void) { - int e = errno; + if (OPT_NO_CURSES) + return; - if (!OPT_NO_CURSES) - { - /* at least in some situations (screen + xterm under SuSE11/12) endwin() - * doesn't properly flush the screen without an explicit call. - */ - mutt_refresh(); - endwin(); - } + int e = errno; - if (msg && *msg) - { - puts(msg); - fflush(stdout); - } + /* at least in some situations (screen + xterm under SuSE11/12) endwin() + * doesn't properly flush the screen without an explicit call. */ + mutt_refresh(); + endwin(); errno = e; } @@ -872,7 +865,7 @@ int mutt_do_pager(const char *banner, const char *tempfile, int do_color, struct { char cmd[STRING]; - mutt_endwin(NULL); + mutt_endwin(); mutt_expand_file_fmt(cmd, sizeof(cmd), Pager, tempfile); if (mutt_system(cmd) == -1) { diff --git a/init.c b/init.c index 8309fd5c018..1865d4f9566 100644 --- a/init.c +++ b/init.c @@ -1495,7 +1495,7 @@ static int parse_attachments(struct Buffer *buf, struct Buffer *s, if (op == '?') { - mutt_endwin(NULL); + mutt_endwin(); fflush(stdout); printf(_("\nCurrent attachments settings:\n\n")); print_attach_list(&AttachAllow, '+', "A"); @@ -2212,7 +2212,7 @@ static int parse_setenv(struct Buffer *tmp, struct Buffer *s, { if (!found) { - mutt_endwin(NULL); + mutt_endwin(); found = 1; } puts(*envp); @@ -3834,7 +3834,7 @@ void mutt_init(int skip_sys_rc, struct ListHead *commands) { if (!HomeDir) { - mutt_endwin(NULL); + mutt_endwin(); fputs(_("unable to determine home directory"), stderr); exit(1); } @@ -3843,7 +3843,7 @@ void mutt_init(int skip_sys_rc, struct ListHead *commands) Username = mutt_str_strdup(p); else { - mutt_endwin(NULL); + mutt_endwin(); fputs(_("unable to determine username"), stderr); exit(1); } @@ -3876,7 +3876,7 @@ void mutt_init(int skip_sys_rc, struct ListHead *commands) */ if ((uname(&utsname)) == -1) { - mutt_endwin(NULL); + mutt_endwin(); perror(_("unable to determine nodename via uname()")); exit(1); } @@ -4063,8 +4063,9 @@ void mutt_init(int skip_sys_rc, struct ListHead *commands) np->data = mutt_str_strdup(buffer); if (access(np->data, F_OK)) { + mutt_endwin(); snprintf(buffer, sizeof(buffer), "%s: %s", np->data, strerror(errno)); - mutt_endwin(buffer); + puts(buffer); exit(1); } } diff --git a/main.c b/main.c index 3981ff0ded3..711eff1fcf7 100644 --- a/main.c +++ b/main.c @@ -69,7 +69,7 @@ char **envlist = NULL; void mutt_exit(int code) { - mutt_endwin(NULL); + mutt_endwin(); exit(code); } @@ -528,7 +528,7 @@ int main(int argc, char **argv, char **env) mutt_flushinp(); ci_send_message(SENDPOSTPONED, NULL, NULL, NULL, NULL); mutt_free_windows(); - mutt_endwin(NULL); + mutt_endwin(); } else if (subject || msg || sendflags || draft_file || include_file || !STAILQ_EMPTY(&attach) || optind < argc) @@ -554,8 +554,7 @@ int main(int argc, char **argv, char **env) { if (url_parse_mailto(msg->env, &bodytext, argv[i]) < 0) { - if (!OPT_NO_CURSES) - mutt_endwin(NULL); + mutt_endwin(); fputs(_("Failed to parse mailto: link\n"), stderr); exit(1); } @@ -566,8 +565,7 @@ int main(int argc, char **argv, char **env) if (!draft_file && Autoedit && !msg->env->to && !msg->env->cc) { - if (!OPT_NO_CURSES) - mutt_endwin(NULL); + mutt_endwin(); fputs(_("No recipients specified.\n"), stderr); exit(1); } @@ -606,8 +604,7 @@ int main(int argc, char **argv, char **env) fin = fopen(expanded_infile, "r"); if (!fin) { - if (!OPT_NO_CURSES) - mutt_endwin(NULL); + mutt_endwin(); perror(expanded_infile); exit(1); } @@ -627,8 +624,7 @@ int main(int argc, char **argv, char **env) fout = mutt_file_fopen(tempfile, "w"); if (!fout) { - if (!OPT_NO_CURSES) - mutt_endwin(NULL); + mutt_endwin(); perror(tempfile); mutt_file_fclose(&fin); FREE(&tempfile); @@ -647,8 +643,7 @@ int main(int argc, char **argv, char **env) fin = fopen(tempfile, "r"); if (!fin) { - if (!OPT_NO_CURSES) - mutt_endwin(NULL); + mutt_endwin(); perror(tempfile); FREE(&tempfile); exit(1); @@ -746,8 +741,7 @@ int main(int argc, char **argv, char **env) msg->content = a = mutt_make_file_attach(np->data); if (!a) { - if (!OPT_NO_CURSES) - mutt_endwin(NULL); + mutt_endwin(); fprintf(stderr, _("%s: unable to attach file.\n"), np->data); mutt_list_free(&attach); exit(1); @@ -766,16 +760,14 @@ int main(int argc, char **argv, char **env) { if (truncate(expanded_infile, 0) == -1) { - if (!OPT_NO_CURSES) - mutt_endwin(NULL); + mutt_endwin(); perror(expanded_infile); exit(1); } fout = mutt_file_fopen(expanded_infile, "a"); if (!fout) { - if (!OPT_NO_CURSES) - mutt_endwin(NULL); + mutt_endwin(); perror(expanded_infile); exit(1); } @@ -798,8 +790,7 @@ int main(int argc, char **argv, char **env) fputc('\n', fout); if ((mutt_write_mime_body(msg->content, fout) == -1)) { - if (!OPT_NO_CURSES) - mutt_endwin(NULL); + mutt_endwin(); mutt_file_fclose(&fout); exit(1); } @@ -817,8 +808,7 @@ int main(int argc, char **argv, char **env) } mutt_free_windows(); - if (!OPT_NO_CURSES) - mutt_endwin(NULL); + mutt_endwin(); if (rv != 0) exit(1); @@ -829,7 +819,8 @@ int main(int argc, char **argv, char **env) { if (!mutt_buffy_check(false)) { - mutt_endwin(_("No mailbox with new mail.")); + mutt_endwin(); + puts(_("No mailbox with new mail.")); exit(1); } folder[0] = '\0'; @@ -844,7 +835,8 @@ int main(int argc, char **argv, char **env) CurrentNewsSrv = nntp_select_server(NewsServer, false); if (!CurrentNewsSrv) { - mutt_endwin(ErrorBuf); + mutt_endwin(); + puts(ErrorBuf); exit(1); } } @@ -852,14 +844,15 @@ int main(int argc, char **argv, char **env) #endif if (!Incoming) { - mutt_endwin(_("No incoming mailboxes defined.")); + mutt_endwin(); + puts(_("No incoming mailboxes defined.")); exit(1); } folder[0] = '\0'; mutt_select_file(folder, sizeof(folder), MUTT_SEL_FOLDER | MUTT_SEL_BUFFY, NULL, NULL); if (folder[0] == '\0') { - mutt_endwin(NULL); + mutt_endwin(); exit(0); } } @@ -892,10 +885,12 @@ int main(int argc, char **argv, char **env) switch (mx_check_empty(folder)) { case -1: - mutt_endwin(strerror(errno)); + mutt_endwin(); + puts(strerror(errno)); exit(1); case 1: - mutt_endwin(_("Mailbox is empty.")); + mutt_endwin(); + puts(_("Mailbox is empty.")); exit(1); } } @@ -922,7 +917,8 @@ int main(int argc, char **argv, char **env) #endif mutt_free_opts(); mutt_free_windows(); - mutt_endwin(ErrorBuf); + mutt_endwin(); + puts(ErrorBuf); } exit(0); diff --git a/mutt_curses.h b/mutt_curses.h index b11fa1cfe7e..4556b4f725c 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -114,7 +114,7 @@ struct Event struct Event mutt_getch(void); -void mutt_endwin(const char *msg); +void mutt_endwin(void); void mutt_flushinp(void); void mutt_refresh(void); void mutt_resize_screen(void); diff --git a/muttlib.c b/muttlib.c index 2a946c55e3c..eab2f929201 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1264,7 +1264,7 @@ FILE *mutt_open_read(const char *path, pid_t *thepid) char *p = mutt_str_strdup(path); p[len - 1] = 0; - mutt_endwin(NULL); + mutt_endwin(); *thepid = mutt_create_filter(p, NULL, &f, NULL); FREE(&p); } diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index 19fda6c3009..bca2b822f23 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -169,7 +169,10 @@ int mutt_protect(struct Header *msg, char *keylist) { /* they really want to send it inline... go for it */ if (!isendwin()) - mutt_endwin(_("Invoking PGP...")); + { + mutt_endwin(); + puts(_("Invoking PGP...")); + } pbody = crypt_pgp_traditional_encryptsign(msg->content, flags, keylist); if (pbody) { @@ -191,7 +194,7 @@ int mutt_protect(struct Header *msg, char *keylist) } if (!isendwin()) - mutt_endwin(NULL); + mutt_endwin(); if ((WithCrypto & APPLICATION_SMIME)) tmp_smime_pbody = msg->content; @@ -742,7 +745,8 @@ void crypt_extract_keys_from_messages(struct Header *h) mutt_copy_message_ctx(fpout, Context, hi, MUTT_CM_DECODE | MUTT_CM_CHARCONV, 0); fflush(fpout); - mutt_endwin(_("Trying to extract PGP keys...\n")); + mutt_endwin(); + puts(_("Trying to extract PGP keys...\n")); crypt_pgp_invoke_import(tempfname); } @@ -763,7 +767,8 @@ void crypt_extract_keys_from_messages(struct Header *h) mbox = tmp ? tmp->mailbox : NULL; if (mbox) { - mutt_endwin(_("Trying to extract S/MIME certificates...\n")); + mutt_endwin(); + puts(_("Trying to extract S/MIME certificates...\n")); crypt_smime_invoke_import(tempfname, mbox); tmp = NULL; } @@ -781,7 +786,8 @@ void crypt_extract_keys_from_messages(struct Header *h) { mutt_copy_message_ctx(fpout, Context, h, MUTT_CM_DECODE | MUTT_CM_CHARCONV, 0); fflush(fpout); - mutt_endwin(_("Trying to extract PGP keys...\n")); + mutt_endwin(); + puts(_("Trying to extract PGP keys...\n")); crypt_pgp_invoke_import(tempfname); } diff --git a/ncrypt/pgp.c b/ncrypt/pgp.c index 516aae41f6b..0336d1396d0 100644 --- a/ncrypt/pgp.c +++ b/ncrypt/pgp.c @@ -801,7 +801,7 @@ void pgp_extract_keys_from_attachment_list(FILE *fp, int tag, struct Body *top) return; } - mutt_endwin(NULL); + mutt_endwin(); OPT_DONT_HANDLE_PGP_KEYS = true; for (; top; top = top->next) diff --git a/ncrypt/smime.c b/ncrypt/smime.c index a1a058de81d..37e82fa8002 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -967,7 +967,7 @@ static int smime_handle_cert_email(char *certificate, char *mailbox, int copy, if (rc == -1) { - mutt_endwin(NULL); + mutt_endwin(); mutt_file_copy_stream(fperr, stdout); mutt_any_key_to_continue(_("Error: unable to create OpenSSL subprocess!")); rc = 1; @@ -1157,7 +1157,7 @@ static char *smime_extract_signer_certificate(char *infile) empty = (fgetc(fpout) == EOF); if (empty) { - mutt_endwin(NULL); + mutt_endwin(); mutt_file_copy_stream(fperr, stdout); mutt_any_key_to_continue(NULL); mutt_file_fclose(&fpout); @@ -1212,11 +1212,11 @@ void smime_invoke_import(char *infile, char *mailbox) } } - mutt_endwin(NULL); + mutt_endwin(); certfile = smime_extract_certificate(infile); if (certfile) { - mutt_endwin(NULL); + mutt_endwin(); thepid = smime_invoke(&smimein, NULL, NULL, -1, fileno(fpout), fileno(fperr), certfile, NULL, NULL, NULL, NULL, NULL, NULL, SmimeImportCertCommand); diff --git a/recvattach.c b/recvattach.c index 8c4c01e1c8c..dbb89158b2c 100644 --- a/recvattach.c +++ b/recvattach.c @@ -729,7 +729,7 @@ void mutt_pipe_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, if (!filter && !AttachSplit) { - mutt_endwin(NULL); + mutt_endwin(); thepid = mutt_create_filter(buf, &state.fpout, NULL, NULL); pipe_attachment_list(buf, actx, fp, tag, top, filter, &state); mutt_file_fclose(&state.fpout); @@ -835,7 +835,7 @@ void mutt_print_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, stru { if (!can_print(actx, top, tag)) return; - mutt_endwin(NULL); + mutt_endwin(); thepid = mutt_create_filter(NONULL(PrintCommand), &state.fpout, NULL, NULL); print_attachment_list(actx, fp, tag, top, &state); mutt_file_fclose(&state.fpout); diff --git a/remailer.c b/remailer.c index a63369f34ec..45220b8c1c0 100644 --- a/remailer.c +++ b/remailer.c @@ -757,8 +757,7 @@ int mix_send_message(struct ListHead *chain, const char *tempfile) (np == STAILQ_FIRST(chain)) ? " -l " : ",", cd_quoted); } - if (!OPT_NO_CURSES) - mutt_endwin(NULL); + mutt_endwin(); i = mutt_system(cmd); if (i != 0)