{- |
Taken from Haskore.
-}

module Sound.MIDI.String where

import Control.Monad.Trans.State (State, runState)

unlinesS :: [ShowS] -> ShowS
unlinesS :: [ShowS] -> ShowS
unlinesS = [ShowS] -> ShowS
concatS forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"\n")

concatS :: [ShowS] -> ShowS
concatS :: [ShowS] -> ShowS
concatS = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) forall a. a -> a
id

rightS, leftS, centreS :: Int -> ShowS -> ShowS
rightS :: Int -> ShowS -> ShowS
rightS  Int
n ShowS
s = String -> ShowS
showString (Int -> ShowS
right  Int
n (ShowS
s String
""))
leftS :: Int -> ShowS -> ShowS
leftS   Int
n ShowS
s = String -> ShowS
showString (Int -> ShowS
left   Int
n (ShowS
s String
""))
centreS :: Int -> ShowS -> ShowS
centreS Int
n ShowS
s = String -> ShowS
showString (Int -> ShowS
centre Int
n (ShowS
s String
""))

right,left, centre :: Int -> String -> String
right :: Int -> ShowS
right  Int
n String
s = Int -> String
spaces (Int
n forall a. Num a => a -> a -> a
- forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s) forall a. [a] -> [a] -> [a]
++ String
s
left :: Int -> ShowS
left   Int
n String
s = String
s forall a. [a] -> [a] -> [a]
++ Int -> String
spaces (Int
n forall a. Num a => a -> a -> a
- forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s)
centre :: Int -> ShowS
centre Int
n String
s = Int -> String
spaces Int
l forall a. [a] -> [a] -> [a]
++ String
s forall a. [a] -> [a] -> [a]
++ Int -> String
spaces (Int
n'forall a. Num a => a -> a -> a
-Int
l)
  where
    n' :: Int
n' = Int
n forall a. Num a => a -> a -> a
- forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s
    l :: Int
l  = Int
n' forall a. Integral a => a -> a -> a
`div` Int
2

spaces :: Int -> String
spaces :: Int -> String
spaces Int
n = forall a. Int -> a -> [a]
replicate (forall a. Ord a => a -> a -> a
max Int
0 Int
n) Char
' '

stateToReadS :: State String a -> ReadS a
stateToReadS :: forall a. State String a -> ReadS a
stateToReadS State String a
state String
string =
   [forall s a. State s a -> s -> (a, s)
runState State String a
state String
string]