peaclock

repository·master·Indexed 21 days ago

https://github.com/octobanana/peaclock

A responsive and customizable terminal-based clock, timer, and stopwatch. It supports multiple views including ASCII, digital, and binary, and allows for deep customization of colors, sizing, and behavior. Features include auto-size mode for terminal responsiveness, the ability to execute shell commands upon timer completion, and a flexible configuration system via CLI flags or config files.

Tokens
2.3K
Snippets
10
Records
13
Agent score
74%

What's inside peaclock

  1. How to read the Binary Clock view

    master

    The binary clock view uses columns to represent digits for Hours (H), Minutes (M), and Seconds (S). Each digit is composed of four bits (values 8, 4, 2, and 1).

    To get the value of a digit, add up the bits that are 'on'.

      |   |   | < 8
      | | | | | < 4
    | | | | | | < 2
    | | | | | | < 1
    H H M M S S < Time Digit
    |   |   | < 8
      | | | | | < 4
    | | | | | | < 2
    | | | | | | < 1
    H H M M S S < Time Digit
  2. How Peaclock modes and views work

    master

    Peaclock's output is determined by the combination of a mode and a view:

    • Modes: Determine the clock value (e.g., clock, timer, or stopwatch).
    • Views: Determine how that value is presented (e.g., ascii, digital, or binary).

    Users can customize the clock's appearance, including width, height, color, padding, and margin. In auto size mode, the clock is responsive and fills the terminal, or can be set to a specific aspect ratio to prevent stretching.

  3. Run peaclock with custom configuration

    master

    You can specify a custom configuration file or directory to initialize peaclock with specific settings.

    • Use --config=<file> to use a specific file for initialization. All other initializations are skipped. Use the special name NONE to skip all initializations.
    • Use --config-dir=<dir> to use a specific directory as the config directory. Use NONE to skip all initializations.

    Note: The config directory and file must be created by the user. If using a directory, the config file must be named config.

    Default config directory: ${HOME}/.peaclock

    peaclock --config "./path/to/config/file"
    peaclock --config-dir "~/.config/peaclock"
  4. Build Peaclock on macOS with GCC or Clang

    master

    The default Apple Clang compiler does not support C++17 features like std::filesystem. You must install a newer version of gcc or clang (e.g., via Homebrew).

    1. Install and link GCC:
    brew install gcc
    brew link gcc
    1. Build using the RUNME.sh script, passing the path to the new compiler via CMake arguments:
    ./RUNME.sh build -- -DCMAKE_CXX_COMPILER='<path-to-g++>'

    Note: Replace <path-to-g++> with the actual path to your new compiler binary.

    # Install GCC via Brew
    brew install gcc
    brew link gcc
    
    # Build with specific compiler
    ./RUNME.sh build -- -DCMAKE_CXX_COMPILER='/usr/local/bin/g++'
  5. Build and Install Peaclock

    master

    Peaclock provides a shell script RUNME.sh to handle building and installation in release mode.

    To build the project:

    ./RUNME.sh build

    To install the project:

    ./RUNME.sh install
    # Build
    ./RUNME.sh build
    
    # Install
    ./RUNME.sh install
  6. Navigate peaclock modes and views using key bindings

    master

    Once peaclock is running, you can switch between different functional modes and visual styles using keyboard shortcuts:

    Modes

    • w: Mode clock (displays current time)
    • e: Mode timer (displays the timer)
    • r: Mode stopwatch (displays the stopwatch)

    Views

    • W: View date
    • E: View ascii clock
    • R: View digital clock
    • T: View binary clock
    • Y: View icon clock

    Controls

    • : Start/stop timer or stopwatch
    • <backspace>: Clear timer or stopwatch
    • a: Toggle 24-hour time
    • s: Toggle seconds
    • d: Toggle date
    • q, Q, or <ctrl-c>: Quit the program
  7. Create and manage configuration files

    master

    peaclock allows you to save your current runtime settings into a configuration file using the command prompt (accessed via :).

    • mkconfig <file>: Creates <file> and writes the current configuration settings to it.
    • mkconfig! <file>: Overwrites or creates <file> and writes the current configuration settings to it.

    Configuration files are plain text files where each command is on its own line. Lines starting with # are treated as comments.

    # Example of a config file content
    mode clock
    view digital
    set seconds on
    style background blue
  8. Configure Peaclock

    master

    Peaclock uses a configuration directory and a configuration file to manage settings.

    Default Locations

    • Config Directory (DIR): ${HOME}/.peaclock
    • Config File: ${HOME}/.peaclock/config
    • History Directory: ${HOME}/.peaclock/history
    • Command History File: ${HOME}/.peaclock/history/command

    Setup and Overrides

    To set up the default configuration, create the directory and copy the default config file:

    mkdir -pv ~/.peaclock
    cp -uv ./cfg/default ~/.peaclock/config

    To override the defaults via CLI:

    • Use --config=<file> to specify a custom config file.
    • Use --config-dir=<dir> to specify a custom config directory.

    To permanently use a custom config directory (e.g., ~/.config/peaclock), add an alias to your shell profile:

    alias peaclock="peaclock --config-dir ~/.config/peaclock"

    Config File Format

    The config file is a plain text file where each command must be on its own line. Lines starting with # are treated as comments. Commands can be found in the --help output.

    # Setup default config
    mkdir -pv ~/.peaclock
    cp -uv ./cfg/default ~/.peaclock/config
    
    # Permanent alias example
    alias peaclock="peaclock --config-dir ~/.config/peaclock"
  9. Understand Peaclock's configuration and history directory structure

    master

    When a configuration directory is provided or detected, Peaclock expects and manages a specific directory structure to persist settings and command history:

    • Configuration Directory: The root folder for Peaclock settings (defaults to ~/.peaclock).
    • history/ subdirectory: A directory within the configuration directory used to store history files.
    • history/command: A specific file within the history directory used to load command history.
    • config file: The main configuration file located at the root of the configuration directory.
  10. Execute shell commands on timer completion

    master

    You can configure peaclock to run a specific shell command automatically when a timer finishes using the timer-exec command.

    • timer-exec <str>: Sets the string to be executed by a shell upon timer completion. Passing an empty string clears this setting.
    # Example command to enter in the prompt
    timer-exec "notify-send 'Timer Finished!'"
  11. Use peaclock CLI options

    master

    The peaclock binary accepts several command-line flags for control and output formatting:

    • --colour=<on|off|auto>: Controls color output for program info. auto detects if stdout is a TTY.
    • -u, --config=<file>: Use the commands in the specified file for initialization. All other initializations are skipped.
    • --config-dir=<dir>: Use the specified directory as the config directory.
    • -h, --help: Print the help output.
    • --license: Print the program license.
    • -v, --version: Print the program version.
    peaclock --help --colour=off
    peaclock --version
  12. Configure visual styles and layout via commands

    master

    You can customize the appearance of the clock using the command prompt (:).

    Color and Style

    Use style <value> <format> to set colors or styles. Supported formats include hex codes (#000000-#ffffff), 0-255, named Colour (e.g., red, bright blue), or reverse.

    Common style targets:

    • active-fg, inactive-fg, colon-fg (foreground colors)
    • active-bg, inactive-bg, colon-bg (background colors)
    • background, date, text, prompt

    Layout and Sizing

    • block <x> <y>: Set the width and height of individual blocks.
    • padding <x> <y>: Set the space between blocks.
    • margin <x> <y>: Set the space around the outside of the clock.
    • ratio <x> <y>: Set the aspect ratio (e.g., 2 1 for terminal cells).
    • set <value> <on|off>: Use auto-size to fill the screen or auto-ratio to follow the set ratio.
    # Examples of commands to enter in the prompt
    style active-fg bright red
    block 2 2
    ratio 2 1
    set seconds on