diff options
author | Andrew Cady <d@cryptonomic.net> | 2022-09-19 11:27:03 -0400 |
---|---|---|
committer | Andrew Cady <d@cryptonomic.net> | 2022-09-19 11:27:03 -0400 |
commit | 2b9a253814de4184d4144600210d5c87b0835acb (patch) | |
tree | cc33c1b713eaf0c4c55056a2a526d94ddf556b81 | |
parent | 3bdc6b3a2d53340ad8205756d6e342c6b67a28d4 (diff) |
hide cosmic conversion table by default (press c to toggle)
-rwxr-xr-x | countdown.hs | 26 |
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 | ||
78 | makeLenses ''St | 79 | makeLenses ''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 | ||
115 | showTime' :: Bool -> NominalDiffTime -> String | ||
116 | showTime' True 1 = printf "%-3s second" ("1" :: Text) | ||
117 | showTime' True t | t < 60 = printf "%.1f seconds" (realToFrac t :: Float) | ||
118 | showTime' _ t = showTime t | ||
119 | |||
114 | showTime :: NominalDiffTime -> String | 120 | showTime :: NominalDiffTime -> String |
115 | showTime t | t < 1 = printf "%.3f seconds" (realToFrac t :: Float) | 121 | showTime t | t < 1 = printf "%.3f seconds" (realToFrac t :: Float) |
116 | showTime t | t == 1 = "1 second" | 122 | showTime 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) | ||
119 | showTime t | t < 60 = printf "%.1f seconds" (realToFrac t :: Float) | 124 | showTime t | t < 60 = printf "%.1f seconds" (realToFrac t :: Float) |
120 | showTime t | t == 60 = formatTime defaultTimeLocale "%M minute" t | 125 | showTime t | t == 60 = formatTime defaultTimeLocale "%M minute" t |
121 | showTime t | t < 60*2 = formatTime defaultTimeLocale "%M minute %Ss" t | 126 | showTime 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 | |||
129 | showTime t | t == 60*60*24*7 = formatTime defaultTimeLocale "%d days" t | 134 | showTime t | t == 60*60*24*7 = formatTime defaultTimeLocale "%d days" t |
130 | showTime t | t < 60*60*24*10 = formatTime defaultTimeLocale "%d days %Hh" t | 135 | showTime t | t < 60*60*24*10 = formatTime defaultTimeLocale "%d days %Hh" t |
131 | showTime t = formatTime defaultTimeLocale "%d days" t | 136 | showTime 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 | ||
134 | yearsToCosmicTime :: Integral i => i -> NominalDiffTime | 139 | yearsToCosmicTime :: Integral i => i -> NominalDiffTime |
135 | yearsToCosmicTime = (/ (realToFrac ageOfUniverseInYears)) . (* lengthOfYear) . realToFrac | 140 | yearsToCosmicTime = (/ (realToFrac ageOfUniverseInYears)) . (* lengthOfYear) . realToFrac |
@@ -189,8 +194,8 @@ showLarge n | n >= 10 * 1000 = printf "%.0f thousand" (n / 1000) | |||
189 | showLarge n | n >= 10 = unpack $ commasF 0 n | 194 | showLarge n | n >= 10 = unpack $ commasF 0 n |
190 | showLarge n = printf "%.3f" n | 195 | showLarge n = printf "%.3f" n |
191 | 196 | ||
192 | countdownWidget :: Bool -> LocalTime -> Widget n | 197 | countdownWidget :: Bool -> Bool -> LocalTime -> Widget n |
193 | countdownWidget isSimulated t = | 198 | countdownWidget 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 | ||
444 | daysInYear :: LocalTime -> Int | 454 | daysInYear :: LocalTime -> Int |