Skip to content

Fix GNU readline support for user input #522

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

Merged
merged 1 commit into from
Oct 30, 2023

Conversation

cowile
Copy link
Contributor

@cowile cowile commented Sep 26, 2023

Describe the changes you have made:

This commit adds an import for the readline module at the top of terminal_interface.py to provide GNU readline support for user input. This will allow Unix users to edit their input and browse their command history like in a UNIX shell. The readline module is imported conditionally, so the script does not break for Windows users where this module is typically not available.

pyproject.toml already mentions the ability to do this when declaring the pyreadline dependency and interpreter.py also imports readline, but it doesn't work unless the import is in the same module using the input function.

And I must credit my co-developer Open Interpreter for identifying the correct file and making the change at my direction.

Reference any relevant issue (Fixes #000)

  • I have performed a self-review of my code:

I have tested the code on the following OS:

  • Windows
  • MacOS
  • Linux

AI Language Model (if applicable)

  • GPT4
  • GPT3
  • Llama 7B
  • Llama 13B
  • Llama 34B
  • Huggingface model (Please specify which one)

This commit adds import for the readline module at the top of
terminal_interface.py to provide GNU readline support for user
input. This will allow Unix users to edit their input and browse their
command history like in a UNIX shell. The readline module is imported
conditionally, so the script does not break for Windows users where
this module is typically not available.

pyproject.toml already mentions the ability to do this when declaring
the pyreadline dependency and interpreter.py also attempts importing
readline, but it doesn't work unless the import is in the same module
using the input function.
@KillianLucas
Copy link
Collaborator

Hi @cowile, thank you for noticing this! I think we should drop the dependency since even the existence of the package caused problem for Windows users. Until we can more thoroughly test it across platforms, I'm not sure if we should try to add it back.

What do you think? Open Interpreter had this until a few days ago -- let me know if it was beneficial to your workflow and then yes, I think a conditional import would be great.

@cowile
Copy link
Contributor Author

cowile commented Sep 28, 2023

@KillianLucas If the pyreadline dependency is causing problems for Windows users then I agree to dropping it.

I can't say pyreadline specifically has benefited my workflow as I have not attempted to use open-interpreter on Windows yet. But I will strongly argue that a line editing feature is a minimum expectation for usability. No one wants to backspace 50 times if they made a typo at the beginning of the line.

The conditional import I added should definitely go in as readline is a system library on Unix-like platforms, no 3rd party dependency needed.

@KillianLucas
Copy link
Collaborator

Oh shit how do we do line editing? Is that a readline thing? That would be awesome.

Ideally we'd have full blown editor stuff like the ability to paste in multiline strings, not sure if that's possible. I'll look into this but if you know already, let me know!

@cowile
Copy link
Contributor Author

cowile commented Sep 30, 2023

"Line editing" is a generic term for the functionality provided by libraries like readline. Mostly it means moving around and editing the line you've typed before submitting it.

readline is powerful and customizable. By default, pressing the enter key triggers the readline action accept-line, but that is configurable. You can make any other key accept-line and have the enter key type an ordinary newline character that can be edited along with the rest. See here. readline supports configuration files. Looks like python gives you readline.read_init_file to read whatever file you choose which can adjust much of readline's behavior without any code changes.

@ericrallen
Copy link
Collaborator

ericrallen commented Oct 8, 2023

I'd like to give a huge +1 to this PR.

Not being able to easily edit the prompt and move my cursor is a constant source of frustration and this PR is a marked improvement in quality of life.

There are some GIFs showing the difference in input ability in my similar PR #606 (now closed to support this PR because I didn't realize this was already proposed).

@ericrallen ericrallen added the Triaged Issue has been reviewed by maintainer label Oct 29, 2023
@KillianLucas
Copy link
Collaborator

Yeah, you're both right. I only saw the error that made me remove it on one Windows machine anyway (and not on another + any Mac or Linux system).

readline is back!

@KillianLucas KillianLucas merged commit 0ea271c into openinterpreter:main Oct 30, 2023
joshuavial pushed a commit to joshuavial/open-interpreter that referenced this pull request Nov 16, 2023
Fix GNU readline support for user input

Former-commit-id: 0ea271c
Former-commit-id: 2ad03e936af737d6dd3f9823a06f95e1eb0b0e19
Former-commit-id: ec0dcc4ea48e160d82b4af4aa13ea2ac614c1acd [formerly a46cc86842ae1266fd02a893f71e9fe428cc36e0]
Former-commit-id: d1b064679966741ccae99b20ff6ed113303c384b
joshuavial pushed a commit to joshuavial/open-interpreter that referenced this pull request Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Triaged Issue has been reviewed by maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants