From 9ef12374ecf08d052ac8cf24c0f5c8b47d016e3c Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 26 Jun 2016 14:06:54 +0200 Subject: prettier printing --- src/Main.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') 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 import Data.Maybe import Data.Bool import Data.Monoid (All(..)) +import Data.Ord import Data.Foldable (toList) @@ -376,4 +377,12 @@ dumpLog = use gLog >>= mapMOf (each . _1) toName >>= shellPutStrLn . toTable printVal :: Completable (Formula Stats) -> Sh GameState () printVal = withArg $ \formula -> withFocus $ \focusId -> do name <- toName focusId - shellPutStrLn . show =<< focusState (gEntities . ix focusId . eStats) (findDistribution' [name] formula) + outline =<< focusState (gEntities . ix focusId . eStats) (findDistribution' [name] formula) + where + outline Nothing = shellPutErrLn "No such value" + outline (Just (Map.toList -> [(v, _)])) = shellPutStrLn $ show v + outline (Just (sortBy (comparing snd) . Map.toList -> vals)) = mapM_ (shellPutStrLn . outline') vals + outline' (v, prob) = pad' 3 (show $ round' prob) ++ " → " ++ show v + round' :: RealFrac a => a -> Float + round' = (/ 10) . fromIntegral . (round :: RealFrac a => a -> Integer) . (* 10) + pad' m ys = replicate (m - length (take m ys)) ' ' ++ ys -- cgit v1.2.3