From 4780960161622d4b501cb16a8d847e41a22e508b Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Wed, 2 Sep 2015 12:00:05 -1000 Subject: [PATCH] windows ANSI console support --- hecl/driver/ToolBase.hpp | 16 --------- hecl/driver/ToolExtract.hpp | 65 ++++++++++++++-------------------- hecl/driver/ToolSpec.hpp | 11 ------ hecl/driver/main.cpp | 14 +++++--- hecl/extern/LogVisor | 2 +- hecl/include/HECL/Database.hpp | 2 +- 6 files changed, 39 insertions(+), 71 deletions(-) diff --git a/hecl/driver/ToolBase.hpp b/hecl/driver/ToolBase.hpp index 319543bec..588ef2293 100644 --- a/hecl/driver/ToolBase.hpp +++ b/hecl/driver/ToolBase.hpp @@ -159,38 +159,26 @@ public: void printBold(const HECL::SystemChar* str) { -#if _WIN32 - HECL::FPrintf(m_sout, _S("%s"), str); -#else if (XTERM_COLOR) HECL::FPrintf(m_sout, _S("" BOLD "%s" NORMAL ""), str); else HECL::FPrintf(m_sout, _S("%s"), str); -#endif } void secHead(const HECL::SystemChar* headName) { -#if _WIN32 - HECL::FPrintf(m_sout, _S("%s\n"), headName); -#else if (XTERM_COLOR) HECL::FPrintf(m_sout, _S("" BOLD "%s" NORMAL "\n"), headName); else HECL::FPrintf(m_sout, _S("%s\n"), headName); -#endif } void optionHead(const HECL::SystemChar* flag, const HECL::SystemChar* synopsis) { -#if _WIN32 - HECL::FPrintf(m_sout, _S("%s (%s)\n"), flag, synopsis); -#else if (XTERM_COLOR) HECL::FPrintf(m_sout, _S("" BOLD "%s" NORMAL " (%s)\n"), flag, synopsis); else HECL::FPrintf(m_sout, _S("%s (%s)\n"), flag, synopsis); -#endif } void beginWrap() @@ -205,15 +193,11 @@ public: void wrapBold(const HECL::SystemChar* str) { -#if _WIN32 - m_wrapBuffer += str; -#else if (XTERM_COLOR) m_wrapBuffer += _S("" BOLD ""); m_wrapBuffer += str; if (XTERM_COLOR) m_wrapBuffer += _S("" NORMAL ""); -#endif } void endWrap() diff --git a/hecl/driver/ToolExtract.hpp b/hecl/driver/ToolExtract.hpp index 289626f30..9538cb045 100644 --- a/hecl/driver/ToolExtract.hpp +++ b/hecl/driver/ToolExtract.hpp @@ -116,14 +116,11 @@ public: { for (int l=0 ; lm_name); -#else if (XTERM_COLOR) HECL::Printf(_S("" MAGENTA BOLD "Using DataSpec %s:" NORMAL "\n"), ds.m_entry->m_name); else HECL::Printf(_S("Using DataSpec %s:\n"), ds.m_entry->m_name); -#endif int lineIdx = 0; - int prevIFactor = -1; ds.m_instance->doExtract(m_einfo, - [&lineIdx, &prevIFactor](const HECL::SystemChar* message, int lidx, float factor) + [&lineIdx](const HECL::SystemChar* message, const HECL::SystemChar* submessage, + int lidx, float factor) { int iFactor = factor * 100.0; - if (iFactor == prevIFactor) - return; - prevIFactor = iFactor; -#ifndef _WIN32 if (XTERM_COLOR) HECL::Printf(_S("" HIDE_CURSOR "")); -#endif if (lidx > lineIdx) { @@ -230,16 +206,34 @@ public: int half = width / 2 - 2; size_t messageLen = HECL::StrLen(message); - if (messageLen > half) - HECL::Printf(_S("%.*s... "), half-3, message); + size_t submessageLen = HECL::StrLen(submessage); + if (half - messageLen < submessageLen-2) + submessageLen = 0; + + if (submessageLen) + { + if (messageLen > half-submessageLen-1) + HECL::Printf(_S("%.*s... "), half-submessageLen-4, message); + else + { + HECL::Printf(_S("%s"), message); + for (int i=half-messageLen-submessageLen-1 ; i>=0 ; --i) + HECL::Printf(_S(" ")); + HECL::Printf(_S("%s "), submessage); + } + } else { - HECL::Printf(_S("%s"), message); - for (int i=half-messageLen ; i>=0 ; --i) - HECL::Printf(_S(" ")); + if (messageLen > half) + HECL::Printf(_S("%.*s... "), half-3, message); + else + { + HECL::Printf(_S("%s"), message); + for (int i=half-messageLen ; i>=0 ; --i) + HECL::Printf(_S(" ")); + } } -#ifndef _WIN32 if (XTERM_COLOR) { size_t blocks = half - 7; @@ -254,7 +248,6 @@ public: } else { -#endif size_t blocks = half - 7; size_t filled = blocks * factor; size_t rem = blocks - filled; @@ -264,15 +257,11 @@ public: for (int b=0 ; bm_name, spec->m_desc); -#else if (XTERM_COLOR) HECL::Printf(_S("" BOLD CYAN "%s" NORMAL "\n"), spec->m_name); else HECL::Printf(_S("%s\n"), spec->m_name); HECL::Printf(_S(" %s\n"), spec->m_desc); -#endif } return 0; } @@ -113,12 +109,6 @@ public: { for (auto& spec : specs) { -#if _WIN32 - HECL::Printf(_S("%s"), spec.spec.m_name); - if (spec.active) - HECL::Printf(_S(" [ENABLED]")); - HECL::Printf(_S("\n %s\n"), spec.spec.m_desc); -#else if (XTERM_COLOR) HECL::Printf(_S("" BOLD CYAN "%s" NORMAL ""), spec.spec.m_name); else @@ -131,7 +121,6 @@ public: HECL::Printf(_S(" [ENABLED]")); } HECL::Printf(_S("\n %s\n"), spec.spec.m_desc); -#endif } return 0; } diff --git a/hecl/driver/main.cpp b/hecl/driver/main.cpp index ebc23c3b6..f86a26c94 100644 --- a/hecl/driver/main.cpp +++ b/hecl/driver/main.cpp @@ -46,14 +46,10 @@ bool XTERM_COLOR = false; /* Main usage message */ static void printHelp(const HECL::SystemChar* pname) { -#if _WIN32 - HECL::Printf(_S("HECL")); -#else if (XTERM_COLOR) HECL::Printf(_S("" BOLD "HECL" NORMAL "")); else HECL::Printf(_S("HECL")); -#endif #if HECL_GIT HECL::Printf(_S(" Commit " HECL_GIT_S " " HECL_BRANCH_S "\nUsage: %s init|add|remove|group|cook|clean|package|help\n"), pname); #elif HECL_VER @@ -75,6 +71,9 @@ static void SIGINTHandler(int sig) exit(1); } +/* SIGWINCH should do nothing */ +static void SIGWINCHHandler(int sig) {} + static LogVisor::LogModule AthenaLog("Athena"); static void AthenaExc(const Athena::error::Level& level, const char* file, const char*, int line, const char* fmt, ...) @@ -98,11 +97,18 @@ int main(int argc, const char** argv) #endif /* Xterm check */ +#if _WIN32 + const char* conemuANSI = getenv("ConEmuANSI"); + if (conemuANSI && !strcmp(conemuANSI, "ON")) + XTERM_COLOR = true; +#else const char* term = getenv("TERM"); if (term && !strncmp(term, "xterm", 5)) XTERM_COLOR = true; +#endif signal(SIGINT, SIGINTHandler); + signal(SIGWINCH, SIGWINCHHandler); LogVisor::RegisterConsoleLogger(); atSetExceptionHandler(AthenaExc); diff --git a/hecl/extern/LogVisor b/hecl/extern/LogVisor index 7be764c38..d133a8cdd 160000 --- a/hecl/extern/LogVisor +++ b/hecl/extern/LogVisor @@ -1 +1 @@ -Subproject commit 7be764c387951cabfc86d52f48bd3dab54127aeb +Subproject commit d133a8cdd46eececcc6c1cb63248166e23791bce diff --git a/hecl/include/HECL/Database.hpp b/hecl/include/HECL/Database.hpp index 112ac5db0..ffa304ecd 100644 --- a/hecl/include/HECL/Database.hpp +++ b/hecl/include/HECL/Database.hpp @@ -91,7 +91,7 @@ public: std::vector childOpts; }; - typedef std::function FExtractProgress; + typedef std::function FExtractProgress; virtual bool canExtract(const ExtractPassInfo& info, std::vector& reps) {(void)info;LogModule.report(LogVisor::Error, "not implemented");return false;}