EarthCitizen / escape-artist

A Haskell library for text decoration with ANSI escape sequences made easy
BSD 3-Clause "New" or "Revised" License
10 stars 1 forks source link

Undecorated Values in Expressions #8

Open EarthCitizen opened 7 years ago

EarthCitizen commented 7 years ago

It would be convenient to do something like the following:

FgRed 5 <> " " <> FgWhite 6

New operator?

EarthCitizen commented 7 years ago

Probably will be />.

Example implementation for String:

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ExtendedDefaultRules #-}

import Data.Monoid ((<>))

default (Integer, Float)

class ToString a where
    toString :: a -> String

instance ToString Char where
    toString = (:[])

instance ToString Integer where
    toString = show

instance ToString Float where
    toString = show

instance ToString String where
    toString = id

infixr 6 />

(/>) :: (ToString a, ToString b) => a -> b -> String
(/>) a b = toString a <> toString b

main = do
    print $ "Hello " /> 5 /> " and " /> 7.3 /> " var " /> 'X'