Various optimizations

This commit is contained in:
Arun Prakash Jana 2017-03-29 19:42:23 +05:30
parent ad0fb1df8c
commit 56dca997b9
No known key found for this signature in database
GPG Key ID: A75979F35C080412
2 changed files with 12 additions and 18 deletions

View File

@ -16,7 +16,7 @@ A fork of the [noice](http://git.2f30.org/noice/) file browser to make it more f
### Introduction ### Introduction
noice is a blazing-fast terminal file browser with easy keyboard shortcuts for navigation, opening files and running tasks. noice is developed with terminal based systems in mind. However, the incredible user-friendliness and speed make it a perfect utility on modern distros. noice is a blazing-fast terminal file browser with easy keyboard shortcuts for navigation, opening files and running tasks. noice is developed with terminal based systems in mind. However, the incredible user-friendliness and speed make it a perfect utility on modern distros. Navigate to `/usr/bin` from your regular file browser and noice to feel the difference.
The only issue with noice is hard-coded file association. There is no config file (better performance and simpler to maintain) and you have to modify the source to change associations (see [how to change file associations](#change-file-associations)). This fork solves the problem by adding the flexibility of using the default desktop opener at runtime. There are several other improvements too (see [fork-toppings](#fork-toppings)). The only issue with noice is hard-coded file association. There is no config file (better performance and simpler to maintain) and you have to modify the source to change associations (see [how to change file associations](#change-file-associations)). This fork solves the problem by adding the flexibility of using the default desktop opener at runtime. There are several other improvements too (see [fork-toppings](#fork-toppings)).

28
noice.c
View File

@ -281,10 +281,8 @@ entrycmp(const void *va, const void *vb)
void void
initcurses(void) initcurses(void)
{ {
char *term;
if (initscr() == NULL) { if (initscr() == NULL) {
term = getenv("TERM"); char *term = getenv("TERM");
if (term != NULL) if (term != NULL)
fprintf(stderr, "error opening terminal: %s\n", term); fprintf(stderr, "error opening terminal: %s\n", term);
else else
@ -399,18 +397,14 @@ char *
mkpath(char *dir, char *name, char *out, size_t n) mkpath(char *dir, char *name, char *out, size_t n)
{ {
/* Handle absolute path */ /* Handle absolute path */
if (name[0] == '/') { if (name[0] == '/')
strlcpy(out, name, n); strlcpy(out, name, n);
} else { else {
/* Handle root case */ /* Handle root case */
if (strcmp(dir, "/") == 0) { if (strcmp(dir, "/") == 0)
strlcpy(out, "/", n); snprintf(out, n, "/%s", name);
strlcat(out, name, n); else
} else { snprintf(out, n, "%s/%s", dir, name);
strlcpy(out, dir, n);
strlcat(out, "/", n);
strlcat(out, name, n);
}
} }
return out; return out;
} }
@ -584,15 +578,15 @@ redraw(char *path)
/* Print listing */ /* Print listing */
odd = ISODD(nlines); odd = ISODD(nlines);
if (cur < nlines / 2) { if (cur < (nlines >> 1)) {
for (i = 0; i < nlines; i++) for (i = 0; i < nlines; i++)
printent(&dents[i], i == cur); printent(&dents[i], i == cur);
} else if (cur >= ndents - nlines / 2) { } else if (cur >= ndents - (nlines >> 1)) {
for (i = ndents - nlines; i < ndents; i++) for (i = ndents - nlines; i < ndents; i++)
printent(&dents[i], i == cur); printent(&dents[i], i == cur);
} else { } else {
for (i = cur - nlines / 2; nlines >>= 1;
i < cur + nlines / 2 + odd; i++) for (i = cur - nlines; i < cur + nlines + odd; i++)
printent(&dents[i], i == cur); printent(&dents[i], i == cur);
} }
} }