mirror of
https://git.shylie.info/shylie/terml.git
synced 2024-11-21 15:40:07 +00:00
Fix windows build and issue with printing codepoints that don't move the cursor
This commit is contained in:
parent
a02ba55ac3
commit
ea1e1cee82
@ -26,17 +26,8 @@ namespace
|
||||
constexpr int THREE_BYTE_FILL = 0b111000001000000010000000;
|
||||
constexpr int FOUR_BYTE_FILL = 0b11110000100000001000000010000000;
|
||||
|
||||
void print_cell(tcell cell, const tcell* last)
|
||||
void print_cell(tcell cell)
|
||||
{
|
||||
if (!last || cell.foreground != last->foreground)
|
||||
{
|
||||
printf(FGP, (cell.foreground & 0xFF0000) >> 16, (cell.foreground & 0xFF00) >> 8, cell.foreground & 0xFF);
|
||||
}
|
||||
if (!last || cell.background != last->background)
|
||||
{
|
||||
printf(BGP, (cell.background & 0xFF0000) >> 16, (cell.background & 0xFF00) >> 8, cell.background & 0xFF);
|
||||
}
|
||||
|
||||
// one-byte codepoints
|
||||
if (cell.codepoint < 0x80)
|
||||
{
|
||||
@ -77,6 +68,20 @@ namespace
|
||||
printf("%s", str);
|
||||
}
|
||||
}
|
||||
|
||||
void print_cell(tcell cell, tcell last)
|
||||
{
|
||||
if (cell.foreground != last.foreground)
|
||||
{
|
||||
printf(FG(%d, %d, %d), (cell.foreground & 0xFF0000) >> 16, (cell.foreground & 0xFF00) >> 8, cell.foreground & 0xFF);
|
||||
}
|
||||
if (cell.background != last.background)
|
||||
{
|
||||
printf(BG(%d, %d, %d), (cell.background & 0xFF0000) >> 16, (cell.background & 0xFF00) >> 8, cell.background & 0xFF);
|
||||
}
|
||||
|
||||
print_cell(cell);
|
||||
}
|
||||
}
|
||||
|
||||
terml::terml() :
|
||||
@ -109,14 +114,17 @@ void terml::set(unsigned int x, unsigned int y, tcell cell)
|
||||
|
||||
void terml::flush() const
|
||||
{
|
||||
printf(CUP(1, 1));
|
||||
fflush(stdout);
|
||||
|
||||
print_cell(cells[0], nullptr);
|
||||
printf(CUP(1, 0));
|
||||
print_cell(cells[0]);
|
||||
for (int i = 1; i < width * height; i++)
|
||||
{
|
||||
print_cell(cells[i], &cells[i - 1]);
|
||||
const unsigned int x = i % width;
|
||||
const unsigned int y = i / width;
|
||||
|
||||
printf(CUP(%d, %d), y, x + 1);
|
||||
print_cell(cells[i], cells[i - 1]);
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
@ -242,8 +250,9 @@ void terml::setup_buffer()
|
||||
void terml::set_console_settings()
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IOFBF, BUFSIZ * BUFSIZ);
|
||||
printf(ALT_BUF() HIDE_CURSOR() SELECT_UTF8());
|
||||
printf(ALT_BUF() HIDE_CURSOR());
|
||||
fflush(stdout);
|
||||
|
||||
set_console_settings_impl();
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,9 @@ void terml_linux::set_console_settings_impl()
|
||||
t.c_lflag &= ~(ICANON | ECHO);
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &t);
|
||||
|
||||
printf(SELECT_UTF8());
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void terml_linux::reset_console_settings_impl()
|
||||
|
@ -26,9 +26,6 @@
|
||||
#define FG(r, g, b) CSI "38;2;" STRINGIFY(r) ";" STRINGIFY(g) ";" STRINGIFY(b) "m"
|
||||
#define BG(r, g, b) CSI "48;2;" STRINGIFY(r) ";" STRINGIFY(g) ";" STRINGIFY(b) "m"
|
||||
|
||||
#define FGP CSI "38;2;%d;%d;%dm"
|
||||
#define BGP CSI "48;2;%d;%d;%dm"
|
||||
|
||||
class terml
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user