diff --git a/src/screen.cc b/src/screen.cc index 5d1bf4a..2907608 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -56,6 +56,10 @@ void ScreenStack::pop_screen() { actions.push_back(PendingAction(Action::POP_SCREEN)); } +void ScreenStack::clear_screens() { + actions.push_back(PendingAction(Action::CLEAR_SCREENS)); +} + ScreenStack::ScreenStack() : self_weak(), stack(), actions() {} void ScreenStack::handle_pending_actions() { @@ -74,6 +78,14 @@ void ScreenStack::handle_pending_actions() { } #endif // NDEBUG break; + case Action::CLEAR_SCREENS: +#ifndef NDEBUG + if (stack.empty()) { + std::cerr << "WARNING: Clearing an empty screen stack!\n"; + } +#endif + stack.clear(); + break; case Action::NOP: // Intentionally left blank. break; diff --git a/src/screen.h b/src/screen.h index fb11512..f9f9e7b 100644 --- a/src/screen.h +++ b/src/screen.h @@ -37,7 +37,7 @@ class Screen { class ScreenStack { private: - enum Action { PUSH_SCREEN, POP_SCREEN, NOP }; + enum Action { PUSH_SCREEN, POP_SCREEN, CLEAR_SCREENS, NOP }; struct PendingAction { PendingAction(); @@ -80,6 +80,8 @@ class ScreenStack { void pop_screen(); + void clear_screens(); + private: ScreenStack();