From 37d4751b275c90d3aa0188d8b888743ba58ff577 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Mon, 21 Oct 2024 20:48:04 +0200 Subject: [PATCH] colored aptos-cli output --- .../cli/runConfigurations/AptosCommandLine.kt | 16 ++++++++++++++++ .../move/cli/runConfigurations/AptosRunState.kt | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) 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