Compare commits

..

No commits in common. "136df93fc5f436cfa8e16379b1570b0272b51976" and "1fa2c13e6e61e3a9a0f80c24494deef94b72884a" have entirely different histories.

View File

@ -37,9 +37,6 @@ void ReloadDirectory(ftxui::ScreenInteractive& screen, const std::filesystem::pa
std::string name = entry.path().filename().string(); std::string name = entry.path().filename().string();
if (!name.empty() && name[0] == '.') // Works in C++11, C++14, and C++17 if (!name.empty() && name[0] == '.') // Works in C++11, C++14, and C++17
continue; // Skip hidden files and directories continue; // Skip hidden files and directories
if (std::filesystem::is_directory(entry.path())) {
name += "/"; // Append slash to directories for clarity
}
entries.push_back(std::to_string(i) + ". " + name); entries.push_back(std::to_string(i) + ". " + name);
clean_names.push_back(name); clean_names.push_back(name);
i++; i++;
@ -58,10 +55,12 @@ int main(int argc, char* argv[]) {
if (argc > 1) if (argc > 1)
{ {
//directory_path = argv[1];
// Convert relative input (like "../../..") into a full absolute path // Convert relative input (like "../../..") into a full absolute path
//std::cout << "argv[1]: " << argv[1] << std::endl;
start_path = std::filesystem::absolute(argv[1]); start_path = std::filesystem::absolute(argv[1]);
// Convert to string // Convert to string
start_path = start_path.lexically_normal(); start_path = start_path.lexically_normal();
std::string path_str = start_path.string(); std::string path_str = start_path.string();
// Manually remove trailing slash if it exists and isn't the root directory // Manually remove trailing slash if it exists and isn't the root directory
@ -70,11 +69,17 @@ int main(int argc, char* argv[]) {
} }
current_path = path_str; 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;
} }
//current_path = start_path.string(); // Sync local
//std::cout << "current path: " << current_path << std::endl;
directory_path = current_path; // Update global directory_path = current_path; // Update global
//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;
@ -82,7 +87,9 @@ int main(int argc, char* argv[]) {
} }
auto screen = ftxui::ScreenInteractive::TerminalOutput(); auto screen = ftxui::ScreenInteractive::TerminalOutput();
//std::cout << "Initial current_path before reload: " << current_path << std::endl;
ReloadDirectory(screen, start_path, entries, clean_names); 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 +105,7 @@ int main(int argc, char* argv[]) {
char c = event.character()[0]; char c = event.character()[0];
if (std::isdigit(c)) { if (std::isdigit(c)) {
input_buffer += c; // Add the digit to our "typing" buffer input_buffer += c; // Add the digit to our "typing" buffer
//std::cout << "Typed so far: " << input_buffer << std::endl; // For debugging
return true; return true;
} }
} }
@ -110,6 +118,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()) {
try try
{ {
@ -136,15 +145,13 @@ 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 directory_path = current_path; // Update global variable
if (std::filesystem::is_regular_file(new_path))
screen.Exit(); // Exit the application
// 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);
selected = 0; // Reset selection to the first item selected = 0; // Reset selection to the first item
//screen.Exit(); // Exit the application
return true; // Event handled return true; // Event handled
} }
@ -202,5 +209,13 @@ int main(int argc, char* argv[]) {
} else { } else {
std::cout << "Selection cancelled or no valid entry selected." << std::endl; std::cout << "Selection cancelled or no valid entry selected." << std::endl;
} }
/*Element document = vbox({
text("left") | border,
text("middle") | border | flex,
text("right") | border,
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();*/
} }