diff options
| author | 2020-10-21 11:34:58 +0200 | |
|---|---|---|
| committer | 2020-10-21 11:34:58 +0200 | |
| commit | 671bf7bdf20ccc61339d0959b1fb2f81a316825b (patch) | |
| tree | 595be6924b831977a8680bb3be9c5bccdf2bc4a6 /cli | |
| parent | d1a947bed91963e788287e186f831202b8355eea (diff) | |
| download | OneRoll-671bf7bdf20ccc61339d0959b1fb2f81a316825b.tar.gz OneRoll-671bf7bdf20ccc61339d0959b1fb2f81a316825b.zip | |
fix output
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/main.cpp | 35 |
1 files changed, 24 insertions, 11 deletions
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("<tspan %2>%1</tspan>").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 { |