diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/Main.hs | 16 | ||||
| -rw-r--r-- | app/Pretty.hs | 85 | ||||
| -rw-r--r-- | app/Sensor.hs | 6 |
3 files changed, 55 insertions, 52 deletions
diff --git a/app/Main.hs b/app/Main.hs index 25a3c97..fd4dc2f 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -200,14 +200,14 @@ createWindow args = do intercalate [pure (lit " ")] $ [ [lit <$> wmWorkspaces], [litShrink <$> wmName, pure fill], - [pure (lit (if args.icons then "\xf4bc " else "cpu ")), lit <$> cpu], - [pure (lit (if args.icons then "\xf035b " else "mem ")), lit <$> mem], - [pure (lit (if args.icons then "\xf0a0 " else "disk ")), lit <$> disk], - [pure (lit (if args.icons then "\xf1638 " else "io ")), lit <$> io], - [pure (lit (if args.icons then "\xf0200 " else "net ")), lit <$> net], - [pure (lit " "), lit <$> Sensor.snd, pure (lit " ")], - [pure (lit (if args.icons then "\xf2cb " else "temp ")), lit <$> thermal], - [pure (lit " "), lit <$> bat], + [pure (lit (if args.icons then "\xf4bc " else "cpu")), lit <$> cpu], + [pure (lit (if args.icons then "\xf035b " else "mem")), lit <$> mem], + [pure (lit (if args.icons then "\xf0a0 " else "disk")), lit <$> disk], + [pure (lit (if args.icons then "\xf1638 " else "io")), lit <$> io], + [pure (lit (if args.icons then "\xf0200 " else "net")), lit <$> net], + [pure (lit (if args.icons then "\xf2cb" else "temp")), lit <$> thermal], + [lit <$> bat], + [lit <$> Sensor.snd], -- [lit <$> weatherForecast], [pure (lit " "), lit <$> date, pure (lit ", "), lit <$> time] ] diff --git a/app/Pretty.hs b/app/Pretty.hs index 8101fb7..b55cf8a 100644 --- a/app/Pretty.hs +++ b/app/Pretty.hs @@ -16,8 +16,10 @@ module Pretty where import Control.DeepSeq +import Data.List.Split import GHC.Generics (Generic) import Pretty.Color +import Text.Printf data Doc = Col [Doc] @@ -57,54 +59,55 @@ diagram :: Int -> a -> Diagram a diagram = Diagram instance Pretty (Diagram [Float]) where - pretty (Diagram ((2 *) -> n) (take n -> xs)) = Col (map chart (discretize xs')) + pretty (Diagram n (take n -> xs)) = + Col (map (\c -> colorize c (Lit Nothing (plot c))) (mapFirst tail (chunksOf 2 (map discretize (0 : xs'))))) where xs' = replicate (n - length xs) 0 ++ xs - chart :: (Int, Int) -> Doc - chart n = colorize n (pretty (chart' n)) - - chart' (0, 0) = '⠀' - chart' (0, 1) = '⢀' - chart' (0, 2) = '⢠' - chart' (0, 3) = '⢰' - chart' (0, 4) = '⢸' - chart' (1, 0) = '⡀' - chart' (1, 1) = '⣀' - chart' (1, 2) = '⣠' - chart' (1, 3) = '⣰' - chart' (1, 4) = '⣸' - chart' (2, 0) = '⡄' - chart' (2, 1) = '⣄' - chart' (2, 2) = '⣤' - chart' (2, 3) = '⣴' - chart' (2, 4) = '⣼' - chart' (3, 0) = '⡆' - chart' (3, 1) = '⣆' - chart' (3, 2) = '⣦' - chart' (3, 3) = '⣶' - chart' (3, 4) = '⣾' - chart' (4, 0) = '⡇' - chart' (4, 1) = '⣇' - chart' (4, 2) = '⣧' - chart' (4, 3) = '⣷' - chart' (4, 4) = '⣿' - chart' x = error (show x) - - colorize (n, m) = colorize' (max n m) - - colorize' 0 = colorDull Green + mapFirst f (x : xs) = f x : xs + + plot [n, m] = chart (max 1 n, max 1 m) + plot [m] = chart (0, max 1 m) + + colorize [n, m] = colorize' (max n m) + colorize [m] = colorize' m + + colorize' 0 = color Black colorize' 1 = color Green colorize' 2 = colorDull Yellow colorize' 3 = color Yellow colorize' 4 = color Red - colorize' x = error (show x) - - discretize :: [Float] -> [(Int, Int)] - discretize [] = [] - discretize (_ : []) = [] - discretize (x1 : x2 : xs) = - (round (x1 * 4), round (x2 * 4)) : discretize xs + colorize' x = error (printf "Pretty.pretty.colorize': %d" x) + + chart (0, 0) = " " + chart (0, 1) = "⢀" + chart (0, 2) = "⢠" + chart (0, 3) = "⢰" + chart (0, 4) = "⢸" + chart (1, 0) = "⡀" + chart (1, 1) = "⣀" + chart (1, 2) = "⣠" + chart (1, 3) = "⣰" + chart (1, 4) = "⣸" + chart (2, 0) = "⡄" + chart (2, 1) = "⣄" + chart (2, 2) = "⣤" + chart (2, 3) = "⣴" + chart (2, 4) = "⣼" + chart (3, 0) = "⡆" + chart (3, 1) = "⣆" + chart (3, 2) = "⣦" + chart (3, 3) = "⣶" + chart (3, 4) = "⣾" + chart (4, 0) = "⡇" + chart (4, 1) = "⣇" + chart (4, 2) = "⣧" + chart (4, 3) = "⣷" + chart (4, 4) = "⣿" + chart x = error (printf "Pretty.pretty.chart: %x" (show x)) + + discretize :: Float -> Int + discretize x = round (x * 4) color :: Color -> Doc -> Doc color c = color' (Vivid, c) diff --git a/app/Sensor.hs b/app/Sensor.hs index de14783..be11e2f 100644 --- a/app/Sensor.hs +++ b/app/Sensor.hs @@ -112,12 +112,12 @@ cpu = step <$$> diagram 3 cpuStat diagram :: Int -> S.Sensor () a -> S.Sensor () (P.Diagram [a]) diagram n sf = S.feedbackS [] $ proc ((), xs) -> do x <- sf -< () - returnA -< (P.diagram n (reverse (x : xs)), take (2 * (n - 1) + 1) (x : xs)) + returnA -< (P.diagram n (reverse (take n (x : xs))), take n (x : xs)) thermal :: S.Sensor () (P.Diagram [Float]) thermal = ((\x -> clamp 0 1 (x / 100)) <$$$>) $ - diagram 1 $ + diagram 3 $ S.sensor (\() -> "thermal") $ \() yield -> forever do yield =<< parse <* sleep where @@ -363,7 +363,7 @@ diskStat = / fi (stat.statVFS_bfree + stat.statVFS_bavail) disk :: S.Sensor () (P.Diagram [Float]) -disk = diagram 1 diskStat +disk = diagram 3 diskStat data Forecast = Forecast { properties :: ForecastProperties |
