summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-09-19 11:27:03 -0400
committerAndrew Cady <d@cryptonomic.net>2022-09-19 11:27:03 -0400
commit2b9a253814de4184d4144600210d5c87b0835acb (patch)
treecc33c1b713eaf0c4c55056a2a526d94ddf556b81
parent3bdc6b3a2d53340ad8205756d6e342c6b67a28d4 (diff)
hide cosmic conversion table by default (press c to toggle)
-rwxr-xr-xcountdown.hs26
1 files changed, 18 insertions, 8 deletions
diff --git a/countdown.hs b/countdown.hs
index f2a41ff..70ecc99 100755
--- a/countdown.hs
+++ b/countdown.hs
@@ -73,6 +73,7 @@ data St =
73 , _stDisplayTime :: LocalTime 73 , _stDisplayTime :: LocalTime
74 , _stNextEvent :: Maybe UTCTime 74 , _stNextEvent :: Maybe UTCTime
75 , _stPaused :: Bool 75 , _stPaused :: Bool
76 , _stShowConversion :: Bool
76 } 77 }
77 78
78makeLenses ''St 79makeLenses ''St
@@ -108,14 +109,18 @@ drawUI st = [a]
108 -- (str $ "Last event: " <> (show $ st ^. stLastBrickEvent)), 109 -- (str $ "Last event: " <> (show $ st ^. stLastBrickEvent)),
109 -- (str "\n"), 110 -- (str "\n"),
110 (str "\n"), 111 (str "\n"),
111 (countdownWidget (isSimulatedTime st) $ st ^. stDisplayTime) 112 (countdownWidget (st ^. stShowConversion) (isSimulatedTime st) $ st ^. stDisplayTime)
112 ] 113 ]
113 114
115showTime' :: Bool -> NominalDiffTime -> String
116showTime' True 1 = printf "%-3s second" ("1" :: Text)
117showTime' True t | t < 60 = printf "%.1f seconds" (realToFrac t :: Float)
118showTime' _ t = showTime t
119
114showTime :: NominalDiffTime -> String 120showTime :: NominalDiffTime -> String
115showTime t | t < 1 = printf "%.3f seconds" (realToFrac t :: Float) 121showTime t | t < 1 = printf "%.3f seconds" (realToFrac t :: Float)
116showTime t | t == 1 = "1 second" 122showTime t | t == 1 = "1 second"
117-- showTime t | t < 10 = formatTime defaultTimeLocale "%2Es seconds" t -- BUG! Doesn't respect <width> parameter at all! 123-- showTime t | t < 10 = formatTime defaultTimeLocale "%2Es seconds" t -- BUG! Doesn't respect <width> parameter at all!
118-- showTime t | t < 10 = printf "%.2f seconds" (realToFrac t :: Float)
119showTime t | t < 60 = printf "%.1f seconds" (realToFrac t :: Float) 124showTime t | t < 60 = printf "%.1f seconds" (realToFrac t :: Float)
120showTime t | t == 60 = formatTime defaultTimeLocale "%M minute" t 125showTime t | t == 60 = formatTime defaultTimeLocale "%M minute" t
121showTime t | t < 60*2 = formatTime defaultTimeLocale "%M minute %Ss" t 126showTime t | t < 60*2 = formatTime defaultTimeLocale "%M minute %Ss" t
@@ -129,7 +134,7 @@ showTime t | t < 60*60*24*2 = formatTime defaultTimeLocale "%d day %Hh" t
129showTime t | t == 60*60*24*7 = formatTime defaultTimeLocale "%d days" t 134showTime t | t == 60*60*24*7 = formatTime defaultTimeLocale "%d days" t
130showTime t | t < 60*60*24*10 = formatTime defaultTimeLocale "%d days %Hh" t 135showTime t | t < 60*60*24*10 = formatTime defaultTimeLocale "%d days %Hh" t
131showTime t = formatTime defaultTimeLocale "%d days" t 136showTime t = formatTime defaultTimeLocale "%d days" t
132-- showTime t = formatTime defaultTimeLocale "%w weeks %D days" t 137-- showTime _ t = formatTime defaultTimeLocale "%w weeks %D days" t
133 138
134yearsToCosmicTime :: Integral i => i -> NominalDiffTime 139yearsToCosmicTime :: Integral i => i -> NominalDiffTime
135yearsToCosmicTime = (/ (realToFrac ageOfUniverseInYears)) . (* lengthOfYear) . realToFrac 140yearsToCosmicTime = (/ (realToFrac ageOfUniverseInYears)) . (* lengthOfYear) . realToFrac
@@ -189,8 +194,8 @@ showLarge n | n >= 10 * 1000 = printf "%.0f thousand" (n / 1000)
189showLarge n | n >= 10 = unpack $ commasF 0 n 194showLarge n | n >= 10 = unpack $ commasF 0 n
190showLarge n = printf "%.3f" n 195showLarge n = printf "%.3f" n
191 196
192countdownWidget :: Bool -> LocalTime -> Widget n 197countdownWidget :: Bool -> Bool -> LocalTime -> Widget n
193countdownWidget isSimulated t = 198countdownWidget showConversion isSimulated t =
194 (border $ vBox [ 199 (border $ vBox [
195 (hCenter $ hBox 200 (hCenter $ hBox
196 [ countdownBox 201 [ countdownBox
@@ -216,8 +221,11 @@ countdownWidget isSimulated t =
216 else 221 else
217 borderWithLabel (txt "Next on the Cosmic Calendar") nextEntry, 222 borderWithLabel (txt "Next on the Cosmic Calendar") nextEntry,
218 -- vBox [ cosmicCalendarCurrent, txt "\n", cosmicCalendarNext ], 223 -- vBox [ cosmicCalendarCurrent, txt "\n", cosmicCalendarNext ],
219 str " ", 224 if showConversion
220 borderWithLabel (str "Cosmic Conversion") (hBox [cosmicConversion, cosmicConversion']) 225 then
226 str " " <=> borderWithLabel (str "Cosmic Conversion") (hBox [cosmicConversion, cosmicConversion'])
227 else
228 str ""
221 ]) 229 ])
222 where 230 where
223 -- TODO: We want to display "today" or "now" on the cosmic calendar; 231 -- TODO: We want to display "today" or "now" on the cosmic calendar;
@@ -406,6 +414,7 @@ handleEvent chan st e =
406 VtyEvent (V.EvKey V.KEnd []) -> cont $ st & stDisplayTime .~ (newYearsEveLast10 $ st ^. stClockTime) 414 VtyEvent (V.EvKey V.KEnd []) -> cont $ st & stDisplayTime .~ (newYearsEveLast10 $ st ^. stClockTime)
407 VtyEvent (V.EvKey V.KEnd [MShift]) -> cont $ st & stDisplayTime .~ (yearEnd $ st ^. stClockTime) 415 VtyEvent (V.EvKey V.KEnd [MShift]) -> cont $ st & stDisplayTime .~ (yearEnd $ st ^. stClockTime)
408 VtyEvent (V.EvKey V.KEnd [MCtrl]) -> cont $ st & stDisplayTime .~ (newYearsEveNoon $ st ^. stClockTime) 416 VtyEvent (V.EvKey V.KEnd [MCtrl]) -> cont $ st & stDisplayTime .~ (newYearsEveNoon $ st ^. stClockTime)
417 VtyEvent (V.EvKey (V.KChar 'c') []) -> cont $ st & stShowConversion %~ not
409 VtyEvent (V.EvKey (V.KChar 'p') []) -> cont $ st & stPaused %~ not 418 VtyEvent (V.EvKey (V.KChar 'p') []) -> cont $ st & stPaused %~ not
410 VtyEvent (V.EvKey (V.KChar ',') []) -> cont $ st & stDisplayTime %~ previousCalendarEntryTime 419 VtyEvent (V.EvKey (V.KChar ',') []) -> cont $ st & stDisplayTime %~ previousCalendarEntryTime
411 VtyEvent (V.EvKey (V.KChar '.') []) -> cont $ st & stDisplayTime %~ nextCalendarEntryTime 420 VtyEvent (V.EvKey (V.KChar '.') []) -> cont $ st & stDisplayTime %~ nextCalendarEntryTime
@@ -439,6 +448,7 @@ initialState t =
439 , _stDisplayTime = t 448 , _stDisplayTime = t
440 , _stNextEvent = Nothing 449 , _stNextEvent = Nothing
441 , _stPaused = False 450 , _stPaused = False
451 , _stShowConversion = False
442 } 452 }
443 453
444daysInYear :: LocalTime -> Int 454daysInYear :: LocalTime -> Int