diff --git a/README b/README index 2a37ae5..262d7de 100644 --- a/README +++ b/README @@ -18,3 +18,8 @@ usage : tty-clock [-iuvsScbtrahDBxn] [-C [0-7]] [-f format] [-d delay] [-a nsdel -B Enable blinking colon -d delay Set the delay between two redraws of the clock. Default 1s. -a nsdelay Additional delay between two redraws in nanoseconds. Default 0ns. + -p [1-9] Position of clock in terminal: 1-9 starting top-left and ending bottom-right: + + 123 + 456 + 789 diff --git a/ttyclock.c b/ttyclock.c index bc2326f..74bb28d 100644 --- a/ttyclock.c +++ b/ttyclock.c @@ -124,7 +124,11 @@ init(void) } clearok(ttyclock->datewin, True); - set_center(ttyclock->option.center); + if (ttyclock->option.center) + set_center(ttyclock->option.center); + else + if (ttyclock->option.position) + set_position(ttyclock->option.position); nodelay(stdscr, True); @@ -375,7 +379,10 @@ set_second(void) clock_move(ttyclock->geo.x, (ttyclock->geo.y - y_adj), new_w, ttyclock->geo.h); - set_center(ttyclock->option.center); + if (ttyclock->option.center) + set_center(ttyclock->option.center); + else + if (ttyclock->option.position) return; } @@ -396,6 +403,34 @@ set_center(Bool b) return; } +void +set_position(int p) +{ + int LINE, COL; + + ttyclock->option.rebound = False; + + if (p >= 1 && p <= 3) + LINE = 0; + if (p >= 4 && p <= 6) + LINE = (LINES / 2) - (ttyclock->geo.h / 2); + if (p >= 7 && p <= 9) + LINE = LINES - ttyclock->geo.h - 2; + + if (p == 1 || p == 4 || p == 7) + COL = 0; + if (p == 2 || p == 5 || p == 8) + COL = (COLS / 2) - (ttyclock->geo.w / 2); + if (p == 3 || p == 6 || p == 9) + COL = COLS - ttyclock->geo.w; + + clock_move(LINE, + COL, + ttyclock->geo.w, + ttyclock->geo.h); + +} + void set_box(Bool b) { @@ -563,13 +598,13 @@ main(int argc, char **argv) atexit(cleanup); - while ((c = getopt(argc, argv, "iuvsScbtrhBxnDC:f:d:T:a:")) != -1) + while ((c = getopt(argc, argv, "iuvsScbtrhBxnDC:f:d:T:a:p:")) != -1) { switch(c) { case 'h': default: - printf("usage : tty-clock [-iuvsScbtrahDBxn] [-C [0-7]] [-f format] [-d delay] [-a nsdelay] [-T tty] \n" + printf("usage : tty-clock [-iuvsScbtrahDBxn] [-C [0-7]] [-f format] [-d delay] [-a nsdelay] [-T tty] [-p [1-9]] \n" " -s Show seconds \n" " -S Screensaver mode \n" " -x Show box \n" @@ -588,7 +623,11 @@ main(int argc, char **argv) " -D Hide date \n" " -B Enable blinking colon \n" " -d delay Set the delay between two redraws of the clock. Default 1s. \n" - " -a nsdelay Additional delay between two redraws in nanoseconds. Default 0ns.\n"); + " -a nsdelay Additional delay between two redraws in nanoseconds. Default 0ns.\n" + " -p [1-9] Position of clock in terminal: 1-9 starting top-left and ending bottom-right:\n\n" + " 123\n" + " 456\n" + " 789\n"); exit(EXIT_SUCCESS); break; case 'i': @@ -644,6 +683,10 @@ main(int argc, char **argv) case 'x': ttyclock->option.box = True; break; + case 'p': + if(atol(optarg) > 0 && atol(optarg) < 10) + ttyclock->option.position = atol(optarg); + break; case 'T': { struct stat sbuf; if (stat(optarg, &sbuf) == -1) { diff --git a/ttyclock.h b/ttyclock.h index 3d22ade..149584d 100644 --- a/ttyclock.h +++ b/ttyclock.h @@ -84,6 +84,7 @@ typedef struct long delay; Bool blink; long nsdelay; + int position; } option; /* Clock geometry */ @@ -125,6 +126,7 @@ void set_second(void); void set_center(Bool b); void set_box(Bool b); void key_event(void); +void set_position(int p); /* Global variable */ ttyclock_t *ttyclock;