Introduce WithRestoredIO (#307)

This function allow running a callback with the terminal hooks
temporarily uninstalled.

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Vladislav Nepogodin
2022-01-19 16:38:39 +04:00
committed by GitHub
parent cd82fccde7
commit b4a655ec65
5 changed files with 93 additions and 14 deletions

View File

@@ -20,20 +20,28 @@ using Component = std::shared_ptr<ComponentBase>;
class ScreenInteractive : public Screen {
public:
using Callback = std::function<void()>;
static ScreenInteractive FixedSize(int dimx, int dimy);
static ScreenInteractive Fullscreen();
static ScreenInteractive FitComponent();
static ScreenInteractive TerminalOutput();
void Loop(Component);
std::function<void()> ExitLoopClosure();
Callback ExitLoopClosure();
void PostEvent(Event event);
CapturedMouse CaptureMouse();
// Decorate a function. The outputted one will execute similarly to the
// inputted one, but with the currently active screen terminal hooks
// temporarily uninstalled.
Callback WithRestoredIO(Callback);
private:
void Install();
void Uninstall();
void Main(Component component);
ScreenInteractive* suspended_screen_ = nullptr;