Introduction
Introduction Statistics Contact Development Disclaimer Help
filter/indent: add color swap via nich swap - lchat - A line oriented chat fron…
git clone git://git.suckless.org/lchat
Log
Files
Refs
README
---
commit eaaf97e1cfa06ef15e4e8a3dbf03b7efd443c8cd
parent b6a559806b16ec704b2bb2cc304aff99a9a96434
Author: Jan Klemkow <[email protected]>
Date: Wed, 22 Feb 2017 17:42:03 +0100
filter/indent: add color swap via nich swap
Diffstat:
M filter/indent.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/filter/indent.c b/filter/indent.c
@@ -6,6 +6,9 @@
#include <time.h>
#include <unistd.h>
+#define color1 34
+#define color2 36
+
int
main(void)
{
@@ -16,6 +19,7 @@ main(void)
char *next, *nick, *word;
struct tm tm;
int cols = 80; /* terminal width */
+ int color = color1;
while (fgets(buf, sizeof buf, stdin) != NULL) {
next = strptime(buf, "%Y-%m-%d %H:%M ", &tm);
@@ -32,9 +36,13 @@ main(void)
strftime(timestr, sizeof timestr, fmt, &tm);
+ /* swap color */
+ if (strcmp(nick, old_nick) != 0)
+ color = color == color1 ? color2 : color1;
+
/* print prompt */
/* HH:MM nnnnnnnnnnnn ttttttttttttt */
- printf("%s %*s", timestr, 12,
+ printf("\033[%dm%s %*s", color, timestr, 12,
strcmp(nick, old_nick) == 0 ? "" : nick);
strlcpy(old_nick, nick, sizeof old_nick);
@@ -56,7 +64,7 @@ main(void)
fputs(word, stdout);
first = false;
}
-
+ fputs("\033[0m", stdout); /* turn color off */
fflush(stdout);
}
You are viewing proxied material from suckless.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.