pom

A simple pomodoro app, suitable for running in a tmux pane.
git clone git://git.jtobin.io/pom.git
Log | Files | Refs | README | git.jtobin.io

commit fdc5c232d1fbd23d3734090a5924ea0e7b1fb3b1
Author: Jared Tobin <jared@jtobin.io>
Date:   Wed,  2 Dec 2026 11:03:19 +0400

pom: initial commit

A pomodoro timer for the terminal: 25-minute pomodoros, 5-minute short
breaks, and 10-minute long breaks, started with p, s, and l, and
stopped, started, and reset with space and r. A tomato sits beside the
time, drawn in large digits, and the terminal bell rings when a timer
runs out.

Diffstat:
A.gitignore | 2++
AREADME.md | 30++++++++++++++++++++++++++++++
Aapp/Main.hs | 281+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aflake.lock | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aflake.nix | 42++++++++++++++++++++++++++++++++++++++++++
Apom.cabal | 23+++++++++++++++++++++++
6 files changed, 439 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,2 @@ +dist-newstyle/ +result diff --git a/README.md b/README.md @@ -0,0 +1,30 @@ +# pom + +A simple pomodoro timer for the terminal, in the spirit of the old +[tomato timer](https://www.toptal.com/project-managers/tomato-timer). + +Pomodoros run for 25 minutes, short breaks for 5, and long breaks for +10. The terminal bell rings when a timer runs out, so tmux will flag +the window if it's in the background. + +## Keys + +* `p`: start a pomodoro +* `s`: start a short break +* `l`: start a long break +* `space`: start or stop the timer +* `r`: reset the timer +* `q`: quit + +## Running + +``` +$ nix run +``` + +or, to build in a development shell: + +``` +$ nix develop +$ cabal run +``` diff --git a/app/Main.hs b/app/Main.hs @@ -0,0 +1,281 @@ +{-# LANGUAGE LambdaCase #-} + +-- | +-- Module: Main +-- Copyright: (c) 2026 Jared Tobin +-- License: MIT +-- Maintainer: Jared Tobin <jared@jtobin.io> +-- +-- A simple pomodoro timer for the terminal. + +module Main where + +import qualified Brick as B +import qualified Brick.BChan as BC +import qualified Brick.Widgets.Center as C +import Control.Concurrent (forkIO, threadDelay) +import Control.Monad (forever) +import Control.Monad.IO.Class (liftIO) +import Data.List (intersperse) +import GHC.Clock (getMonotonicTime) +import qualified Graphics.Vty as V + +-- timer ---------------------------------------------------------------------- + +-- | Timer modes. +data Mode = + Pomodoro + | Short + | Long + deriving Eq + +-- | Duration of a mode, in seconds. +duration :: Mode -> Double +duration = \case + Pomodoro -> 25 * 60 + Short -> 05 * 60 + Long -> 10 * 60 + +-- | A timer either runs toward a deadline on the monotonic clock, or is +-- stopped with some time remaining. +data Timer = + Running !Double + | Stopped !Double + +-- | Application state. +data State = State { + st_mode :: !Mode + , st_timer :: !Timer + , st_now :: !Double + } + +-- | Seconds remaining on the timer. +remaining :: State -> Double +remaining (State _ t now) = case t of + Running d -> max 0 (d - now) + Stopped r -> r + +-- events --------------------------------------------------------------------- + +-- | Clock ticks. +data Tick = Tick + +handle :: B.BrickEvent () Tick -> B.EventM () State () +handle = \case + B.AppEvent Tick -> do + now <- liftIO getMonotonicTime + st <- B.get + case st_timer st of + Running d | now >= d -> do + B.put st { st_timer = Stopped 0, st_now = now } + bell + _ -> B.put st { st_now = now } + B.VtyEvent (V.EvKey k ms) -> case (k, ms) of + (V.KChar 'p', []) -> start Pomodoro + (V.KChar 's', []) -> start Short + (V.KChar 'l', []) -> start Long + (V.KChar ' ', []) -> toggle + (V.KChar 'r', []) -> reset + (V.KChar 'q', []) -> B.halt + (V.KEsc, []) -> B.halt + (V.KChar 'c', [V.MCtrl]) -> B.halt + _ -> pure () + _ -> pure () + +-- | Start a fresh timer in the given mode. +start :: Mode -> B.EventM () State () +start m = do + now <- liftIO getMonotonicTime + B.put (State m (Running (now + duration m)) now) + +-- | Start or stop the timer. A timer that has run out starts afresh. +toggle :: B.EventM () State () +toggle = do + now <- liftIO getMonotonicTime + B.modify $ \st -> st { + st_now = now + , st_timer = case st_timer st of + Running d -> Stopped (max 0 (d - now)) + Stopped r + | r > 0 -> Running (now + r) + | otherwise -> Running (now + duration (st_mode st)) + } + +-- | Stop the timer and restore the full duration of the current mode. +reset :: B.EventM () State () +reset = B.modify $ \st -> st { st_timer = Stopped (duration (st_mode st)) } + +-- | Ring the terminal bell. +bell :: B.EventM () State () +bell = do + vty <- B.getVtyHandle + liftIO (V.ringTerminalBell (V.outputIface vty)) + +-- drawing -------------------------------------------------------------------- + +draw :: State -> [B.Widget ()] +draw st = pure . C.center $ + B.raw (sprite tomato) B.<+> B.padLeft (B.Pad 3) (B.vBox [ + clock st + , B.padTop (B.Pad 1) (tabs (st_mode st)) + , B.padTop (B.Pad 1) (help st) + ]) + +-- | The time remaining, in large digits. +clock :: State -> B.Widget () +clock st = B.withAttr attr . B.vBox . fmap B.str $ + foldr1 (zipWith (\a b -> a <> " " <> b)) (fmap glyph (mmss secs)) + where + secs = ceiling (remaining st) :: Int + attr = case st_timer st of + Running _ -> running_attr + Stopped _ -> stopped_attr + +-- | Render seconds as MM:SS. +mmss :: Int -> String +mmss s = pad (s `quot` 60) <> ":" <> pad (s `rem` 60) where + pad n = if n < 10 then '0' : show n else show n + +-- | A large glyph, five rows tall. +glyph :: Char -> [String] +glyph = fmap (concatMap px) . \case + '0' -> ["###", "#.#", "#.#", "#.#", "###"] + '1' -> [".#.", "##.", ".#.", ".#.", "###"] + '2' -> ["###", "..#", "###", "#..", "###"] + '3' -> ["###", "..#", "###", "..#", "###"] + '4' -> ["#.#", "#.#", "###", "..#", "..#"] + '5' -> ["###", "#..", "###", "..#", "###"] + '6' -> ["###", "#..", "###", "#.#", "###"] + '7' -> ["###", "..#", "..#", "..#", "..#"] + '8' -> ["###", "#.#", "###", "#.#", "###"] + '9' -> ["###", "#.#", "###", "..#", "###"] + _ -> [".", "#", ".", "#", "."] + where + px '#' = "██" + px _ = " " + +-- | The mode tabs, with the current mode highlighted and each mode's key +-- underlined. +tabs :: Mode -> B.Widget () +tabs cur = B.hBox (fmap tab modes) where + modes = [ + (Pomodoro, "pomodoro") + , (Short, "short break") + , (Long, "long break") + ] + tab (m, label) = + let a = if m == cur then current_attr else tab_attr + (k, rest) = splitAt 1 label + in B.withAttr a $ B.hBox [ + B.str " " + , B.withAttr (a <> key_attr) (B.str k) + , B.str (rest <> " ") + ] + +-- | Key hints. +help :: State -> B.Widget () +help st = B.withAttr help_attr . B.hBox . intersperse (B.str " ") $ + [hint "space" toggle_label, hint "r" "reset", hint "q" "quit"] + where + hint k v = + B.withAttr (help_attr <> key_attr) (B.str k) B.<+> B.str (' ' : v) + toggle_label = case st_timer st of + Running _ -> "stop" + Stopped _ -> "start" + +-- | Render rows of pixels, two to a cell, with half blocks. +sprite :: [String] -> V.Image +sprite = \case + (a:b:rest) -> V.horizCat (zipWith cell a b) V.<-> sprite rest + _ -> V.emptyImage + where + cell t b = case (pixel t, pixel b) of + (Nothing, Nothing) -> V.char V.defAttr ' ' + (Just f, Nothing) -> V.char (V.defAttr `V.withForeColor` f) '▀' + (Nothing, Just g) -> V.char (V.defAttr `V.withForeColor` g) '▄' + (Just f, Just g) -> V.char (f `B.on` g) '▀' + +-- | Tomato palette. +pixel :: Char -> Maybe V.Color +pixel = \case + 'R' -> Just red + 'r' -> Just (rgb 150 25 25) + 'H' -> Just (rgb 255 150 130) + 'G' -> Just (rgb 70 160 50) + 'g' -> Just (rgb 40 100 30) + _ -> Nothing + +red :: V.Color +red = rgb 220 50 40 + +rgb :: Int -> Int -> Int -> V.Color +rgb = V.linearColor + +tomato :: [String] +tomato = [ + "...........gg..........." + , "...........gg..........." + , "....GGGRRRRggRRRRGGG...." + , "...RRRGGGGGGGGGGGGRRr..." + , "..RRGGGGRGGGGGGRGGGGRr.." + , ".RRRRRRRRGRGGRGRRRRRRRr." + , "RRRRRHHRRRRRRRRRRRRRRRrr" + , "RRRRHRRRRRRRRRRRRRRRRRrr" + , "RRRHRRRRRRRRRRRRRRRRRRrr" + , "RRRHRRRRRRRRRRRRRRRRRRrr" + , "RRRRRRRRRRRRRRRRRRRRRRrr" + , "RRRRRRRRRRRRRRRRRRRRRrrr" + , ".RRRRRRRRRRRRRRRRRRRRrr." + , ".RRRRRRRRRRRRRRRRRRRrrr." + , "..RRRRRRRRRRRRRRRRRrrr.." + , "...RRRRRRRRRRRRRRrrrr..." + , ".....rRRRRRRRRrrrrr....." + , "........rrrrrrrr........" + ] + +-- attributes ----------------------------------------------------------------- + +running_attr, stopped_attr, tab_attr, current_attr, help_attr, key_attr + :: B.AttrName +running_attr = B.attrName "running" +stopped_attr = B.attrName "stopped" +tab_attr = B.attrName "tab" +current_attr = B.attrName "current" +help_attr = B.attrName "help" +key_attr = B.attrName "key" + +attrs :: B.AttrMap +attrs = B.attrMap V.defAttr [ + (running_attr, B.fg red `V.withStyle` V.bold) + , (stopped_attr, V.defAttr `V.withStyle` V.dim) + , (tab_attr, V.defAttr `V.withStyle` V.dim) + , (tab_attr <> key_attr, V.defAttr `V.withStyle` V.dim + `V.withStyle` V.underline) + , (current_attr, (V.brightWhite `B.on` red) `V.withStyle` V.bold) + , (current_attr <> key_attr, V.defAttr `V.withStyle` V.bold + `V.withStyle` V.underline) + , (help_attr, V.defAttr `V.withStyle` V.dim) + , (help_attr <> key_attr, V.defAttr `V.withStyle` V.bold) + ] + +-- main ----------------------------------------------------------------------- + +app :: B.App State Tick () +app = B.App { + B.appDraw = draw + , B.appChooseCursor = B.neverShowCursor + , B.appHandleEvent = handle + , B.appStartEvent = pure () + , B.appAttrMap = const attrs + } + +main :: IO () +main = do + chan <- BC.newBChan 1 + _ <- forkIO . forever $ do + BC.writeBChan chan Tick + threadDelay 200000 + now <- getMonotonicTime + let st = State Pomodoro (Stopped (duration Pomodoro)) now + (_, vty) <- B.customMainWithDefaultVty (Just chan) app st + V.shutdown vty diff --git a/flake.lock b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1766840161, + "narHash": "sha256-Ss/LHpJJsng8vz1Pe33RSGIWUOcqM1fjrehjUkdrWio=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3edc4a30ed3903fdf6f90c837f961fa6b49582d1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix @@ -0,0 +1,42 @@ +{ + description = "A simple pomodoro timer for the terminal."; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + exe = "pom"; + + pkgs = import nixpkgs { inherit system; }; + hlib = pkgs.haskell.lib; + hpkgs = pkgs.haskellPackages.extend (new: old: { + ${exe} = new.callCabal2nix exe ./. { }; + }); + + ghc = hpkgs.ghc; + cabal = hpkgs.cabal-install; + in + { + packages.default = hlib.justStaticExecutables hpkgs.${exe}; + + devShells.default = hpkgs.shellFor { + packages = p: [ p.${exe} ]; + + buildInputs = [ + cabal + ]; + + shellHook = '' + PS1="[${exe}] \w$ " + echo "entering ${system} shell, using" + echo "ghc: $(${ghc}/bin/ghc --version)" + echo "cabal: $(${cabal}/bin/cabal --version)" + ''; + }; + } + ); +} diff --git a/pom.cabal b/pom.cabal @@ -0,0 +1,23 @@ +cabal-version: 3.0 +name: pom +version: 0.1.0 +synopsis: A simple pomodoro timer for the terminal. +author: Jared Tobin +maintainer: jared@jtobin.io +category: Utility +build-type: Simple +tested-with: GHC == 9.10.3 +description: + A simple pomodoro timer for the terminal, with 25-minute pomodoros, + 5-minute short breaks, and 10-minute long breaks. + +executable pom + default-language: Haskell2010 + hs-source-dirs: app + main-is: Main.hs + ghc-options: + -Wall -threaded + build-depends: + base >= 4.11 && < 5 + , brick >= 2 && < 3 + , vty >= 6 && < 7