packages feed

text-ansi (empty) → 0.1.0

raw patch · 6 files changed

+454/−0 lines, 6 filesdep +basedep +textdep +text-builder

Dependencies added: base, text, text-builder

Files

+ .travis.yml view
@@ -0,0 +1,107 @@+# This Travis job script has been generated by a script via+#+#   runghc make_travis_yml_2.hs 'text-ansi.cabal'+#+# For more information, see https://github.com/haskell-CI/haskell-ci+#+language: c+sudo: false++git:+  submodules: false  # whether to recursively clone submodules++cache:+  directories:+    - $HOME/.cabal/packages+    - $HOME/.cabal/store++before_cache:+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log+  # remove files that are regenerated by 'cabal update'+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.*+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx++  - rm -rfv $HOME/.cabal/packages/head.hackage++matrix:+  include:+    - compiler: "ghc-8.6.2"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.2], sources: [hvr-ghc]}}+    - compiler: "ghc-8.4.4"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.4], sources: [hvr-ghc]}}+    - compiler: "ghc-8.2.2"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.2.2], sources: [hvr-ghc]}}++before_install:+  - HC=${CC}+  - HCPKG=${HC/ghc/ghc-pkg}+  - unset CC+  - ROOTDIR=$(pwd)+  - mkdir -p $HOME/.local/bin+  - "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH"+  - HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') ))+  - echo $HCNUMVER++install:+  - cabal --version+  - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"+  - BENCH=${BENCH---enable-benchmarks}+  - TEST=${TEST---enable-tests}+  - HADDOCK=${HADDOCK-true}+  - UNCONSTRAINED=${UNCONSTRAINED-true}+  - NOINSTALLEDCONSTRAINTS=${NOINSTALLEDCONSTRAINTS-false}+  - GHCHEAD=${GHCHEAD-false}+  - travis_retry cabal update -v+  - "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config"+  - rm -fv cabal.project cabal.project.local+  - grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$'+  - "printf 'packages: \".\"\\n' > cabal.project"+  - touch cabal.project.local+  - "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg  | grep -vw -- text-ansi | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi"+  - cat cabal.project || true+  - cat cabal.project.local || true+  - if [ -f "./configure.ac" ]; then+      (cd "." && autoreconf -i);+    fi+  - rm -f cabal.project.freeze+  - cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all+  - cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2 all+  - rm -rf .ghc.environment.* "."/dist+  - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)++# Here starts the actual work to be performed for the package under test;+# any command which exits with a non-zero exit code causes the build to fail.+script:+  # test that source-distributions can be generated+  - cabal new-sdist all+  - mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/+  - cd ${DISTDIR} || false+  - find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;+  - "printf 'packages: text-ansi-*/*.cabal\\n' > cabal.project"+  - touch cabal.project.local+  - "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg  | grep -vw -- text-ansi | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi"+  - cat cabal.project || true+  - cat cabal.project.local || true+  # this builds all libraries and executables (without tests/benchmarks)+  - cabal new-build -w ${HC} --disable-tests --disable-benchmarks all++  # build & run tests, build benchmarks+  - cabal new-build -w ${HC} ${TEST} ${BENCH} all++  # cabal check+  - (cd text-ansi-* && cabal check)++  # haddock+  - if $HADDOCK; then cabal new-haddock -w ${HC} ${TEST} ${BENCH} all; else echo "Skipping haddock generation";fi++  # Build without installed constraints for packages in global-db+  - if $UNCONSTRAINED; then rm -f cabal.project.local; echo cabal new-build -w ${HC} --disable-tests --disable-benchmarks all; else echo "Not building without installed constraints"; fi++# REGENDATA ["text-ansi.cabal"]+# EOF
+ CHANGELOG.md view
@@ -0,0 +1,11 @@+# Changelog++All notable changes to this project will be documented in this file.++The format is based on [Keep a Changelog](http://keepachangelog.com/)+and this project adheres to the [Haskell Package Versioning Policy](https://pvp.haskell.org/).++## [0.1.0] - 2018-11-14++### Added+- Initial release
+ Data/Text/ANSI.hs view
@@ -0,0 +1,275 @@+{-# LANGUAGE OverloadedStrings #-}++module Data.Text.ANSI+  ( -- $intro++    -- * Foreground color+    black+  , red+  , green+  , yellow+  , blue+  , magenta+  , cyan+  , white+  , brightBlack+  , brightRed+  , brightGreen+  , brightYellow+  , brightBlue+  , brightMagenta+  , brightCyan+  , brightWhite+  , rgb++    -- * Background color+  , blackBg+  , redBg+  , greenBg+  , yellowBg+  , blueBg+  , magentaBg+  , cyanBg+  , whiteBg+  , brightBlackBg+  , brightRedBg+  , brightGreenBg+  , brightYellowBg+  , brightBlueBg+  , brightMagentaBg+  , brightCyanBg+  , brightWhiteBg+  , rgbBg++    -- * Style+  , bold+  , faint+  , italic+  , underline+  , doubleUnderline+  , strikethrough+  , frame+  , encircle+  , overline+  ) where++import Data.Semigroup ((<>))+import Data.Text+import Data.Word (Word8)+import Foreign.C (CInt(CInt))+import System.IO.Unsafe (unsafePerformIO)+import Text.Builder (Builder)++import qualified Text.Builder as Builder++-- $intro+--+-- Text styling for ANSI terminals using SGR codes, as defined by the+-- <https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf ECMA-48>+-- standard.+--+-- Supports foreground\/background color, bold\/faint intensity, italic,+-- single\/double underline, strikethrough, frame, encircle, and overline escape+-- sequences. Some styles may not work on your terminal.+--+-- Also features terminal detection, so redirecting styled output to a file will+-- automatically strip the ANSI escape sequences.++{-# INLINABLE black           #-}+{-# INLINABLE red             #-}+{-# INLINABLE green           #-}+{-# INLINABLE yellow          #-}+{-# INLINABLE blue            #-}+{-# INLINABLE magenta         #-}+{-# INLINABLE cyan            #-}+{-# INLINABLE white           #-}+{-# INLINABLE brightBlack     #-}+{-# INLINABLE brightRed       #-}+{-# INLINABLE brightGreen     #-}+{-# INLINABLE brightYellow    #-}+{-# INLINABLE brightBlue      #-}+{-# INLINABLE brightMagenta   #-}+{-# INLINABLE brightCyan      #-}+{-# INLINABLE brightWhite     #-}+{-# INLINABLE blackBg         #-}+{-# INLINABLE redBg           #-}+{-# INLINABLE greenBg         #-}+{-# INLINABLE yellowBg        #-}+{-# INLINABLE blueBg          #-}+{-# INLINABLE magentaBg       #-}+{-# INLINABLE cyanBg          #-}+{-# INLINABLE whiteBg         #-}+{-# INLINABLE brightBlackBg   #-}+{-# INLINABLE brightRedBg     #-}+{-# INLINABLE brightGreenBg   #-}+{-# INLINABLE brightYellowBg  #-}+{-# INLINABLE brightBlueBg    #-}+{-# INLINABLE brightMagentaBg #-}+{-# INLINABLE brightCyanBg    #-}+{-# INLINABLE brightWhiteBg   #-}++black, red, green, yellow, blue, magenta, cyan, white, brightBlack, brightRed,+  brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan,+  brightWhite, blackBg, redBg, greenBg,+  yellowBg, blueBg, magentaBg, cyanBg,+  whiteBg, brightBlackBg, brightRedBg,+  brightGreenBg, brightYellowBg, brightBlueBg,+  brightMagentaBg, brightCyanBg,+  brightWhiteBg :: Text -> Text++-- | Black foreground.+black           = surround "30"  "39"+-- | Red foreground.+red             = surround "31"  "39"+-- | Green foreground.+green           = surround "32"  "39"+-- | Yellow foreground.+yellow          = surround "33"  "39"+-- | Blue foreground.+blue            = surround "34"  "39"+-- | Magenta foreground.+magenta         = surround "35"  "39"+-- | Cyan foreground.+cyan            = surround "36"  "39"+-- | White foreground.+white           = surround "37"  "39"+-- | Bright black foreground.+brightBlack     = surround "90"  "39"+-- | Bright red foreground.+brightRed       = surround "91"  "39"+-- | Bright green foreground.+brightGreen     = surround "92"  "39"+-- | Bright yellow foreground.+brightYellow    = surround "93"  "39"+-- | Bright blue foreground.+brightBlue      = surround "94"  "39"+-- | Bright magenta foreground.+brightMagenta   = surround "95"  "39"+-- | Bright cyan foreground.+brightCyan      = surround "96"  "39"+-- | Bright white foreground.+brightWhite     = surround "97"  "39"+-- | Black background.+blackBg         = surround "40"  "49"+-- | Red background.+redBg           = surround "41"  "49"+-- | Green background.+greenBg         = surround "42"  "49"+-- | Yellow background.+yellowBg        = surround "43"  "49"+-- | Blue background.+blueBg          = surround "44"  "49"+-- | Magenta background.+magentaBg       = surround "45"  "49"+-- | Cyan background.+cyanBg          = surround "46"  "49"+-- | White background.+whiteBg         = surround "47"  "49"+-- | Bright black background.+brightBlackBg   = surround "100" "49"+-- | Bright red background.+brightRedBg     = surround "101" "49"+-- | Bright green background.+brightGreenBg   = surround "102" "49"+-- | Bright yellow background.+brightYellowBg  = surround "103" "49"+-- | Bright blue background.+brightBlueBg    = surround "104" "49"+-- | Bright magenta background.+brightMagentaBg = surround "105" "49"+-- | Bright cyan background.+brightCyanBg    = surround "106" "49"+-- | Bright white background.+brightWhiteBg   = surround "107" "49"++-- | RGB foreground.+{-# INLINABLE rgb #-}+rgb :: Word8 -> Word8 -> Word8 -> Text -> Text+rgb r g b =+  surround+    ("38;2;" <>+     Builder.unsignedDecimal r <>+     semi <>+     Builder.unsignedDecimal g <>+     semi <>+     Builder.unsignedDecimal b)+    "39"++-- | RGB background.+{-# INLINABLE rgbBg #-}+rgbBg :: Word8 -> Word8 -> Word8 -> Text -> Text+rgbBg r g b =+  surround+    ("48;2;" <>+     Builder.unsignedDecimal r <>+     semi <>+     Builder.unsignedDecimal g <>+     semi <>+     Builder.unsignedDecimal b)+    "49"++{-# INLINABLE bold            #-}+{-# INLINABLE faint           #-}+{-# INLINABLE italic          #-}+{-# INLINABLE underline       #-}+{-# INLINABLE doubleUnderline #-}+{-# INLINABLE strikethrough   #-}+{-# INLINABLE frame           #-}+{-# INLINABLE encircle        #-}+{-# INLINABLE overline        #-}++bold, faint, italic, underline, doubleUnderline, strikethrough, frame,+  encircle, overline :: Text -> Text++-- | __Bold__ style (high intensity).+bold            = surround "1"  "22"+-- | Faint style (low intensity).+faint           = surround "2"  "22"+-- | /Italic/ style.+italic          = surround "3"  "32"+-- | U̲n̲d̲e̲r̲l̲i̲n̲e̲ style.+underline       = surround "4"  "24"+-- | D̳o̳u̳b̳l̳e̳ ̳u̳n̳d̳e̳r̳l̳i̳n̳e̳ style.+doubleUnderline = surround "21" "24"+-- | S̶t̶r̶i̶k̶e̶t̶h̶r̶o̶u̶g̶h̶ style.+strikethrough   = surround "9"  "29"+-- | Frame style.+frame           = surround "51" "54"+-- | Encircle style.+encircle        = surround "52" "54"+-- | O̅v̅e̅r̅l̅i̅n̅e̅ style.+overline        = surround "53" "55"++++--------------------------------------------------------------------------------++-- Don't inline before phase 1+{-# NOINLINE [1] surround #-}+surround :: Builder -> Builder -> Text -> Text+surround open close text+  | isatty = Builder.run (esc <> open <> m <> Builder.text text <> esc <> close <> m)+  | otherwise = text++esc :: Builder+esc = "\ESC["++m, semi :: Builder+m    = Builder.char 'm'+semi = Builder.char ';'++{-# NOINLINE isatty #-}+isatty :: Bool+isatty =+  unsafePerformIO (c_isatty 1) == 1++foreign import ccall unsafe "isatty"+  c_isatty :: CInt -> IO CInt++-- Collapse surround/surround to a single surround before phase 1+{-# RULES+  "surround/surround" [~1]+  forall a b c d s.+  surround a b (surround c d s) =+  surround (a <> semi <> c) (b <> semi <> d) s+#-}
+ LICENSE view
@@ -0,0 +1,11 @@+Copyright 2018 Mitchell Rosen++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++2. 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.++3. Neither the name of the copyright holder nor the names of its 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 HOLDER 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.
+ README.md view
@@ -0,0 +1,2 @@+[![Build Status](https://travis-ci.com/mitchellwrosen/text-ansi.svg?branch=master)](https://travis-ci.com/mitchellwrosen/text-ansi)+[![Hackage](https://img.shields.io/hackage/v/text-ansi.svg)](https://hackage.haskell.org/package/text-ansi)
+ text-ansi.cabal view
@@ -0,0 +1,48 @@+cabal-version: 2.2++name: text-ansi+version: 0.1.0+category: Data+synopsis: Text styling for ANSI terminals.+description:+  Text styling for ANSI terminals using SGR codes, as defined by the+  <https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf ECMA-48>+  standard.+  .+  Supports foreground\/background color, bold\/faint intensity, italic,+  single\/double underline, strikethrough, frame, encircle, and overline escape+  sequences. Some styles may not work on your terminal.+  .+  Also features terminal detection, so redirecting styled output to a file will+  automatically strip the ANSI escape sequences.+author: Mitchell Rosen+maintainer: Mitchell Rosen <mitchellwrosen@gmail.com>+homepage: https://github.com/mitchellwrosen/text-ansi+bug-reports: https://github.com/mitchellwrosen/text-ansi/issues+copyright: (c) 2018, Mitchell Rosen+license: BSD-3-Clause+license-file: LICENSE+build-type: Simple+tested-with: GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.2++extra-source-files:+  .travis.yml+  CHANGELOG.md+  README.md++source-repository head+  type: git+  location: git://github.com/mitchellwrosen/text-ansi.git++library+  build-depends:+      base ^>= 4.10 || ^>= 4.11 || ^>= 4.12+    , text ^>= 1.0 || ^>= 1.1 || ^>= 1.2+    , text-builder ^>= 0.6+  default-language:+    Haskell2010+  exposed-modules:+    Data.Text.ANSI+  ghc-options:+    -Wall+    -Wcompat