Repository: xonsh/xonsh

Issue:
KeyError with pygments when setting stderr prefix/postfix
Seems to be very similar to #2778.

## xonfig
```
jbleger@gertrude ~ $ xonfig                                                                                                                                                                                                                                                      
+------------------+----------------------+
| xonsh            | 0.8.3                |
| Git SHA          | eac1333f             |
| Commit Date      | Nov 29 13:34:58 2018 |
| Python           | 3.7.1                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 2.0.7                |
| shell type       | prompt_toolkit2      |
| pygments         | 2.3.0                |
| on posix         | True                 |
| on linux         | True                 |
| distro           | debian               |
| 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      |
+------------------+----------------------+
```

## Current Behavior
```
jbleger@gertrude ~ $ $XONSH_STDERR_POSTFIX = '{NO_COLOR}'                                                                                                                                                                 
jbleger@gertrude ~ $ $XONSH_STDERR_PREFIX = '{RED}'
Traceback (most recent call last):
  File "/home/jbleger/geek/xonsh/xonsh/main.py", line 401, in main
    return main_xonsh(args)
  File "/home/jbleger/geek/xonsh/xonsh/main.py", line 430, in main_xonsh
    shell.shell.cmdloop()
  File "/home/jbleger/geek/xonsh/xonsh/ptk2/shell.py", line 194, in cmdloop
    self.default(line)
  File "/home/jbleger/geek/xonsh/xonsh/base_shell.py", line 357, in default
    tee = Tee(encoding=enc, errors=err)
  File "/home/jbleger/geek/xonsh/xonsh/base_shell.py", line 265, in __init__
    poststderr = format_std_prepost(env.get("XONSH_STDERR_POSTFIX"))
  File "/home/jbleger/geek/xonsh/xonsh/tools.py", line 1924, in format_std_prepost
    s = shell.format_color(invis + s + invis, force_string=True)
  File "/home/jbleger/geek/xonsh/xonsh/ptk2/shell.py", line 289, in format_color
    formatter = pyghooks.XonshTerminal256Formatter(style=proxy_style)
  File "/home/jbleger/geek/xonsh/xonsh/lazyasd.py", line 79, in __call__
    return obj(*args, **kwargs)
  File "/home/jbleger/geek/xonsh/xonsh/pyghooks.py", line 1447, in __init__
    super().__init__(*args, **kwargs)
  File "/home/jbleger/.local/lib/python3.7/site-packages/pygments/formatters/terminal256.py", line 134, in __init__
    self._setup_styles()  # convert selected style's colors to term. colors
  File "/home/jbleger/.local/lib/python3.7/site-packages/pygments/formatters/terminal256.py", line 224, in _setup_styles
    self.style_string[str(ttype)] = (escape.color_string(),
  File "/home/jbleger/.local/lib/python3.7/site-packages/pygments/formatters/terminal256.py", line 53, in color_string
    esc = codes[self.fg[5:]]
KeyError: 'lack'
Xonsh encountered an issue during launch
Failback to /bin/sh
$ 
```

Thanks,


Discussion:
The problem is that Pygments' `terminal256` expect the items in `pygments.style.ansicolors` to have `#` prefix. We deliberately violate the assumption [here](https://github.com/xonsh/xonsh/blob/69e5a6fa5f802e250df2458f51cf38f86d06bc40/xonsh/pyghooks.py#L499-L504) by patching in our own unprefixed items. Pygments eventually crash [here](https://bitbucket.org/birkenfeld/pygments-main/src/cb543fa1cc0031bf5fdcd2e8ee95dd3409fe89dc/pygments/formatters/terminal256.py?at=default&fileviewer=file-view-default#terminal256.py-53) or [here](https://bitbucket.org/birkenfeld/pygments-main/src/cb543fa1cc0031bf5fdcd2e8ee95dd3409fe89dc/pygments/formatters/terminal256.py?at=default&fileviewer=file-view-default#terminal256.py-62) while trying to map corresponding terminal control sequence to the malformed color name.
Any Ideas?
It is too far away. But everything about the new color names is a bit of hack until the names gets into pygments (see this [PR to pygments](https://bitbucket.org/birkenfeld/pygments-main/pull-requests/777/change-ansi-color-names-to-more-saying/diff))

I think we can probably fix this similar to how colored output is handled. But I simply can't rember what we did. I will look into it when I have a little more time.

Resolving patch:
diff --git a/xonsh/pyghooks.py b/xonsh/pyghooks.py
--- a/xonsh/pyghooks.py
+++ b/xonsh/pyghooks.py
@@ -1431,7 +1431,7 @@ def XonshTerminal256Formatter():
         ptk_version_info()
         and ptk_version_info() > (2, 0)
         and pygments_version_info()
-        and (2, 2) <= pygments_version_info() < (2, 3)
+        and (2, 2, 0) <= pygments_version_info() <= (2, 3, 0)
     ):
         # Monky patch pygments' dict of console codes
         # with the new color names used by PTK2


Test patch: