summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2009-09-19 14:24:38 +0000
committerDimitri Sokolyuk <demon@dim13.org>2009-09-19 14:24:38 +0000
commit11ce711234046559decc9270aee8eb638a9e5cec (patch)
tree09bb4c522d88c5e31d41a3f3008c912e1e23b4e1
parent0d9838b7712b9f2a8732f2989f9af05926533319 (diff)
add xclock-like colors
-rw-r--r--aclock.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/aclock.c b/aclock.c
index c91a71c..7065025 100644
--- a/aclock.c
+++ b/aclock.c
@@ -19,6 +19,7 @@
int die = 0;
int redraw = 0;
+enum {RED = 1, CYAN, BLUE};
void
catch(int sig)
@@ -51,13 +52,19 @@ void
draw_circle(int hand_max, int sYcen, int sXcen, int FontHW)
{
int x, y, r;
- char c;
for (r = 0; r < 60; r++) {
x = cos(r * M_PI / 180 * 6) * hand_max * FontHW + sXcen;
y = sin(r * M_PI / 180 * 6) * hand_max + sYcen;
- c = ".o"[!(r%5)];
- mvaddch(y, x, c);
+ if (r % 5) {
+ attron(COLOR_PAIR(CYAN));
+ mvaddch(y, x, '.');
+ attroff(COLOR_PAIR(CYAN));
+ } else {
+ attron(COLOR_PAIR(RED));
+ mvaddch(y, x, 'o');
+ attroff(COLOR_PAIR(RED));
+ }
}
}
@@ -87,6 +94,7 @@ main(void)
struct tm *ltime;
struct winsize ws;
struct timeval tv;
+ int hascolors;
signal(SIGWINCH, catch);
@@ -94,7 +102,14 @@ main(void)
signal(SIGINT, catch);
initscr();
curs_set(0);
-
+ if ((hascolors = has_colors()))
+ start_color();
+ init_pair(RED, COLOR_RED, COLOR_BLACK);
+ init_pair(CYAN, COLOR_CYAN, COLOR_BLACK);
+ init_pair(BLUE, COLOR_BLUE, COLOR_BLACK);
+
+ if (hascolors)
+ attron(A_BOLD);
while (!die) {
gettimeofday(&tv, NULL);
settimer(0, 1000000 - tv.tv_usec);
@@ -123,18 +138,30 @@ main(void)
erase();
draw_circle(hand_max, sYcen, sXcen, FontHW);
+ attron(COLOR_PAIR(RED));
draw_hand((ltime->tm_hour * 5) + (ltime->tm_min / 10),
2 * hand_max / 3, '#', sXcen, sYcen, FontHW);
+ attroff(COLOR_PAIR(RED));
+ attron(COLOR_PAIR(CYAN));
draw_hand(ltime->tm_min, hand_max - 2, '*', sXcen, sYcen, FontHW);
+ attroff(COLOR_PAIR(CYAN));
+ attron(COLOR_PAIR(BLUE));
draw_hand(ltime->tm_sec, hand_max - 1, '.', sXcen, sYcen, FontHW);
+ attroff(COLOR_PAIR(BLUE));
+ attron(COLOR_PAIR(CYAN));
mvaddstr(sYmax / 4, sXcen - 5, ".:ACLOCK:.");
mvprintw(4 * sYmax / 5, sXcen - 5, "[%02d:%02d:%02d]",
ltime->tm_hour, ltime->tm_min, ltime->tm_sec);
+ mvprintw(4 * sYmax / 3, sXcen - 5, "[%02d.%02d.%02d]",
+ ltime->tm_mday, ltime->tm_mon, ltime->tm_year);
+ attroff(COLOR_PAIR(CYAN));
refresh();
pause();
}
+ if (hascolors)
+ attroff(A_BOLD);
curs_set(1);
endwin();