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

User-specified continuation prompt #793

Closed
wants to merge 3 commits into from
Closed

User-specified continuation prompt #793

wants to merge 3 commits into from

Conversation

zao111222333
Copy link

I believe the user-specified continuation prompt is a crucial feature, especially in scenarios where indentation is important (such as Python shell). I have implemented this feature by replacing the '\n' character in multi-line input with \n+continuation_prompt in display phase (in Renderer::refresh_line). This approach can cause a misalignment between the displayed cursor position and the actual editing position. To address this, I used State::continuation_prompt_move_cursor to correct these misalignments.

Additionally, I have added an example. You can run it with the following command:

cargo run --release --example continuation_prompt --features="custom-bindings derive"

And the demo results:
image

However, the current implementation only meets the minimum use case (i.e., continuation prompt works when pasting multi-line text into rustyline), but I have still encountered some bugs:

  • Cursor misalignment when inserting/deleting text.
  • Cursor misalignment when moving the cursor to the top or bottom of the input.
  • Cursor misalignment when using Cmd::Newline.

Since I'm not very familiar with rustyline, I want to share my current implementation and seek help and suggestions here. Thank you!

@zao111222333 zao111222333 changed the title Prototype implementation of continuation prompt User-specified implementation of continuation prompt Aug 12, 2024
@zao111222333 zao111222333 changed the title User-specified implementation of continuation prompt User-specified continuation prompt Aug 12, 2024
@gwenn
Copy link
Collaborator

gwenn commented Aug 13, 2024

@zao111222333
Copy link
Author

See #372 And https://github.com/gwenn/rustyline-notes/blob/master/src/design.md

Hi, I agree with "split the input by line" mentioned in design.md, the implementation here is essentially split the input in renderer (soft wrapped), and then re-align cursor.

And I'd like to contribute for continuation prompt if the new Vec<(Range,Style)> API is finished.

@gwenn
Copy link
Collaborator

gwenn commented Aug 13, 2024

We might be able to fix the Highlighter API like isocline.
And also check how isocline handles continuation prompt:

@gwenn
Copy link
Collaborator

gwenn commented Aug 13, 2024

Also I don't want you to waste your time.
So maybe you should check if some alternatives already supports continuation prompt.
For example: nushell/reedline#112

@zao111222333
Copy link
Author

Also I don't want you to waste your time. So maybe you should check if some alternatives already supports continuation prompt. For example: nushell/reedline#112

Thank you a lot for your time and information, I will have a try for those alternatives.
Also I will still try to implement this feature for rustyline.

@gwenn
Copy link
Collaborator

gwenn commented Aug 15, 2024

For the highlighting part, we might use this library:
https://crates.io/crates/ansi-str

A library which provides a set of methods to work with ANSI strings
It's an agnostic library in regard to different color libraries.

This method seems to do the job:
https://docs.rs/ansi-str/latest/ansi_str/fn.get_blocks.html

@gwenn gwenn mentioned this pull request Aug 15, 2024
4 tasks
@gwenn
Copy link
Collaborator

gwenn commented Aug 19, 2024

Just in case if you are still interested,
Could you please have a look at:
6b34d32
?
I guess it should be feasible like the Split iterator but I am not sure.

@zao111222333
Copy link
Author

Just in case if you are still interested,

Could you please have a look at:

6b34d32

?

I guess it should be feasible like the Split iterator but I am not sure.

Thank you for informing, I will try it :)

@gwenn
Copy link
Collaborator

gwenn commented Aug 21, 2024

Just in case if you are still interested,
Could you please have a look at:
6b34d32
?
I guess it should be feasible like the Split iterator but I am not sure.

Thank you for informing, I will try it :)

Sorry I mean help me to fix it if you can...
(you cannot give it a try because it doesn't type-check)

@zao111222333
Copy link
Author

Just in case if you are still interested,
Could you please have a look at:
6b34d32
?
I guess it should be feasible like the Split iterator but I am not sure.

Thank you for informing, I will try it :)

Sorry I mean help me to fix it if you can... (you cannot give it a try because it doesn't type-check)

Oh I see, sure I can help to try how to fix it (might be this weekend). Thanks!

@gwenn gwenn mentioned this pull request Oct 21, 2024
3 tasks
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 this pull request may close these issues.

2 participants