Created
August 15, 2014 15:32
-
-
Save ryo1kato/a28b579c05a2c621ff51 to your computer and use it in GitHub Desktop.
highlightRange
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import System.Console.ANSI | |
| import qualified Data.ByteString.Lazy.Char8 as BS | |
| import Text.Regex.PCRE | |
| import Text.Regex.PCRE.ByteString | |
| import Data.Int | |
| hlCode = setSGRCode [SetColor Foreground Vivid Red] | |
| hlReset = setSGRCode [Reset] | |
| d = map BS.pack [ | |
| "foo", | |
| "bar", | |
| "baz", | |
| "----", | |
| "hoge", | |
| "piyo" ] | |
| highlightRange :: BS.ByteString -> Int64 -> Int64 -> BS.ByteString | |
| highlightRange str start len = | |
| BS.concat [ (BS.take start str), (BS.pack hlCode) , | |
| (BS.take len $ BS.drop start str), (BS.pack hlReset) , | |
| (BS.drop (start+len) str)] | |
| main = BS.putStrLn $ highlightRange (BS.concat d) 6 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment