[ZOIS] Home Page * Contact ZOIS * Technical Notes

A Curses Based Clock

ZOIS Technical Note TN-1991-01-01.

Author and Audience

This TN is intended for persons interested in the curses(3) library and its use in C programs for UNIX systems. UNIX systems' and C programming skills are assumed. Written by Martin Sullivan[1], ZOIS Limited, Cockermouth.

Abstract

A program which displays the time in analogue form on a character based terminal is presented, both as an exemplar and as an amusement.

Introduction

The curses(3) library allows programmers to write text-based user interfaces on terminals with a directly addressable cursor (such as the DEC VT100). Cleverly, the library allows for the independent use of a wide variety of such terminals and optimises output to reduce the amount of traffic between the central computer and terminal by only writing portions of the screen that need rewriting. Lately this library has been upgraded and extended as 'ncurses'[2] and in this format is most widely known and distributed. This TN introduces a program, written in C, which can run on a variety of UNIX platforms to display a clock using curses.

Materials and Platform

The code is written in K&R C, and thus can be compiled on quite ancient kit (as well as more modern OS). It works fine on Linux with a GCC compiler. The clock may be displayed using xterm(1).

Method

The code for the clock is found in the downloads area as a compressed (with gzip(1)) tar(1) archive[3]. In most cases it will need adaption to the environment of the site you are running on. Since we are publishing this as an exemplar, then figuring out the compilation should be considered as part of the exercise. The following should be sufficient for most UNIX systems:

 make clock

Once made the clock provides the following options:

-f
Display the date and day of week on the clock face.
-r
Use a square face with roman numerals. This replaces the default round clock face.
-s
Start clock with the seconds turned on. By default, the clock starts with seconds turned off, and updates every minute. With seconds turned on, it updates every second and displays a second hand.
-d
Display the date and time (in digital format) on the clock face.

Any text given on the command line is taken as a 'title' and displayed on the clock face in deference to the default.

As a bonus, the tar-ball also contains some other cursor based toys, including one, bubbles which was inspired by the rain demo and in turn inspired at least one book.

Conclusion

The somewhat elderly curses clock has been described and is available for download. The download includes a number of other curses based demonstrations. A man(1) page and build instructions are included.

References

References found in this section, and in particular the HTML links were correct at time of writing (2007-11-14).

1. Martin Sullivan:
http://www.zois.co.uk/people/martin_sullivan
2. Ncurses:
http://www.gnu.org/software/ncurses
3. Clock download:
http://www.zois.co.uk/dl/clock.tar.gz (Size: 9588 bytes, MD5 checksum: 7e05357a4acb9e8414c44b253c18d583).

$Date: 2007/11/15 14:44:11 $


Break Frame * E-mail Webmaster * Copyright