Skip to content

ulahello/sw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sw

sw is a terminal stopwatch that runs as a shell.

Quick Start

First, install Rust. Then, to build and install sw:

# build sw
cargo build --release

# make sw available in your $PATH
cargo install --locked --path .

If you wish to build and install the man pages for your POSIX system, make sure you have scdoc installed. Having Make is nice because you can use the provided Makefile, but it’s not strictly required.

# install the documentation to $PREFIX
PREFIX="/usr/local" make -B -C docs install

Usage

Arguments

--help

Display usage information.

--no-visual-cues

Disable text-based graphics and visual cues.

To toggle this value at runtime, use the visuals command.

For more details, see the section on visual cues.

--no-colors

Disable the use of colors in output.

For more details, see the section on colors.

--no-tty-check

Disable the TTY check.

Typically, sw will check if standard output and input are terminals, and exit abnormally if either aren’t. This flag disables the check.

--version

Display the version of sw.

Commands

The shell interface allows you to manipulate a stopwatch by issuing commands and responding to prompts that may follow.

The following table is a quick overview of the available commands. The “input” field shows which key combination maps to the command. The command’s name is also a valid input.

Command nameInputDescription
HelphShow help
Display<Enter>Display elapsed time
TogglesToggle stopwatch
ResetrReset stopwatch
ChangecChange elapsed time
OffsetoOffset elapsed time
NamenSet stopwatch name
PrecisionpSet display precision
VisualsvToggle visual cues
LicenselPrint license info
QuitqAbandon all Data

Help

Lists the available commands and their description.

Each line of the output corresponds to a command, and contains the required key combination and a description of the command.

Display

Displays the state of the stopwatch.

The first line of output contains the elapsed time. The subsecond precision of this output is affected by the precision command.

The second line indicates whether the stopwatch is running or stopped. The colors used to indicate this are an exception to their typical meaning. For more information, see the the section on colors.

Toggle

Toggles whether the stopwatch is running or stopped.

If the stopwatch is running, it is stopped. If the new elapsed time overflows, it prints a warning.

If stopped, it starts the stopwatch. Then it prints the duration that has elapsed since the last time it was stopped. This may be useful if you forget to start the stopwatch, since you can start it and it’ll tell you how long the stopwatch was idling. The precision of this output is affected by the precision command.

Reset

Resets the stopwatch.

This command stops the stopwatch and sets its elapsed time to zero.

Change

Stops and sets the elapsed time.

This command prompts you for a new elapsed time.

The duration will be parsed according to the duration formats. It must be positive. If the duration is invalid, it will be printed back with the errors colored red.

Offset

Offsets the elapsed time by a positive or negative duration.

This command prompts you for a positive or negative duration. If it parses according to the duration formats, the elapsed time will be offset by it without changing whether the stopwatch is running. Otherwise, the invalid duration will be printed with errors indicated in red.

Name

Sets the name of the stopwatch.

This command will prompt you to name the stopwatch.

The name is purely for display: it’s literal text that prefixes the prompt. It may be useful for distinguishing the meaning of the stopwatch if you have multiple instances open.

Precision

Sets the decimal precision used to display the subsecond component of durations.

Several commands output formatted elapsed times and durations. This command is used to configure the decimal precision of this output.

The default precision is 2, meaning two subsecond digits will be displayed.

Visuals

Toggles whether text-based graphics and visual cues are enabled (they are by default).

This parameter can be controlled with the –no-visual-cues flag.

For more details, see the section on visual cues.

License

Prints license and copyright information for sw and its direct dependencies.

Quit

Terminates the program with a successful exit code, abandoning all stopwatch state.

Prompt

sw displays a prompt before commands are entered.

The prompt contains the name of the stopwatch. If visual cues are enabled, the name is followed by a character indicating the stopwatch state. This indicator is ‘;’ if the stopwatch is stopped and ‘*’ if it’s running.

For example, if the stopwatch is named “work” and stopped, it will prompt with the following with visual cues enabled:

work ; 

And if it’s running:

work * 

With the same stopwatch but visual cues disabled, it will prompt with this:

work. 

Duration input format

The offset and change commands accept a duration as input. The following formats are supported.

Unit format

number unit

number is a whole or decimal number, and unit is one of “s”, “m”, or “h”, meaning seconds, minutes, and hours respectively.

Whitespace is ignored, so “1s” is just as valid as “1 s”.

Stopwatch format

sign hours : minutes : seconds . subseconds

The details shouldn’t be surprising, it’s a superset of how durations are displayed.

hours, minutes, seconds and subseconds are all integers.

sign is optional, and one of “+” or “-“. It indicates whether the duration is positive or negative, defaulting to positive.

It’s okay to omit separators and values. Rightmost values are the most important, so the meaning of the input will be inferred from right to left.

Some examples of terse inputs:

  • “:5” and “::5” represent 5 seconds
  • “:5:” represents 5 minutes
  • ”:.6” represents 0.6 seconds
  • “1::1.1” represents 1 hour and 1.1 seconds

It’s also okay to add whitespace between separators.

Duration output format

With visual cues enabled, durations are formatted as hours:minutes:seconds.subseconds. Otherwise they’re formatted as they would be spoken. For example, “00:05:32.98” would be formatted as “5 minutes, 32.98 seconds”. If the precision is zero, this will simply be “5 minutes, 32 seconds”.

Colors

sw will use colors if they are supported by the terminal, or as directed by the –no-colors flag.

The following table documents the meaning of each color as it appears:

ColorMeaning
MagentaInformation about program state change
CyanInformation, but state is unchanged
YellowWarning
RedError

The indication for whether the stopwatch is running or stopped in the display command is an exception to this, with “running” colored green and “stopped” colored yellow.

Visual cues

Visual cues and text-based graphics are enabled by default, but can be disabled using the visuals command and the –no-visual-cues flag.

The following aspects of the interface are affected by this parameter:

Contributions

Tickets and improvements are welcome and appreciated! The issue tracker is available on GitHub.

Contributions will be licensed under the same license as sw.

License

sw is licensed under the GNU General Public License v3.0 or later.

See LICENSE for the full license text.

About

terminal stopwatch

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages