Reputation: 73
I'm making a simple program in Tcl/Tk that uses git stash list
, git stash show stash@{n}
and git stash show -p stash@{n}
to populate a listbox and show the content of the stash in a text widget, when one is selected.
However, this git commands outputs a colored result in stdout.
How to get the color of stdout and reproduce them in the text widget?
Upvotes: 0
Views: 194
Reputation: 1551
In my quick read of git commands, it seems that the default configuration is to color the output when it goes to a terminal. Git is apparently smart enough to exclude the color control codes when output is going to a pipe or file since there is nothing there to interpret such codes. It also seems that you can include a --color
option to force the color control codes into the output. So as I see it, you have a couple of options:
I think the second option is probably more difficult to implement, but will be more resilient to changes in the way git colors output. Of course, the way the text widget colors text is to annotate the text with a tag and then set the properties for how the tagged text is displayed.
If you wish to post some code showing your approach and how far you have gotten, I'm sure there will be folks here to help you along.
Upvotes: 1