Repository: xonsh/xonsh

Issue:
UnboundLocalError: local variable 'complete_style' referenced before assignment
<!--- 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: http://xon.sh/bash_to_xsh.html
If you don't find an answer there, please do open an issue! -->

## xonfig
<!--- Please post the output of the `xonfig` command (run from inside xonsh) so we know more about your current setup -->

```
λ xonfig                                                                                                                                                                 
+------------------+---------------------+
| xonsh            | 0.7.3               |
| Git SHA          | 9bbbf07b            |
| Commit Date      | Aug 2 18:08:44 2018 |
| Python           | 3.6.6               |
| PLY              | 3.9                 |
| have readline    | True                |
| prompt toolkit   | 2.0.4               |
| shell type       | prompt_toolkit2     |
| pygments         | 2.2.0               |
| on posix         | True                |
| on linux         | True                |
| distro           | Gentoo Base System  |
| on darwin        | False               |
| on windows       | False               |
| on cygwin        | False               |
| on msys2         | False               |
| is superuser     | True                |
| default encoding | utf-8               |
| xonsh encoding   | utf-8               |
| encoding errors  | surrogateescape     |
+------------------+---------------------+
```

## Current Behavior
<!--- Tell us what happens instead of the expected behavior -->
<!--- If part of your bug report is a traceback, please first enter debug mode before triggering the error
To enter debug mode, set the environment variable `XONSH_DEBUG=1` _before_ starting `xonsh`.  
On Linux and OSX, an easy way to to do this is to run `env XONSH_DEBUG=1 xonsh` -->

I have set `$COMPLETIONS_DISPLAY = "single"` and get error. 
Now I change it to `multi` depended on line 73 in `xonsh/ptk2/shell.py`, it works.

I am on GENTOO. xonsh/0.7.3

```
Traceback (most recent call last):
  File "/root/.local/lib64/python3.6/site-packages/xonsh/main.py", line 342, in main
    return main_xonsh(args)
  File "/root/.local/lib64/python3.6/site-packages/xonsh/main.py", line 368, in main_xonsh
    shell.shell.cmdloop()
  File "/root/.local/lib64/python3.6/site-packages/xonsh/ptk2/shell.py", line 158, in cmdloop
    line = self.singleline(auto_suggest=auto_suggest)
  File "/root/.local/lib64/python3.6/site-packages/xonsh/ptk2/shell.py", line 110, in singleline
    'complete_style': complete_style,
UnboundLocalError: local variable 'complete_style' referenced before assignment
Xonsh encountered an issue during launch
Failback to /bin/bash
```



Discussion:
Thanks for reporting @nasyxx!

Resolving patch:
diff --git a/xonsh/environ.py b/xonsh/environ.py
--- a/xonsh/environ.py
+++ b/xonsh/environ.py
@@ -448,6 +448,8 @@ def DEFAULT_DOCS():
         '  single column while typing.\n'
         "- If ``$COMPLETIONS_DISPLAY`` is ``multi`` or ``true``, display completions\n"
         "  in multiple columns while typing.\n\n"
+        "- If ``$COMPLETIONS_DISPLAY`` is ``readline``, display completions\n"
+        "  will emulate the behavior of readline.\n\n"
         'These option values are not case- or type-sensitive, so e.g.'
         "writing ``$COMPLETIONS_DISPLAY = None`` "
         "and ``$COMPLETIONS_DISPLAY = 'none'`` are equivalent. Only usable with "
diff --git a/xonsh/ptk2/shell.py b/xonsh/ptk2/shell.py
--- a/xonsh/ptk2/shell.py
+++ b/xonsh/ptk2/shell.py
@@ -41,6 +41,13 @@
 class PromptToolkit2Shell(BaseShell):
     """The xonsh shell for prompt_toolkit v2."""
 
+    completion_displays_to_styles = {
+        "multi": CompleteStyle.MULTI_COLUMN,
+        "single": CompleteStyle.COLUMN,
+        "readline": CompleteStyle.READLINE_LIKE,
+        "none": None,
+    }
+
     def __init__(self, **kwargs):
         super().__init__(**kwargs)
         if ON_WINDOWS:
@@ -70,8 +77,8 @@ def singleline(self, auto_suggest=None, enable_history_search=True,
         mouse_support = env.get('MOUSE_SUPPORT')
         auto_suggest = auto_suggest if env.get('AUTO_SUGGEST') else None
         completions_display = env.get('COMPLETIONS_DISPLAY')
-        if completions_display == 'multi':
-            complete_style = CompleteStyle.MULTI_COLUMN
+        complete_style = self.completion_displays_to_styles[completions_display]
+
         complete_while_typing = env.get('UPDATE_COMPLETIONS_ON_KEYPRESS')
         if complete_while_typing:
             # PTK requires history search to be none when completing while typing
diff --git a/xonsh/tools.py b/xonsh/tools.py
--- a/xonsh/tools.py
+++ b/xonsh/tools.py
@@ -1408,7 +1408,7 @@ def to_completions_display_value(x):
         x = 'none'
     elif x in {'multi', 'true'}:
         x = 'multi'
-    elif x == 'single':
+    elif x in {'single', 'readline'}:
         pass
     else:
         msg = '"{}" is not a valid value for $COMPLETIONS_DISPLAY. '.format(x)


Test patch: