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

colored aptos-cli output #213

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading