prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Tab completing on empty line with prompt_toolkit kills terminal
  Arch Linux with xonsh 0.2.2 and using prompt toolkit.  Hitting TAB on an empty line crashes the terminal (rxvt-unicode).  I can see the traceback for a split second but then the terminal is gone.  
  
  This doesn't happen using readline.
  
  
  </issue>
  <code>
  [start of xonsh/prompt_toolkit_key_bindings.py]
  1 """Key bindings for prompt_toolkit xonsh shell."""
  2 import builtins
  3 
  4 from prompt_toolkit.filters import Filter
  5 from prompt_toolkit.keys import Keys
  6 
  7 
  8 class TabShouldInsertIndentFilter(Filter):
  9     """
  10     Filter that is intended to check if <Tab> should insert indent instead of
  11     starting autocompletion.
  12     It basically just checks if there are only whitespaces before the cursor -
  13     if so indent should be inserted, otherwise autocompletion.
  14     """
  15     def __call__(self, cli):
  16         before_cursor = cli.current_buffer.document.current_line_before_cursor
  17 
  18         return bool(not before_cursor or before_cursor.isspace())
  19 
  20 
  21 def load_xonsh_bindings(key_bindings_manager):
  22     """
  23     Load custom key bindings.
  24     """
  25     handle = key_bindings_manager.registry.add_binding
  26     env = builtins.__xonsh_env__
  27 
  28     @handle(Keys.Tab, filter=TabShouldInsertIndentFilter())
  29     def _(event):
  30         """
  31         If there are only whitespaces before current cursor position insert
  32         indent instead of autocompleting.
  33         """
  34         event.cli.current_buffer.insert_text(env['INDENT'])
  35 
  36 
  37
  [end of xonsh/prompt_toolkit_key_bindings.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_key_bindings.py b/xonsh/prompt_toolkit_key_bindings.py
  --- a/xonsh/prompt_toolkit_key_bindings.py
  +++ b/xonsh/prompt_toolkit_key_bindings.py
  @@ -15,7 +15,7 @@
       def __call__(self, cli):
           before_cursor = cli.current_buffer.document.current_line_before_cursor
   
  -        return bool(not before_cursor or before_cursor.isspace())
  +        return bool(before_cursor.isspace())
   
   
   def load_xonsh_bindings(key_bindings_manager):
  @@ -31,6 +31,6 @@
           If there are only whitespaces before current cursor position insert
           indent instead of autocompleting.
           """
  -        event.cli.current_buffer.insert_text(env['INDENT'])
  +        event.cli.current_buffer.insert_text(env.get('INDENT'))
  
verification_info: {"golden_diff": "diff --git a/xonsh/prompt_toolkit_key_bindings.py b/xonsh/prompt_toolkit_key_bindings.py\n--- a/xonsh/prompt_toolkit_key_bindings.py\n+++ b/xonsh/prompt_toolkit_key_bindings.py\n@@ -15,7 +15,7 @@\n     def __call__(self, cli):\n         before_cursor = cli.current_buffer.document.current_line_before_cursor\n \n-        return bool(not before_cursor or before_cursor.isspace())\n+        return bool(before_cursor.isspace())\n \n \n def load_xonsh_bindings(key_bindings_manager):\n@@ -31,6 +31,6 @@\n         If there are only whitespaces before current cursor position insert\n         indent instead of autocompleting.\n         \"\"\"\n-        event.cli.current_buffer.insert_text(env['INDENT'])\n+        event.cli.current_buffer.insert_text(env.get('INDENT'))\n", "issue": "Tab completing on empty line with prompt_toolkit kills terminal\nArch Linux with xonsh 0.2.2 and using prompt toolkit.  Hitting TAB on an empty line crashes the terminal (rxvt-unicode).  I can see the traceback for a split second but then the terminal is gone.  \n\nThis doesn't happen using readline.\n\n", "before_files": [{"content": "\"\"\"Key bindings for prompt_toolkit xonsh shell.\"\"\"\nimport builtins\n\nfrom prompt_toolkit.filters import Filter\nfrom prompt_toolkit.keys import Keys\n\n\nclass TabShouldInsertIndentFilter(Filter):\n    \"\"\"\n    Filter that is intended to check if <Tab> should insert indent instead of\n    starting autocompletion.\n    It basically just checks if there are only whitespaces before the cursor -\n    if so indent should be inserted, otherwise autocompletion.\n    \"\"\"\n    def __call__(self, cli):\n        before_cursor = cli.current_buffer.document.current_line_before_cursor\n\n        return bool(not before_cursor or before_cursor.isspace())\n\n\ndef load_xonsh_bindings(key_bindings_manager):\n    \"\"\"\n    Load custom key bindings.\n    \"\"\"\n    handle = key_bindings_manager.registry.add_binding\n    env = builtins.__xonsh_env__\n\n    @handle(Keys.Tab, filter=TabShouldInsertIndentFilter())\n    def _(event):\n        \"\"\"\n        If there are only whitespaces before current cursor position insert\n        indent instead of autocompleting.\n        \"\"\"\n        event.cli.current_buffer.insert_text(env['INDENT'])\n\n\n", "path": "xonsh/prompt_toolkit_key_bindings.py"}]}