- cleanup and fixes in console code

* consolidated C_MidPrint and C_MidPrintBold.
* removed some unused code from the console buffer.
* handle console output of centered messages to ensure they get written to the log file and to stdout.
* replaced the non-standard bar strings with simple '-'s. These were making things needlessly complicated when redirecting console output and the new font does not have the characters anyway.
* removed some old code from a time when during console drawing new network events could come and have more text printed. This can not happen anymore with how 2D elements are being handled now so all this code was redundant.
This commit is contained in:
Christoph Oelckers 2019-03-16 13:02:38 +01:00
commit 669b13ab8a
11 changed files with 73 additions and 283 deletions

View file

@ -55,33 +55,6 @@ FConsoleBuffer::FConsoleBuffer()
mBrokenStart.Push(0);
}
//==========================================================================
//
//
//
//==========================================================================
FConsoleBuffer::~FConsoleBuffer()
{
FreeBrokenText();
}
//==========================================================================
//
//
//
//==========================================================================
void FConsoleBuffer::FreeBrokenText(unsigned start, unsigned end)
{
if (end > m_BrokenConsoleText.Size()) end = m_BrokenConsoleText.Size();
for (unsigned i = start; i < end; i++)
{
m_BrokenConsoleText[i].Clear();
m_BrokenConsoleText[i].ShrinkToFit();
}
}
//==========================================================================
//
// Adds a new line of text to the console
@ -95,7 +68,7 @@ void FConsoleBuffer::FreeBrokenText(unsigned start, unsigned end)
//
//==========================================================================
void FConsoleBuffer::AddText(int printlevel, const char *text, FILE *logfile)
void FConsoleBuffer::AddText(int printlevel, const char *text)
{
FString build = TEXTCOLOR_TAN;
@ -135,117 +108,9 @@ void FConsoleBuffer::AddText(int printlevel, const char *text, FILE *logfile)
mAddType = APPENDLINE;
}
// don't bother about linefeeds etc. inside the text, we'll let the formatter sort this out later.
// don't bother with linefeeds etc. inside the text, we'll let the formatter sort this out later.
build.AppendCStrPart(text, textsize);
mConsoleText.Push(build);
if (logfile != NULL) WriteLineToLog(logfile, text);
}
//==========================================================================
//
//
//
//==========================================================================
void FConsoleBuffer::WriteLineToLog(FILE *LogFile, const char *outline)
{
// Strip out any color escape sequences before writing to the log file
TArray<char> copy(strlen(outline)+1);
const char * srcp = outline;
char * dstp = copy.Data();
while (*srcp != 0)
{
if (*srcp != TEXTCOLOR_ESCAPE)
{
switch (*srcp)
{
case '\35':
*dstp++ = '<';
break;
case '\36':
*dstp++ = '-';
break;
case '\37':
*dstp++ = '>';
break;
default:
*dstp++=*srcp;
break;
}
srcp++;
}
else if (srcp[1] == '[')
{
srcp+=2;
while (*srcp != ']' && *srcp != 0) srcp++;
if (*srcp == ']') srcp++;
}
else
{
if (srcp[1]!=0) srcp+=2;
else break;
}
}
*dstp=0;
fputs (copy.Data(), LogFile);
fflush (LogFile);
}
//==========================================================================
//
//
//
//==========================================================================
void FConsoleBuffer::WriteContentToLog(FILE *LogFile)
{
if (LogFile != NULL)
{
for (unsigned i = 0; i < mConsoleText.Size(); i++)
{
WriteLineToLog(LogFile, mConsoleText[i]);
}
}
}
//==========================================================================
//
// ensures that the following text is not appended to the current line.
//
//==========================================================================
void FConsoleBuffer::Linefeed(FILE *Logfile)
{
if (mAddType != NEWLINE && Logfile != NULL) fputc('\n', Logfile);
mAddType = NEWLINE;
}
//==========================================================================
//
//
//
//==========================================================================
static const char bar1[] = TEXTCOLOR_RED "\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36"
"\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_TAN "\n";
static const char bar2[] = TEXTCOLOR_RED "\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36"
"\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_GREEN "\n";
static const char bar3[] = TEXTCOLOR_RED "\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36"
"\36\36\36\36\36\36\36\36\36\36\36\36\37" TEXTCOLOR_NORMAL "\n";
void FConsoleBuffer::AddMidText(const char *string, bool bold, FILE *Logfile)
{
Linefeed(Logfile);
AddText (-1, bold? bar2 : bar1, Logfile);
AddText (-1, string, Logfile);
Linefeed(Logfile);
AddText(-1, bar3, Logfile);
}
//==========================================================================
@ -258,7 +123,6 @@ void FConsoleBuffer::FormatText(FFont *formatfont, int displaywidth)
{
if (formatfont != mLastFont || displaywidth != mLastDisplayWidth || mBufferWasCleared)
{
FreeBrokenText();
m_BrokenConsoleText.Clear();
mBrokenStart.Clear();
mBrokenStart.Push(0);