Introduction
Introduction Statistics Contact Development Disclaimer Help
Add colors - noice - small file browser (mirror / fork from 2f30.org)
git clone git://git.codemadness.org/noice
Log
Files
Refs
README
LICENSE
---
commit 383abc8aa9265f3a81142973106dcaeaded63e85
parent ffd423c6175d8c219ae4a6d939670e81845c68fc
Author: dok <[email protected]>
Date: Sun, 6 Jan 2019 14:10:16 +0100
Add colors
Diffstat:
M config.def.h | 18 ++++++++++++++++++
M noice.c | 51 +++++++++++++++++++++++------…
2 files changed, 56 insertions(+), 13 deletions(-)
---
diff --git a/config.def.h b/config.def.h
@@ -8,6 +8,24 @@ int idletimeout = 0; /* Screensaver timeout in seconds, 0 to d…
int showhidden = 0; /* Set to 1 to show hidden files by default */
char *idlecmd = "rain"; /* The screensaver program */
+#define CURSR_ATTR A_REVERSE
+#define DIR_ATTR A_BOLD | COLOR_PAIR(4)
+#define LINK_ATTR A_BOLD | COLOR_PAIR(6)
+#define SOCK_ATTR A_BOLD | COLOR_PAIR(1)
+#define FIFO_ATTR A_BOLD | COLOR_PAIR(5)
+#define EXEC_ATTR A_BOLD | COLOR_PAIR(2)
+
+struct cpair pairs[] = {
+ { .fg = 0, .bg = 0 },
+ /* pairs start at 1 */
+ { COLOR_RED, 0 },
+ { COLOR_GREEN, 0 },
+ { COLOR_YELLOW, 0 },
+ { COLOR_BLUE, 0 },
+ { COLOR_MAGENTA, 0 },
+ { COLOR_CYAN, 0 },
+};
+
struct assoc assocs[] = {
{ "\\.(avi|mp4|mkv|mp3|ogg|flac|mov)$", "mpv" },
{ "\\.(png|jpg|gif)$", "sxiv" },
diff --git a/noice.c b/noice.c
@@ -45,6 +45,11 @@ struct assoc {
char *bin; /* Program */
};
+struct cpair {
+ int fg;
+ int bg;
+};
+
/* Supported actions */
enum action {
SEL_QUIT = 1,
@@ -270,6 +275,16 @@ entrycmp(const void *va, const void *vb)
}
void
+initcolor(void)
+{
+ int i;
+
+ start_color();
+ for (i = 1; i < LEN(pairs); i++)
+ init_pair(i, pairs[i].fg, pairs[i].bg);
+}
+
+void
initcurses(void)
{
char *term;
@@ -282,6 +297,8 @@ initcurses(void)
fprintf(stderr, "failed to initialize curses\n");
exit(1);
}
+ if (has_colors())
+ initcolor();
cbreak();
noecho();
nonl();
@@ -420,37 +437,45 @@ void
printent(struct entry *ent, int active)
{
char name[PATH_MAX];
- unsigned int maxlen = COLS - strlen(CURSR) - 1;
+ unsigned int len = COLS - strlen(CURSR) - 1;
char cm = 0;
+ int attr = 0;
/* Copy name locally */
strlcpy(name, ent->name, sizeof(name));
+ /* No text wrapping in entries */
+ if (strlen(name) < len)
+ len = strlen(name) + 1;
+
if (S_ISDIR(ent->mode)) {
cm = '/';
- maxlen--;
+ attr |= DIR_ATTR;
} else if (S_ISLNK(ent->mode)) {
cm = '@';
- maxlen--;
+ attr |= LINK_ATTR;
} else if (S_ISSOCK(ent->mode)) {
cm = '=';
- maxlen--;
+ attr |= SOCK_ATTR;
} else if (S_ISFIFO(ent->mode)) {
cm = '|';
- maxlen--;
+ attr |= FIFO_ATTR;
} else if (ent->mode & S_IXUSR) {
cm = '*';
- maxlen--;
+ attr |= EXEC_ATTR;
}
- /* No text wrapping in entries */
- if (strlen(name) > maxlen)
- name[maxlen] = '\0';
+ if (active)
+ attr |= CURSR_ATTR;
- if (cm == 0)
- printw("%s%s\n", active ? CURSR : EMPTY, name);
- else
- printw("%s%s%c\n", active ? CURSR : EMPTY, name, cm);
+ if (cm) {
+ name[len-1] = cm;
+ name[len] = '\0';
+ }
+
+ attron(attr);
+ printw("%s%s\n", active ? CURSR : EMPTY, name);
+ attroff(attr);
}
int
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.