Repository: xonsh/xonsh

Issue:
ls broken with $XONSH_COLOR_STYLE = 'bw'
## xonfig

<details>

```
$ xonfig
+------------------+-----------------+
| xonsh            | 0.9.3           |
| Python           | 3.7.3           |
| PLY              | 3.11            |
| have readline    | True            |
| prompt toolkit   | 2.0.9           |
| shell type       | prompt_toolkit2 |
| pygments         | 2.3.1           |
| on posix         | True            |
| on linux         | True            |
| distro           | unknown         |
| 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
`ls works`

## Current Behavior
```
ValueError: when converting 'BACKGROUND_BLACK', did not recognize '0;30' within the following color map as
 a valid color:

{'BLACK': '0;30', 'BLUE': '0;37', 'CYAN': '0;37', 'GREEN': '0;37', 'INTENSE_BLACK': '0;90', 'INTENSE_BLUE'
: '0;97', 'INTENSE_CYAN': '0;97', 'INTENSE_GREEN': '0;97', 'INTENSE_PURPLE': '0;97', 'INTENSE_RED': '0;97'
, 'INTENSE_WHITE': '0;97', 'INTENSE_YELLOW': '0;97', 'NO_COLOR': '0', 'PURPLE': '0;37', 'RED': '0;37', 'WH
ITE': '0;37', 'YELLOW': '0;37', 'BOLD_RED': '1;0;37', 'BOLD_PURPLE': '1;0;37'}
```

### Traceback (if applicable)

<details>

```
Traceback (most recent call last):
  File "/nix/store/gazjvyirnxpqkz5rgvv7krcs3i90lbl4-xonsh-0.9.3/lib/python3.7/site-packages/xonsh/proc.py"
, line 1856, in __init__
    proc = spec.run(pipeline_group=pipeline_group)
  File "/nix/store/gazjvyirnxpqkz5rgvv7krcs3i90lbl4-xonsh-0.9.3/lib/python3.7/site-packages/xonsh/built_in
s.py", line 541, in run
    self.prep_env(kwargs)
  File "/nix/store/gazjvyirnxpqkz5rgvv7krcs3i90lbl4-xonsh-0.9.3/lib/python3.7/site-packages/xonsh/built_in
s.py", line 576, in prep_env
    denv = builtins.__xonsh__.env.detype()
  File "/nix/store/gazjvyirnxpqkz5rgvv7krcs3i90lbl4-xonsh-0.9.3/lib/python3.7/site-packages/xonsh/environ.
py", line 1364, in detype
    deval = ensurer.detype(val)
  File "/nix/store/gazjvyirnxpqkz5rgvv7krcs3i90lbl4-xonsh-0.9.3/lib/python3.7/site-packages/xonsh/tools.py
", line 1095, in detype
    return x.detype()
  File "/nix/store/gazjvyirnxpqkz5rgvv7krcs3i90lbl4-xonsh-0.9.3/lib/python3.7/site-packages/xonsh/environ.
py", line 373, in detype
    for key, val in sorted(self._d.items())
  File "/nix/store/gazjvyirnxpqkz5rgvv7krcs3i90lbl4-xonsh-0.9.3/lib/python3.7/site-packages/xonsh/environ.
py", line 373, in <listcomp>
    for key, val in sorted(self._d.items())
  File "/nix/store/gazjvyirnxpqkz5rgvv7krcs3i90lbl4-xonsh-0.9.3/lib/python3.7/site-packages/xonsh/environ.
py", line 371, in <listcomp>
    [ansi_color_name_to_escape_code(v, cmap=style) for v in val]
  File "/nix/store/gazjvyirnxpqkz5rgvv7krcs3i90lbl4-xonsh-0.9.3/lib/python3.7/site-packages/xonsh/ansi_col
ors.py", line 82, in ansi_color_name_to_escape_code
    raise ValueError(msg.format(name, fgcolor, cmap))
ValueError: when converting 'BACKGROUND_BLACK', did not recognize '0;30' within the following color map as
 a valid color:

{'BLACK': '0;30', 'BLUE': '0;37', 'CYAN': '0;37', 'GREEN': '0;37', 'INTENSE_BLACK': '0;90', 'INTENSE_BLUE'
: '0;97', 'INTENSE_CYAN': '0;97', 'INTENSE_GREEN': '0;97', 'INTENSE_PURPLE': '0;97', 'INTENSE_RED': '0;97'
, 'INTENSE_WHITE': '0;97', 'INTENSE_YELLOW': '0;97', 'NO_COLOR': '0', 'PURPLE': '0;37', 'RED': '0;37', 'WH
ITE': '0;37', 'YELLOW': '0;37', 'BOLD_RED': '1;0;37', 'BOLD_PURPLE': '1;0;37'}
```
</details>

## Steps to Reproduce
Execute `ls` with a `.xonsh` consisting of `$XONSH_COLOR_STYLE = 'bw'`


Discussion:
My attempt at bisecting:

```
There are only 'skip'ped commits left to test.
The first bad commit could be any of:
4c3a5c98dd2b096d95e00928e2bbde1efe8f838d
e07bc664e28c523bd3b0ade273c47907b0b3988b
We cannot bisect more!
```

Paging @scopatz 



Resolving patch:
diff --git a/xonsh/ansi_colors.py b/xonsh/ansi_colors.py
--- a/xonsh/ansi_colors.py
+++ b/xonsh/ansi_colors.py
@@ -343,10 +343,23 @@ def ansi_color_escape_code_to_name(escape_code, style, reversed_style=None):
 
 def _bw_style():
     style = {
+        "NO_COLOR": "0",
         "BLACK": "0;30",
         "BLUE": "0;37",
         "CYAN": "0;37",
         "GREEN": "0;37",
+        "PURPLE": "0;37",
+        "RED": "0;37",
+        "WHITE": "0;37",
+        "YELLOW": "0;37",
+        "BACKGROUND_BLACK": "40",
+        "BACKGROUND_RED": "47",
+        "BACKGROUND_GREEN": "47",
+        "BACKGROUND_YELLOW": "47",
+        "BACKGROUND_BLUE": "47",
+        "BACKGROUND_PURPLE": "47",
+        "BACKGROUND_CYAN": "47",
+        "BACKGROUND_WHITE": "47",
         "INTENSE_BLACK": "0;90",
         "INTENSE_BLUE": "0;97",
         "INTENSE_CYAN": "0;97",
@@ -355,11 +368,6 @@ def _bw_style():
         "INTENSE_RED": "0;97",
         "INTENSE_WHITE": "0;97",
         "INTENSE_YELLOW": "0;97",
-        "NO_COLOR": "0",
-        "PURPLE": "0;37",
-        "RED": "0;37",
-        "WHITE": "0;37",
-        "YELLOW": "0;37",
     }
     return style
 


Test patch:
diff --git a/tests/test_ansi_colors.py b/tests/test_ansi_colors.py
--- a/tests/test_ansi_colors.py
+++ b/tests/test_ansi_colors.py
@@ -5,6 +5,7 @@
     ansi_color_escape_code_to_name,
     ansi_reverse_style,
     ansi_color_name_to_escape_code,
+    ansi_color_style_names,
 )
 
 
@@ -119,3 +120,16 @@ def test_ansi_reverse_style(key, value):
 def test_ansi_color_escape_code_to_name(inp, exp):
     obs = ansi_color_escape_code_to_name(inp, "default", reversed_style=RS)
     assert obs == exp
+
+
+@pytest.mark.parametrize(
+    "color, style",
+    [
+        (color, style)
+        for color in DEFAULT_CMAP.keys()
+        for style in ansi_color_style_names()
+    ],
+)
+def test_ansi_color_name_to_escape_code_for_all_styles(color, style):
+    escape_code = ansi_color_name_to_escape_code(color, style)
+    assert len(escape_code) > 0