7 releases (2 stable)

1.0.1 Oct 13, 2023
0.1.4 Jun 21, 2019

#133 in Command line utilities

46 downloads per month

MIT license

96KB
633 lines

tock

A digital clock for the terminal, inspired by tty-clock. Unfortunately only works on UNIX systems due to the use of the termios and sigaction related function calls.

Note: emulating all features of tty-clock is not a goal of this project.

Features

  • Efficient bitmap and diff-based drawing
  • Timezone support via the TZ environment variable and tzselect utility
  • Military time and second display toggling
  • Color customization using ANSI, 8-bit, or 24-bit color values
  • Arbitrary date formatting
  • Positioned or centered clock
  • Adjustable display size
  • Synchronization with system clock seconds
  • Minimal syscalls (about one read, write, nanosleep per second)

Screenshots

Screenshot of clock

asciicast of multiple clocks

Installation

Currently requires a Rust installation with version >= 1.70.0 (due to the IsTerminal trait, and is only available from either:

  1. crates.io using cargo-install
cargo install tock
  1. Building from source
git clone https://github.com/nwtnni/tock.git
cargo build --release
./target/release/tock

Usage

A digital clock for the terminal.

Usage: tock [OPTIONS]

Options:
  -x, --x <X>            Horizontal 0-indexed position of top-left corner [default: 0]
  -y, --y <Y>            Vertical 0-indexed position of top-left corner [default: 0]
  -W, --width <WIDTH>    Font width in characters per tile [default: 2]
  -H, --height <HEIGHT>  Font height in characters per tile [default: 1]
  -s, --second           Display seconds
  -m, --military         Display military (24-hour) time
  -c, --center           Center the clock in the terminal. Overrides manual positioning
  -C, --color <COLOR>    Change the color of the time [default: 2]
  -f, --format <FORMAT>  Change the date format [default: "%F | %Z"]
  -h, --help             Print help (see more with '--help')

Currently compiles with the interactive feature flag set by default, which polls stdin for user input once per second. Available commands with this feature flag set are:

  • q or Q or <ESC>: Exit.
  • s: Toggle second display.
  • m: Toggle military (24H) time.
  • 0..=7: Change to corresponding ANSI color.

References

Dependencies

~2.5–9.5MB
~64K SLoC