diff --git a/joomer-ftxui-file-browser.cpp b/joomer-ftxui-file-browser.cpp index c724167..bb03c18 100644 --- a/joomer-ftxui-file-browser.cpp +++ b/joomer-ftxui-file-browser.cpp @@ -14,8 +14,7 @@ void ReloadDirectory(ftxui::ScreenInteractive& screen, const std::filesystem::pa entries.clear(); clean_names.clear(); - //std::string directory_path = new_path.string; // Replace with your directory path // linux - std::string directory_path = new_path.string(); // Replace with your directory path //windows + //std::string directory_path = new_path.string(); // Replace with your directory path //windows // Check if the path is a valid directory if (!std::filesystem::exists(new_path) || !std::filesystem::is_directory(new_path)) { // Handle error case (optional: display a warning in the TUI) @@ -51,16 +50,22 @@ int main(int argc, char* argv[]) { 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(); if (argc > 1) { //directory_path = argv[1]; // Convert relative input (like "../../..") into a full absolute path - std::filesystem::path directory_path = std::filesystem::absolute(argv[1]).lexically_normal(); - current_path = directory_path.string(); + 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; + //current_path = directory_path.string(); //current_path = directory_path; } - + 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; @@ -68,8 +73,9 @@ int main(int argc, char* argv[]) { } auto screen = ftxui::ScreenInteractive::TerminalOutput(); - ReloadDirectory(screen, directory_path, entries, clean_names); - + 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; int selected = 0; auto menu = ftxui::Menu({ .entries = &entries, @@ -98,6 +104,7 @@ 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; if (!input_buffer.empty()) { // Convert buffer to integer and check bounds int requested_index = std::stoi(input_buffer);// -1; @@ -122,6 +129,7 @@ int main(int argc, char* argv[]) { new_path = std::filesystem::absolute(new_path).lexically_normal(); new_path.make_preferred(); current_path = new_path.string(); + directory_path = current_path; // Update global variable // Call the function to switch and reload ReloadDirectory(screen, new_path, entries,clean_names); @@ -140,7 +148,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({