Repository: xonsh/xonsh

Issue:
xonsh sudoedit (nano as root) queues up lines of keystrokes
## xonfig

<details>
```
jimbo1qaz@manjaro ~ $ xonfig
+------------------+-----------------+
| xonsh            | 0.9.0           |
| Python           | 3.7.3           |
| PLY              | 3.11            |
| have readline    | True            |
| prompt toolkit   | None            |
| shell type       | readline        |
| pygments         | None            |
| on posix         | True            |
| on linux         | True            |
| distro           | manjaro         |
| on darwin        | False           |
| on windows       | False           |
| on cygwin        | False           |
| on msys2         | False           |
| is superuser     | False           |
| default encoding | utf-8           |
| xonsh encoding   | utf-8           |
| encoding errors  | surrogateescape |
+------------------+-----------------+
```
</details>

## Expected Behavior
xonsh's `sudoedit /etc/filename` functions like bash's `sudoedit /etc/filename`. Keystrokes are sent to vim/nano when I press them, and the editor handles redrawing screen.

## Current Behavior
xonsh queues up an entire line of keystrokes and control codes, drawing them to screen. Only when pressing Enter are they sent to vim/nano.

## Steps to Reproduce
- Open xonsh (in Konsole).
- `sudoedit /etc/filename` and type password.
- Type characters, press arrow keys or pagedown, etc.

--------

- `sudo nano` is unaffected.
- `sudo su -c xonsh` plus `nano` is unaffected.
- bash `sudoedit /etc/filename` is unaffected.


Discussion:
Hi @jimbo1qaz, can you please try the following workaround?
```
$ __xonsh__.commands_cache.threadable_predictors['sudoedit'] = lambda args: False
$ sudoedit /etc/filename
```

The workaround works.

Can this issue be fixed globally, or only by blacklisting individual program names from "line buffering"? In other words, will renaming sudoedit cause it to break again?

I had the same issue when running `pamac` and asking it to edit PKGBUILD. In this case, *pamac calls vim/nano directly (does **not** use sudoedit)*, but experiences the same problem.

- When running pamac in xonsh OR bash, ^C is buffered (and ignored) until I press Enter: `Edit build files ? [y/N] ^C^C^C^Cn` (if I press ^C^C^Cy, it opens an editor)
- If I tell pamac to edit the file, bash (but not xonsh) properly switches to raw input when the editor opens.
> Can this issue be fixed globally

Unfortunately, no - not easily. The issue is due to the way Xonsh handles subprocesses. Xonsh does its best to predict which executables enter the problematic alternate terminal mode, but the detection is not 100% reliable, so Xonsh sometimes needs our help.  

> or only by blacklisting individual program names from "line buffering"? In other words, will renaming sudoedit cause it to break again?

Yes, you need to individually "blacklist" each problematic executable and renaming will break it again.

> I had the same issue when running pamac and asking it to edit PKGBUILD. In this case, pamac calls vim/nano directly (does not use sudoedit), but experiences the same problem.

Sounds like the same problem to me. You can put the workaround line into your `.xonshrc` for pamac.

Resolving patch:
diff --git a/xonsh/commands_cache.py b/xonsh/commands_cache.py
--- a/xonsh/commands_cache.py
+++ b/xonsh/commands_cache.py
@@ -479,6 +479,7 @@ def default_threadable_predictors():
         "ssh": predict_false,
         "startx": predict_false,
         "sudo": predict_help_ver,
+        "sudoedit": predict_help_ver,
         "tcsh": predict_shell,
         "telnet": predict_false,
         "tput": predict_false,


Test patch: