displayLayout and Rendering TUI library |
git clone git://git.dimitrijedobrota.com/display.git |
Log | Files | Refs | README | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING | |
commit | 5d72bc83d55bf33579c79bb100f437241918f6cb |
parent | 5aeddc86c66cd8a845f0d0ae753f5062e158504c |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Wed, 5 Feb 2025 12:00:38 +0100 |
Handle screen resize signal
Diffstat:M | example/example.cpp | | | ---- |
M | source/display.cpp | | | +++++++++++++++++++-- |
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/example/example.cpp b/example/example.cpp
@@ -13,10 +13,6 @@ int main()
if (event.type() == alec::event::Type::KEY && event.key() == 'q') {
break;
}
const auto size = alec::get_screen_size();
std::cout << std::format("({}, {})\n", std::get<0>(size), std::get<1>(size))
<< std::flush;
}
display::stop();
diff --git a/source/display.cpp b/source/display.cpp
@@ -4,6 +4,7 @@
#include "display/display.hpp"
#include <alec/alec.hpp>
#include <signal.h>
#include <termios.h>
#include <unistd.h>
@@ -23,6 +24,12 @@ namespace display
static int start_count = 0; // NOLINT
void handle_sigwinch(int)
{
const auto [col, row] = alec::get_screen_size();
std::cout << col << " " << row << std::endl;
}
void exit()
{
stop(/* force= */ true);
@@ -39,8 +46,19 @@ void start(exit_f f_exit)
throw std::runtime_error("Can't register new exit function");
}
struct sigaction old_sig_action = {};
sigaction(SIGWINCH, nullptr, &old_sig_action);
if (old_sig_action.sa_handler != SIG_IGN) {
struct sigaction new_sig_action = {};
new_sig_action.sa_handler = handle_sigwinch;
sigemptyset(&new_sig_action.sa_mask);
new_sig_action.sa_flags = SA_RESTART;
alec::init_buffer(2);
sigaction(SIGWINCH, &new_sig_action, nullptr);
}
alec::init_buffer(STDIN_FILENO);
write<alec::abuf_enable_v>();
write<alec::cursor_hide_v>();
}
@@ -52,7 +70,6 @@ void stop(bool force)
return;
}
alec::dest_buffer();
write<alec::cursor_show_v>();
}