{-# LANGUAGE OverloadedStrings #-}
module ITermShow
( displayImage
, displayImageBuilder
, displayImageString
) where
import qualified Data.ByteString.Lazy.Char8 as LB
import qualified Data.ByteString.Lazy.Builder as LB
import qualified Data.ByteString.Base64.Lazy as LB64
displayImageBuilder :: LB.ByteString -> LB.Builder
displayImageBuilder bs = mconcat
[ LB.byteString "\x1b]1337;File=inline=1:"
, LB.lazyByteString $ LB64.encode bs
, LB.byteString "\x07"
]
displayImage :: LB.ByteString -> LB.ByteString
displayImage = LB.toLazyByteString . displayImageBuilder
displayImageString :: LB.ByteString -> String
displayImageString = LB.unpack . displayImage