Preserve color codes from os.proc.spawn stdout #219
Replies: 12 comments 1 reply
|
It is indeed not connected to a terminal, I am writing a terminal emulator using JavaFX. Is there a way I could fake a terminal? I found this: https://github.com/JetBrains/pty4j which is apparently a way to fake a TTY which seems to be exactly what I need. I will investigate on my side, but if it turns out to work it would be nice to implement this out-of-the-box for os-lib! |
|
If you emulate a terminal, you might want to set the |
|
Thank you, will try it out tonight |
|
Following up on this, I did the following: os.proc(cmd :: params).call(
cwd = wd,
env = Map("TERM" -> "xterm-color"), // tried also just "xterm"
stdout = processStdout
)But I am still not getting the color codes... And to make matters worse, the pty4j library can't be installed with SBT - at least it threw an error during installation. I am on Windows 10 by the way, sorry for mentioning this so late. |
|
Any update on this? |
|
Huh, what kind of update? I though, you are the one who wants to emulate a terminal? I guess you need to inspect at least one of the tools you want colored output of, and find out, on what criteria it decides to disable color. After knowning what's needed, we can think about how to provide it via os-lib. |
|
Ok, I think I might have not made myself clear. My "terminal emulator" that I am writing is simply a Scala Swing frame/window. |
|
I don't think this is an issue with os-lib. I believe you would experience the exact same issue using, for example, I don't fault you for hoping we might have further advice for you, but regardless, I don't think this ticket should remain open, and I'm afraid you may need to seek advice elsewhere, since the os-lib bug tracker is focused on issues with os-lib itself. |
|
I moved this issue into a discussion, so you can still comment and share idea or progress. But as @SethTisue said, it's nothing we can directly "fix" or "improve" in os-lib. I think, tools like |
|
Thank you all for the advice, I'll keep trying I guess, and, if you don't mind, post the solution here if I find one. |
|
The equivalent Maven/Gradle fix for installing pty4j for SBT is as follows: resolvers +=
"JetBrains IntelliJ Dependencies" at "https://packages.jetbrains.team/maven/p/ij/intellij-dependencies"which will let you properly libraryDependencies +=
"org.jetbrains.pty4j" % "pty4j" % "0.12.13"In Ammonite: @ import coursierapi.MavenRepository
import coursierapi.MavenRepository
@ interp.repositories.update(
> interp.repositories() ::: List(MavenRepository.of("https://packages.jetbrains.team/maven/p/ij/intellij-dependencies"))
> )
@ import $ivy.`org.jetbrains.pty4j:pty4j:0.12.13` |

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I would like to get the colors from a subprocess stdout (e.g.
git statuswill show the "modified" lines in green). From what I have seen, there is no way to do that in os-lib, maybe even in Java in general.I have tried the following:
In this example, the stdout is printed as an array of Char but it is missing the color info such as
�[92m some text here �[0mAlso tried to print each byte using
proc.stdout.data.readBytewith no luck:From what I understand, I need to specify to the subprocess that it is a "pseudo terminal" according to this link
Any idea how to do such a thing?
Thanks!
All reactions