Skip to content

Commit

Permalink
endwin: separate curses from the message
Browse files Browse the repository at this point in the history
  • Loading branch information
flatcap committed Mar 15, 2018
1 parent 9289b81 commit 8d4bf0e
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 79 deletions.
12 changes: 6 additions & 6 deletions attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
10 changes: 5 additions & 5 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 10 additions & 17 deletions curs_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand Down
13 changes: 7 additions & 6 deletions init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
54 changes: 25 additions & 29 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ char **envlist = NULL;

void mutt_exit(int code)
{
mutt_endwin(NULL);
mutt_endwin();
exit(code);
}

Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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';
Expand All @@ -844,22 +835,24 @@ 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);
}
}
else
#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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion mutt_curses.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 8d4bf0e

Please sign in to comment.