X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-ui%2Fcurs_lib.c;h=b283e42cb37b662d6777b5cb09c2e47bde432ea1;hp=a2b88c811d79fa6fad31a3454e6cdd7b50176e86;hb=88d239144bf6f50ca1eda6db7742281f0ad0f97f;hpb=a4b9983ca0d2e7654b552c3648792cff279bdf9a diff --git a/lib-ui/curs_lib.c b/lib-ui/curs_lib.c index a2b88c8..b283e42 100644 --- a/lib-ui/curs_lib.c +++ b/lib-ui/curs_lib.c @@ -21,7 +21,7 @@ #include #include "menu.h" -#include "enter.h" +#include "browser.h" #include "mutt.h" #include "pager.h" @@ -42,7 +42,7 @@ event_t mutt_getch (void) event_t err = { -1, OP_NULL }, ret; if (!option (OPTUNBUFFEREDINPUT) && UngetCount) - return (KeyEvent[--UngetCount]); + return KeyEvent[--UngetCount]; SigInt = 0; @@ -58,45 +58,7 @@ event_t mutt_getch (void) ret.ch = ch; ret.op = 0; - return (ch == ctrl ('G') ? err : ret); -} - -#ifndef waddnwstr -int waddwch(WINDOW *win, wchar_t wc) -{ - char buf[MB_LEN_MAX * 2]; - mbstate_t mbstate; - ssize_t n1, n2; - - p_clear(&mbstate, 1); - if ((n1 = wcrtomb(buf, wc, &mbstate)) == -1 - || (n2 = wcrtomb(buf + n1, 0, &mbstate)) == -1) - return -1; /* ERR */ - return waddstr(win, buf); -} -#endif - - -int _mutt_get_field ( const char *field, char *buf, ssize_t buflen, - int complete, int multiple, char ***files, int *numfiles) -{ - int ret; - int x, y; - - ENTER_STATE *es = mutt_new_enter_state (); - - do { - CLEARLINE(stdscr, LINES - 1); - waddstr (stdscr, field); - mutt_refresh (); - getyx (stdscr, y, x); - ret = _mutt_enter_string(buf, buflen, y, x, complete, multiple, files, - numfiles, es); - } while (ret == 1); - CLEARLINE(stdscr, LINES - 1); - mutt_free_enter_state (&es); - - return (ret); + return ch == ctrl ('G') ? err : ret; } int mutt_get_field_unbuffered (char *msg, char *buf, ssize_t buflen, int flags) @@ -107,7 +69,7 @@ int mutt_get_field_unbuffered (char *msg, char *buf, ssize_t buflen, int flags) rc = mutt_get_field (msg, buf, buflen, flags); unset_option (OPTUNBUFFEREDINPUT); - return (rc); + return rc; } void mutt_clear_error (void) @@ -117,16 +79,83 @@ void mutt_clear_error (void) CLEARLINE(stdscr, LINES - 1); } +static struct timeval const slice = { 0, 1000 * 1000 / 100 }; +static struct timeval timeval_add(struct timeval a, struct timeval b) +{ + int usec = a.tv_usec + b.tv_usec; + a.tv_sec += b.tv_sec; + while (usec > 1000 * 1000) { + a.tv_sec += 1; + usec -= 1000 * 1000; + } + a.tv_usec = usec; + return a; +} + +static int is_expired(struct timeval now, struct timeval expiry) +{ + return now.tv_sec > expiry.tv_sec + || (now.tv_sec == expiry.tv_sec && now.tv_usec > expiry.tv_usec); +} + void mutt_edit_file(const char *data) { - char cmd[LONG_STRING]; - - mutt_endwin (NULL); - m_quotefile_fmt(cmd, sizeof (cmd), mod_core.editor, data); - if (mutt_system (cmd) == -1) - mutt_error (_("Error running \"%s\"!"), cmd); - keypad (stdscr, TRUE); - clearok (stdscr, TRUE); + char cmd[STRING]; + const char *args[] = { "/bin/sh", "-c", cmd, NULL }; + int dirty = 0, ch, res, mh, mw, pty, pid; + struct timeval next; + madtty_t *rt; + + m_quotefile_fmt(cmd, sizeof(cmd), mod_core.editor, data); + getmaxyx(main_w, mh, mw); + SigChild = 0; + + rt = madtty_create(mh - 2, mw); + pid = madtty_forkpty(rt, args[0], args, &pty); + if (pid < 0) { + madtty_destroy(rt); + mutt_error(_("unable to start editor")); + return; + } + + SETCOLOR(main_w, MT_COLOR_SIDEBAR); + mvwhline(main_w, 0, 0, ACS_HLINE, mw); + + nodelay(stdscr, true); + gettimeofday(&next, NULL); + while (!SigChild) { + struct timeval tv = { 0, 1000 * 1000 / 100 }; + fd_set rfds; + + FD_ZERO(&rfds); + FD_SET(0, &rfds); + FD_SET(pty, &rfds); + + if (select(pty + 1, &rfds, NULL, NULL, &tv) < 0) + break; + + if (FD_ISSET(pty, &rfds)) { + madtty_process(rt); + dirty = 1; + } + + while ((ch = getch()) != ERR) { + madtty_keypress(rt, ch); /* pass the keypress for handling */ + dirty = 1; + } + + gettimeofday(&tv, NULL); + if (dirty && is_expired(tv, next)) { + madtty_draw(rt, main_w, 1, 0); + wrefresh(main_w); + dirty = 0; + next = timeval_add(tv, slice); + } + } + while (waitpid(pid, &res, 0) < 0 && errno == EINTR); + nodelay(stdscr, false); + close(pty); + madtty_destroy(rt); } int mutt_yesorno (const char *msg, int def) @@ -201,7 +230,7 @@ int mutt_yesorno (const char *msg, int def) mutt_refresh (); } CLEARLINE(stdscr, LINES - 1); - return (def); + return def; } /* this function is called when the user presses the abort key */ @@ -324,27 +353,6 @@ void curses_initialize(void) ESCDELAY = 50; } -/* - * prompts the user to enter a keystroke, and displays the octal value back - * to the user. - */ -void mutt_what_key (void) -{ - int ch; - - mvwprintw(stdscr, LINES - 1, 0, _("Enter keys (^G to abort): ")); - do { - ch = getch(); - if (ch != ERR && ch != ctrl ('G')) { - mutt_message (_("Char = %s, Octal = %o, Decimal = %d"), - km_keyname (ch), ch, ch); - } - } - while (ch != ERR && ch != ctrl ('G')); - - mutt_flushinp (); -} - int mutt_any_key_to_continue (const char *s) { struct termios t; @@ -370,7 +378,7 @@ int mutt_any_key_to_continue (const char *s) close (f); fputs ("\r\n", stdout); mutt_clear_error (); - return (ch); + return ch; } int _mutt_enter_fname (const char *prompt, char *buf, ssize_t blen, @@ -389,7 +397,7 @@ int _mutt_enter_fname (const char *prompt, char *buf, ssize_t blen, ch = mutt_getch (); if (ch.ch == -1) { CLEARLINE(stdscr, LINES - 1); - return (-1); + return -1; } else if (ch.ch == '?') { mutt_refresh (); @@ -498,13 +506,13 @@ ssize_t mutt_pretty_size(char *s, ssize_t len, ssize_t n) if (n < 1023949) /* 10K - 999K */ /* 51 is magic which causes 10189/10240 to be rounded up to 10 */ - return snprintf(s, len, "%ldK", (n + 51) / 1024); + return snprintf(s, len, "%ldK", (n + 51) / 1024L); if (n < 10433332) /* 1.0M - 9.9M */ return snprintf(s, len, "%3.1fM", n / 1048576.0); /* (10433332 + 52428) / 1048576 = 10 */ - return snprintf (s, len, "%ldM", (n + 52428) / 1048576); + return snprintf (s, len, "%ldM", (n + 52428) / 1048576L); } /*