sync path vars

This commit is contained in:
Jason Ly 2025-12-21 17:31:06 -05:00
parent 85b7ba00f6
commit 2300a34f5a

View File

@ -14,8 +14,7 @@ void ReloadDirectory(ftxui::ScreenInteractive& screen, const std::filesystem::pa
entries.clear(); entries.clear();
clean_names.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 // Check if the path is a valid directory
if (!std::filesystem::exists(new_path) || !std::filesystem::is_directory(new_path)) { if (!std::filesystem::exists(new_path) || !std::filesystem::is_directory(new_path)) {
// Handle error case (optional: display a warning in the TUI) // Handle error case (optional: display a warning in the TUI)
@ -51,16 +50,22 @@ int main(int argc, char* argv[]) {
std::vector<std::string> entries; std::vector<std::string> entries;
std::vector<std::string> clean_names; // New vector for logic std::vector<std::string> clean_names; // New vector for logic
std::string current_path = std::filesystem::current_path().string(); std::string current_path = std::filesystem::current_path().string();
std::filesystem::path start_path = std::filesystem::current_path();
if (argc > 1) if (argc > 1)
{ {
//directory_path = argv[1]; //directory_path = argv[1];
// Convert relative input (like "../../..") into a full absolute path // Convert relative input (like "../../..") into a full absolute path
std::filesystem::path directory_path = std::filesystem::absolute(argv[1]).lexically_normal(); std::cout << "argv[1]: " << argv[1] << std::endl;
current_path = directory_path.string(); 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; //current_path = directory_path;
} }
std::cout << "Initial current_path after argc: " << current_path << std::endl;
// Check if the directory exists // Check if the directory exists
if (!std::filesystem::exists(directory_path) || !std::filesystem::is_directory(directory_path)) { 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; 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(); 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; int selected = 0;
auto menu = ftxui::Menu({ auto menu = ftxui::Menu({
.entries = &entries, .entries = &entries,
@ -98,6 +104,7 @@ int main(int argc, char* argv[]) {
// Handle the 'Enter' key press // Handle the 'Enter' key press
if (event == ftxui::Event::Return) { if (event == ftxui::Event::Return) {
std::cout << "Enter pressed. Input buffer: " << input_buffer << std::endl;
if (!input_buffer.empty()) { if (!input_buffer.empty()) {
// Convert buffer to integer and check bounds // Convert buffer to integer and check bounds
int requested_index = std::stoi(input_buffer);// -1; 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 = std::filesystem::absolute(new_path).lexically_normal();
new_path.make_preferred(); new_path.make_preferred();
current_path = new_path.string(); current_path = new_path.string();
directory_path = current_path; // Update global variable
// Call the function to switch and reload // Call the function to switch and reload
ReloadDirectory(screen, new_path, entries,clean_names); 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) // so the Menu can handle it (like arrow keys)
return false; return false;
}); });
std::cout << "Initial current_path: " << current_path << std::endl;
// Create a renderer that defines the layout of your application // Create a renderer that defines the layout of your application
auto main_renderer = ftxui::Renderer(menu_with_event_handler, [&] { auto main_renderer = ftxui::Renderer(menu_with_event_handler, [&] {
return ftxui::vbox({ return ftxui::vbox({