1
0
cuberite-2a/src/CommandOutput.cpp

71 lines
1.2 KiB
C++
Raw Normal View History

// CommandOutput.cpp
// Implements the various classes that process command output
#include "Globals.h"
#include "CommandOutput.h"
////////////////////////////////////////////////////////////////////////////////
// cCommandOutputCallback:
2020-05-04 14:21:48 -04:00
void cCommandOutputCallback::vOut(const char * a_Fmt, fmt::printf_args a_ArgList)
{
2020-05-04 14:21:48 -04:00
AString Output = ::vPrintf(a_Fmt, a_ArgList);
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());
}
2016-02-05 16:45:45 -05:00
// Clear the buffer for the next command output:
m_Accum.clear();
}