Skip to content

Commit

Permalink
colored aptos-cli output (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov authored Oct 21, 2024
1 parent 41c37e3 commit 2db094c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/main/kotlin/org/move/cli/runConfigurations/AptosCommandLine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2db094c

Please sign in to comment.