Skip to content

Commit

Permalink
Fixed \r to \n transformation. (Fixes bug on Windows.)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanslenders committed Jan 3, 2015
1 parent 67a489f commit a5aba5d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion prompt_toolkit/key_binding/bindings/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from prompt_toolkit.keys import Keys
import prompt_toolkit.filters as filters

from ..input_processor import KeyPress
from .utils import create_handle_decorator


Expand Down Expand Up @@ -151,8 +152,26 @@ def _(event):
"""
Transform ControlM (\r) by default into ControlJ (\n).
(This way it is sufficient for other key bindings to handle only ControlJ.)
Windows sends \r instead of \n when pressing enter.
"""
event.cli.input_processor.feed_key(Keys.ControlJ)
def feed():
event.cli.input_processor.feed_key(KeyPress(Keys.ControlJ, ''))

# We use `call_from_executor`, to schedule this for later execution,
# otherwise, we're sending data into a generator which is already
# executing.
event.cli.call_from_executor(feed)

@handle(Keys.Escape, Keys.ControlM)
def _(event):
"""
Transform Esc-ControlM into Esc-ControlJ.
"""
def feed():
event.cli.input_processor.feed_key(KeyPress(Keys.Escape, ''))
event.cli.input_processor.feed_key(KeyPress(Keys.ControlJ, ''))

event.cli.call_from_executor(feed)

@handle(Keys.ControlJ, filter= ~has_selection)
def _(event):
Expand Down

0 comments on commit a5aba5d

Please sign in to comment.