Commit Graph

32 Commits (0f0f221180b1fec3254e74d8d657c3a929870b1b)

Author SHA1 Message Date
Eric Freese a437544cc5 Degrade gracefully on systems missing zsh/system module
When using async mode, stale background processes will not be cancelled
when a new one starts. This shouldn't cause any real issues since the
processes should eventually finish and be cleaned up anyway, and
removing the handler with `zle -F` means that stale suggestions should
never be shown.
6 years ago
Eric Freese 68343c8de4 Allow suggestions to suggest trailing newlines
Command substitution via $() trims trailing newlines so the old approach
to reading everything from the fd was preventing suggestions from ending
with newlines.

Found the read solution here: https://stackoverflow.com/a/15184414/154703
6 years ago
Eric Freese 4cd210b70d Fix async suggestions when SH_WORD_SPLIT is set 6 years ago
Eric Freese e405afab29 Refactor async mode to no longer use zpty
See technique used in `fast-syntax-highlighting`:
- ca2e18bbc9
- http://www.zsh.org/mla/users/2018/msg00424.html

Also see http://www.zsh.org/mla/users/2018/msg00432.html

In async response handler:
- We only want to read data in case of POLLIN or POLLHUP. Not POLLNVAL
  or select error.
- We always want to remove the handler, so it doesn't get called in an
  infinite loop when error is nval or err.

There is an upstream bug that prevents ctrl-c from resetting the prompt
immediately after a suggestion has been fetched asynchronously. A patch
has been submitted, but a workaround for now is to add `command true`
after the exec.

See https://github.com/zsh-users/zsh-autosuggestions/issues/364
6 years ago
Eric Freese a78ea16c50 Support fallback strategies by setting array in config 7 years ago
Eric Freese 0f80f9511d Fix handling of newline + carriage return in async pty (#333) 7 years ago
Eric Freese df5fb858aa Destroy old pty even if it's no longer running (#249)
For unknown reasons, the pty will occasionally quit running. In these
cases, we still want to remove it so that a fresh one can be created. We
don't actually need this check because error messages from `zle` and
`zpty` are redirected to /dev/null.

One sure way to kill all currently running pty's is to run `exit` in a
subshell. Even without zsh-autosuggestions loaded, the following works:

    % zmodload zsh/zpty
    % zpty -b foo cat
    % zpty -b bar cat
    % zpty
    (31689) bar: cat
    (31666) foo: cat
    % $(exit)
    % zpty
    (finished) bar: cat
    (finished) foo: cat
7 years ago
Eric Freese 60aff2d944 Remove unused local `$suggestion` variable 7 years ago
Kaleb Elwert 940e10a691 Fix conditionals to use [[ and (( rather than [
This fixes a small issue in src/widgets.zsh which makes it so if you
alias [ to g[ (as is done in prezto if the gnu-utility module is loaded)
autosuggestions would fail.

The documentation for GNU test mentions that -o and -a should be avoided
if possible because it's not very clear. Also, with zsh and [[ -o
actually tests if an option is set, which makes this option even more
confusing.
8 years ago
Eric Freese c9a51e0c4c Handle dashes at the beginning of commands 9 years ago
Eric Freese 48a21bf79e [cleanup] Remove an extra newline 9 years ago
Eric Freese 4afbbbadda We only need to run the feature detection if starting async 9 years ago
Eric Freese a0fcd81ce1 Destroy zpty on load if it already exists 9 years ago
Eric Freese 9feac573c9 Do not show any error output from async zpty server process 9 years ago
Eric Freese ed8056c5e8 Lots of async changes 9 years ago
Eric Freese 2c465a932a Rename async pty name config var 9 years ago
Eric Freese e3eb286ea2 Lots of little async cleanups 9 years ago
Eric Freese 40bb2e7804 little cleanup 9 years ago
Eric Freese 16666da488 Handle versions of zsh where zpty does not set REPLY to fd of opened pty
Based on e702ec4697/async.zsh (L400-L406)
9 years ago
Eric Freese f33b605a63 Move async initialization into `start` function to keep in one place 9 years ago
Eric Freese 6c5cd42331 Go back to tracking last pid because `kill %1` didn't seem to be working 9 years ago
Eric Freese 21d9eda5dd Wrap suggestion fetch command in parens to actually run in background 9 years ago
Eric Freese b3208b08af Pass the chosen strategy into the suggestion server pty 9 years ago
Eric Freese e5a5b0c1e0 Output only newlines in the pty 9 years ago
Eric Freese 0337005eb0 Disable word splitting while reading to preserve whitespace 9 years ago
Eric Freese b530b0c996 Use `zpty -r` with pattern matching to fetch suggestion 9 years ago
Eric Freese 5c891afd48 Reset zsh options inside pty (from zsh-async) 9 years ago
Eric Freese e33eb570c4 Send only the prefix to the suggestion server 9 years ago
Eric Freese fba20b042e Use %1 instead of tracking pid 9 years ago
Eric Freese 0308ed797e Rename worker to server 9 years ago
Eric Freese e72c2d87e5 add a bunch of comments 9 years ago
Eric Freese ab8f295225 First pass at async functionality 9 years ago