From 915b186bdc94c6a79537dbe1e7479af2d26f5081 Mon Sep 17 00:00:00 2001 From: Adam Saponara Date: Sun, 2 Apr 2023 20:06:56 -0400 Subject: [PATCH] invalidate last_(fg|bg) after mode switch last_(fg|bg) are no longer valid after a mode switch. see the test for an example of the bug in action. --- termbox2.h | 2 ++ tests/test_output_mode/expected.ansi | 24 ++++++++++++++++++++++++ tests/test_output_mode/test.php | 17 +++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 tests/test_output_mode/expected.ansi create mode 100755 tests/test_output_mode/test.php diff --git a/termbox2.h b/termbox2.h index 584cf91..e2311e8 100644 --- a/termbox2.h +++ b/termbox2.h @@ -1690,6 +1690,8 @@ int tb_set_output_mode(int mode) { #ifdef TB_OPT_TRUECOLOR case TB_OUTPUT_TRUECOLOR: #endif + global.last_fg = ~global.fg; + global.last_bg = ~global.bg; global.output_mode = mode; return TB_OK; } diff --git a/tests/test_output_mode/expected.ansi b/tests/test_output_mode/expected.ansi new file mode 100644 index 0000000..466ae50 --- /dev/null +++ b/tests/test_output_mode/expected.ansi @@ -0,0 +1,24 @@ +#5cyan (even after mode switch) +#5[0;38:5:238mg[0;38:5:238mr[0;38:5:238ma[0;38:5:238my + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_output_mode/test.php b/tests/test_output_mode/test.php new file mode 100755 index 0000000..cee4897 --- /dev/null +++ b/tests/test_output_mode/test.php @@ -0,0 +1,17 @@ +ffi->tb_init(); + +$y = 0; +$fg = 7; + +$test->ffi->tb_printf(0, $y++, $fg, 0, "cyan (even after mode switch)"); +$test->ffi->tb_present(); + +$test->ffi->tb_set_output_mode($test->defines['TB_OUTPUT_GRAYSCALE']); + +$test->ffi->tb_printf(0, $y++, $fg, 0, "gray"); +$test->ffi->tb_present(); + +$test->screencap(); -- 2.39.5