summaryrefslogtreecommitdiffstats
path: root/src/MCLogger.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-29 20:22:03 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-29 20:22:03 +0100
commit7d03876a3e11aedff0201a8330bfdb2b5523fc5e (patch)
tree04f795a2ff37644aa47c0b0d86f648eec949fba3 /src/MCLogger.cpp
parentFixed redstone simulator crash found in #570 (diff)
downloadcuberite-7d03876a3e11aedff0201a8330bfdb2b5523fc5e.tar
cuberite-7d03876a3e11aedff0201a8330bfdb2b5523fc5e.tar.gz
cuberite-7d03876a3e11aedff0201a8330bfdb2b5523fc5e.tar.bz2
cuberite-7d03876a3e11aedff0201a8330bfdb2b5523fc5e.tar.lz
cuberite-7d03876a3e11aedff0201a8330bfdb2b5523fc5e.tar.xz
cuberite-7d03876a3e11aedff0201a8330bfdb2b5523fc5e.tar.zst
cuberite-7d03876a3e11aedff0201a8330bfdb2b5523fc5e.zip
Diffstat (limited to 'src/MCLogger.cpp')
-rw-r--r--src/MCLogger.cpp58
1 files changed, 52 insertions, 6 deletions
diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp
index 4f3e5dc0f..632ea2efe 100644
--- a/src/MCLogger.cpp
+++ b/src/MCLogger.cpp
@@ -119,13 +119,51 @@ void cMCLogger::LogSimple(const char* a_Text, int a_LogType /* = 0 */ )
-void cMCLogger::Log(const char * a_Format, va_list a_ArgList)
+void cMCLogger::Log(const char * a_Format, va_list a_ArgList, bool a_ShouldReplaceLine)
{
cCSLock Lock(m_CriticalSection);
- SetColor(csRegular);
- m_Log->Log(a_Format, a_ArgList);
- ResetColor();
- puts("");
+
+ if (!m_BeginLineUpdate && a_ShouldReplaceLine)
+ {
+ a_ShouldReplaceLine = false; // Print a normal line first if this is the initial replace line
+ m_BeginLineUpdate = true;
+ }
+ else if (m_BeginLineUpdate && !a_ShouldReplaceLine)
+ {
+ m_BeginLineUpdate = false;
+ }
+
+ if (a_ShouldReplaceLine)
+ {
+#ifdef _WIN32
+ HANDLE Output = GetStdHandle(STD_OUTPUT_HANDLE);
+
+ CONSOLE_SCREEN_BUFFER_INFO csbi;
+ GetConsoleScreenBufferInfo(Output, &csbi);
+
+ COORD Position = { 0, csbi.dwCursorPosition.Y - 1 }; // Move cursor up one line
+ SetConsoleCursorPosition(Output, Position);
+
+ SetColor(csRegular);
+ m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine);
+ ResetColor();
+
+ Position = { 0, csbi.dwCursorPosition.Y }; // Set cursor to original position
+ SetConsoleCursorPosition(Output, Position);
+#else // _WIN32
+ fputs("\033[1A", stdout); // Move cursor up one line
+ SetColor(csRegular);
+ m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine);
+ ResetColor();
+#endif
+ }
+ else
+ {
+ SetColor(csRegular);
+ m_Log->Log(a_Format, a_ArgList, a_ShouldReplaceLine);
+ ResetColor();
+ puts("");
+ }
}
@@ -188,7 +226,7 @@ void cMCLogger::SetColor(eColorScheme a_Scheme)
default: ASSERT(!"Unhandled color scheme");
}
SetConsoleTextAttribute(g_Console, Attrib);
- #elif defined(__linux) && !defined(ANDROID_NDK)
+ #elif (defined(__linux) || defined(__apple)) && !defined(ANDROID_NDK)
switch (a_Scheme)
{
case csRegular: printf("\x1b[0m"); break; // Whatever the console default is
@@ -224,6 +262,14 @@ void cMCLogger::ResetColor(void)
//////////////////////////////////////////////////////////////////////////
// Global functions
+void LOGREPLACELINE(const char* a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ cMCLogger::GetInstance()->Log(a_Format, argList, true);
+ va_end(argList);
+}
+
void LOG(const char* a_Format, ...)
{
va_list argList;