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

Look into a pure Python readline replacement #185

Closed
andychu opened this issue Oct 1, 2018 · 7 comments
Closed

Look into a pure Python readline replacement #185

andychu opened this issue Oct 1, 2018 · 7 comments

Comments

@andychu
Copy link
Contributor

andychu commented Oct 1, 2018

This is kind of vague, but it's a good first issue for somebody who already has expertise in the area. It's not something I know a ton about (other than the fact that I can't live without set -o vi).

The author/maintainer of bpython has a lot of interesting things to say about terminals and REPLs.

http://ballingt.com/blog/

  • python-prompt-toolkit
  • curtsies
  • blessings
  • the stdlib curses module? That doesn't do what readline does.
@watk
Copy link
Collaborator

watk commented Oct 26, 2018

Excuse my ignorance, but would you mind writing some rationale for this?

@andychu
Copy link
Contributor Author

andychu commented Oct 26, 2018

Here's one motivation. Start zsh and then try to complete 2 or more flags, like

ls --a<TAB>

then pick a suggestion

ls --all --s<TAB>

zsh doesn't redraw the prompt. Now compare with bash.

Maybe readline can already do this? Again it's something I don't know much about :)


Another motivation is that GNU readline is GPL, which I think caused problems for Python at one point. It would be nice to have an alternative.

I think Python links with libedit or something on Mac? Oil only links with readline.

Anyway, this is not all that solid an issue, hence the disclaimer that it's vague :) Some people have higher standards for interactive shells (namely zsh users) so I was just throwing this out there.

As far as being pure Python, I think it would help iterate more quickly on the UI. There is a lot of precedent for that in the 3 libraries I mentioned.

@andychu
Copy link
Contributor Author

andychu commented Dec 14, 2018

Notes:

A big difference between bash and fish/zsh is that the latter two both display flag descriptions.

I think it's possible to write a custom readline display hook to do this, but I'm not sure.

In other words, it might be worthwhile to reuse readline for vi editing mode, but try to replace its completion display routines. That is not trivial because I think it has to respond to SIGWINCH and stuff like that.

@andychu
Copy link
Contributor Author

andychu commented Dec 15, 2018

In summary, things I want:

  • Don't reprint the prompt line on successive tab completions, which preserves vertical screen space
    • Also erase the prompt on Ctrl-C
  • Display "first words" and flags with additional info like description
    • Maybe smarter prioritization of candidates. Readline has a coarse prompt: "Display all 3000 possibilities?"
  • Preserve vi bindings of readline

@andychu
Copy link
Contributor Author

andychu commented Feb 6, 2019

Update: This is less urgent because I figured out how to use readline in the way I want, with demoish.py. It has those 3 properties.

/~https://github.com/oilshell/blog-code/tree/master/interactive-shell

@andychu
Copy link
Contributor Author

andychu commented Mar 20, 2019

Update: a problem with using readline is that I don't know how to detect when the user typed past the last column in the terminal, and then clear that next line of completion suggestions.

@andychu
Copy link
Contributor Author

andychu commented May 6, 2020

Closing in favor of #460, and #653 (ble.sh)

@andychu andychu closed this as completed May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants