CleanTrailingSlash() after selecting a folder
This commit is contained in:
parent
136df93fc5
commit
212a1882cf
@ -7,6 +7,15 @@
|
|||||||
|
|
||||||
std::string directory_path = ".";
|
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.
|
// Note: You must pass the ScreenInteractive object to trigger a redraw.
|
||||||
void ReloadDirectory(ftxui::ScreenInteractive& screen, const std::filesystem::path& new_path, std::vector<std::string>& entries, std::vector<std::string>& clean_names) {
|
void ReloadDirectory(ftxui::ScreenInteractive& screen, const std::filesystem::path& new_path, std::vector<std::string>& entries, std::vector<std::string>& clean_names) {
|
||||||
if (!std::filesystem::exists(new_path) || !std::filesystem::is_directory(new_path)) return;
|
if (!std::filesystem::exists(new_path) || !std::filesystem::is_directory(new_path)) return;
|
||||||
@ -135,9 +144,12 @@ 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();
|
||||||
|
|
||||||
|
CleanTrailingSlash(current_path);
|
||||||
directory_path = current_path; // Update global variable
|
directory_path = current_path; // Update global variable
|
||||||
if (std::filesystem::is_regular_file(new_path))
|
if (std::filesystem::is_regular_file(new_path))
|
||||||
screen.Exit(); // Exit the application
|
screen.Exit(); // Exit the application
|
||||||
@ -158,7 +170,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({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user