1
0
cuberite-2a/src/CommandOutput.cpp
peterbell10 757231cc6e
Add the fmt library (#4065)
* Replaces AppendVPrintf with fmt::sprintf
* fmt::ArgList now used as a type safe alternative to varargs.
* Removed SIZE_T_FMT compatibility macros. fmt::sprintf is fully portable and supports %zu.
* Adds FLOG functions to log with fmt's native formatting style.
2018-01-03 17:41:16 +00:00

71 lines
1.2 KiB
C++

// CommandOutput.cpp
// Implements the various classes that process command output
#include "Globals.h"
#include "CommandOutput.h"
////////////////////////////////////////////////////////////////////////////////
// cCommandOutputCallback:
void cCommandOutputCallback::Out(const char * a_Fmt, fmt::ArgList args)
{
AString Output = Printf(a_Fmt, args);
Output.append("\n");
Out(Output);
}
////////////////////////////////////////////////////////////////////////////////
// cStringAccumCommandOutputCallback:
void cStringAccumCommandOutputCallback::Out(const AString & a_Text)
{
m_Accum.append(a_Text);
}
////////////////////////////////////////////////////////////////////////////////
// cLogCommandOutputCallback:
void cLogCommandOutputCallback::Finished(void)
{
// Log each line separately:
size_t len = m_Accum.length();
size_t last = 0;
for (size_t i = 0; i < len; i++)
{
switch (m_Accum[i])
{
case '\n':
{
LOG("%s", m_Accum.substr(last, i - last).c_str());
last = i + 1;
break;
}
}
} // for i - m_Buffer[]
if (last < len)
{
LOG("%s", m_Accum.substr(last).c_str());
}
// Clear the buffer for the next command output:
m_Accum.clear();
}