Console: delay newline rendering until non newline character
This commit is contained in:
parent
722494af44
commit
601ea50e4b
@ -34,6 +34,9 @@ struct Console
|
||||
/** Current page cursor Y position. */
|
||||
private static __gshared size_t m_y;
|
||||
|
||||
/** Number of delayed newline characters. */
|
||||
private static __gshared size_t m_newlines;
|
||||
|
||||
/**
|
||||
* Initialize the console.
|
||||
*/
|
||||
@ -57,12 +60,38 @@ struct Console
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a character to the console.
|
||||
* Write a character to the console (buffer newlines).
|
||||
*
|
||||
* @param ch Character to write.
|
||||
*/
|
||||
public static void write(char ch)
|
||||
{
|
||||
if (ch == '\n')
|
||||
{
|
||||
m_newlines++;
|
||||
}
|
||||
else
|
||||
{
|
||||
dowrite(ch);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a character to the console (no newline buffering).
|
||||
*
|
||||
* @param ch Character to write.
|
||||
*/
|
||||
private static void dowrite(char ch)
|
||||
{
|
||||
if (m_newlines != 0u)
|
||||
{
|
||||
size_t newlines = m_newlines;
|
||||
m_newlines = 0u;
|
||||
for (size_t i = 0u; i < newlines; i++)
|
||||
{
|
||||
dowrite('\n');
|
||||
}
|
||||
}
|
||||
if (ch == '\n')
|
||||
{
|
||||
m_x = 0u;
|
||||
|
Loading…
x
Reference in New Issue
Block a user