Fixed: Terminal resize warning getting stuck

This commit is contained in:
aristocratos 2022-02-09 15:42:09 +01:00
parent ec4bc6823f
commit c77aee2211
3 changed files with 12 additions and 3 deletions

View file

@ -157,6 +157,11 @@ void argumentParser(const int& argc, char **argv) {
//* Handler for SIGWINCH and general resizing events, does nothing if terminal hasn't been resized unless force=true
void term_resize(bool force) {
static atomic<bool> resizing (false);
if (Input::polling) {
Global::resized = true;
Input::interrupt = true;
return;
}
atomic_lock lck(resizing, true);
if (auto refreshed = Term::refresh(true); refreshed or force) {
if (force and refreshed) force = false;
@ -182,8 +187,9 @@ void term_resize(bool force) {
<< Mv::to((Term::height / 2) + 1, (Term::width / 2) - 12) << Global::fg_white
<< "Needed for current config:" << Mv::to((Term::height / 2) + 2, (Term::width / 2) - 10)
<< "Width = " << min_size.at(0) << " Height = " << min_size.at(1) << flush;
while (not Term::refresh() and not Input::poll()) sleep_ms(10);
if (Input::poll()) {
bool got_key = false;
for (; not Term::refresh() and not got_key; got_key = Input::poll(10));
if (got_key) {
auto key = Input::get();
if (key == "q")
clean_quit(0);
@ -899,7 +905,7 @@ int main(int argc, char **argv) {
else if (Global::should_sleep) { Global::should_sleep = false; _sleep(); }
//? Make sure terminal size hasn't changed (in case of SIGWINCH not working properly)
term_resize();
term_resize(Global::resized);
//? Trigger secondary thread to redraw if terminal has been resized
if (Global::resized) {

View file

@ -74,6 +74,7 @@ namespace Input {
};
std::atomic<bool> interrupt (false);
std::atomic<bool> polling (false);
array<int, 2> mouse_pos;
unordered_flat_map<string, Mouse_loc> mouse_mappings;
@ -133,6 +134,7 @@ namespace Input {
};
bool poll(int timeout) {
atomic_lock lck(polling);
if (timeout < 1) return InputThr::instance().avail() > 0;
while (timeout > 0) {
if (interrupt) {

View file

@ -42,6 +42,7 @@ namespace Input {
extern unordered_flat_map<string, Mouse_loc> mouse_mappings;
extern atomic<bool> interrupt;
extern atomic<bool> polling;
//* Mouse column and line position
extern array<int, 2> mouse_pos;