Simpler regular listing

This commit is contained in:
Arun Prakash Jana 2017-03-30 02:25:51 +05:30
parent 5c7aaa6d0d
commit 98e3f22cb4
No known key found for this signature in database
GPG key ID: A75979F35C080412
2 changed files with 17 additions and 35 deletions

View file

@ -44,7 +44,7 @@ I chose to fork noice because:
### Fork toppings ### Fork toppings
- Behaviour and navigation - Behaviour and navigation
- Optional detailed view with file type and size (default: disabled) - Optional detail view with file type and size (default: disabled)
- Case-insensitive alphabetic content listing instead of upper case first - Case-insensitive alphabetic content listing instead of upper case first
- Roll over at the first and last entries of a directory (with Up/Down keys) - Roll over at the first and last entries of a directory (with Up/Down keys)
- Sort entries by file size (largest to smallest) - Sort entries by file size (largest to smallest)
@ -98,7 +98,7 @@ Start noice (default: current directory):
| `~` | jump to home dir | | `~` | jump to home dir |
| `/`, `&` | filter dir contents | | `/`, `&` | filter dir contents |
| `c` | show change dir prompt | | `c` | show change dir prompt |
| 'd' | toggle detail view | | `d` | toggle detail view |
| `.` | toggle hide dot files | | `.` | toggle hide dot files |
| `s` | toggle sort by file size | | `s` | toggle sort by file size |
| `t` | toggle sort by modified time | | `t` | toggle sort by modified time |

48
noice.c
View file

@ -420,38 +420,18 @@ mkpath(char *dir, char *name, char *out, size_t n)
void void
printent(struct entry *ent, int active) printent(struct entry *ent, int active)
{ {
char name[PATH_MAX]; if (S_ISDIR(ent->mode))
unsigned int maxlen = COLS - strlen(CURSR) - 1; printw("%s%s/\n", active ? CURSR : EMPTY, ent->name);
char cm = 0; else if (S_ISLNK(ent->mode))
printw("%s%s@\n", active ? CURSR : EMPTY, ent->name);
/* Copy name locally */ else if (S_ISSOCK(ent->mode))
strlcpy(name, ent->name, sizeof(name)); printw("%s%s=\n", active ? CURSR : EMPTY, ent->name);
else if (S_ISFIFO(ent->mode))
if (S_ISDIR(ent->mode)) { printw("%s%s|\n", active ? CURSR : EMPTY, ent->name);
cm = '/'; else if (ent->mode & S_IXUSR)
maxlen--; printw("%s%s*\n", active ? CURSR : EMPTY, ent->name);
} else if (S_ISLNK(ent->mode)) {
cm = '@';
maxlen--;
} else if (S_ISSOCK(ent->mode)) {
cm = '=';
maxlen--;
} else if (S_ISFIFO(ent->mode)) {
cm = '|';
maxlen--;
} else if (ent->mode & S_IXUSR) {
cm = '*';
maxlen--;
}
/* No text wrapping in entries */
if (strlen(name) > maxlen)
name[maxlen] = '\0';
if (cm == 0)
printw("%s%s\n", active ? CURSR : EMPTY, name);
else else
printw("%s%s%c\n", active ? CURSR : EMPTY, name, cm); printw("%s%s\n", active ? CURSR : EMPTY, ent->name);
} }
char* char*
@ -485,9 +465,11 @@ printent_long(struct entry *ent, int active)
else if (S_ISCHR(ent->mode)) else if (S_ISCHR(ent->mode))
printw("%s%-32.32s C\n", active ? CURSR : EMPTY, ent->name); printw("%s%-32.32s C\n", active ? CURSR : EMPTY, ent->name);
else if (ent->mode & S_IXUSR) else if (ent->mode & S_IXUSR)
printw("%s%-32.32s E %s\n", active ? CURSR : EMPTY, ent->name, coolsize(ent->size)); printw("%s%-32.32s E %s\n", active ? CURSR : EMPTY, ent->name,
coolsize(ent->size));
else else
printw("%s%-32.32s R %s\n", active ? CURSR : EMPTY, ent->name, coolsize(ent->size)); printw("%s%-32.32s R %s\n", active ? CURSR : EMPTY, ent->name,
coolsize(ent->size));
} }
int int