Repository: xonsh/xonsh

Issue:
PTK prompt does not honor custom style colors
<!--- Provide a general summary of the issue in the Title above -->
<!--- If you have a question along the lines of "How do I do this Bash command in xonsh"
please first look over the Bash to Xonsh translation guide: https://xon.sh/bash_to_xsh.html
If you don't find an answer there, please do open an issue! -->

## xonfig

<details>
<summary>xonfig</summary>

```
+------------------+----------------------+
| xonsh            | 0.9.27               |
| Git SHA          | 71fe9014             |
| Commit Date      | Jan 29 08:58:58 2021 |
| Python           | 3.9.5                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 3.0.18               |
| shell type       | prompt_toolkit       |
| pygments         | 2.9.0                |
| 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      |
| on jupyter       | False                |
| jupyter kernel   | None                 |
| xontrib          | []                   |
+------------------+----------------------+
```

</details>
<details>
<summary>.xonshrc</summary>

```
#!/usr/bin/env xonsh

from xonsh.tools import register_custom_style

register_custom_style(
    'test',
    {
        'YELLOW': '#b58900',
        'Token.Literal.Number': '#b58900',
    },
    base='monokai'
)
$XONSH_COLOR_STYLE = 'test'
$PROMPT = '{YELLOW}yellow{RESET}> '
```
</details>

## Expected Behavior
The word "yellow" in the prompt should be highlighted in the "yellow" color from the custom style.

## Current Behavior
With the PTK prompt, the word "yellow" instead uses the "yellow" color from the base style. [![asciicast](https://asciinema.org/a/SETNah0ZQmXFlbrEsNNhJZzzs.svg)](https://asciinema.org/a/SETNah0ZQmXFlbrEsNNhJZzzs)

## Steps to Reproduce

Use the config above, or another config that registers a custom style that changes the base colors. Observe that the colors in the prompt do not respect the custom style.

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:
Hi @dyuri ! Please take a look.
You can use `Token.Color.COLOR` to override default color tokens until I check why the short names doesn't work.

This works for me:
```
#!/usr/bin/env xonsh

from xonsh.tools import register_custom_style

register_custom_style(
    'test',
    {
        'Token.Color.YELLOW': '#b58900',
        'Token.Literal.Number': '#b58900',
    },
    base='monokai'
)
$XONSH_COLOR_STYLE = 'test'
$PROMPT = '{YELLOW}yellow{RESET}> '
```

Resolving patch:
diff --git a/xonsh/pyghooks.py b/xonsh/pyghooks.py
--- a/xonsh/pyghooks.py
+++ b/xonsh/pyghooks.py
@@ -245,18 +245,21 @@ def color_token_by_name(xc: tuple, styles=None) -> _TokenType:
         try:
             styles = XSH.shell.shell.styler.styles  # type:ignore
         except AttributeError:
-            return Color
+            pass
 
     tokName = xc[0]
-    pc = color_name_to_pygments_code(xc[0], styles)
+    if styles:
+        pc = color_name_to_pygments_code(xc[0], styles)
 
-    if len(xc) > 1:
-        pc += " " + color_name_to_pygments_code(xc[1], styles)
-        tokName += "__" + xc[1]
+        if len(xc) > 1:
+            pc += " " + color_name_to_pygments_code(xc[1], styles)
+            tokName += "__" + xc[1]
 
     token = getattr(Color, norm_name(tokName))
-    if token not in styles or not styles[token]:
+
+    if styles and (token not in styles or not styles[token]):
         styles[token] = pc
+
     return token
 
 


Test patch:
diff --git a/tests/test_pyghooks.py b/tests/test_pyghooks.py
--- a/tests/test_pyghooks.py
+++ b/tests/test_pyghooks.py
@@ -365,6 +365,11 @@ def mock_os_listxattr(*args, **kwards):
             {"completion-menu.completion.current": "#00ff00"},
             {Token.PTK.CompletionMenu.Completion.Current: "#00ff00"},
         ),  # ptk style
+        (
+            "test6",
+            {"RED": "#ff0000"},
+            {Token.Color.RED: "#ff0000"},
+        ),  # short color name
     ],
 )
 def test_register_custom_pygments_style(name, styles, refrules):