diff --git a/src/main/kotlin/org/move/cli/runConfigurations/AptosCommandLine.kt b/src/main/kotlin/org/move/cli/runConfigurations/AptosCommandLine.kt index a6527b310..9b98215b0 100644 --- a/src/main/kotlin/org/move/cli/runConfigurations/AptosCommandLine.kt +++ b/src/main/kotlin/org/move/cli/runConfigurations/AptosCommandLine.kt @@ -2,6 +2,7 @@ package org.move.cli.runConfigurations import com.intellij.execution.configuration.EnvironmentVariablesData import com.intellij.execution.configurations.GeneralCommandLine +import com.intellij.execution.configurations.PtyCommandLine import com.intellij.openapi.util.text.StringUtil import java.nio.file.Path @@ -27,6 +28,21 @@ data class AptosCommandLine( return generalCommandLine } + fun toColoredCommandLine(cliExePath: Path): GeneralCommandLine { + // preudo-tty emulation makes aptos-cli recognize console as tty and show ANSI colors + val generalCommandLine = PtyCommandLine() + .withExePath(cliExePath.toString()) + // subcommand can be null + .withParameters(subCommand?.split(" ").orEmpty()) + .withParameters(this.arguments) + .withWorkDirectory(this.workingDirectory?.toString()) + .withCharset(Charsets.UTF_8) + // disables default coloring for stderr + .withRedirectErrorStream(true) + this.environmentVariables.configureCommandLine(generalCommandLine, true) + return generalCommandLine + } + // fun createRunConfiguration( // moveProject: MoveProject, // configurationName: String, diff --git a/src/main/kotlin/org/move/cli/runConfigurations/AptosRunState.kt b/src/main/kotlin/org/move/cli/runConfigurations/AptosRunState.kt index 3b7b8f128..79a679d74 100644 --- a/src/main/kotlin/org/move/cli/runConfigurations/AptosRunState.kt +++ b/src/main/kotlin/org/move/cli/runConfigurations/AptosRunState.kt @@ -18,7 +18,7 @@ abstract class AptosRunStateBase( val commandLine: AptosCommandLine = config.cmd override fun startProcess(): ProcessHandler { - val generalCommandLine = commandLine.toGeneralCommandLine(config.aptosPath) + val generalCommandLine = commandLine.toColoredCommandLine(config.aptosPath) val handler = KillableColoredProcessHandler(generalCommandLine) consoleBuilder.console.attachToProcess(handler) ProcessTerminatedListener.attach(handler) // shows exit code upon termination