Compare commits
No commits in common. "536aa57761229c27d4773c720f97e4a875d0800e" and "e1b0831854b58eea3381e29cee39f3f076ee5d7c" have entirely different histories.
536aa57761
...
e1b0831854
38
sdn.cpp
38
sdn.cpp
@ -318,9 +318,9 @@ fun invert (cchar_t &ch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun apply_attrs (const wstring &w, attr_t attrs) -> ncstring {
|
fun apply_attrs (const wstring &w, attr_t attrs) -> ncstring {
|
||||||
ncstring res (w.size (), cchar_t {});
|
ncstring res;
|
||||||
for (size_t i = 0; i < w.size (); i++)
|
for (auto c : w)
|
||||||
res[i] = cchar (attrs, w[i]);
|
res += cchar (attrs, c);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,8 +557,8 @@ static struct {
|
|||||||
|
|
||||||
// Refreshed by reload():
|
// Refreshed by reload():
|
||||||
|
|
||||||
map<uid_t, wstring> unames; ///< User names by UID
|
map<uid_t, string> unames; ///< User names by UID
|
||||||
map<gid_t, wstring> gnames; ///< Group names by GID
|
map<gid_t, string> gnames; ///< Group names by GID
|
||||||
struct tm now; ///< Current local time for display
|
struct tm now; ///< Current local time for display
|
||||||
} g;
|
} g;
|
||||||
|
|
||||||
@ -638,8 +638,9 @@ fun make_entry (const struct dirent *f) -> entry {
|
|||||||
e.info.st_mode = DTTOIF (f->d_type);
|
e.info.st_mode = DTTOIF (f->d_type);
|
||||||
auto &info = e.info;
|
auto &info = e.info;
|
||||||
|
|
||||||
// io_uring is only at most about 50% faster, though it might help with
|
// TODO: benchmark just readdir() vs. lstat(), also on dead mounts;
|
||||||
// slowly statting devices, at a major complexity cost.
|
// it might make sense to stat asynchronously in threads
|
||||||
|
// http://lkml.iu.edu/hypermail//linux/kernel/0804.3/1616.html
|
||||||
if (lstat (f->d_name, &info)) {
|
if (lstat (f->d_name, &info)) {
|
||||||
e.cols[entry::MODES] = apply_attrs ({ decode_type (info.st_mode),
|
e.cols[entry::MODES] = apply_attrs ({ decode_type (info.st_mode),
|
||||||
L'?', L'?', L'?', L'?', L'?', L'?', L'?', L'?', L'?' }, 0);
|
L'?', L'?', L'?', L'?', L'?', L'?', L'?', L'?', L'?' }, 0);
|
||||||
@ -674,12 +675,12 @@ fun make_entry (const struct dirent *f) -> entry {
|
|||||||
|
|
||||||
auto usr = g.unames.find (info.st_uid);
|
auto usr = g.unames.find (info.st_uid);
|
||||||
e.cols[entry::USER] = (usr != g.unames.end ())
|
e.cols[entry::USER] = (usr != g.unames.end ())
|
||||||
? apply_attrs (usr->second, 0)
|
? apply_attrs (to_wide (usr->second), 0)
|
||||||
: apply_attrs (to_wstring (info.st_uid), 0);
|
: apply_attrs (to_wstring (info.st_uid), 0);
|
||||||
|
|
||||||
auto grp = g.gnames.find (info.st_gid);
|
auto grp = g.gnames.find (info.st_gid);
|
||||||
e.cols[entry::GROUP] = (grp != g.gnames.end ())
|
e.cols[entry::GROUP] = (grp != g.gnames.end ())
|
||||||
? apply_attrs (grp->second, 0)
|
? apply_attrs (to_wide (grp->second), 0)
|
||||||
: apply_attrs (to_wstring (info.st_gid), 0);
|
: apply_attrs (to_wstring (info.st_gid), 0);
|
||||||
|
|
||||||
auto size = to_wstring (info.st_size);
|
auto size = to_wstring (info.st_size);
|
||||||
@ -689,16 +690,16 @@ fun make_entry (const struct dirent *f) -> entry {
|
|||||||
else if (info.st_size >> 10) size = to_wstring (info.st_size >> 10) + L"K";
|
else if (info.st_size >> 10) size = to_wstring (info.st_size >> 10) + L"K";
|
||||||
e.cols[entry::SIZE] = apply_attrs (size, 0);
|
e.cols[entry::SIZE] = apply_attrs (size, 0);
|
||||||
|
|
||||||
wchar_t buf[32] = L"";
|
char buf[32] = "";
|
||||||
auto tm = localtime (&info.st_mtime);
|
auto tm = localtime (&info.st_mtime);
|
||||||
wcsftime (buf, sizeof buf / sizeof *buf,
|
strftime (buf, sizeof buf,
|
||||||
(tm->tm_year == g.now.tm_year) ? L"%b %e %H:%M" : L"%b %e %Y", tm);
|
(tm->tm_year == g.now.tm_year) ? "%b %e %H:%M" : "%b %e %Y", tm);
|
||||||
e.cols[entry::MTIME] = apply_attrs (buf, 0);
|
e.cols[entry::MTIME] = apply_attrs (to_wide (buf), 0);
|
||||||
|
|
||||||
auto &fn = e.cols[entry::FILENAME] =
|
auto &fn = e.cols[entry::FILENAME] =
|
||||||
apply_attrs (to_wide (e.filename), ls_format (e, false));
|
apply_attrs (to_wide (e.filename), ls_format (e, false));
|
||||||
if (!e.target_path.empty ()) {
|
if (!e.target_path.empty ()) {
|
||||||
fn.append (apply_attrs (L" -> ", 0));
|
fn.append (apply_attrs (to_wide (" -> "), 0));
|
||||||
fn.append (apply_attrs (to_wide (e.target_path), ls_format (e, true)));
|
fn.append (apply_attrs (to_wide (e.target_path), ls_format (e, true)));
|
||||||
}
|
}
|
||||||
return e;
|
return e;
|
||||||
@ -784,10 +785,9 @@ fun update () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun operator< (const entry &e1, const entry &e2) -> bool {
|
fun operator< (const entry &e1, const entry &e2) -> bool {
|
||||||
static string dotdot {".."};
|
auto t1 = make_tuple (e1.filename != "..",
|
||||||
auto t1 = make_tuple (e1.filename != dotdot,
|
|
||||||
!S_ISDIR (e1.info.st_mode) && !S_ISDIR (e1.target_info.st_mode));
|
!S_ISDIR (e1.info.st_mode) && !S_ISDIR (e1.target_info.st_mode));
|
||||||
auto t2 = make_tuple (e2.filename != dotdot,
|
auto t2 = make_tuple (e2.filename != "..",
|
||||||
!S_ISDIR (e2.info.st_mode) && !S_ISDIR (e2.target_info.st_mode));
|
!S_ISDIR (e2.info.st_mode) && !S_ISDIR (e2.target_info.st_mode));
|
||||||
if (t1 != t2)
|
if (t1 != t2)
|
||||||
return t1 < t2;
|
return t1 < t2;
|
||||||
@ -836,12 +836,12 @@ fun resort (const string anchor = at_cursor ().filename) {
|
|||||||
fun reload (bool keep_anchor) {
|
fun reload (bool keep_anchor) {
|
||||||
g.unames.clear();
|
g.unames.clear();
|
||||||
while (auto *ent = getpwent ())
|
while (auto *ent = getpwent ())
|
||||||
g.unames.emplace (ent->pw_uid, to_wide (ent->pw_name));
|
g.unames.emplace (ent->pw_uid, ent->pw_name);
|
||||||
endpwent();
|
endpwent();
|
||||||
|
|
||||||
g.gnames.clear();
|
g.gnames.clear();
|
||||||
while (auto *ent = getgrent ())
|
while (auto *ent = getgrent ())
|
||||||
g.gnames.emplace (ent->gr_gid, to_wide (ent->gr_name));
|
g.gnames.emplace (ent->gr_gid, ent->gr_name);
|
||||||
endgrent();
|
endgrent();
|
||||||
|
|
||||||
string anchor;
|
string anchor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user