From 1fa2c13e6e61e3a9a0f80c24494deef94b72884a Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 22 Dec 2025 02:01:31 +0000 Subject: [PATCH] remove slash at the end for path to work in linux --- joomer-ftxui-file-browser.cpp | 50 ++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/joomer-ftxui-file-browser.cpp b/joomer-ftxui-file-browser.cpp index bb03c18..9e609f2 100644 --- a/joomer-ftxui-file-browser.cpp +++ b/joomer-ftxui-file-browser.cpp @@ -49,6 +49,7 @@ int main(int argc, char* argv[]) { int final_selected_index = -1; // Use -1 to indicate no selection was made std::vector entries; std::vector clean_names; // New vector for logic + std::string current_path = std::filesystem::current_path().string(); std::filesystem::path start_path = std::filesystem::current_path(); @@ -56,16 +57,29 @@ int main(int argc, char* argv[]) { { //directory_path = argv[1]; // Convert relative input (like "../../..") into a full absolute path - std::cout << "argv[1]: " << argv[1] << std::endl; - start_path = std::filesystem::absolute(argv[1]).lexically_normal(); - directory_path = start_path.string(); // Update global - std::cout << "directory_path: " << directory_path << std::endl; - current_path = directory_path; // Sync local - std::cout << "current_path: " << current_path << std::endl; + //std::cout << "argv[1]: " << argv[1] << std::endl; + start_path = std::filesystem::absolute(argv[1]); + // Convert to string + + 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() == '\\')) { + path_str.pop_back(); + } + + current_path = path_str; + //std::cout << "directory_path: " << directory_path << std::endl; + + //std::cout << "current_path: " << current_path << std::endl; //current_path = directory_path.string(); //current_path = directory_path; } - std::cout << "Initial current_path after argc: " << current_path << std::endl; + + //current_path = start_path.string(); // Sync local + //std::cout << "current path: " << current_path << std::endl; + directory_path = current_path; // Update global + //std::cout << "Initial current_path after argc: " << current_path << std::endl; // Check if the directory exists if (!std::filesystem::exists(directory_path) || !std::filesystem::is_directory(directory_path)) { std::cerr << "Error: Directory '" << directory_path << "' not found or is not a directory." << std::endl; @@ -73,9 +87,9 @@ int main(int argc, char* argv[]) { } auto screen = ftxui::ScreenInteractive::TerminalOutput(); - std::cout << "Initial current_path before reload: " << current_path << std::endl; + //std::cout << "Initial current_path before reload: " << current_path << std::endl; ReloadDirectory(screen, start_path, entries, clean_names); - std::cout << "Initial current_path after reload: " << current_path << std::endl; + //std::cout << "Initial current_path after reload: " << current_path << std::endl; int selected = 0; auto menu = ftxui::Menu({ .entries = &entries, @@ -104,13 +118,16 @@ int main(int argc, char* argv[]) { // Handle the 'Enter' key press if (event == ftxui::Event::Return) { - std::cout << "Enter pressed. Input buffer: " << input_buffer << std::endl; + //std::cout << "Enter pressed. Input buffer: " << input_buffer << std::endl; if (!input_buffer.empty()) { - // Convert buffer to integer and check bounds - int requested_index = std::stoi(input_buffer);// -1; - if (requested_index >= 0 && requested_index < (int)clean_names.size()) { - selected = requested_index; // Move the highlight to the typed index - } + try + { + // Convert buffer to integer and check bounds + int requested_index = std::stoi(input_buffer);// -1; + if (requested_index >= 0 && requested_index < (int)clean_names.size()) { + selected = requested_index; // Move the highlight to the typed index + } + } catch (...) {} input_buffer.clear(); // Clear buffer after use } std::string selected_name; @@ -181,7 +198,8 @@ int main(int argc, char* argv[]) { }); screen.Loop(main_renderer); - + // This will print to your terminal AFTER you press 'q' to quit + std::cout << "Final Path on Exit: " << current_path << std::endl; // ---------------------------------------------------- // --- OUTPUT AFTER THE LOOP HAS CLEANLY EXITED --- // ----------------------------------------------------