From a254e36632d3b16d1441f7467a843fe7ad42b3f9 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 4 Mar 2022 20:23:31 +0800 Subject: [PATCH] component/catch_event: improve the example for CatchEvent() (#351) before this change, the example in the doxygen document for CatchEvent() does not use the documented function. hence the example is not that useful for developers interested in a typical usage of this function. after this change, the example is improved to added the call to CatchEvent(), which allows the application to the Loop() function at user input. Signed-off-by: Kefu Chai --- src/ftxui/component/catch_event.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ftxui/component/catch_event.cpp b/src/ftxui/component/catch_event.cpp index aec519d..fc51a1d 100644 --- a/src/ftxui/component/catch_event.cpp +++ b/src/ftxui/component/catch_event.cpp @@ -39,7 +39,14 @@ class CatchEventBase : public ComponentBase { /// auto renderer = Renderer([] { /// return text("My interface"); /// }); -/// screen.Loop(renderer); +/// auto component = CatchEvent(renderer, [&](Event event) { +/// if (event == Event::Character('q')) { +/// screen.ExitLoopClosure()(); +/// return true; +/// } +/// return false; +/// }); +/// screen.Loop(component); /// ``` Component CatchEvent(Component child, std::function on_event) {