Cuberite
A lightweight, fast and extensible game server for Minecraft
CommandOutput.cpp
Go to the documentation of this file.
1 
2 // CommandOutput.cpp
3 
4 // Implements the various classes that process command output
5 
6 #include "Globals.h"
7 #include "CommandOutput.h"
8 
9 
10 
11 
12 
14 // cStringAccumCommandOutputCallback:
15 
17 {
18  m_Accum.append(a_Text);
19 }
20 
21 
22 
23 
24 
26 // cLogCommandOutputCallback:
27 
29 {
30  // Log each line separately:
31  size_t len = m_Accum.length();
32  size_t last = 0;
33  for (size_t i = 0; i < len; i++)
34  {
35  switch (m_Accum[i])
36  {
37  case '\n':
38  {
39  LOG("%s", m_Accum.substr(last, i - last));
40  last = i + 1;
41  break;
42  }
43  }
44  } // for i - m_Buffer[]
45  if (last < len)
46  {
47  LOG("%s", m_Accum.substr(last));
48  }
49 
50  // Clear the buffer for the next command output:
51  m_Accum.clear();
52 }
53 
54 
55 
56 
void LOG(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:55
std::string AString
Definition: StringUtils.h:11
AString m_Accum
Output is stored here until the command finishes processing.
Definition: CommandOutput.h:71
virtual void Out(const AString &a_Text) override
Called when the command wants to output anything; may be called multiple times.
virtual void Finished() override
Called when the command processing has been finished.