Add console escape sequences to draw headings
This commit is contained in:
1 parent
601ea50e4b
commit
7632445d43
5 files changed
+69
-3
No files matched your search
@@ -19,6 +19,9 @@ struct Console
|
||||
/** Border color. */
|
||||
private enum BORDER_COLOR = 0xFF8000u;
|
||||
|
||||
/** Heading color. */
|
||||
private enum HEADING_COLOR = 0x0066FFu;
|
||||
|
||||
/** Console page width in text columns. */
|
||||
private static __gshared size_t m_width;
|
||||
|
||||
@@ -37,6 +40,12 @@ struct Console
|
||||
/** Number of delayed newline characters. */
|
||||
private static __gshared size_t m_newlines;
|
||||
|
||||
/** Active console escape code. */
|
||||
private static __gshared char m_escape_code;
|
||||
|
||||
/** Flag to indicate the previous character was an escape character. */
|
||||
private static __gshared bool m_escape;
|
||||
|
||||
/**
|
||||
* Initialize the console.
|
||||
*/
|
||||
@@ -68,6 +77,8 @@ struct Console
|
||||
{
|
||||
if (ch == '\n')
|
||||
{
|
||||
render_heading_end();
|
||||
m_escape_code = 0u;
|
||||
m_newlines++;
|
||||
}
|
||||
else
|
||||
@@ -76,6 +87,46 @@ struct Console
|
||||
}
|
||||
}
|
||||
|
||||
private static void render_heading_start()
|
||||
{
|
||||
if ('0' <= m_escape_code && m_escape_code <= '9' && m_x < (m_width - 1))
|
||||
{
|
||||
size_t heading_level = m_escape_code - ('0' - 1);
|
||||
size_t nx = m_x + heading_level;
|
||||
if (nx >= m_width)
|
||||
{
|
||||
nx = m_width - 1;
|
||||
}
|
||||
size_t hx = fb_x(m_page, m_x);
|
||||
size_t hy = fb_y(m_y) + Kfont.line_height / 2 - 1;
|
||||
size_t hwidth = (nx - m_x - 1) * Kfont.advance + Kfont.advance / 2 - 1;
|
||||
Fb.rect(hx, hy, hwidth, 2, HEADING_COLOR);
|
||||
Fb.rect(hx + hwidth, fb_y(m_y) + Kfont.line_height / 8,
|
||||
2, Kfont.line_height * 3 / 4, HEADING_COLOR);
|
||||
m_x = nx;
|
||||
}
|
||||
}
|
||||
|
||||
private static void render_heading_end()
|
||||
{
|
||||
if ('0' <= m_escape_code && m_escape_code <= '9' && m_x < (m_width - 1))
|
||||
{
|
||||
size_t heading_level = m_escape_code - ('0' - 1);
|
||||
size_t nx = m_x + heading_level;
|
||||
if (nx >= m_width)
|
||||
{
|
||||
nx = m_width - 1;
|
||||
}
|
||||
size_t hwidth = (nx - m_x - 1) * Kfont.advance + Kfont.advance / 2 - 1;
|
||||
size_t hx = fb_x(m_page, nx) - hwidth;
|
||||
size_t hy = fb_y(m_y) + Kfont.line_height / 2 - 1;
|
||||
Fb.rect(hx, hy, hwidth, 2, HEADING_COLOR);
|
||||
Fb.rect(hx - 2, fb_y(m_y) + Kfont.line_height / 8,
|
||||
2, Kfont.line_height * 3 / 4, HEADING_COLOR);
|
||||
m_x = nx;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a character to the console (no newline buffering).
|
||||
*
|
||||
@@ -92,6 +143,18 @@ struct Console
|
||||
dowrite('\n');
|
||||
}
|
||||
}
|
||||
if (m_escape)
|
||||
{
|
||||
m_escape_code = ch;
|
||||
render_heading_start();
|
||||
m_escape = false;
|
||||
return;
|
||||
}
|
||||
if (ch == '\a')
|
||||
{
|
||||
m_escape = true;
|
||||
return;
|
||||
}
|
||||
if (ch == '\n')
|
||||
{
|
||||
m_x = 0u;
|
||||
|
||||
Reference in new issue
Block a user