Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion prettyprinter-ansi-terminal/prettyprinter-ansi-terminal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ source-repository head
type: git
location: https://github.com/quchen/prettyprinter

flag text
description: While it's a core value of @prettyprinter@ packages to use @Text@, there are rare
circumstances (mostly when @prettyprinter@ arises as a dependency of
test suites of packages like @bytestring@ or @text@ themselves) when
this is inconvenient. In this case one can disable this flag, so that
@prettyprinter-ansi-terminal@ fallbacks to @String@.
default: True
manual: True

library
exposed-modules: Data.Text.Prettyprint.Doc.Render.Terminal
, Data.Text.Prettyprint.Doc.Render.Terminal.Internal
Expand All @@ -37,8 +46,17 @@ library
build-depends:
base >= 4.5 && < 5
, ansi-terminal >= 0.4.0
, text >= 1.2
, prettyprinter >= 1.7.0
if flag(text)
build-depends: text >= 1.2
else
-- A fake text package, emulating the same API, but backed by String
hs-source-dirs: src-text
other-modules:
Data.Text
, Data.Text.IO
, Data.Text.Lazy
, Data.Text.Lazy.Builder

if impl(ghc >= 8.0)
ghc-options: -Wcompat
Expand Down
46 changes: 46 additions & 0 deletions prettyprinter-ansi-terminal/src-text/Data/Text.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- Provide a fake API, mimicking Data.Text from text package,
-- but actually backed by type Text = String. It is used only in rare
-- circumstances, when prettyprinter is built with -text flag.
--

{-# OPTIONS_GHC -fno-warn-missing-signatures #-}

module Data.Text where

import Prelude hiding (head, length, null, replicate)
import qualified Data.Char
import qualified Data.List

type Text = String
cons = (:)
dropWhileEnd = Data.List.dropWhileEnd
head = Data.List.head
intercalate = Data.List.intercalate
length = Data.List.length :: [Char] -> Int
lines = Data.List.lines
map = Data.List.map
null = Data.List.null :: [Char] -> Bool
pack = id
replicate = (Data.List.concat .) . Data.List.replicate
singleton = (:[])
snoc xs x = xs ++ [x]
stripEnd = dropWhileEnd Data.Char.isSpace
unlines = Data.List.unlines
unpack = id
words = Data.List.words

uncons :: Text -> Maybe (Char, Text)
uncons [] = Nothing
uncons (x : xs) = Just (x, xs)

splitOn :: Text -> Text -> [Text]
splitOn pat src
| null pat = error "splitOn: empty pattern"
| otherwise = go [] src
where
go acc [] = [reverse acc]
go acc xs@(y : ys)
| pat `Data.List.isPrefixOf` xs
= reverse acc : go [] (drop (length pat) xs)
| otherwise
= go (y : acc) ys
13 changes: 13 additions & 0 deletions prettyprinter-ansi-terminal/src-text/Data/Text/IO.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Provide a fake API, mimicking Data.Text.IO from text package,
-- but actually backed by type Text = String. It is used only in rare
-- circumstances, when prettyprinter is built with -text flag.
--

{-# OPTIONS_GHC -fno-warn-missing-signatures #-}

module Data.Text.IO where

import qualified System.IO

hPutStr = System.IO.hPutStr
putStrLn = System.IO.putStrLn
15 changes: 15 additions & 0 deletions prettyprinter-ansi-terminal/src-text/Data/Text/Lazy.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Provide a fake API, mimicking Data.Text.Lazy from text package,
-- but actually backed by type Text = String. It is used only in rare
-- circumstances, when prettyprinter is built with -text flag.
--

{-# OPTIONS_GHC -fno-warn-missing-signatures #-}

module Data.Text.Lazy where

import Data.Text as T

type Text = T.Text
length = T.length
lines = T.lines
toStrict = id
13 changes: 13 additions & 0 deletions prettyprinter-ansi-terminal/src-text/Data/Text/Lazy/Builder.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Provide a fake API, mimicking Data.Text.Lazy.Builder from text package,
-- but actually backed by type Builder = String. It is used only in rare
-- circumstances, when prettyprinter is built with -text flag.
--

{-# OPTIONS_GHC -fno-warn-missing-signatures #-}

module Data.Text.Lazy.Builder where

type Builder = String
fromText = id
singleton = (:[])
toLazyText = id
Loading