Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE OverloadedStrings #-}
- module Main where
- import Data.ByteString (ByteString)
- import qualified Data.ByteString.Char8 as BS
- import Data.ByteString.Lazy.Char8 ()
- import Text.Regex.Posix
- import Control.Applicative ((<$>))
- matcher :: ByteString -> ByteString -> Maybe (ByteString, ByteString, ByteString, [ByteString])
- matcher = (=~~)
- colorize :: ByteString -> ByteString
- colorize bs = case bs `matcher` "(HTTP/1..\" )([2345][0-9][0-9])" of
- Nothing -> bs
- Just (bef, mat, aft, (http:code:_)) ->
- BS.concat [bef, http, color, code, "\x1b[0m", aft]
- where color = case BS.head code of
- '2' -> "\x1b[34m"
- '3' -> "\x1b[32m"
- '4' -> "\x1b[33m"
- '5' -> "\x1b[31m"
- main :: IO ()
- main = BS.getContents >>=
- return . map colorize . BS.lines >>=
- mapM_ BS.putStrLn
Add Comment
Please, Sign In to add comment