-
Notifications
You must be signed in to change notification settings - Fork 4
/
pour.hs
72 lines (60 loc) · 1.86 KB
/
pour.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import System.Environment (getArgs)
import Data.List
import Data.List.Split
import Control.Monad
import System.Console.ANSI
import Juicer.Freeze
import Juicer.Puree
main :: IO()
main = do
args <- getArgs
case args of
(archivename:[]) -> do
maybeArchive <- thaw archivename
case maybeArchive of
Nothing -> return ()
Just archive -> pour archive
otherwise -> putStrLn "pour [archive]"
pour :: Feed -> IO ()
pour (Feed (Channel title desc) posts) = do
channelTitleStyle
putStrLn title
channelDescStyle
putStrLn desc
textStyle
putStrLn "---------------------------------------------------"
mapM_ showPost posts
textStyle
showPost :: Metapost -> IO()
showPost (Metapost _ (Post title desc)) = do
titleStyle
putStrLn title
textStyle
showContent desc
putStrLn ""
showContent :: Content -> IO()
showContent (Content elements) = do
mapM_ showElement elements
putStrLn ""
showElement :: Element -> IO()
showElement (Text s) = do
textStyle
putStr s
showElement (Link title maybeHref) = do
linkStyle
putStr title
showElement (Image link maybeHeight maybeWidth) = do
imageStyle
putStr link
channelTitleStyle :: IO()
channelTitleStyle = setSGR [SetConsoleIntensity BoldIntensity, SetColor Foreground Dull Green]
channelDescStyle :: IO()
channelDescStyle = setSGR [SetConsoleIntensity BoldIntensity, SetColor Foreground Dull Magenta]
titleStyle :: IO()
titleStyle = setSGR [SetConsoleIntensity BoldIntensity, SetColor Foreground Vivid Blue]
textStyle :: IO()
textStyle = setSGR [SetConsoleIntensity NormalIntensity, SetColor Foreground Dull White]
linkStyle :: IO()
linkStyle = setSGR [SetConsoleIntensity NormalIntensity, SetColor Foreground Dull Red]
imageStyle :: IO()
imageStyle = setSGR [SetConsoleIntensity NormalIntensity, SetColor Foreground Dull Blue]