Closed nsbruce closed 6 months ago
@stephenafamo I think this may be related to the log writer you implemented. Let me know if you have time to look at this :)
Colorized output works. I suspect the issue is somehow in checking if the terminal supports colors, and this is likely to be more of an issue with the shell interpreter than with the log writer.
To prevent using the log writer, try adding interactive: true
to the task definition and see what it outputs @nsbruce
I got some more time to look at this, and it is indeed the logwriter.
The issue is that when checking if output should be colourized, commands like ls
check if the output stream is a terminal.
From my first look around, there is no way to fake this, so I am conflicted about how best to proceed.
The most likely solution is that these tools decide to "FORCE_COLOR".
I'm also under the impression that we cannot fake a terminal in this case. What I'm thinking is that we could set CLICOLOR_FORCE=1 so long as NO_COLOR is not set.
I'm also under the impression that we cannot fake a terminal in this case. What I'm thinking is that we could set CLICOLOR_FORCE=1 so long as NO_COLOR is not set.
I think we should set both CLICOLOR_FORCE
and FORCE_COLOR
but first check if the caller is a terminal.
Good point, will look into that.
Created a fix branch for this, would love to see if it works for people before merging!
I just cloned main, switched to term-colors branch, ran go install ./cmd/xc
and am getting the same result as when I posted the issue.
That's unfortunate, is this still the ls
command?
Hey I apologize but it is working. To make troubleshooting easier I just spun up a MWE to show you it not working but must have erred the other day. It is properly colorizing now.
from ubuntu:22.04
run apt-get update && apt-get -y install git curl
run rm -rf /usr/local/go && \
curl -L -o go1.21.6.linux-386.tar.gz https://go.dev/dl/go1.21.6.linux-386.tar.gz && \
tar -C /usr/local -xzf go1.21.6.linux-386.tar.gz
env PATH $PATH:/usr/local/go/bin
env GOBIN /usr/local/go/bin
run git clone https://github.com/joerdav/xc && \
cd xc && \
git switch term-colours && \
git pull && \
go install ./cmd/xc
run echo '## Tasks\n\n### ls\n\n```bash\nls --color\n```' > /README.md
entrypoint cd / && ls --color && xc ls
Then running docker build -t xc-test . && docker run --rm -it xc-test
Thanks for the work on this! I look forward to the merge.
If the task being run has a colorized output when run without xc, I think xc should pass that colorized output through.
Trivial example:
A more valid example is that when using testing suites like pytest where successful tests are shown in green and failures in red.