windows ANSI console support

This commit is contained in:
Jack Andersen 2015-09-02 12:00:05 -10:00
parent 1091f93536
commit 4780960161
6 changed files with 39 additions and 71 deletions

View File

@ -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()

View File

@ -116,14 +116,11 @@ public:
{
for (int l=0 ; l<level ; ++l)
HECL::Printf(_S(" "));
#if _WIN32
HECL::Printf(_S("%s"), rep.name.c_str());
#else
if (XTERM_COLOR)
HECL::Printf(_S("" BOLD "%s" NORMAL ""), rep.name.c_str());
else
HECL::Printf(_S("%s"), rep.name.c_str());
#endif
if (rep.desc.size())
HECL::Printf(_S(" [%s]"), rep.desc.c_str());
HECL::Printf(_S("\n"));
@ -135,25 +132,17 @@ public:
{
if (m_specPasses.empty())
{
#if _WIN32
HECL::Printf(_S("NOTHING TO EXTRACT\n"));
#else
if (XTERM_COLOR)
HECL::Printf(_S("" RED BOLD "NOTHING TO EXTRACT" NORMAL "\n"));
else
HECL::Printf(_S("NOTHING TO EXTRACT\n"));
#endif
return -1;
}
#if _WIN32
HECL::Printf(_S("ABOUT TO EXTRACT:\n"));
#else
if (XTERM_COLOR)
HECL::Printf(_S("" GREEN BOLD "ABOUT TO EXTRACT:" NORMAL "\n"));
else
HECL::Printf(_S("ABOUT TO EXTRACT:\n"));
#endif
for (HECL::Database::IDataSpec::ExtractReport& rep : m_reps)
{
@ -161,14 +150,10 @@ public:
HECL::Printf(_S("\n"));
}
#if _WIN32
HECL::Printf(_S("\nContinue? (Y/n) "));
#else
if (XTERM_COLOR)
HECL::Printf(_S("\n" BLUE BOLD "Continue?" NORMAL " (Y/n) "));
else
HECL::Printf(_S("\nContinue? (Y/n) "));
#endif
int ch;
#ifndef _WIN32
@ -195,28 +180,19 @@ public:
for (SpecExtractPass& ds : m_specPasses)
{
#if _WIN32
HECL::Printf(_S("Using DataSpec %s:\n"), ds.m_entry->m_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 ; b<rem ; ++b)
HECL::Printf(_S("-"), message);
HECL::Printf(_S("]"));
#ifndef _WIN32
}
#endif
HECL::Printf(_S("\r"));
#ifndef _WIN32
if (XTERM_COLOR)
HECL::Printf(_S("" SHOW_CURSOR ""));
#endif
fflush(stdout);
});
HECL::Printf(_S("\n\n"));

View File

@ -95,15 +95,11 @@ public:
{
for (const HECL::Database::DataSpecEntry* spec : HECL::Database::DATA_SPEC_REGISTRY)
{
#if _WIN32
HECL::Printf(_S("%s\n %s\n"), spec->m_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;
}

View File

@ -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);

@ -1 +1 @@
Subproject commit 7be764c387951cabfc86d52f48bd3dab54127aeb
Subproject commit d133a8cdd46eececcc6c1cb63248166e23791bce

View File

@ -91,7 +91,7 @@ public:
std::vector<ExtractReport> childOpts;
};
typedef std::function<void(const HECL::SystemChar*, int, float)> FExtractProgress;
typedef std::function<void(const HECL::SystemChar*, const HECL::SystemChar*, int, float)> FExtractProgress;
virtual bool canExtract(const ExtractPassInfo& info, std::vector<ExtractReport>& reps)
{(void)info;LogModule.report(LogVisor::Error, "not implemented");return false;}