packages feed

fuzzytime 0.6 → 0.7

raw patch · 2 files changed

+87/−61 lines, 2 filesdep +process

Dependencies added: process

Files

fuzzytime.cabal view
@@ -1,5 +1,5 @@ Name:                fuzzytime-Version:             0.6+Version:             0.7 Description:         A clock and timer that tell the time in a more human way Synopsis:            A clock and timer that tell the time in a more human way Category:            Utils@@ -12,4 +12,4 @@  Executable fuzzytime     Main-is:           fuzzytime.hs-    Build-Depends:     base >= 4 && < 5, cmdargs, haskell98, old-time+    Build-Depends:     base >= 4 && < 5, cmdargs, haskell98, old-time, process
fuzzytime.hs view
@@ -1,8 +1,27 @@--- fuzzytime timer (no END) when timer is set+{- |+fuzzytime is a small utility which tells what time it is or how much time there is left till something happens, in a more familiar way such as "ten to six" rather than 17:51 (telling the time), or "in five minutes" (telling the left time). +There are two modes: telling the time / the time left till some event, and setting the timer. See main below.++The intended use is in an environment which does not provide a status bar with a built-in clock. It is expected to be piper to a status bar and run every minute or so in the clock mode.+The timer can be set via the timer-setting mode. When the timer is set, the clock mode will show how much time there is left till some event. To get back to showing the actual time, timer has to be unset.++Example use:+Say you have fuzzytime piped to your status bar and it serves as a usual clock applet. Then you got an e-mail saying that you're going to have a meeting at one o'clock. You set the timer to 13:00 and instead of the current time, fuzzytime begins to show you how much time you have left till the meeting. After you come back, you unset the timer and have fuzzytime display the current time again.++More technically, this module provides an interface to FuzzyTime which does all the conversion from time to string.++Depends on N. Mitchell's System.Console.CmdArds 0.6.4-1+.++To add a new language, two things need to be done:+(1) The new language needs to be added to confAvailLangs in fuzzytime.hs.+(2) A module FuzzyTime.NewLanguge needs to be created and added to the list of imports and to the instance Show FuzzyTime in FuzzyTime.hs.+-}++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ---- |----- Module			: Fuzzytime+---- Module			: Main ---- Copyright		: (C) Kamil Stachowski <kamil.stachowski@gmail.com> ---- License		: GPL3+ ---- Maintainer		: Kamil Stachowski <kamil.stachowski@gmail.com>@@ -11,45 +30,27 @@ ---- A clock that ells the time in a more human way (the \"ten past six\"-style). -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + {-# LANGUAGE DeriveDataTypeable #-}  module Main (-	-- * Description-	-- $description 	  main 	) where  +import Control.Monad (when) import Data.Char (isDigit) import Data.List (intercalate)-import System.Directory (removeFile)+import Directory (removeFile)+import System.Cmd (system) import System.Console.CmdArgs import System.Environment (getEnv)+import System.Exit (ExitCode (ExitFailure), exitFailure) import System.Time (getClockTime)  import FuzzyTime  --- $description--- fuzzytime is a small utility which tells what time it is or how much time there is left to something, in a more familiar way such as "ten to six" rather than 17:51 (telling the time), or "in five minutes" (telling the left time).------ There are two modes: telling the time / the time left till some event, and setting the timer. See main below.------ The intended use is in an environment which does not provide a status bar with a built-in clock. It is expected to be piper to a status bar and run every minute or so in the clock mode.--- The timer can be set via the timer-setting mode. When the timer is set, the clock mode will show how much time there is left till some event. To get back to showing the actual time, timer has to be unset.------ Example use:--- Say you have fuzzytime piped to your status bar and it serves as a usual clock applet. Then you got an e-mail saying that you're going to have a meeting at one o'clock. You set the timer to 13:00 and instead of the current time, fuzzytime begins to show you how much time you have left till the meeting. After you come back, you unset the timer and have fuzzytime display the current time again.------ Depends on N. Mitchell's System.Console.CmdArds 0.6.4-1+.------ To add a new language, two things need to be done:------ (1) The new language needs to be added to confAvailLangs (in fuzzytime.hs) and to instance Show FuzzyTime (in FuzzyTime.hs).------ (2) A module FuzzyTime.NewLanguge needs to be created and added to the list of imports in FuzzyTime.hs.-- -- config =========================================================================================================================================================================  -- available ----------------------------------------------------------------------------------------------------------------------------------------------------------------------@@ -57,7 +58,7 @@  -- | \[config] Languages available. confAvailLangs :: [String]-confAvailLangs = ["da", "de", "el", "en", "es", "fr", "nl", "pl", "tr"]+confAvailLangs = ["da", "de", "el", "en", "es", "fr", "nb", "nl", "pl", "tr"]   -- defaults -----------------------------------------------------------------------------------------------------------------------------------------------------------------------@@ -84,7 +85,7 @@ getDefClockConf :: IO FuzzyTimeConf getDefClockConf = do 	nowClock <- getClockTime-	let nowString = take 5. drop 11 $ show nowClock+	let nowString = take 5 . drop 11 $ show nowClock 	return $ ClockConf { 		  clock	= confDefClockClock	&= help confHelpClockClock 		, lang	= confDefLang		&= help confHelpClockLang@@ -102,8 +103,8 @@ 	let endString = take 5 endFile 	return $ TimerConf { 		  end	= endString			&= args &= typ "END"-		, lang	= confDefLang		&= ignore-		, now	= nowString			&= ignore+		, lang	= confDefLang		&= ignore				-- will be taken from ClockConf anyway+		, now	= nowString			&= ignore				-- will be taken from ClockConf anyway 		} &= name "timer" &= help confHelpTimer  @@ -117,6 +118,11 @@ 	return $ home ++ "/.fuzzytimer"  +-- | \[config] The default command for playing the timer sound.+confTimerSoundCmd :: String+confTimerSoundCmd = "aplay /usr/share/fuzzytime/sound.wav &> /dev/null"++ -- | Print nicely what languages are available. showAvailLangs :: String -> String showAvailLangs i = case length confAvailLangs of@@ -168,7 +174,7 @@  -- | \[config] Help message for summary confHelpSummary :: String-confHelpSummary = "A clock and timer that tell the time in a more human way.\nv0.6, 2011.01.21, kamil.stachowski@gmail.com, GPL3+"+confHelpSummary = "A clock and timer that tell the time in a more human way.\nv0.7, 2011.01.24, kamil.stachowski@gmail.com, GPL3+"   -- check --------------------------------------------------------------------------------------------------------------------------------------------------------------------------@@ -180,9 +186,9 @@ checkFTConf c@(ClockConf clock lang prec time style) 	| clock `notElem` [12, 24]	= Left "--clock must be either 12 or 24." 	| lang `notElem` confAvailLangs = Left ("--lang must be " ++ showAvailLangs "or" ++ ".")-	| prec < 1 || prec > 60		= Left "--prec must be 1 < prec < 60."+	| prec < 1 || prec > 60		= Left "--prec must be in [1..60]." 	| not (checkTimeOk time)	= Left "--time must be given as HH:MM, where HH is in [0..23] and MM is in [0..59]."-	| style `notElem` [1, 2]	= Left "--style must be either 1 or 2 (see the man page)."+	| style < 1 || style > 3	= Left "--style must be in [1..3] (see the man page)." 	| otherwise					= Right c  checkFTConf t@(TimerConf end lang now)@@ -193,7 +199,7 @@   -- | \[config] Check that a string is a properly formatted time (HH:MM).-checkTimeOk :: String -> Bool+checkTimeOk :: Time -> Bool checkTimeOk time = case break (== ':') time of 	(hh, _:mm)	->	not (null hh || null mm) 					&& all isDigit hh && all isDigit mm@@ -202,6 +208,15 @@ 	_			->	False  +-- other --------------------------------------------------------------------------------------------------------------------------------------------------------------------------+++exitWithError :: String -> IO ()+exitWithError error = do+	putStrLn error+	exitFailure++ -- main ===========================================================================================================================================================================  @@ -215,29 +230,40 @@ 	timerConf <- getDefTimerConf 	conf <- cmdArgs (modes [clockConf, timerConf] &= program confHelpProgram &= summary confHelpSummary) 	case conf of-		-- Showing the time mode.-		cc@(ClockConf _ _ _ _ _)-			->	do-				let realConf = if end timerConf == "empty" then-									conf-									else-									timerConf {-										  lang	= lang conf-										, now	= time conf-									}-				case checkFTConf realConf of-					Left e	-> putStrLn e-					Right c	-> print $ toFuzzyTime c-		-- Setting the timer mode.-		tc@(TimerConf end _ _)-			->	do-				path <- confTimerFileLoc-				case checkFTConf tc of-					Left e	-> 	putStrLn e-					Right c	->	do-								removeFile path `catch` (\_ -> putStrLn "Timer is not set.")-								if end == "unset" then-									putStrLn "Timer has been unset."-									else do-									writeFile path end-									putStrLn $ "Timer has been set to " ++ end ++ "."+		cc@(ClockConf _ _ _ _ _)	-> runModeShow $ if end timerConf == "empty" then+														conf+														else+														timerConf {+															lang = lang conf,+															now = time conf+														}+		tc@(TimerConf _ _ _)		-> runModeTimer tc+++-- modes --------------------------------------------------------------------------------------------------------------------------------------------------------------------------+++-- | The time-showing mode.+runModeShow :: FuzzyTimeConf -> IO ()+runModeShow conf =+	case checkFTConf conf of+		Left e	->	exitWithError e+		Right c	->	do+					let time = toFuzzyTime c+					when (isTimerZero time) (do system confTimerSoundCmd; return ())+					print time+++-- | The timer-setting mode.+runModeTimer :: FuzzyTimeConf -> IO ()+runModeTimer conf@(TimerConf end _ _) =+	case checkFTConf conf of+		Left e	-> 	exitWithError e+		Right c	->	do+					path <- confTimerFileLoc+					removeFile path `catch` (\_ -> return ())+					if end == "unset" then+						putStrLn "Timer has been unset."+						else do+						writeFile path end+						putStrLn $ "Timer has been set to " ++ end ++ "."