add keylock option

reverse-branch
martin 18 years ago
parent 2eda6156bb
commit 1e3e955979
  1. 1
      README
  2. 128
      clock.c

@ -1,5 +1,6 @@
tty-clock usage : tty-clock -[option] -[option] <arg> tty-clock usage : tty-clock -[option] -[option] <arg>
-s, --second Show seconds -s, --second Show seconds
-b, --block Lock the keyboard\n\
-t, --tw Set the hour in 12h format -t, --tw Set the hour in 12h format
-x <integer> Set the clock to X -x <integer> Set the clock to X
-y <integer> Set the clock to Y -y <integer> Set the clock to Y

@ -26,6 +26,7 @@
#define printh() printf("tty-clock usage : tty-clock -[option] -[option] <arg>\n\n\ #define printh() printf("tty-clock usage : tty-clock -[option] -[option] <arg>\n\n\
-s, --second Show seconds\n\ -s, --second Show seconds\n\
-b, --block Lock the keyboard\n\
-t, --tw Set the hour in 12h format\n\ -t, --tw Set the hour in 12h format\n\
-x <integer> Set the clock to X\n\ -x <integer> Set the clock to X\n\
-y <integer> Set the clock to Y\n\ -y <integer> Set the clock to Y\n\
@ -70,6 +71,7 @@ static struct option long_options[] ={
typedef struct { typedef struct {
bool second; bool second;
bool twelve; bool twelve;
bool keylock;
} OPTIONS; } OPTIONS;
OPTIONS option; OPTIONS option;
@ -219,65 +221,68 @@ arrange_clock(int h1, int h2,
/* ********************* */ /* ********************* */
void void
check_key(void) { check_key(int keylock) {
int c;
c = getch(); if (keylock) {
switch(c) { int c;
case KEY_UP: c = getch();
case 'k': switch(c) {
case 'K': case KEY_UP:
if(defx > 1) case 'k':
--defx; case 'K':
clear(); if(defx > 1)
break; --defx;
case KEY_DOWN: clear();
case 'j': break;
case 'J': case KEY_DOWN:
if(defx + XLENGTH + 2 < maxcol) case 'j':
++defx; case 'J':
clear(); if(defx + XLENGTH + 2 < maxcol)
break; ++defx;
case KEY_LEFT: clear();
case 'h': break;
case 'H': case KEY_LEFT:
if(defy > 1) case 'h':
--defy; case 'H':
clear(); if(defy > 1)
break; --defy;
case KEY_RIGHT: clear();
case 'l': break;
case 'L': case KEY_RIGHT:
if(defy + YLENGTH - SCHANGE + 1 < maxlin) case 'l':
case 'L':
if(defy + YLENGTH - SCHANGE + 1 < maxlin)
++defy; ++defy;
clear(); clear();
break; break;
case 's': case 's':
case 'S': case 'S':
if(!option.second ){ if(!option.second){
SCHANGE = 0; SCHANGE = 0;
clear(); clear();
option.second = 1; option.second = 1;
} else { } else {
SCHANGE = 19; SCHANGE = 19;
clear(); clear();
option.second = 0; option.second = 0;
} }
break; break;
case 't': case 't':
case 'T': case 'T':
if(!option.twelve) { if(!option.twelve) {
clear(); clear();
option.twelve = 1; option.twelve = 1;
} else { } else {
clear(); clear();
option.twelve = 0; option.twelve = 0;
}
break;
case 'q':
case 'Q':
endwin();
exit(EXIT_SUCCESS);
break;
} }
break;
case 'q':
case 'Q':
endwin();
exit(EXIT_SUCCESS);
break;
} }
} }
@ -287,6 +292,7 @@ check_key(void) {
void void
get_time(void) { get_time(void) {
int ihour; int ihour;
tm = localtime(&lt); tm = localtime(&lt);
lt = time(NULL); lt = time(NULL);
@ -344,17 +350,18 @@ run(void) {
int int
main(int argc,char **argv) { main(int argc,char **argv) {
int c; int c;
option.keylock = 1;
static struct option long_options[] ={ static struct option long_options[] ={
{"help", 0, NULL, 'h'}, {"help", 0, NULL, 'h'},
{"version", 0, NULL, 'v'}, {"version", 0, NULL, 'v'},
{"info", 0, NULL, 'i'}, {"info", 0, NULL, 'i'},
{"second", 0, NULL, 's'}, {"second", 0, NULL, 's'},
{"twelve", 0, NULL, 't'}, {"twelve", 0, NULL, 't'},
{"block", 0, NULL, 'b'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
while ((c = getopt_long(argc,argv,"tx:y:vsih", while ((c = getopt_long(argc,argv,"tx:y:vsbih",
long_options,NULL)) != -1) { long_options,NULL)) != -1) {
switch(c) { switch(c) {
case 'h': case 'h':
@ -391,6 +398,9 @@ main(int argc,char **argv) {
case 't': case 't':
option.twelve = 1; option.twelve = 1;
break; break;
case 'b':
option.keylock = 0;
break;
} }
} }
@ -404,7 +414,7 @@ main(int argc,char **argv) {
while(1) { while(1) {
usleep(10000); usleep(10000);
check_key(); check_key(option.keylock);
run(); run();
} }
endwin(); endwin();

Loading…
Cancel
Save