prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Add 'edit and execute command` function
  bash and zsh (and I'm sure others) have an edit and execute command that is invoked with Ctrl-e + Ctrl-x which opens the current contents of the command prompt in the system editor.  Edits made to the command are then run on save and quit.  
  
  It could be this functionality is already baked in and I'm missing it?  In any case, it's especially handy for longer commands -- and given xonsh's multi-line input capabilities this seems like a good fit.
  
  Thoughts?
  
  
  </issue>
  <code>
  [start of xonsh/prompt_toolkit_shell.py]
  1 """The prompt_toolkit based xonsh shell"""
  2 import os
  3 import builtins
  4 from warnings import warn
  5 
  6 from prompt_toolkit.shortcuts import get_input
  7 from prompt_toolkit.key_binding.manager import KeyBindingManager
  8 from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
  9 from pygments.token import Token
  10 from pygments.style import Style
  11 
  12 from xonsh.base_shell import BaseShell
  13 from xonsh.tools import format_prompt_for_prompt_toolkit
  14 from xonsh.prompt_toolkit_completer import PromptToolkitCompleter
  15 from xonsh.prompt_toolkit_history import LimitedFileHistory
  16 from xonsh.prompt_toolkit_key_bindings import load_xonsh_bindings
  17 
  18 
  19 def setup_history():
  20     """Creates history object."""
  21     env = builtins.__xonsh_env__
  22     hfile = env.get('XONSH_HISTORY_FILE')
  23     history = LimitedFileHistory()
  24     try:
  25         history.read_history_file(hfile)
  26     except PermissionError:
  27         warn('do not have read permissions for ' + hfile, RuntimeWarning)
  28     return history
  29 
  30 
  31 def teardown_history(history):
  32     """Tears down the history object."""
  33     env = builtins.__xonsh_env__
  34     hsize = env.get('XONSH_HISTORY_SIZE')[0]
  35     hfile = env.get('XONSH_HISTORY_FILE')
  36     try:
  37         history.save_history_to_file(hfile, hsize)
  38     except PermissionError:
  39         warn('do not have write permissions for ' + hfile, RuntimeWarning)
  40 
  41 
  42 class PromptToolkitShell(BaseShell):
  43     """The xonsh shell."""
  44 
  45     def __init__(self, **kwargs):
  46         super().__init__(**kwargs)
  47         self.history = setup_history()
  48         self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx)
  49         self.key_bindings_manager = KeyBindingManager(
  50             enable_auto_suggest_bindings=True,
  51             enable_search=True, enable_abort_and_exit_bindings=True)
  52         load_xonsh_bindings(self.key_bindings_manager)
  53 
  54     def __del__(self):
  55         if self.history is not None:
  56             teardown_history(self.history)
  57 
  58     def cmdloop(self, intro=None):
  59         """Enters a loop that reads and execute input from user."""
  60         if intro:
  61             print(intro)
  62         _auto_suggest = AutoSuggestFromHistory()
  63         while not builtins.__xonsh_exit__:
  64             try:
  65                 token_func, style_cls = self._get_prompt_tokens_and_style()
  66                 mouse_support = builtins.__xonsh_env__.get('MOUSE_SUPPORT')
  67                 if builtins.__xonsh_env__.get('AUTO_SUGGEST'):
  68                     auto_suggest = _auto_suggest
  69                 else:
  70                     auto_suggest = None
  71                 completions_display = builtins.__xonsh_env__.get('COMPLETIONS_DISPLAY')
  72                 multicolumn = (completions_display == 'multi')
  73                 completer = None if completions_display == 'none' else self.pt_completer
  74                 line = get_input(
  75                     mouse_support=mouse_support,
  76                     auto_suggest=auto_suggest,
  77                     get_prompt_tokens=token_func,
  78                     style=style_cls,
  79                     completer=completer,
  80                     history=self.history,
  81                     key_bindings_registry=self.key_bindings_manager.registry,
  82                     display_completions_in_columns=multicolumn)
  83                 if not line:
  84                     self.emptyline()
  85                 else:
  86                     line = self.precmd(line)
  87                     self.default(line)
  88             except KeyboardInterrupt:
  89                 self.reset_buffer()
  90             except EOFError:
  91                 break
  92 
  93     def _get_prompt_tokens_and_style(self):
  94         """Returns function to pass as prompt to prompt_toolkit."""
  95         token_names, cstyles, strings = format_prompt_for_prompt_toolkit(self.prompt)
  96         tokens = [getattr(Token, n) for n in token_names]
  97 
  98         def get_tokens(cli):
  99             return list(zip(tokens, strings))
  100 
  101         class CustomStyle(Style):
  102             styles = {
  103                 Token.Menu.Completions.Completion.Current: 'bg:#00aaaa #000000',
  104                 Token.Menu.Completions.Completion: 'bg:#008888 #ffffff',
  105                 Token.Menu.Completions.ProgressButton: 'bg:#003333',
  106                 Token.Menu.Completions.ProgressBar: 'bg:#00aaaa',
  107                 Token.AutoSuggestion: '#666666',
  108                 Token.Aborted: '#888888',
  109             }
  110             # update with the prompt styles
  111             styles.update({t: s for (t, s) in zip(tokens, cstyles)})
  112             # Update with with any user styles
  113             userstyle = builtins.__xonsh_env__.get('PROMPT_TOOLKIT_STYLES')
  114             if userstyle is not None:
  115                 styles.update(userstyle)
  116 
  117         return get_tokens, CustomStyle
  118
  [end of xonsh/prompt_toolkit_shell.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/xonsh/prompt_toolkit_shell.py b/xonsh/prompt_toolkit_shell.py
  --- a/xonsh/prompt_toolkit_shell.py
  +++ b/xonsh/prompt_toolkit_shell.py
  @@ -48,6 +48,7 @@
           self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx)
           self.key_bindings_manager = KeyBindingManager(
               enable_auto_suggest_bindings=True,
  +            enable_open_in_editor=True,
               enable_search=True, enable_abort_and_exit_bindings=True)
           load_xonsh_bindings(self.key_bindings_manager)
  
verification_info: {"golden_diff": "diff --git a/xonsh/prompt_toolkit_shell.py b/xonsh/prompt_toolkit_shell.py\n--- a/xonsh/prompt_toolkit_shell.py\n+++ b/xonsh/prompt_toolkit_shell.py\n@@ -48,6 +48,7 @@\n         self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx)\n         self.key_bindings_manager = KeyBindingManager(\n             enable_auto_suggest_bindings=True,\n+            enable_open_in_editor=True,\n             enable_search=True, enable_abort_and_exit_bindings=True)\n         load_xonsh_bindings(self.key_bindings_manager)\n", "issue": "Add 'edit and execute command` function\nbash and zsh (and I'm sure others) have an edit and execute command that is invoked with Ctrl-e + Ctrl-x which opens the current contents of the command prompt in the system editor.  Edits made to the command are then run on save and quit.  \n\nIt could be this functionality is already baked in and I'm missing it?  In any case, it's especially handy for longer commands -- and given xonsh's multi-line input capabilities this seems like a good fit.\n\nThoughts?\n\n", "before_files": [{"content": "\"\"\"The prompt_toolkit based xonsh shell\"\"\"\nimport os\nimport builtins\nfrom warnings import warn\n\nfrom prompt_toolkit.shortcuts import get_input\nfrom prompt_toolkit.key_binding.manager import KeyBindingManager\nfrom prompt_toolkit.auto_suggest import AutoSuggestFromHistory\nfrom pygments.token import Token\nfrom pygments.style import Style\n\nfrom xonsh.base_shell import BaseShell\nfrom xonsh.tools import format_prompt_for_prompt_toolkit\nfrom xonsh.prompt_toolkit_completer import PromptToolkitCompleter\nfrom xonsh.prompt_toolkit_history import LimitedFileHistory\nfrom xonsh.prompt_toolkit_key_bindings import load_xonsh_bindings\n\n\ndef setup_history():\n    \"\"\"Creates history object.\"\"\"\n    env = builtins.__xonsh_env__\n    hfile = env.get('XONSH_HISTORY_FILE')\n    history = LimitedFileHistory()\n    try:\n        history.read_history_file(hfile)\n    except PermissionError:\n        warn('do not have read permissions for ' + hfile, RuntimeWarning)\n    return history\n\n\ndef teardown_history(history):\n    \"\"\"Tears down the history object.\"\"\"\n    env = builtins.__xonsh_env__\n    hsize = env.get('XONSH_HISTORY_SIZE')[0]\n    hfile = env.get('XONSH_HISTORY_FILE')\n    try:\n        history.save_history_to_file(hfile, hsize)\n    except PermissionError:\n        warn('do not have write permissions for ' + hfile, RuntimeWarning)\n\n\nclass PromptToolkitShell(BaseShell):\n    \"\"\"The xonsh shell.\"\"\"\n\n    def __init__(self, **kwargs):\n        super().__init__(**kwargs)\n        self.history = setup_history()\n        self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx)\n        self.key_bindings_manager = KeyBindingManager(\n            enable_auto_suggest_bindings=True,\n            enable_search=True, enable_abort_and_exit_bindings=True)\n        load_xonsh_bindings(self.key_bindings_manager)\n\n    def __del__(self):\n        if self.history is not None:\n            teardown_history(self.history)\n\n    def cmdloop(self, intro=None):\n        \"\"\"Enters a loop that reads and execute input from user.\"\"\"\n        if intro:\n            print(intro)\n        _auto_suggest = AutoSuggestFromHistory()\n        while not builtins.__xonsh_exit__:\n            try:\n                token_func, style_cls = self._get_prompt_tokens_and_style()\n                mouse_support = builtins.__xonsh_env__.get('MOUSE_SUPPORT')\n                if builtins.__xonsh_env__.get('AUTO_SUGGEST'):\n                    auto_suggest = _auto_suggest\n                else:\n                    auto_suggest = None\n                completions_display = builtins.__xonsh_env__.get('COMPLETIONS_DISPLAY')\n                multicolumn = (completions_display == 'multi')\n                completer = None if completions_display == 'none' else self.pt_completer\n                line = get_input(\n                    mouse_support=mouse_support,\n                    auto_suggest=auto_suggest,\n                    get_prompt_tokens=token_func,\n                    style=style_cls,\n                    completer=completer,\n                    history=self.history,\n                    key_bindings_registry=self.key_bindings_manager.registry,\n                    display_completions_in_columns=multicolumn)\n                if not line:\n                    self.emptyline()\n                else:\n                    line = self.precmd(line)\n                    self.default(line)\n            except KeyboardInterrupt:\n                self.reset_buffer()\n            except EOFError:\n                break\n\n    def _get_prompt_tokens_and_style(self):\n        \"\"\"Returns function to pass as prompt to prompt_toolkit.\"\"\"\n        token_names, cstyles, strings = format_prompt_for_prompt_toolkit(self.prompt)\n        tokens = [getattr(Token, n) for n in token_names]\n\n        def get_tokens(cli):\n            return list(zip(tokens, strings))\n\n        class CustomStyle(Style):\n            styles = {\n                Token.Menu.Completions.Completion.Current: 'bg:#00aaaa #000000',\n                Token.Menu.Completions.Completion: 'bg:#008888 #ffffff',\n                Token.Menu.Completions.ProgressButton: 'bg:#003333',\n                Token.Menu.Completions.ProgressBar: 'bg:#00aaaa',\n                Token.AutoSuggestion: '#666666',\n                Token.Aborted: '#888888',\n            }\n            # update with the prompt styles\n            styles.update({t: s for (t, s) in zip(tokens, cstyles)})\n            # Update with with any user styles\n            userstyle = builtins.__xonsh_env__.get('PROMPT_TOOLKIT_STYLES')\n            if userstyle is not None:\n                styles.update(userstyle)\n\n        return get_tokens, CustomStyle\n", "path": "xonsh/prompt_toolkit_shell.py"}]}