Tidying up
This commit is contained in:
parent
170fb41568
commit
3678e7608f
68
bb.c
68
bb.c
@ -186,31 +186,30 @@ static void render(bb_state_t *state)
|
|||||||
entry_t **files = state->files;
|
entry_t **files = state->files;
|
||||||
for (int i = state->scroll; i < state->scroll + height - 3 && i < state->nfiles; i++) {
|
for (int i = state->scroll; i < state->scroll + height - 3 && i < state->nfiles; i++) {
|
||||||
entry_t *entry = files[i];
|
entry_t *entry = files[i];
|
||||||
|
struct stat info = {0};
|
||||||
|
lstat(entry->d_fullname, &info);
|
||||||
|
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = i - state->scroll + 2;
|
int y = i - state->scroll + 2;
|
||||||
term_move(x, y);
|
term_move(x, y);
|
||||||
|
|
||||||
// Selection box:
|
{ // Selection box:
|
||||||
if (IS_SELECTED(entry))
|
if (IS_SELECTED(entry))
|
||||||
writez(termfd, "\e[43m \e[0m");
|
writez(termfd, "\e[43m \e[0m");
|
||||||
else
|
else
|
||||||
writez(termfd, " ");
|
writez(termfd, " ");
|
||||||
|
|
||||||
if (i == state->cursor)
|
if (i == state->cursor)
|
||||||
writez(termfd, "\e[30;47m");
|
writez(termfd, "\e[30;47m");
|
||||||
else if (entry->d_isdir && entry->d_type == DT_LNK)
|
else if (entry->d_isdir && entry->d_type == DT_LNK)
|
||||||
writez(termfd, "\e[36m");
|
writez(termfd, "\e[36m");
|
||||||
else if (entry->d_isdir)
|
else if (entry->d_isdir)
|
||||||
writez(termfd, "\e[34m");
|
writez(termfd, "\e[34m");
|
||||||
else if (entry->d_type == DT_LNK)
|
else if (entry->d_type == DT_LNK)
|
||||||
writez(termfd, "\e[33m");
|
writez(termfd, "\e[33m");
|
||||||
|
}
|
||||||
|
|
||||||
struct stat info = {0};
|
{ // Filesize:
|
||||||
lstat(entry->d_fullname, &info);
|
|
||||||
|
|
||||||
{
|
|
||||||
// Filesize:
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
const char* units = "BKMGTPEZY";
|
const char* units = "BKMGTPEZY";
|
||||||
double bytes = (double)info.st_size;
|
double bytes = (double)info.st_size;
|
||||||
@ -223,8 +222,7 @@ static void render(bb_state_t *state)
|
|||||||
writez(termfd, buf);
|
writez(termfd, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{ // Date:
|
||||||
// Date:
|
|
||||||
char buf[64];
|
char buf[64];
|
||||||
strftime(buf, sizeof(buf), "%l:%M%p %b %e %Y", localtime(&(info.st_mtime)));
|
strftime(buf, sizeof(buf), "%l:%M%p %b %e %Y", localtime(&(info.st_mtime)));
|
||||||
writez(termfd, buf);
|
writez(termfd, buf);
|
||||||
@ -232,8 +230,7 @@ static void render(bb_state_t *state)
|
|||||||
writez(termfd, " │ ");
|
writez(termfd, " │ ");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{ // Permissions:
|
||||||
// Permissions:
|
|
||||||
char buf[] = {
|
char buf[] = {
|
||||||
'0' + ((info.st_mode >> 6) & 7),
|
'0' + ((info.st_mode >> 6) & 7),
|
||||||
'0' + ((info.st_mode >> 3) & 7),
|
'0' + ((info.st_mode >> 3) & 7),
|
||||||
@ -243,21 +240,22 @@ static void render(bb_state_t *state)
|
|||||||
writez(termfd, " │ ");
|
writez(termfd, " │ ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name:
|
{ // Name:
|
||||||
write(termfd, entry->d_name, entry->d_namlen);
|
write(termfd, entry->d_name, entry->d_namlen);
|
||||||
if (entry->d_isdir)
|
|
||||||
writez(termfd, "/");
|
|
||||||
|
|
||||||
if (entry->d_type == DT_LNK) {
|
|
||||||
char linkpath[MAX_PATH] = {0};
|
|
||||||
ssize_t pathlen;
|
|
||||||
if ((pathlen = readlink(entry->d_name, linkpath, sizeof(linkpath))) < 0)
|
|
||||||
err("readlink() failed");
|
|
||||||
//writez(termfd, "\e[36m -> "); // Cyan FG
|
|
||||||
writez(termfd, " -> ");
|
|
||||||
write(termfd, linkpath, pathlen);
|
|
||||||
if (entry->d_isdir)
|
if (entry->d_isdir)
|
||||||
writez(termfd, "/");
|
writez(termfd, "/");
|
||||||
|
|
||||||
|
if (entry->d_type == DT_LNK) {
|
||||||
|
char linkpath[MAX_PATH] = {0};
|
||||||
|
ssize_t pathlen;
|
||||||
|
if ((pathlen = readlink(entry->d_name, linkpath, sizeof(linkpath))) < 0)
|
||||||
|
err("readlink() failed");
|
||||||
|
//writez(termfd, "\e[36m -> "); // Cyan FG
|
||||||
|
writez(termfd, " -> ");
|
||||||
|
write(termfd, linkpath, pathlen);
|
||||||
|
if (entry->d_isdir)
|
||||||
|
writez(termfd, "/");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
writez(termfd, " \e[0m"); // Reset color and attributes
|
writez(termfd, " \e[0m"); // Reset color and attributes
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user