Skip to content
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

runs into error in docker environment Error reading output: read /dev/ptmx: input/output error #184

Open
kcmvp opened this issue Jan 13, 2024 · 5 comments

Comments

@kcmvp
Copy link

kcmvp commented Jan 13, 2024

in order to captue the original output color, I used this library. it works well on my local environment(mac os). but it runs into error in the docker environment

here is the link https://github.com/kcmvp/archunit/actions/runs/7511175563/job/20450454708

image

here is the code using this library.

https://github.com/kcmvp/gob/blob/main/cmd/shared/util.go

am I using wrong way of this library or it's an environment issue? If it's a environment issue, are there any walk around?

thank you very much!

@creack
Copy link
Owner

creack commented Jan 13, 2024

This sounds outside the scope of the library.

If it works on your machine but not in Docker it is likely a configuration issue in Docker, probably around the TTY allocation. If the TTY isn't properly allocated, /dev/ptmx may not be present, or wouldn't behave as expected.

Did you try something like https://github.com/gfx/example-github-actions-with-tty?

When you say you want to capture the original color, I am not sure to understand though. Looking at util.go, it seems like you try to strip away the ansi escape sequences? The PTY has little to do with colors, it is more a terminal emulator thing. Programs usually check whether or not they run inside a tty to know whether or not to output escape sequences, but most of those, like colors, are interpreted by the terminal emulator, not the pty.

@kcmvp
Copy link
Author

kcmvp commented Jan 13, 2024

Thank your quick response very much!

In fact I am building a tool which can take any other tool as a plugin. just as you know there might be colored text from external tool. I need to keep the original color as well. at very beginning I just read from output of exec.Command. it always print plaint text. I ask chat-gpt then I know it's not possible to extract color from the output. it recommend your library.(:greaat!

it works well on my local device. below is the screen from my local device, the green 'PASS' is from external tool

image

about your saying "extract ansi escape sequences"

it's partial right. as I need to print the capture from external on the terminate(color) and need to save it to a file. in the file I need to remoe those escape sequences.

below is from chag-gpt

I apologize for the confusion. You are correct that extracting the actual colors used in the output of an external program can be challenging, especially if the program uses complex color formatting.
ANSI escape codes are interpreted by the terminal emulator, and extracting the actual colors from the escape codes is >> not straightforward. The escape codes typically specify color attributes or color codes that are interpreted by the terminal emulator to display the desired colors.
To accurately extract the actual colors used in the output, you would need to parse and interpret the escape codes yourself, which can be quite complex.
If you have control over the external program, one possible approach is to modify it to output the color information in a format that can be easily parsed. For example, the program could output color names or RGB values instead of using ANSI escape codes.
Alternatively, you could consider using a library or tool specifically designed for parsing and interpreting ANSI escape codes, such as github.com/mgutz/ansi in Go. These libraries can provide functions to extract color information from the escape codes.
However, please note that extracting the actual colors used in the output of an external program is not a trivial task and may require significant effort and customization depending on the complexity of the color formatting used by the program.
`

@kcmvp
Copy link
Author

kcmvp commented Jan 13, 2024

at least your library is very close to my target. not sure why it does not work in git github workflow.
by the way it's the github workflow configuration file https://github.com/kcmvp/archunit/blob/main/.github/workflows/build.yml

@kcmvp
Copy link
Author

kcmvp commented Jan 13, 2024

In fact no one library works by now. I tried all the libraries chat-gpt suggested. none of them work. I know very little about this area. it's something like to cheat 'OS'( my guess) it's a terminal then I can get the color(data) then print it again on the screen.
not sure my understanding is correct or not?

@kcmvp
Copy link
Author

kcmvp commented Jan 13, 2024

docker/cli#2067
it's a docker related issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants