From 597fa89e4ea98f8f51c99b65f3deac15b3a18b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 25 Aug 2022 12:55:48 +0200 Subject: [PATCH] sceneconverter: move colored output logic at the top as well. Will eventually be needed for more than just --info. --- src/Magnum/SceneTools/sceneconverter.cpp | 50 ++++++++++++------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Magnum/SceneTools/sceneconverter.cpp b/src/Magnum/SceneTools/sceneconverter.cpp index 9191b9e3d..a663d1e90 100644 --- a/src/Magnum/SceneTools/sceneconverter.cpp +++ b/src/Magnum/SceneTools/sceneconverter.cpp @@ -325,6 +325,31 @@ attributes that are present in the first mesh are taken, if --only-attributes is specified as well, the IDs reference attributes of the first mesh.)") .parse(argc, argv); + /* Colored output. Enable only if a TTY. */ + Debug::Flags useColor; + bool useColor24; + if(args.value("color") == "on") { + useColor = Debug::Flags{}; + useColor24 = true; + } else if(args.value("color") == "4bit") { + useColor = Debug::Flags{}; + useColor24 = false; + } else if(args.value("color") == "off") { + useColor = Debug::Flag::DisableColors; + useColor24 = false; + } else if(Debug::isTty()) { + useColor = Debug::Flags{}; + /* https://unix.stackexchange.com/a/450366, not perfect but good enough + I'd say */ + /** @todo make this more robust and put directly on Debug, + including a "Disable 24 colors" flag */ + const Containers::StringView colorterm = std::getenv("COLORTERM"); + useColor24 = colorterm == "truecolor"_s || colorterm == "24bit"_s; + } else { + useColor = Debug::Flag::DisableColors; + useColor24 = false; + } + /* Generic checks */ if(!args.value("output").isEmpty()) { /* Not an error in this case, it should be possible to just append @@ -801,31 +826,6 @@ is specified as well, the IDs reference attributes of the first mesh.)") imageInfos = Trade::Implementation::imageInfo(*importer, error, importTime); } - /* Colored output. Enable only if a TTY. */ - Debug::Flags useColor; - bool useColor24; - if(args.value("color") == "on") { - useColor = Debug::Flags{}; - useColor24 = true; - } else if(args.value("color") == "4bit") { - useColor = Debug::Flags{}; - useColor24 = false; - } else if(args.value("color") == "off") { - useColor = Debug::Flag::DisableColors; - useColor24 = false; - } else if(Debug::isTty()) { - useColor = Debug::Flags{}; - /* https://unix.stackexchange.com/a/450366, not perfect but good - enough I'd say */ - /** @todo make this more robust and put directly on Debug, - including a "Disable 24 colors" flag */ - const Containers::StringView colorterm = std::getenv("COLORTERM"); - useColor24 = colorterm == "truecolor"_s || colorterm == "24bit"_s; - } else { - useColor = Debug::Flag::DisableColors; - useColor24 = false; - } - std::size_t totalSceneDataSize = 0; for(const SceneInfo& info: sceneInfos) { Debug d{useColor};