[CORDA-2374] Avoid using Unicode in the Progress Tracker output on Windows (#4485)

* Avoid Unicode output from the Progress Tracker on Windows
* Fix an issue with the Progress Tracker where the currently executing state is reported as done
This commit is contained in:
JamesHR3 2019-01-03 13:34:34 +00:00 committed by GitHub
parent ea1111418c
commit f9e0c518b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package net.corda.tools.shell.utlities
import net.corda.core.internal.Emoji
import net.corda.core.messaging.FlowProgressHandle
import org.apache.commons.lang.SystemUtils
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.LogEvent
import org.apache.logging.log4j.core.LoggerContext
@ -22,6 +23,7 @@ abstract class ANSIProgressRenderer {
protected var usingANSI = false
protected var checkEmoji = false
private val usingUnicode = !SystemUtils.IS_OS_WINDOWS
protected var treeIndex: Int = 0
protected var treeIndexProcessed: MutableSet<Int> = mutableSetOf()
@ -115,7 +117,8 @@ abstract class ANSIProgressRenderer {
var newLinesDrawn = 1 + renderLevel(ansi, error != null)
if (error != null) {
ansi.a("${Emoji.skullAndCrossbones} ${error.message}")
val errorIcon = if (usingUnicode) Emoji.skullAndCrossbones else "ERROR: "
ansi.a("$errorIcon ${error.message}")
ansi.eraseLine(Ansi.Erase.FORWARD)
ansi.newline()
newLinesDrawn++
@ -152,10 +155,10 @@ abstract class ANSIProgressRenderer {
val activeStep = index == treeIndex
val marker = when {
processedStep -> " ${Emoji.greenTick} "
activeStep -> if (usingUnicode) "${Emoji.rightArrow} " else "CURRENT: "
processedStep -> if (usingUnicode) " ${Emoji.greenTick} " else "DONE: "
skippedStep -> " "
activeStep -> "${Emoji.rightArrow} "
error -> "${Emoji.noEntry} "
error -> if (usingUnicode) "${Emoji.noEntry} " else "ERROR: "
else -> " " // Not reached yet.
}
a(" ".repeat(step.first))
@ -226,7 +229,6 @@ object StdoutANSIProgressRenderer : ANSIProgressRenderer() {
override fun setup() {
AnsiConsole.systemInstall()
checkEmoji = true
// This line looks weird as hell because the magic code to decide if we really have a TTY or not isn't

View File

@ -9,6 +9,7 @@ import net.corda.core.messaging.DataFeed
import net.corda.core.messaging.FlowProgressHandleImpl
import net.corda.tools.shell.utlities.ANSIProgressRenderer
import net.corda.tools.shell.utlities.CRaSHANSIProgressRenderer
import org.apache.commons.lang.SystemUtils
import org.assertj.core.api.Assertions.assertThat
import org.crsh.text.RenderPrintWriter
import org.junit.Test
@ -28,9 +29,9 @@ class ANSIProgressRendererTest {
private const val STEP_2_LABEL = "Running step 2"
private const val STEP_3_LABEL = "Running step 3"
private const val STEP_1_SUCCESS_OUTPUT = """$STEP_1_LABEL"""
private val STEP_1_SUCCESS_OUTPUT = if (SystemUtils.IS_OS_WINDOWS) """DONE: $STEP_1_LABEL""" else """$STEP_1_LABEL"""
private const val STEP_2_SKIPPED_OUTPUT = """ $INTENSITY_FAINT_ON_ASCII$STEP_2_LABEL$INTENSITY_OFF_ASCII"""
private const val STEP_3_ACTIVE_OUTPUT = """ $INTENSITY_BOLD_ON_ASCII$STEP_3_LABEL$INTENSITY_OFF_ASCII"""
private val STEP_3_ACTIVE_OUTPUT = if (SystemUtils.IS_OS_WINDOWS) """CURRENT: $INTENSITY_BOLD_ON_ASCII$STEP_3_LABEL$INTENSITY_OFF_ASCII""" else """▶︎ $INTENSITY_BOLD_ON_ASCII$STEP_3_LABEL$INTENSITY_OFF_ASCII"""
}
lateinit var printWriter: RenderPrintWriter