mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 13:25:51 +03:00
[GH-ISSUE #774] Text selection in TextView #567
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#567
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @F1bonacc1 on GitHub (Nov 29, 2022).
Original GitHub issue: https://github.com/rivo/tview/issues/774
First of all, absolutely love the library, its flexibility, the extensive documentation, and all the examples you provide.
I noticed that you've asked before about text selection in #694
My issue is a little different - when using the regular (terminal) selection (mouse mode on + shift || mouse off) it also selects the borders which surround the TextView.
You mentioned that maybe it can be done using regions. I also have been thinking along those lines, but I am not sure it will be responsive enough with the regex (for region eval) that runs during the selection.
Do you have any ideas what would be the best way to approach this?
Thanks!
@rivo commented on GitHub (Dec 2, 2022):
Well, I guess I was a bit quick to say that because while I still think it may be possible, it might be difficult to be made to work. Regions allow you to show selections in a
TextViewobject. But then you still have to map mouse positions to locations in the text. Or you have to insert regions inbetween each character, which could work but is not great.Would the new
TextAreaprimitive help you? That primitive supports text selections like the ones you're asking for. You'd still have to integrate the clipboard with your OS's clipboard, though. And it's not a read-only element. (I don't know your use case so maybe that's ok?)@F1bonacc1 commented on GitHub (Dec 2, 2022):
@rivo Thank you for getting back to me.
Using TextArea is an interesting idea... Maybe if I can convert it to a read-only, it would actually work.
My use case is a log viewer for running processes and some users asked for the ability to select snippets from that log. It's an open-source project so feel free to check it out here:
https://github.com/F1bonacc1/process-compose
Also, TextArea doesn't implement the Writer pattern, which is very useful for a log viewer.
I suppose that can be added. I am still not sure what is the best direction here:
@rivo commented on GitHub (Dec 4, 2022):
With the
TextArea, you could set max-length to 1 or something. But thinking about it some more, I don't think it's a great solution.TextAreais made for text input primarily. Scrolling, for example, happens by positioning the cursor. Its keyboard controls are very different from those ofTextView. It doesn't support colours etc.I guess the only correct way to do it is for me to implement mouse selection support in
TextView.I will keep this issue open until this has been added. I should note, though, that I don't want to give you false hope of this being available very soon. I.e. it might take a while. There are a bunch of other issues that need to be taken care of first.
@F1bonacc1 commented on GitHub (Dec 4, 2022):
Thank you for taking this under consideration.
And once again thank you for such a great library!
@F1bonacc1 commented on GitHub (Dec 26, 2022):
@digitallyserviced
Thanks for pointing this out, I will definitely check it.
The solution that I eventually implemented in my project is:
Surprisingly this wasn't the most difficult part. The most difficult part was finding a cross-platform clipboard library.
There are solutions that require additional installations (
xcliporxsel), and I didn't want to ask my users to mess with all that. So I created a new Frankenstein package from all the pieces that I found:https://github.com/F1bonacc1/glippy
@quantonganh commented on GitHub (Mar 30, 2023):
I'm building a simple terminal UI for ChatGPT: https://github.com/quantonganh/chatgpt
My issue is the same as @F1bonacc1:
Could you please elaborate more? How can I use regions to make the selections does not select the border?
I can use mouse to select text in TextView, but the issue is, as I said above, it also selects the border:
Btw, do you know why the highlight is not clear?
Do you have a plan to add it?
Thank you for great work!
Not sure if I miss something, but when I select text in TextArea, it also selects the border:
@quantonganh commented on GitHub (Mar 30, 2023):
As a workaround, I have to hold the
option-commandkey down while dragging the left mouse button to select block of text.@rivo commented on GitHub (Mar 30, 2023):
@quantonganh The answers to all of your questions are given in this thread further above.