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

Implement readline functionality for line editing #6

Open
krishnakumarg1984 opened this issue Jul 28, 2023 · 8 comments
Open

Implement readline functionality for line editing #6

krishnakumarg1984 opened this issue Jul 28, 2023 · 8 comments

Comments

@krishnakumarg1984
Copy link

Great work on the kalc terminal calculator application. I am thoroughly enjoying it.

However, one dampener on the user experience is that there is no support for readline motions on the command line. This makes it really tedious to edit and move around to edit the expression to be calculated. Nearly every reasonable CLI program has a readline-like feature (it is almost a given), and I hope that kalc also implements this feature soon.

Once again, congrats on making this impressive and useful application.

@bgkillas
Copy link
Owner

i have absolutely no idea what this means, give examples of what my program does not do that this does.

@LowLevelLoser
Copy link
Contributor

i have absolutely no idea what this means, give examples of what my program does not do that this does.

In the context of text editing, "readline motions" typically refer to the movement commands used in the GNU Readline library. Readline is a software library for creating text-based user interfaces, and it is widely used in command-line interfaces for tasks like text editing.

Here are some common readline motions:

  1. Ctrl+A (or Home): Move the cursor to the beginning of the line.
  2. Ctrl+E (or End): Move the cursor to the end of the line.
  3. Ctrl+B (or Left Arrow): Move the cursor one character to the left.
  4. Ctrl+F (or Right Arrow): Move the cursor one character to the right.
  5. Alt+B (or Esc+B): Move the cursor one word to the left.
  6. Alt+F (or Esc+F): Move the cursor one word to the right.
  7. Ctrl+XX: Toggle between the start of the line and the current cursor position.
  8. Ctrl+U: Cut the text from the current cursor position to the beginning of the line and save it in the cut buffer.
  9. Ctrl+K: Cut the text from the current cursor position to the end of the line and save it in the cut buffer.
  10. Ctrl+Y: Paste the contents of the cut buffer at the current cursor position.
  11. Alt+D (or Esc+D): Cut the next word after the cursor and save it in the cut buffer.
  12. Ctrl+W: Cut the previous word before the cursor and save it in the cut buffer.
  13. Ctrl+T: Transpose (swap) the characters before and after the cursor.
  14. Alt+T (or Esc+T): Transpose (swap) the words before and after the cursor.
  15. Ctrl+L: Clear the screen (similar to running the clear command).

@bgkillas
Copy link
Owner

bgkillas commented Sep 9, 2023

whats an example of a program that implements these properly? i want to test some edge cases for defining what to cut when you are in the middle of a word for ctrl+w and alt+t

implemented all but alt+d, ctrl+w, alt+t, ctrl+xx(that one confuses me also) of the listed stuff 939486a

@LowLevelLoser
Copy link
Contributor

LowLevelLoser commented Sep 9, 2023

Most terminal emulators implement these motions personally I don't mind if they're not there since I don't really use them. If I were making a cli program I would probably try to use the GNU readline library instead of implementing the motions myself from scratch but I don't have much experience with rust so I wouldn't know how to do that.

EDIT: There are probably rust libraries that function as a readline alternative so you could try using those

btw this is a great project I use this regularly keep up the good work.

@bgkillas
Copy link
Owner

bgkillas commented Sep 9, 2023

the problem with just using readline like normal is i dont think i can work with a real time output while preserving everything

@LowLevelLoser
Copy link
Contributor

Maybe, if I find the time I'll try to implement it myself but it could be more work than just doing it from scratch so that might be the best approach.

@krishnakumarg1984
Copy link
Author

Apologies @bgkillas that I couldn't reply earlier. Virtually every terminal/command-line application (from the most famous to the most obscure) typically provides readline motions, and is a de-facto standard feature expected.#

Readline is such a ubiquitous library and language bindings or native implementations are available for almost any language you can name.

For rust, have a look at the crates: https://crates.io/crates/reedline and https://crates.io/crates/rustyline

@xero-lib
Copy link

I'll try to work on this a bit as well

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

No branches or pull requests

4 participants