2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 21:07:42 +00:00

Add parallel progress printing

This commit is contained in:
Jack Andersen
2018-03-23 11:40:12 -10:00
parent 6180ec82b3
commit d1a66e15d4
14 changed files with 638 additions and 201 deletions

View File

@@ -270,115 +270,4 @@ static hecl::SystemString MakePathArgAbsolute(const hecl::SystemString& arg,
#endif
}
static bool g_HasLastProgTime = false;
static std::chrono::steady_clock::time_point g_LastProgTime;
void ToolPrintProgress(const hecl::SystemChar* message, const hecl::SystemChar* submessage,
int lidx, float factor, int& lineIdx)
{
if (g_HasLastProgTime)
{
std::chrono::steady_clock::time_point newPoint = std::chrono::steady_clock::now();
std::chrono::milliseconds::rep delta =
std::chrono::duration_cast<std::chrono::milliseconds>(newPoint - g_LastProgTime).count();
if (delta < 50)
return;
g_LastProgTime = newPoint;
}
else
{
g_HasLastProgTime = true;
g_LastProgTime = std::chrono::steady_clock::now();
}
auto lk = logvisor::LockLog();
bool blocks = factor >= 0.0;
factor = std::max(0.0f, std::min(1.0f, factor));
int iFactor = factor * 100.0;
if (XTERM_COLOR)
hecl::Printf(_S("" HIDE_CURSOR ""));
if (lidx > lineIdx)
{
hecl::Printf(_S("\n "));
lineIdx = lidx;
}
else
hecl::Printf(_S(" "));
int width = (hecl::GuiMode ? 120 : std::max(80, hecl::ConsoleWidth()));
int half;
if (blocks)
half = width / 2 - 2;
else
half = width - 4;
if (!message)
message = _S("");
int messageLen = hecl::StrLen(message);
if (!submessage)
submessage = _S("");
int submessageLen = hecl::StrLen(submessage);
if (half - messageLen < submessageLen-2)
submessageLen = 0;
if (submessageLen)
{
if (messageLen > half-submessageLen-1)
hecl::Printf(_S("%.*s... %s "), half-submessageLen-4, message, submessage);
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
{
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(" "));
}
}
if (blocks)
{
if (XTERM_COLOR)
{
int blocks = half - 7;
int filled = blocks * factor;
int rem = blocks - filled;
hecl::Printf(_S("" BOLD "%3d%% ["), iFactor);
for (int b=0 ; b<filled ; ++b)
hecl::Printf(_S("#"));
for (int b=0 ; b<rem ; ++b)
hecl::Printf(_S("-"));
hecl::Printf(_S("]" NORMAL ""));
}
else
{
int blocks = half - 7;
int filled = blocks * factor;
int rem = blocks - filled;
hecl::Printf(_S("%3d%% ["), iFactor);
for (int b=0 ; b<filled ; ++b)
hecl::Printf(_S("#"));
for (int b=0 ; b<rem ; ++b)
hecl::Printf(_S("-"));
hecl::Printf(_S("]"));
}
}
hecl::Printf(_S("\r"));
if (XTERM_COLOR)
hecl::Printf(_S("" SHOW_CURSOR ""));
fflush(stdout);
}
#endif // CTOOL_BASE