* Add the -T <tty> and -n options to facilitate use

through inittab(5)
* Update and fix the man page.
* Adjust default date format which was left over from a previous
  failed merge.
reverse-branch
Carla Valenti 15 years ago
parent 31529219f9
commit 6607fc1a63
  1. 47
      tty-clock.1
  2. 53
      ttyclock.c
  3. 9
      ttyclock.h

@ -7,28 +7,30 @@
tty-clock - a terminal digital clock
.SH SYNOPSIS
.LP
\fBtty\-clock [\-sSbctrvih] [\-C [\fP\fI0\-7\fP\fB]] [\-f\fP \fIformat\fP\fB] [\-d \fIdelay\fP\fB]\fP
\fBtty\-clock [\-sSbctrvih] [\-C [\fI0\-7\fB]] [\-f \fIformat\fB] [\-d \fIdelay\fB] \fB[\-T \fItty\fB]\fR
.SH DESCRIPTION
.LP
\fItty-clock\fP displays a simple digital clock on the terminal
\fItty-clock\fR displays a simple digital clock on the terminal. Invoked without options
it will display the clock on the upper left corner of the screen on the terminal it was
executed from.
.SH COMMANDS
.LP
\fItty-clock\fP accepts a number of runtime keyboard commands, upper and lower case characters are
\fItty-clock\fR accepts a number of runtime keyboard commands, upper and lower case characters are
treated identically.
.TP
K,J,H,L
vi-style movement commands to set the position of the displayed clock.
These commands have no effect when the \fBcentered\fP option is set.
These commands have no effect when the \fBcentered\fR option is set.
.TP
B
Toggles displaying a box around the clock. options is disabled by default.
Toggles displaying a box around the clock. This option is disabled by default.
.TP
C
Toggle the clock's position to \fBcentered\fP.
Toggle the clock's position to \fBcentered\fR.
When set the movement commands are disabled.
.TP
R
Set the clock to \fBrebound\fP along the edges of the terminal.
Set the clock to \fBrebound\fR along the edges of the terminal.
.TP
S
Display seconds.
@ -53,17 +55,27 @@ Show box.
\fB\-c\fR
Set the clock at the center of the terminal
.TP
\fB\-C\fR \fI[0\-7]\fP
\fB\-C\fR \fI[0\-7]\fR
Set the clock color.
.TP
\fB\-t\fR
Set the hour in 12h format.
.TP
\fB\-T\fR \fItty\fR
Display the clock on the given \fItty\fR. \fItty\fR must be
a valid character device to which the user has rw access permissions.
(See \fBEXAMPLES\fR)
.TP
\fB\-r\fR
Do rebound the clock.
.TP
\fB\-f\fR \fIformat\fP
Set the date format as described in \fBstrftime(3)\fP.
\fB\-f\fR \fIformat\fR
Set the date format as described in \fBstrftime(3)\fR.
.TP
\fB\-n\fR
Do not quit the program when the Q key is pressed (or when any
key is pressed while in \fBScreensaver\fR mode). A signal must
be sent to \fItty\-clock\fR in order to terminate its execution. (See \fBEXAMPLES\fR)
.TP
\fB\-v\fR
Show tty\-clock version.
@ -74,9 +86,20 @@ Show some info about tty\-clock.
\fB\-h\fR
Show usage information.
.TP
\fB\-d\fR \fIdelay\fP
\fB\-d\fR \fIdelay\fR
Set the delay between two redraws of the clock.
.SH "AUTHOR"
.SH "EXAMPLES"
.LP
The following example displays a fullscreen clock at boot on one of
the Virtual Terminals on a Linux system using an
.B inittab(5)
entry:
.IP
# /etc/inittab:
.br
9:2345:respawn:/usr/bin/tty-clock -c -n -T /dev/tty9
.LP
.SH "AUTHORS"
Written by Martin Duquesnoy <xorg62@gmail.com>.
.LP
manpage written by Carla Valenti <valenti.karla@gmail.com>.

@ -39,7 +39,19 @@ init(void)
ttyclock->bg = COLOR_BLACK;
/* Init ncurses */
initscr();
if (ttyclock->tty) {
FILE *ftty = fopen(ttyclock->tty, "r+");
if (!ftty) {
fprintf(stderr, "tty-clock: error: '%s' couldn't be opened: %s.\n",
ttyclock->tty, strerror(errno));
exit(EXIT_FAILURE);
}
ttyclock->ttyscr = newterm(NULL, ftty, ftty);
assert(ttyclock->ttyscr != NULL);
set_term(ttyclock->ttyscr);
} else
initscr();
cbreak();
noecho();
keypad(stdscr, True);
@ -138,6 +150,11 @@ signal_handler(int signal)
void
cleanup(void)
{
if (ttyclock->ttyscr)
delscreen(ttyclock->ttyscr);
if (ttyclock && ttyclock->tty)
free(ttyclock->tty);
if (ttyclock && ttyclock->option.format)
free(ttyclock->option.format);
if (ttyclock)
@ -366,7 +383,7 @@ key_event(void)
if (ttyclock->option.screensaver)
{
c = wgetch(stdscr);
if(c != ERR)
if(c != ERR && ttyclock->option.noquit == False)
{
ttyclock->running = False;
}
@ -421,7 +438,8 @@ key_event(void)
case 'q':
case 'Q':
ttyclock->running = False;
if (ttyclock->option.noquit == False)
ttyclock->running = False;
break;
case 's':
@ -476,11 +494,13 @@ main(int argc, char **argv)
/* Alloc ttyclock */
ttyclock = malloc(sizeof(ttyclock_t));
assert(ttyclock != NULL);
memset(ttyclock, 0, sizeof(ttyclock_t));
/* Date format */
ttyclock->option.format = malloc(sizeof(char) * 100);
/* Default date format */
strncpy(ttyclock->option.format, "%d/%m/%Y", 100);
strncpy(ttyclock->option.format, "%F", 100);
/* Default color */
ttyclock->option.color = COLOR_GREEN; /* COLOR_GREEN = 2 */
/* Default delay */
@ -488,21 +508,23 @@ main(int argc, char **argv)
atexit(cleanup);
while ((c = getopt(argc, argv, "tvsSrcihbf:d:C:")) != -1)
while ((c = getopt(argc, argv, "tT:nvsSrcihbf:d:C:")) != -1)
{
switch(c)
{
case 'h':
default:
printf("usage : tty-clock [-sSbctrvih] [-C [0-7]] [-f format] [-d delay] \n"
printf("usage : tty-clock [-sSbctrnvih] [-C [0-7]] [-f format] [-d delay] [-T tty] \n"
" -s Show seconds \n"
" -S Screensaver mode \n"
" -b Show box \n"
" -c Set the clock at the center of the terminal \n"
" -C [0-7] Set the clock color \n"
" -t Set the hour in 12h format \n"
" -T tty Display the clock on the specified terminal \n"
" -r Do rebound the clock \n"
" -f format Set the date format \n"
" -n Don't quit on keypress \n"
" -v Show tty-clock version \n"
" -i Show some info about tty-clock \n"
" -h Show this page \n"
@ -546,6 +568,25 @@ main(int argc, char **argv)
case 'b':
ttyclock->option.box = True;
break;
case 'T': {
struct stat sbuf;
if (stat(optarg, &sbuf) == -1) {
fprintf(stderr, "tty-clock: error: couldn't stat '%s': %s.\n",
optarg, strerror(errno));
exit(EXIT_FAILURE);
} else if (!S_ISCHR(sbuf.st_mode)) {
fprintf(stderr, "tty-clock: error: '%s' doesn't appear to be a character device.\n",
optarg);
exit(EXIT_FAILURE);
} else {
if (ttyclock->tty)
free(ttyclock->tty);
ttyclock->tty = strdup(optarg);
}}
break;
case 'n':
ttyclock->option.noquit = True;
break;
}
}

@ -33,8 +33,12 @@
#ifndef TTYCLOCK_H_INCLUDED
#define TTYCLOCK_H_INCLUDED
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#include <ncurses.h>
@ -55,6 +59,10 @@ typedef struct
{
/* while() boolean */
Bool running;
/* terminal variables */
SCREEN *ttyscr;
char *tty;
int bg;
/* Running option */
@ -66,6 +74,7 @@ typedef struct
Bool center;
Bool rebound;
Bool box;
Bool noquit;
char *format;
int color;
long delay;

Loading…
Cancel
Save