module Test.HUnit.Terminal (
terminalAppearance
) where
import Data.Char (isPrint)
terminalAppearance :: String -> String
terminalAppearance :: String -> String
terminalAppearance String
str = forall t. (String -> t) -> String -> String -> String -> t
ta forall a. a -> a
id String
"" String
"" String
str
ta
:: ([Char] -> t)
-> [Char]
-> [Char]
-> [Char]
-> t
ta :: forall t. (String -> t) -> String -> String -> String -> t
ta String -> t
f String
bs String
as (Char
'\n':String
cs) = forall t. (String -> t) -> String -> String -> String -> t
ta (\String
t -> String -> t
f (forall a. [a] -> [a]
reverse String
bs forall a. [a] -> [a] -> [a]
++ String
as forall a. [a] -> [a] -> [a]
++ Char
'\n' forall a. a -> [a] -> [a]
: String
t)) String
"" String
"" String
cs
ta String -> t
f String
bs String
as (Char
'\r':String
cs) = forall t. (String -> t) -> String -> String -> String -> t
ta String -> t
f String
"" (forall a. [a] -> [a]
reverse String
bs forall a. [a] -> [a] -> [a]
++ String
as) String
cs
ta String -> t
f (Char
b:String
bs) String
as (Char
'\b':String
cs) = forall t. (String -> t) -> String -> String -> String -> t
ta String -> t
f String
bs (Char
bforall a. a -> [a] -> [a]
:String
as) String
cs
ta String -> t
_ String
"" String
_ (Char
'\b': String
_) = forall a. HasCallStack => String -> a
error String
"'\\b' at beginning of line"
ta String -> t
f String
bs String
as (Char
c:String
cs)
| Bool -> Bool
not (Char -> Bool
isPrint Char
c) = forall a. HasCallStack => String -> a
error String
"invalid nonprinting character"
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
as = forall t. (String -> t) -> String -> String -> String -> t
ta String -> t
f (Char
cforall a. a -> [a] -> [a]
:String
bs) String
"" String
cs
| Bool
otherwise = forall t. (String -> t) -> String -> String -> String -> t
ta String -> t
f (Char
cforall a. a -> [a] -> [a]
:String
bs) (forall a. [a] -> [a]
tail String
as) String
cs
ta String -> t
f String
bs String
as String
"" = String -> t
f (forall a. [a] -> [a]
reverse String
bs forall a. [a] -> [a] -> [a]
++ String
as)