diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2002-07-01 09:54:47 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2002-07-01 09:54:47 +0000 |
commit | a18f0202824ccd29a931edd2abc6d2caee23296c (patch) | |
tree | 50a2dca5e58acc6272778e6fb787d78c3d422e3e /Src/Zle/zle_main.c | |
parent | 053629183d8075c5bd122c9767f0b4f8bf8be870 (diff) | |
download | zsh-a18f0202824ccd29a931edd2abc6d2caee23296c.tar.gz zsh-a18f0202824ccd29a931edd2abc6d2caee23296c.tar.xz zsh-a18f0202824ccd29a931edd2abc6d2caee23296c.zip |
17384: new recursive-edit widget.
Diffstat (limited to 'Src/Zle/zle_main.c')
-rw-r--r-- | Src/Zle/zle_main.c | 152 |
1 files changed, 86 insertions, 66 deletions
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 782bd472c..9332b509d 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -89,10 +89,11 @@ mod_export int eofchar; static int eofsent; static long keytimeout; -#ifdef HAVE_SELECT +#if defined(HAVE_SELECT) || defined(HAVE_POLL) /* Terminal baud rate */ static int baud; +static long costmult; #endif /* flags associated with last command */ @@ -631,6 +632,74 @@ getkey(int keytmout) return ret; } +/**/ +void +zlecore(void) +{ +#if !defined(HAVE_POLL) && defined(HAVE_SELECT) + struct timeval tv; + fd_set foofd; + + FD_ZERO(&foofd); +#endif + + zrefresh(); + + while (!done && !errflag) { + + statusline = NULL; + vilinerange = 0; + reselectkeymap(); + selectlocalmap(NULL); + bindk = getkeycmd(); + if (!ll && isfirstln && unset(IGNOREEOF) && c == eofchar) { + eofsent = 1; + break; + } + if (bindk) { + if (execzlefunc(bindk, zlenoargs)) + handlefeep(zlenoargs); + handleprefixes(); + /* for vi mode, make sure the cursor isn't somewhere illegal */ + if (invicmdmode() && cs > findbol() && + (cs == ll || line[cs] == '\n')) + cs--; + if (undoing) + handleundo(); + } else { + errflag = 1; + break; + } +#ifdef HAVE_POLL + if (baud && !(lastcmd & ZLE_MENUCMP)) { + struct pollfd pfd; + int to = cost * costmult / 1000; /* milliseconds */ + + if (to > 500) + to = 500; + pfd.fd = SHTTY; + pfd.events = POLLIN; + if (!kungetct && poll(&pfd, 1, to) <= 0) + zrefresh(); + } else +#else +# ifdef HAVE_SELECT + if (baud && !(lastcmd & ZLE_MENUCMP)) { + FD_SET(SHTTY, &foofd); + tv.tv_sec = 0; + if ((tv.tv_usec = cost * costmult) > 500000) + tv.tv_usec = 500000; + if (!kungetct && select(SHTTY+1, (SELECT_ARG_2_T) & foofd, + NULL, NULL, &tv) <= 0) + zrefresh(); + } else +# endif +#endif + if (!kungetct) + zrefresh(); + } +} + /* Read a line. It is returned metafied. */ /**/ @@ -641,14 +710,7 @@ zleread(char *lp, char *rp, int flags) int old_errno = errno; int tmout = getiparam("TMOUT"); -#if defined(HAVE_SELECT) || defined(HAVE_POLL) - long costmult; -# ifdef HAVE_POLL -# else - struct timeval tv; - fd_set foofd; -# endif - +#if defined(HAVE_POLL) || defined(HAVE_SELECT) baud = getiparam("BAUD"); costmult = (baud) ? 3840000L / baud : 0; #endif @@ -693,11 +755,6 @@ zleread(char *lp, char *rp, int flags) zlereadflags = flags; histline = curhist; -#ifndef HAVE_POLL -# ifdef HAVE_SELECT - FD_ZERO(&foofd); -# endif -#endif undoing = 1; line = (unsigned char *)zalloc((linesz = 256) + 2); virangeflag = lastcmd = done = cs = ll = mark = 0; @@ -732,60 +789,9 @@ zleread(char *lp, char *rp, int flags) lastcol = -1; initmodifier(&zmod); prefixflag = 0; - zrefresh(); - while (!done && !errflag) { - statusline = NULL; - vilinerange = 0; - reselectkeymap(); - selectlocalmap(NULL); - bindk = getkeycmd(); - if (!ll && isfirstln && unset(IGNOREEOF) && c == eofchar) { - eofsent = 1; - break; - } - if (bindk) { - if (execzlefunc(bindk, zlenoargs)) - handlefeep(zlenoargs); - handleprefixes(); - /* for vi mode, make sure the cursor isn't somewhere illegal */ - if (invicmdmode() && cs > findbol() && - (cs == ll || line[cs] == '\n')) - cs--; - if (undoing) - handleundo(); - } else { - errflag = 1; - break; - } -#ifdef HAVE_POLL - if (baud && !(lastcmd & ZLE_MENUCMP)) { - struct pollfd pfd; - int to = cost * costmult / 1000; /* milliseconds */ + zlecore(); - if (to > 500) - to = 500; - pfd.fd = SHTTY; - pfd.events = POLLIN; - if (!kungetct && poll(&pfd, 1, to) <= 0) - zrefresh(); - } else -#else -# ifdef HAVE_SELECT - if (baud && !(lastcmd & ZLE_MENUCMP)) { - FD_SET(SHTTY, &foofd); - tv.tv_sec = 0; - if ((tv.tv_usec = cost * costmult) > 500000) - tv.tv_usec = 500000; - if (!kungetct && select(SHTTY+1, (SELECT_ARG_2_T) & foofd, - NULL, NULL, &tv) <= 0) - zrefresh(); - } else -# endif -#endif - if (!kungetct) - zrefresh(); - } statusline = NULL; invalidatelist(); trashzle(); @@ -1234,6 +1240,20 @@ whereis(char **args) } /**/ +int +recursiveedit(char **args) +{ + int locerror; + + zlecore(); + + locerror = errflag; + errflag = done = 0; + + return locerror; +} + +/**/ mod_export void trashzle(void) { |