Guest User

Untitled

a guest
Oct 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. {-# LANGUAGE OverloadedStrings #-}
  2.  
  3. module Main where
  4.  
  5. import Data.ByteString (ByteString)
  6. import qualified Data.ByteString.Char8 as BS
  7. import Data.ByteString.Lazy.Char8 ()
  8. import Text.Regex.Posix
  9. import Control.Applicative ((<$>))
  10.  
  11. matcher :: ByteString -> ByteString -> Maybe (ByteString, ByteString, ByteString, [ByteString])
  12. matcher = (=~~)
  13.  
  14. colorize :: ByteString -> ByteString
  15. colorize bs = case bs `matcher` "(HTTP/1..\" )([2345][0-9][0-9])" of
  16. Nothing -> bs
  17. Just (bef, mat, aft, (http:code:_)) ->
  18. BS.concat [bef, http, color, code, "\x1b[0m", aft]
  19. where color = case BS.head code of
  20. '2' -> "\x1b[34m"
  21. '3' -> "\x1b[32m"
  22. '4' -> "\x1b[33m"
  23. '5' -> "\x1b[31m"
  24.  
  25. main :: IO ()
  26. main = BS.getContents >>=
  27. return . map colorize . BS.lines >>=
  28. mapM_ BS.putStrLn
Add Comment
Please, Sign In to add comment