From 671bf7bdf20ccc61339d0959b1fb2f81a316825b Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 21 Oct 2020 11:34:58 +0200 Subject: fix output --- cli/main.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'cli') diff --git a/cli/main.cpp b/cli/main.cpp index e28e0e6..981c1a0 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -328,12 +328,19 @@ int startDiceParsing(QStringList& cmds, bool withColor, EXPORTFORMAT format, QJs allSameColor= true; QString colorP; json= parser.resultAsJSon( - [&colorP, &allSameColor](const QString& value, const QString& color, bool highlight) { + [&colorP, &allSameColor](const QString& value, const QString& color, bool) { if(colorP.isNull()) colorP= color; else if(colorP != color) allSameColor= false; + return value; + }, + true); + + if(!allSameColor) + { + json= parser.resultAsJSon([](const QString& value, const QString& color, bool highlight) { QString result= value; bool hasColor= !color.isEmpty(); QString style; @@ -352,21 +359,27 @@ int startDiceParsing(QStringList& cmds, bool withColor, EXPORTFORMAT format, QJs result= QString("%1").arg(value).arg(style); return result; }); + } } else if(TERMINAL == format) { allSameColor= true; QString colorP; - json= parser.resultAsJSon([&colorP, &allSameColor](const QString& result, const QString& color, bool) { - if(colorP.isNull()) - colorP= color; - else if(colorP != color) - allSameColor= false; - - auto front= DisplayToolBox::colorToTermCode(color); - auto end= front.isEmpty() ? "" : DisplayToolBox::colorToTermCode("reset"); - return result; - }); + json= parser.resultAsJSon( + [&colorP, &allSameColor](const QString& result, const QString& color, bool hightlight) { + auto trueColor= color; + if(color.isEmpty()) + trueColor= "red"; + + if(colorP.isEmpty()) + colorP= trueColor; + else if(colorP != trueColor) + allSameColor= false; + + auto front= DisplayToolBox::colorToTermCode(trueColor); + auto end= front.isEmpty() ? "" : DisplayToolBox::colorToTermCode("reset"); + return hightlight ? QString("%1%2%3").arg(front).arg(result).arg(end) : result; + }); } else { -- cgit v1.2.3-70-g09d2