summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-09-15 21:04:32 -0400
committerAndrew Cady <d@cryptonomic.net>2022-09-15 21:04:32 -0400
commitb780b57488c5caf277609880f9a6e62f4a38de9b (patch)
tree8e2b6a770f9733730ec14687f8021bdc18e4e136
parent99196ea09ccc07574c3b1233d7885fbc1f934d5f (diff)
add cosmic conversion table
-rwxr-xr-xcountdown.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/countdown.hs b/countdown.hs
index e2a667e..1cf7a55 100755
--- a/countdown.hs
+++ b/countdown.hs
@@ -53,6 +53,7 @@ import Brick.Widgets.Core
53import Brick.AttrMap as A 53import Brick.AttrMap as A
54import Brick.Util (fg, bg, on, clamp) 54import Brick.Util (fg, bg, on, clamp)
55import Brick.Widgets.Core 55import Brick.Widgets.Core
56import Brick.Widgets.Table
56 57
57billion :: Integer 58billion :: Integer
58billion = 1000 * 1000 * 1000 59billion = 1000 * 1000 * 1000
@@ -135,6 +136,28 @@ drawUI st = [a]
135 136
136printRemain unit quantity = printf "%d %s%s remain%s" 137printRemain unit quantity = printf "%d %s%s remain%s"
137 138
139showTime :: NominalDiffTime -> String
140showTime t | t < 1 = printf "%.3f seconds" (realToFrac t :: Float)
141showTime t | t == 1 = "1 second"
142-- showTime t | t < 10 = formatTime defaultTimeLocale "%2Es seconds" t -- BUG! Doesn't respect <width> parameter at all!
143showTime t | t < 10 = printf "%.2f seconds" (realToFrac t :: Float)
144showTime t | t < 60 = printf "%.1f seconds" (realToFrac t :: Float)
145showTime t | t == 60 = formatTime defaultTimeLocale "%M minute" t
146showTime t | t < 60*10 = formatTime defaultTimeLocale "%M minutes %Ss" t
147showTime t | t < 60*60 = formatTime defaultTimeLocale "%M minutes" t
148showTime t | t == 60*60 = "1 hour"
149showTime t | t < 60*60*2 = formatTime defaultTimeLocale "%H hour %Mm" t
150showTime t | t < 60*60*24 = formatTime defaultTimeLocale "%H hours %Mm" t
151showTime t | t < 60*60*24*2 = formatTime defaultTimeLocale "%d day %Hh" t
152showTime t | t < 60*60*24*10 = formatTime defaultTimeLocale "%d days %Hh" t
153showTime t = formatTime defaultTimeLocale "%d days" t
154-- showTime t = formatTime defaultTimeLocale "%w weeks %D days" t
155
156yearsToCosmicTime :: Integral i => i -> NominalDiffTime
157yearsToCosmicTime = (/ (realToFrac ageOfUniverseInYears)) . (* lengthOfYear) . realToFrac
158
159showCosmicYears = str . showTime . yearsToCosmicTime
160
138countdownWidget :: Bool -> LocalTime -> Widget n 161countdownWidget :: Bool -> LocalTime -> Widget n
139countdownWidget isSimulated (truncateTime -> t) = 162countdownWidget isSimulated (truncateTime -> t) =
140 (hCenter (borderWithLabel (str $ printf "Current time%s" (if isSimulated then " (SIMULATED)" else "")) $ 163 (hCenter (borderWithLabel (str $ printf "Current time%s" (if isSimulated then " (SIMULATED)" else "")) $
@@ -169,6 +192,19 @@ countdownWidget isSimulated (truncateTime -> t) =
169 ]) 192 ])
170 ]) 193 ])
171 <=> 194 <=>
195 (borderWithLabel (str "Cosmic Conversion") $ renderTable $
196 table
197 [
198 [str "1 billion years" , showCosmicYears $ 1000 * 1000 * 1000],
199 [str "100 million years" , showCosmicYears $ 100 * 1000 * 1000],
200 [str "10 million years" , showCosmicYears $ 10 * 1000 * 1000],
201 [str "1 million years" , showCosmicYears $ 1000 * 1000],
202 [str "100 thousand years" , showCosmicYears $ 100 * 1000],
203 [str "10 thousand years" , showCosmicYears $ 10 * 1000],
204 [str "1 thousand years" , showCosmicYears 1000],
205 [str "100 years" , showCosmicYears 100]
206 ])
207 <=>
172 (borderWithLabel (str progressLabel) $ 208 (borderWithLabel (str progressLabel) $
173 updateAttrMap 209 updateAttrMap
174 (A.mapAttrName yDoneAttr P.progressCompleteAttr . 210 (A.mapAttrName yDoneAttr P.progressCompleteAttr .