-
Notifications
You must be signed in to change notification settings - Fork 70
TUI feature request: grow text field vertically instead of scrolling #101 #183
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
Conversation
|
One thing that I couldn't figure out how to do is: |
|
Awesome, thanks for the patch! Great work overall. Before looking at the code in detail I tried a few things. It mostly looks good. Some comments below.
Btw, have you seen the TUI tests? It'd be good to add some test about these, especially for resizing and rendering on small screens. Thanks again! |
|
Thanks for the feedback! I will try to implement these suggestions when I get some more time. |
|
@osa1 Hey, I'm making some good progress, but I'm finding it difficult to add a configuration parameter...It doesn't look like there's a nice way to configure a setting on the TextField without passing down the config all the way from main.rs...Any ideas? Also, I'm pretty overwhelmed with the test framework...I never really worked in testing a TUI before 😩 I wasn't able to reproduce the problem you're seeing and mentioned above in your screenshot. You can see from the video below that I don't have that issue on my terminal emulator...I may need to try some other terminals. |
|
Hey @trevarj,
TUI has its own config format and parser, see
TUI test library is really simple, have you seen some of the tests in creates a TUI and then compares the screen with the textual representation ( To update the TUI after it's initialized you can either send key press events using the
Here's how to produce it:
Let me know if you have any more questions! |
|
Which terminal do you use? Below is me following the steps 😟 |
|
I installed on linux and ran some testing...looks ok for me. Maybe you didn't pull the most recent changes? |
osa1
left a comment
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.
This works really great, thanks!
There's currently one inconsistency in how we split long lines in messaging area vs. in text field. In messaging area we only split lines at word boundaries (at whitespaces). That works really well I think and renders nicely. I wonder if we could do the same for the text field.
I haven't read the entire rendering code, which is the tricky part of this code, so I'll be doing more reviews later. I should say, I'm amazed by how well it works currently.
One bug I managed to trigger is when text field has some text and I resize the window to small sizes and then make it larger. Here's what I end up with:
Could you investigate this?
Other than this bug I can't really see any problems. Great work!
I did notice then when I first started playing with the tui to make my change. It seemed a little difficult for me to extract out, especially with how the autocomplete stuff is right now...Maybe some day I can implement it though.
Finished up all other suggestions. Just need to debug this bug and I will commit to the PR again! |
a17ad13 to
c505e00
Compare
|
Sorry for the delay, I've been busy with work and life. I'll try to take another look today. |
osa1
left a comment
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.
OK, this looks good. I'll first merge this into a staging area where I'll squash the commits and make some documentation changes. I'll then merge it. Thanks!
libtiny_tui/src/text_field.rs
Outdated
| // TODO: Make these settings | ||
| const SCROLLOFF: i32 = 5; | ||
| const SCROLL_OFF: i32 = 5; | ||
| const OVERFLOW_WIDTH: i32 = 36; |
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.
This badly needs a documentation!
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.
I don't understand why this is necessary. @trevarj could you document this please before I merge this PR?
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.
I will add some documentation comments and rename OVERFLOW_WIDTH
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.
Honestly, I don't even know what SCROLL_OFF does! I'm playing around with changing its value and it doesn't seem like it does anything.
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.
I'm playing around with changing its value and it doesn't seem like it does anything.
Yeah I tried this as well. Also tried just deleting it, and nothing broke! Let's remove it.
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.
It's inspired by vim's scrolloff ;-)
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.
About OVERFLOW_WIDTH, I renamed it to SCROLL_FALLBACK_WIDTH. It's the value that is used when you have text_field_wrap=true and then resize the terminal. When the text_field's width is < 36 it will fall back to scroll mode.
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.
Why is this necessary? If the terminal width is 20, with enough height it should be possible to use wrapping. Is there a problem with this?
I don't know if you've changed the code, but in the version I've reviewed I removed this variable (and the conditional) and everything worked as before -- I was able to use wrapping on a small terminal. So I'm also not sure if it works as intended.
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.
Oh, I just thought you wanted it to fall back to scrolling when the terminal is too small.
From your first comment:
* On small screens we should fall back to the current behavior, which is more compact (always takes 1 row). When to fall back exactly? A few random ideas (feel free to suggest more):
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.
I just thought you wanted it to fall back to scrolling when the terminal is too small.
I still do, but I'm not sure if this is the best way to do it.
I guess it's fine for now. I just tried again and it seems to work as advertised.
|
@trevarj in my "extensive" testing of this PR I found a bug in rendering of ExitDialogue (unrelated to this patch), which I just fixed on master. Unfortunately it caused a merge conflict in this PR. Would you be able to fix the conflict? If not let me know and I'm going to fix it myself. The change is simple: I removed Sorry again for the trouble.. |
No problem, I will take care of it. |
|
Thanks! |
|
Unfortunately because you did a merge rather than rebase I can't squash these commits now. Anyways I'll be rebasing in my staging branch. |
|
Sorry! 😞 Do you want me to revert? |
|
No need! Already rebased in |
|
Sigh.. I keep finding bugs: I'll give instructions for reproducing in a bit. Let's continue development and bug fixing in a branch that I can commit to. @trevarj would you like to give me commit access to your repo so that I can update your branch? |
- Improve error reporting on test failure - Use smaller screen in text_field_wrap tests, document screen size - Combine multiple text_field_wrap tests in single test (not complete)
9c83985 to
e413786
Compare
|
Should I close this PR since the changes are already in your repo? |
|
We can close this and create a new PR from my branch to continue discussion. Or just continue here. I don't have a preference. |
|
Let's continue from this branch as both of us have push access here. I'll have to give you push access to the main repo (to all branches, as far as I can see) if we want to collaborate on this patch using a branch on my repo. |
Ok, sounds good. |
Hmm, I'm afraid I don't see why this is difficult. Here's what I have in mind: when rendering the text field we already now the cursor position. Render it char-by-char while counting current char index (use I'll take a look at the code and see what the problem is.
I think this should be calculated when we call |
|
I've put up a PR over on my fork (here) with a working solution to the input field wrapping on words. It's working nicely as far as I can tell...even works with autocompletion. |
…mp and nick length
We don't update it, and Github maintains an up-to-date list for us anyway (in 'contributors' page).
…mp and nick length
…into textfield-overflow
|
@osa1 have you gotten a chance to play around with this latest build? I'm interested in your thoughts after using it for a bit. |
|
I just installed the latest version. Let me use it for a bit, I'll update. |
|
I've been using this for the last couple of days. Here's a screenshot of this patch in action: (text field is empty as that's the same as before, only the changes in the messaging area are visible in this SS) The main issue is that this does opposite of what I suggested above (sorry if my wording was not clear enough), namely, it aligns everything, rather than not aligning user input. I think it doesn't look good even though it's consistent (both input field and messaging area are formatted the same way), but more importantly tiny is supposed to compact, and for that I'd much rather skip the alignment and start consecutive lines at column 0. Only bug I could find is also visible in this SS, if you look at the line with the long link you'll see it's in a new line for no reason. I'm busy with work and other stuff these days so I couldn't review this line by line, but here's a suggestion (feel free to ignore if you think it wouldn't work or would be too much work): implement something like
This code should live in its own module. Once we have that it'll be trivial to replace the current Btw, I just realized that it's not possible to implement this feature without calling One edge case here is what happens if I keep adding more characters and messaging area becomes too small. I think we should handle this by falling back to the scroll mode. The actual resizing logic (when terminal size changes) should be the one I describe above. |
|
I forgot to mention, thanks for your persistence and sorry that I've not been more responsive. One problem is I do code reviews at work, so that's not something I've been super keen on doing in my free time. But I'm actually keen on merging this! Hopefully we'll get there. |
It's not a problem. Thanks for guiding me through this. I will admit that I am a bit weary of doing a full re-factor because I'm worried I don't have a good idea of what you have in mind. It is a good Rust learning experience for me though, so I will try to attempt something. |
|
Hi @osa1 , Do you think you could take a look at it when you have time? I don't want to do too much and go off track of what you are envisioning. High level overview:
Thank you. |
|
Hey @trevarj, Just took a look -- the code looks great, thanks! It's easy to review the changes in I found some bugs while testing but you said you haven't thoroughly tested everything so not reporting those now.
This makes sense to me 👍 Regarding BTreeSet vs. Vec: I think nothing's going to beat Vec iteration performance, but looking at the code, it doesn't seem too hard to replace the BTreeSet with Vec if needed later. So use whatever's most convenient for you, we can replace it later if needed, using some benchmarks to guide the changes. I think we could cache It'd great if you could rebase your branch on Overall looks great! Thanks again! |
|
New conversation here: #200 |





Modified text_fields.rs to expand vertically when reaching the end of the line.
@osa1 let me know if there's anything I should fix or look out for (maybe I didn't test enough areas).
Side by side diff may be easier to see the changes.