mirror of
https://github.com/rivo/tview.git
synced 2026-04-27 05:45:49 +03:00
[GH-ISSUE #782] [QUESTION] About automatically coloring specific word patterns in TextView #573
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#573
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 @AmrGanz on GitHub (Dec 17, 2022).
Original GitHub issue: https://github.com/rivo/tview/issues/782
Hello Rivo,
I usually use the same method as in here to color specific words. For example, making the word "error" shown in red and the word "success" shown in green.
I was wondering, is there a way to make it happen without explicitly reformat each instance of these words? Maybe to give an example, when I use a terminal like MobaXterm, it has this functionality of coloring specific words with a unique color automatically.
If this is can be already achieved, then I would really appreciate you pointing me to the document covering it and I will read more about it.
Kind regards
@rivo commented on GitHub (Dec 21, 2022):
Every colour tag introduces a new colour for the following characters, until the next colour tag. So, no, there is no way to automatically colour specific words. But I think it should be fairly straightforward to come up with a regular expression to wrap specific words with colour tags.
@AmrGanz commented on GitHub (Dec 27, 2022):
Thanks @digitallyserviced , I didn't know about it before and I have started testing it and hopefully it will get me the results I am seeking.
@rivo @digitallyserviced BTW, the reason I am asking this question is because when I use a
TextView(while enabling dynamic coloring) and I wanted to format the shown text, lets say by column-formatting the output. The added color tags mess it up.For example:
This code block will work perfectly fine and will show the desired column-formatted output:
output:
Now, if I added color tags like the below example, it will mess up the output formatting:
output (coloring will work fine in the terminal):
I understand that this is working as designed since the
Columnizesee the colors tag as text and working as expected. And this is why I am looking for other ways to natively color specific words/patterns instead.@rivo commented on GitHub (Aug 26, 2023):
@AmrGanz I think you'll want to add color tags at the end of your text processing chain, i.e. after using
columnize. You might be able to insert them at specific locations in the string or use regular expressions to insert them.Finally, to answer your initial question, no, there is no way to apply colours to specific word patterns. This kind of behaviour is meant to be implemented outside of
tview.I'm closing this now as I don't think there is anything to do for me here. Feel free to respond or open a new issue if necessary.