ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.73k stars 401 forks source link

Screen.ExitLoopClosure() | Not exiting the program. #783

Closed J0sephDavis closed 9 months ago

J0sephDavis commented 9 months ago

Expected Behavior:

Call screen.ExitLoopClosure() within a component (or component decorator) constructed by CatchEvent(...). Application exits.

Experienced Beahavior:

Nothing.

Workaround:

Replace screen.ExitLoopClosure() with screen.Exit().

Code similar to the FTXUI Main Page, section: Catch Event

#include <ftxui/component/screen_interactive.hpp>
#include <ftxui/component/component.hpp> //for CatchEvent()
using namespace ftxui;
int main(void) {
    auto screen = ScreenInteractive::TerminalOutput();
    auto renderer = Renderer([] {
        return text("TESTING");
    });
    auto comp = CatchEvent(renderer, [&](Event event) {
        if (event == Event::Character('q')) {
            screen.ExitLoopClosure();
            return true;
        }
        return false;
    });
    screen.Loop(comp);
    return EXIT_SUCCESS;    
};

The Cmake used

cmake_minimum_required (VERSION 3.11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 
# --- Fetch FTXUI --------------------------------------------------------------
include(FetchContent)
set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
set(FETCHCONTENT_QUIET FALSE)

FetchContent_Declare(ftxui
    GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
    GIT_TAG v5.0.0 #bfadcb71658e8622211591d69616eeb9a3bfc90e 
    GIT_PROGRESS TRUE
    GIT_SHALLOW FALSE 
)

FetchContent_GetProperties(ftxui)
if(NOT ftxui_POPULATED)
    FetchContent_Populate(ftxui)
    add_subdirectory(
        ${ftxui_SOURCE_DIR}
        ${ftxui_BINARY_DIR}
        EXCLUDE_FROM_ALL
    )
endif()

# --- Build --------------------------------------------------------------------
project(ftxuiFileViewer
  LANGUAGES CXX
  VERSION 1.0.0
)
add_executable(ftxuiFileViewer 
    src/main.cc
)

target_include_directories(ftxuiFileViewer PRIVATE src)
target_link_libraries(ftxuiFileViewer
    PRIVATE ftxui::screen
    PRIVATE ftxui::dom
    PRIVATE ftxui::component
)
set_target_properties(ftxuiFileViewer PROPERTIES CXX_STANDARD 20)
ArthurSonzogni commented 9 months ago

Thanks! Very nicely formatted bug report.

See the functions:

  // Start/Stop the main loop.
  void Loop(Component);
  void Exit();
  Closure ExitLoopClosure();

ExitLoopClosure() return a closure. If you don't call it, you get nothing. You should use screen.ExitLoopClosure()() or directly screen.Exit().