From 212a1882cfb9bd26657189be4c21b1d7f45ddcd9 Mon Sep 17 00:00:00 2001 From: Jason Ly Date: Mon, 22 Dec 2025 20:02:36 -0500 Subject: [PATCH] CleanTrailingSlash() after selecting a folder --- joomer-ftxui-file-browser.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/joomer-ftxui-file-browser.cpp b/joomer-ftxui-file-browser.cpp index aa25dd2..8e8b302 100644 --- a/joomer-ftxui-file-browser.cpp +++ b/joomer-ftxui-file-browser.cpp @@ -7,6 +7,15 @@ std::string directory_path = "."; +void CleanTrailingSlash(std::string& path) { + // Only strip if it's longer than a root path (e.g., "/" or "C:\") +#if defined(_WIN32) + if (path.size() > 3 && (path.back() == '/' || path.back() == '\\')) path.pop_back(); +#else + if (path.size() > 1 && path.back() == '/') path.pop_back(); +#endif +} + // Note: You must pass the ScreenInteractive object to trigger a redraw. void ReloadDirectory(ftxui::ScreenInteractive& screen, const std::filesystem::path& new_path, std::vector& entries, std::vector& clean_names) { if (!std::filesystem::exists(new_path) || !std::filesystem::is_directory(new_path)) return; @@ -62,7 +71,7 @@ int main(int argc, char* argv[]) { start_path = std::filesystem::absolute(argv[1]); // Convert to string - start_path = start_path.lexically_normal(); + start_path = start_path.lexically_normal(); std::string path_str = start_path.string(); // Manually remove trailing slash if it exists and isn't the root directory if (path_str.size() > 1 && (path_str.back() == '/' || path_str.back() == '\\')) { @@ -135,9 +144,12 @@ int main(int argc, char* argv[]) { } new_path = std::filesystem::absolute(new_path).lexically_normal(); + new_path.make_preferred(); current_path = new_path.string(); + + CleanTrailingSlash(current_path); directory_path = current_path; // Update global variable if (std::filesystem::is_regular_file(new_path)) screen.Exit(); // Exit the application @@ -158,7 +170,7 @@ int main(int argc, char* argv[]) { // so the Menu can handle it (like arrow keys) return false; }); - std::cout << "Initial current_path: " << current_path << std::endl; + // Create a renderer that defines the layout of your application auto main_renderer = ftxui::Renderer(menu_with_event_handler, [&] { return ftxui::vbox({