diff options
author | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-06-26 14:06:54 +0200 |
---|---|---|
committer | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-06-26 14:06:54 +0200 |
commit | 9ef12374ecf08d052ac8cf24c0f5c8b47d016e3c (patch) | |
tree | 1c8ef1046da3e495bc7ed078db572dca6d0a3f46 /src | |
parent | cec7e775320343b49024c1c03cc19b5e7366d034 (diff) | |
download | 2017-01-16_17:13:37-9ef12374ecf08d052ac8cf24c0f5c8b47d016e3c.tar 2017-01-16_17:13:37-9ef12374ecf08d052ac8cf24c0f5c8b47d016e3c.tar.gz 2017-01-16_17:13:37-9ef12374ecf08d052ac8cf24c0f5c8b47d016e3c.tar.bz2 2017-01-16_17:13:37-9ef12374ecf08d052ac8cf24c0f5c8b47d016e3c.tar.xz 2017-01-16_17:13:37-9ef12374ecf08d052ac8cf24c0f5c8b47d016e3c.zip |
prettier printing
Diffstat (limited to 'src')
-rw-r--r-- | src/Main.hs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/Main.hs b/src/Main.hs index eeed4d9..169c900 100644 --- a/src/Main.hs +++ b/src/Main.hs | |||
@@ -35,6 +35,7 @@ import Data.List | |||
35 | import Data.Maybe | 35 | import Data.Maybe |
36 | import Data.Bool | 36 | import Data.Bool |
37 | import Data.Monoid (All(..)) | 37 | import Data.Monoid (All(..)) |
38 | import Data.Ord | ||
38 | 39 | ||
39 | import Data.Foldable (toList) | 40 | import Data.Foldable (toList) |
40 | 41 | ||
@@ -376,4 +377,12 @@ dumpLog = use gLog >>= mapMOf (each . _1) toName >>= shellPutStrLn . toTable | |||
376 | printVal :: Completable (Formula Stats) -> Sh GameState () | 377 | printVal :: Completable (Formula Stats) -> Sh GameState () |
377 | printVal = withArg $ \formula -> withFocus $ \focusId -> do | 378 | printVal = withArg $ \formula -> withFocus $ \focusId -> do |
378 | name <- toName focusId | 379 | name <- toName focusId |
379 | shellPutStrLn . show =<< focusState (gEntities . ix focusId . eStats) (findDistribution' [name] formula) | 380 | outline =<< focusState (gEntities . ix focusId . eStats) (findDistribution' [name] formula) |
381 | where | ||
382 | outline Nothing = shellPutErrLn "No such value" | ||
383 | outline (Just (Map.toList -> [(v, _)])) = shellPutStrLn $ show v | ||
384 | outline (Just (sortBy (comparing snd) . Map.toList -> vals)) = mapM_ (shellPutStrLn . outline') vals | ||
385 | outline' (v, prob) = pad' 3 (show $ round' prob) ++ " → " ++ show v | ||
386 | round' :: RealFrac a => a -> Float | ||
387 | round' = (/ 10) . fromIntegral . (round :: RealFrac a => a -> Integer) . (* 10) | ||
388 | pad' m ys = replicate (m - length (take m ys)) ' ' ++ ys | ||