summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-06-26 14:06:54 +0200
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-06-26 14:06:54 +0200
commit9ef12374ecf08d052ac8cf24c0f5c8b47d016e3c (patch)
tree1c8ef1046da3e495bc7ed078db572dca6d0a3f46
parentcec7e775320343b49024c1c03cc19b5e7366d034 (diff)
download2017-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
-rw-r--r--src/Main.hs11
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
35import Data.Maybe 35import Data.Maybe
36import Data.Bool 36import Data.Bool
37import Data.Monoid (All(..)) 37import Data.Monoid (All(..))
38import Data.Ord
38 39
39import Data.Foldable (toList) 40import Data.Foldable (toList)
40 41
@@ -376,4 +377,12 @@ dumpLog = use gLog >>= mapMOf (each . _1) toName >>= shellPutStrLn . toTable
376printVal :: Completable (Formula Stats) -> Sh GameState () 377printVal :: Completable (Formula Stats) -> Sh GameState ()
377printVal = withArg $ \formula -> withFocus $ \focusId -> do 378printVal = 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