Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation Keys are not working in better-exception Repl(MacOs) #90

Open
abdulniyaspm opened this issue Jun 18, 2019 · 3 comments
Open

Comments

@abdulniyaspm
Copy link

I am using Macos and I am unable to use the navigation keys to jump into my previous Repl line, Instead it showing me escape characters.

Abduls-Air:better-exceptions abdulniyas$ python3 -m better_exceptions
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(BetterExceptionsConsole)
>>> import sys
>>> ^[[A # This is what I am getting when I press Up arrow.

I tried the same in my python interpreter but it does shows me the correct result.

Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> import platform # It shows the correct result when I press Up arrow.

I think sys.__interactivehook__ is not getting called(in order register the readline) while initialising better-exception Repl. So if I do the following in better-exception Repl I am getting correct result.

Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(BetterExceptionsConsole)
>>> a = 0     
>>> ^[[A # while clicking up arrow.
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/code.py", line 64, in runsource
    code = self.compile(source, filename, symbol)
           │            │       │         └ 'single'
           │            │       └ '@@@REPL@@@1'
           │            └ '\x1b[A'
           └ <better_exceptions.repl.BetterExceptionsConsole object at 0x10249a048>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/codeop.py", line 168, in __call__
    return _maybe_compile(self.compiler, source, filename, symbol)
           │              │              │       │         └ 'single'
           │              │              │       └ '@@@REPL@@@1'
           │              │              └ '\x1b[A'
           │              └ <codeop.CommandCompiler object at 0x10249a080>
           └ <function _maybe_compile at 0x1024961e0>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/codeop.py", line 99, in _maybe_compile
    raise err1
          └ SyntaxError('invalid syntax', ('@@@REPL@@@1', 1, 1, '\x1b[A\n'))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/codeop.py", line 87, in _maybe_compile
    code1 = compiler(source + '
'", filename, symbol)
    │       │        │              │         └ 'single'
    │       │        │              └ '@@@REPL@@@1'
    │       │        └ '\x1b[A'
    │       └ <codeop.Compile object at 0x10249a0b8>
    └ None
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/codeop.py", line 133, in __call__
    codeob = compile(source, filename, symbol, self.flags, 1)
                     │       │         │       └ <codeop.Compile object at 0x10249a0b8>
                     │       │         └ 'single'
                     │       └ '@@@REPL@@@1'
                     └ '\x1b[A\n'
File "@@@REPL@@@1", line 1
    ^
SyntaxError: invalid syntax
>>> import sys
>>> sys.__interactivehook__() # Register the readline
>>> # Now onwards the navigation keys are working
@Qix-
Copy link
Owner

Qix- commented Jun 18, 2019

PR is welcome :)

@kevgathuku
Copy link

I also experienced the same on MacOS and Python 3.7.4
I'll look into it some more.

@kevgathuku
Copy link

I've added a potential fix for this in https://github.com/Qix-/better-exceptions/pull/91
Please check it out when you get a chance
cc @abdulniyaspm @Qix-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants