From 297fd607461a62a40195024084bbc40c5f20a7d0 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sun, 29 Aug 2021 17:42:53 +0200 Subject: [PATCH] Fix colors in preview --- src/report/handle.js | 14 ++++++++++---- src/run/preview/update/bottom_bar.js | 19 +++++++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/report/handle.js b/src/report/handle.js index be5b20db1..ea3259474 100644 --- a/src/report/handle.js +++ b/src/report/handle.js @@ -11,11 +11,17 @@ import { wrapRows } from './utils/wrap.js' // lines will be eventually filled (e.g. when combinations stats become // available). export const handleContent = function ({ content, output, format, colors }) { + const padding = FORMATS[format].padding !== undefined + const contentA = handleContentString({ content, padding, colors }) + return { content: contentA, output } +} + +export const handleContentString = function ({ content, padding, colors }) { const contentA = handleColors(content, colors) const contentB = trimEnd(contentA) const contentC = wrapRows(contentB) - const contentD = padContents(contentC, format) - return { content: contentD, output } + const contentD = padContents(contentC, padding) + return contentD } // Reporters should always assume `colors` are true, but the core remove this @@ -33,8 +39,8 @@ const trimEndLine = function (line) { return line.trimEnd() } -const padContents = function (joinedContents, format) { - if (FORMATS[format].padding === undefined) { +const padContents = function (joinedContents, padding) { + if (!padding) { return joinedContents } diff --git a/src/run/preview/update/bottom_bar.js b/src/run/preview/update/bottom_bar.js index 3bce3a654..a67156a06 100644 --- a/src/run/preview/update/bottom_bar.js +++ b/src/run/preview/update/bottom_bar.js @@ -1,17 +1,28 @@ +import stripFinalNewline from 'strip-final-newline' + +import { handleContentString } from '../../../report/handle.js' import { goodColor, noteColor } from '../../../report/utils/colors.js' -import { addPadding } from '../../../report/utils/indent.js' import { wrapPaddedRows } from '../../../report/utils/wrap.js' // Retrieve bottom bar of preview export const getBottomBar = function ({ - previewState: { actions }, + previewState: { + actions, + reporters: [ + { + config: { colors }, + }, + ], + }, leftWidth, progressRow, counterRow, }) { const actionsA = getActions(actions, leftWidth) - const rows = addPadding(`${progressRow}\n\n${counterRow}\n\n${actionsA}`) - return rows + const content = `${progressRow}\n\n${counterRow}\n\n${actionsA}` + const bottomBar = handleContentString({ content, padding: true, colors }) + const bottomBarA = stripFinalNewline(bottomBar) + return bottomBarA } // Show keys available for user actions in previews.