packages feed

iterm-show (empty) → 0.1.0.0

raw patch · 6 files changed

+120/−0 lines, 6 filesdep +basedep +base64-bytestringdep +bytestringsetup-changed

Dependencies added: base, base64-bytestring, bytestring, iterm-show

Files

+ ChangeLog.md view
@@ -0,0 +1,7 @@+# Revision history for iterm-show++## 0.1.0.0  -- 2018-10-10++* Introducing iterm-show, a library for displaying documents inline in+  some terminals.+* Includes it2-show commandline utility for displaying documents inline.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2018, Luke Clifton++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Luke Clifton nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ it2-show.hs view
@@ -0,0 +1,12 @@+module Main where++import ITermShow+import System.Environment (getArgs)+import qualified Data.ByteString.Lazy as B+import Control.Monad++main :: IO ()+main = getArgs >>= mapM_ showFile++showFile :: FilePath -> IO ()+showFile f = B.readFile f >>= B.putStr . displayImage
+ iterm-show.cabal view
@@ -0,0 +1,38 @@+-- Initial iterm-show.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++name:                iterm-show+version:             0.1.0.0+synopsis:            Enable graphical display of images inline on some terminals+description:         Enable graphical display of images inline on some terminals.+homepage:            https://github.com/luke-clifton/iterm-show+license:             BSD3+license-file:        LICENSE+author:              Luke Clifton+maintainer:          lukec@themk.net+copyright:           (c) 2018 Luke Clifton+category:            Development+build-type:          Simple+extra-source-files:  ChangeLog.md+cabal-version:       >=1.10+source-repository head+  type: git+  location: https://github.com/luke-clifton/iterm-show++library+  exposed-modules:     ITermShow+  other-extensions:    OverloadedStrings+  build-depends:+    base >= 4.9 && < 4.13,+    bytestring,+    base64-bytestring+  hs-source-dirs:      src+  default-language:    Haskell2010++executable it2-show+  build-depends:+    base >= 4.9 && < 4.13,+    bytestring,+    iterm-show+  main-is: it2-show.hs+  default-language: Haskell2010
+ src/ITermShow.hs view
@@ -0,0 +1,31 @@+{-# 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++-- | Wrap and transform a bytestring representing the encoding of+-- a file that iTerm understands how to display such that iTerm+-- will display it when the resulting bytestring is printed to the+-- terminal.+displayImageBuilder :: LB.ByteString -> LB.Builder+displayImageBuilder bs = mconcat+    [ LB.byteString "\x1b]1337;File=inline=1:"+    , LB.lazyByteString $ LB64.encode bs+    , LB.byteString "\x07"+    ]++-- | Convinience wrapper around displayImageBuilder+displayImage :: LB.ByteString -> LB.ByteString+displayImage = LB.toLazyByteString . displayImageBuilder++-- | Convinience wrapper around displayImageBuilder. Useful for `Show`+-- instances.+displayImageString :: LB.ByteString -> String+displayImageString = LB.unpack . displayImage+