@@ -13,9 +13,6 @@ import CppUtils.Terminal.Area;
1313import CppUtils.Terminal.TextStyle;
1414import CppUtils.Terminal.TextColor;
1515import CppUtils.Terminal.BackgroundColor;
16- import CppUtils.Execution.Event;
17- import CppUtils.Thread.Scheduler;
18- import CppUtils.Execution.EventSystem;
1916
2017export namespace CppUtils::Terminal
2118{
@@ -107,6 +104,10 @@ export namespace CppUtils::Terminal
107104 Area{size, optionalViewport.value_or(Viewport{size, {0, 0}})},
108105 m_previousBuffer{size}
109106 {
107+ m_widgetManager.eventDispatcher.subscribe<"RequestUpdate">([this](std::nullptr_t) -> void {
108+ print();
109+ });
110+ setWidgetManager(m_widgetManager);
110111 setConsoleOutputUTF8();
111112 enableAnsi();
112113 }
@@ -175,37 +176,31 @@ export namespace CppUtils::Terminal
175176 auto view = WritableAreaView{*this, m_viewport};
176177 m_widget->draw(view);
177178 }
178- if (m_forceReprint )
179+ if (m_firstPrint )
179180 {
180181 std::print("{}", std::string(m_viewport.getSize().height(), '\n'));
181- m_forceReprint = false;
182+ m_firstPrint = false;
182183 }
183184 applyDifferences();
184185 }
185186
186- inline auto reprint() noexcept -> void
187- {
188- m_forceReprint = true;
189- print();
190- }
191-
192187 inline auto wait() noexcept -> void
193188 {
194189 print();
195- m_stopEvent.wait();
190+ m_stopEvent.wait(false );
196191 }
197192
198193 inline auto close() noexcept -> void
199194 {
200- m_stopEvent.notify();
195+ m_stopEvent.store(true, std::memory_order_release);
196+ m_stopEvent.notify_all();
201197 }
202198
203199 private:
204- bool m_forceReprint = true;
200+ bool m_firstPrint = true;
201+ std::atomic_bool m_stopEvent = false;
205202 AreaBuffer m_previousBuffer;
206- Execution::Event m_stopEvent;
207- Thread::Scheduler m_scheduler;
208- Execution::EventSystem m_eventSystem;
203+ WidgetManager m_widgetManager;
209204 };
210205 }
211206}
0 commit comments