Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions src/file_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
#include <sys/stat.h>
#include <pwd.h>
#include <grp.h>
#ifndef __APPLE__
#include <sys/inotify.h>
#endif
#include <poll.h>
#include <cerrno>

Expand Down Expand Up @@ -1439,6 +1441,7 @@ class FileManager {

// --- Auto-Update (Inotify) Functions ---
void initInotify() {
#ifndef __APPLE__
inotifyFd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
if (inotifyFd < 0) {
inotifyFd = inotify_init();
Expand All @@ -1447,9 +1450,11 @@ class FileManager {
stopInotify = false;
inotifyThread = std::thread(&FileManager::inotifyWorker, this);
}
#endif
}

void inotifyWorker() {
#ifndef __APPLE__
struct pollfd pfd;
pfd.fd = inotifyFd;
pfd.events = POLLIN;
Expand Down Expand Up @@ -1503,9 +1508,11 @@ class FileManager {
}
}
}
#endif
}

void updateInotifyWatches() {
#ifndef __APPLE__
if (inotifyFd < 0) return;

std::lock_guard<std::mutex> lock(inotifyMutex);
Expand Down Expand Up @@ -1562,6 +1569,7 @@ class FileManager {
}
} catch (...) {}
}
#endif
}

// --- Async Size Worker Function ---
Expand Down Expand Up @@ -4368,6 +4376,15 @@ class FileManager {

int maxLines = getmaxy(win) - 2;
if (paneFiles.empty()) {
if (!paneIsSearching) {
int my = getmaxy(win);
int mx = getmaxx(win);
std::string emptyMsg = "󰉖 This directory is empty";
size_t len = utf8_length(emptyMsg);
wattron(win, COLOR_PAIR(7) | A_BOLD);
mvwprintw(win, my / 2, (mx - (int)len) / 2, "%s", emptyMsg.c_str());
wattroff(win, COLOR_PAIR(7) | A_BOLD);
}
wnoutrefresh(win);
return;
}
Expand Down Expand Up @@ -5894,11 +5911,13 @@ class FileManager {
wattron(winPreview, COLOR_PAIR(1) | A_BOLD);
mvwprintw(winPreview, contentStart, 2, "󰉖 Content:");
wattroff(winPreview, COLOR_PAIR(1) | A_BOLD);
int line = contentStart + 1;
try {
int line = contentStart + 1;
bool hasVisibleContent = false;
for (const auto& entry : fs::directory_iterator(file.path)) {
if (!showHidden && entry.path().filename().string().front() == '.')
continue;
hasVisibleContent = true;
if (line >= height - 3)
break;
std::string subName = entry.path().filename().string();
Expand Down Expand Up @@ -5942,7 +5961,15 @@ class FileManager {
mvwprintw(winPreview, line++, 4, "%s %s", s.icon, subName.c_str());
wattroff(winPreview, COLOR_PAIR(s.pair));
}
if (!hasVisibleContent) {
wattron(winPreview, COLOR_PAIR(7) | A_BOLD);
mvwprintw(winPreview, line, 4, "󰉖 This directory is empty");
wattroff(winPreview, COLOR_PAIR(7) | A_BOLD);
}
} catch (...) {
wattron(winPreview, COLOR_PAIR(7) | A_BOLD);
mvwprintw(winPreview, line, 4, "󰉖 This directory is empty");
wattroff(winPreview, COLOR_PAIR(7) | A_BOLD);
}
wnoutrefresh(winPreview);
} else if (isDoc || isXls || isPpt) {
Expand Down Expand Up @@ -6315,16 +6342,32 @@ class FileManager {
attroff(COLOR_PAIR(9) | A_BOLD);
}

// Compute directory statistics
size_t numFolders = 0;
size_t numFiles = 0;
for (const auto& f : currentFiles) {
if (f.is_directory) {
numFolders++;
} else {
numFiles++;
}
}
std::string statsStr = " 📁 " + std::to_string(numFolders) + " folders | 📄 " + std::to_string(numFiles) + " files";

attron(A_DIM);
std::string pathStr = isTrashMode ? "trash://" : currentPath.string();
int maxPathW = width - 35;
if (maxPathW < 10) maxPathW = 10;
int maxPathW = width - 35 - (int)utf8_length(statsStr);
if (maxPathW < 15) maxPathW = 15;
if ((int)pathStr.length() > maxPathW) {
pathStr = utf8_safe_truncate_left(pathStr, maxPathW - 3);
}
printw(" %s", pathStr.c_str());
attroff(A_DIM);

attron(COLOR_PAIR(6));
printw("%s", statsStr.c_str());
attroff(COLOR_PAIR(6));

if (!isTrashMode) {
try {
fs::space_info si = fs::space(currentPath);
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ int main(int argc, char* argv[]) {
if (arg == "-v" || arg == "--version") {
std::cout << "Fyzenor version " << VERSION << std::endl;
return 0;
} else if (arg == "-a" || arg == "--about") {
std::cout << "Fyzenor - The Blazing Fast, Modern C++ Terminal File Manager Version: " << VERSION << std::endl;
return 0;
} else if (arg == "-h" || arg == "--help") {
std::cout << "Fyzenor - The Blazing Fast, Modern C++ Terminal File Manager" << std::endl;
std::cout << "Usage: fyzenor [options]" << std::endl;
std::cout << "Options:" << std::endl;
std::cout << " -v, --version Show version information" << std::endl;
std::cout << " -a, --about Show about information" << std::endl;
std::cout << " -h, --help Show this help message" << std::endl;
return 0;
}
Expand Down
Loading