Skip to content

Instantly share code, notes, and snippets.

@ryo1kato
Created August 15, 2014 15:32
Show Gist options
  • Select an option

  • Save ryo1kato/a28b579c05a2c621ff51 to your computer and use it in GitHub Desktop.

Select an option

Save ryo1kato/a28b579c05a2c621ff51 to your computer and use it in GitHub Desktop.
highlightRange
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