-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
feat(examples): cursor can be moved left/right and character at cursor position can be deleted/inserted #302
feat(examples): cursor can be moved left/right and character at cursor position can be deleted/inserted #302
Conversation
Codecov Report
@@ Coverage Diff @@
## main #302 +/- ##
=======================================
Coverage 83.21% 83.21%
=======================================
Files 37 37
Lines 7764 7764
=======================================
Hits 6461 6461
Misses 1303 1303 |
Let's not get too much more complicated with this example. An example that uses the tui-textarea or tui-input libraries might be worth considering. |
c409d45
to
9741ce2
Compare
This example in it's current state also has a couple bugs with unicode characters width, so might be interesting to look into how those crates handle unicode char width and if their solution might be better. I'm unsure though about including examples using external crate widgets. Would you add another example alongside this one or would it take it's place ? |
9741ce2
to
515aa0d
Compare
Agree. Examples should be as simple as possible, and not deviate from demonstrating its primary use case. Related/unrelated, we should probably have unicode handling built-in. I believe this falls under this crate's primary objectives. EDIT: Sorry, I see now, ratatui already handles unicode width where possible... but it's not abstracted enough. |
I realize now that the previously mentioned crates, tui-input and tui-textarea, are meant for that purpose xD In my application I often end up needing some kind of input field. In my opinion an input field example with a non-adjustable cursor seems not particular useful to me and the lack of Unicode width support appears like a trap which bites me back later. As a new user of ratatui I would appreciate 2 kind of examples in the area of input boxes.
Both example should include input with unicode width support and the ability to move the cursor around. if this is out of the scope for this crate, then I find examples for user input more useful if they at least show that you use these external crates for input boxes. That said, I would also not mind if my solution is replaced by such an example with the usage of an external crate. |
I think eventually we should combine the two crates and bring them into ratatui as a core widget (or perhaps as a separate widgets crate?) |
@mindoodoo wrote:
My intent was to communicate that we don't need to try to re-implement those crates in this example. Perhaps it would be a good idea to add a small comment in the current example pointing readers in the correct direction of the crates. |
Ah I see what you mean now. I think it might be interesting to provide examples for those external crates in the meantime, but bringing one or a combination of the two into ratatui would be interesting I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved subject to the small requested change (document the reason for not using input.remove())
Also, please rebase this (there's some small changes to the imports in the main branch.
515aa0d
to
9e20ff0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks for submitting this PR. :)
I'll leave this to @mindoodoo to merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, would just like to see a mention that this example does not try to handle unicode characters and then will merge !
The user_input example now responds to left/right and allows the character at the cursor position to be deleted / inserted. Co-authored-by: Leon Sautour <[email protected]>
2b35f1c
to
0a5ab2c
Compare
force push has the comment update, a rebase on main and a cargo fmt of the new comment |
Hey @BoolPurist thanks for your contribution. The changes are merged. |
The user_input example now responds to left/right and allows the character at the cursor position to be deleted / inserted. Co-authored-by: Leon Sautour <[email protected]>
Changes
Added cursor navigation to the user input example. User can now move cursor left and right. In addition user can also insert/delete characters at the cursor position.
Demo
Note
Could also put this demonstration into a new example file if you prefer it this way.