($con2tag_Highlight) :: Highlight -> Int#module Language.Haskell.HsColour.ColourHighlight
  ( Colour(..)
  , Highlight(..)
  , base256, unbase
  , rgb24bit_to_xterm256
  ,   projectToBasicColour8
  , hlProjectToBasicColour8
  ) where

import Data.Word

-- | Colours supported by ANSI codes.
data Colour = Black :: ColourBlack | Red :: ColourRed | Green :: ColourGreen | Yellow :: ColourYellow | Blue :: ColourBlue | Magenta :: ColourMagenta | Cyan :: ColourCyan | White :: ColourWhite | Rgb :: Word8 -> Word8 -> Word8 -> ColourRgb Word8 Word8 Word8
  deriving (D:Eq :: (a -> a -> Bool) -> (a -> a -> Bool) -> T:Eq aEq,D:Show ::
  (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> T:Show aShow,D:Read ::
  (Int -> ReadS a)
  -> ReadS [a]
  -> ReadPrec a
  -> ReadPrec [a]
  -> T:Read aRead)

-- | Convert an integer in the range [0,2^24-1] to its base 256-triplet, passing the result to the given continuation (avoid unnecessary tupleism).
base256 :: Integral int => (Word8 -> Word8 -> Word8 -> r) -> int -> r
base256 ::
  Integral int => (Word8 -> Word8 -> Word8 -> r) -> int -> rbase256 kont :: Word8 -> Word8 -> Word8 -> rkont x :: intx =
    let
        (r :: intr,gb :: intgb) = divMod :: Integral a => a -> a -> (a, a)divMod x :: Intx 256
        (g :: intg,b :: intb)  = divMod :: Integral a => a -> a -> (a, a)divMod gb :: intgb 256
        fi :: int -> Word8fi = fromIntegral :: (Integral a, Num b) => a -> bfromIntegral
    in 
        kont :: Word8 -> Word8 -> Word8 -> rkont (fi :: int -> Word8fi r :: Word8r) (fi :: int -> Word8fi g :: Word8g) (fi :: int -> Word8fi b :: Word8b)

-- | Convert a three-digit numeral in the given (as arg 1) base to its integer value.
unbase :: Integral int => int -> Word8 -> Word8 -> Word8 -> int
unbase :: Integral int => int -> Word8 -> Word8 -> Word8 -> intunbase base :: intbase r :: Word8r g :: Word8g b :: Word8b = (fi :: int -> Word8fi r :: Word8r(*) :: Num a => a -> a -> a*base :: intbase(+) :: Num a => a -> a -> a+fi :: int -> Word8fi g :: Word8g)(*) :: Num a => a -> a -> a*base :: intbase(+) :: Num a => a -> a -> a+fi :: int -> Word8fi b :: Word8b
    where fi :: Word8 -> intfi = fromIntegral :: (Integral a, Num b) => a -> bfromIntegral

-- | Approximate a 24-bit Rgb colour with a colour in the xterm256 6x6x6 colour cube, returning its index.
rgb24bit_to_xterm256 :: (Integral t) => Word8 -> Word8 -> Word8 -> t
rgb24bit_to_xterm256 :: Integral t => Word8 -> Word8 -> Word8 -> trgb24bit_to_xterm256 r :: Word8r g :: Word8g b :: Word8b = let f :: Word8 -> Word8f = (div :: Integral a => a -> a -> a`div` 43)
                          in 16 (+) :: Num a => a -> a -> a+ unbase :: Integral int => int -> Word8 -> Word8 -> Word8 -> intunbase 6 (f :: Word8 -> Word8f r :: Word8r) (f :: Word8 -> Word8f g :: Word8g) (f :: Word8 -> Word8f b :: Word8b)


-- | Ap\"proxi\"mate a 24-bit Rgb colour with an ANSI8 colour. Will leave other colours unchanged and will never return an 'Rgb' constructor value. 
projectToBasicColour8 ::  Colour -> Colour
projectToBasicColour8 :: Colour -> ColourprojectToBasicColour8 (Rgb r :: Word8r g :: Word8g b :: Word8b) = let f :: Word8 -> Word8f = (div :: Integral a => a -> a -> a`div` 128)
                          in  toEnum :: Enum a => Int -> atoEnum ( unbase :: Integral int => int -> Word8 -> Word8 -> Word8 -> intunbase 2 (f :: Word8 -> Word8f r :: Word8r) (f :: Word8 -> Word8f g :: Word8g) (f :: Word8 -> Word8f b :: Word8b) )
projectToBasicColour8 x :: Colourx = x :: Intx


-- | Lift 'projectToBasicColour8' to 'Highlight's
hlProjectToBasicColour8 ::  Highlight -> Highlight
hlProjectToBasicColour8 :: Highlight -> HighlighthlProjectToBasicColour8 (Foreground c :: Colourc) = Foreground :: Colour -> HighlightForeground (projectToBasicColour8 :: Colour -> ColourprojectToBasicColour8 c :: Colourc)
hlProjectToBasicColour8 (Background c :: Colourc) = Background :: Colour -> HighlightBackground (projectToBasicColour8 :: Colour -> ColourprojectToBasicColour8 c :: Colourc)
hlProjectToBasicColour8 h :: Highlighth = h :: Highlighth

        

instance D:Enum ::
  (a -> a)
  -> (a -> a)
  -> (Int -> a)
  -> (a -> Int)
  -> (a -> [a])
  -> (a -> a -> [a])
  -> (a -> a -> [a])
  -> (a -> a -> a -> [a])
  -> T:Enum aEnum Colour where
    toEnum 0 = Black :: ColourBlack
    toEnum 1 = Red :: ColourRed 
    toEnum 2 = Green :: ColourGreen 
    toEnum 3 = Yellow :: ColourYellow 
    toEnum 4 = Blue :: ColourBlue 
    toEnum 5 = Magenta :: ColourMagenta 
    toEnum 6 = Cyan :: ColourCyan 
    toEnum 7 = White :: ColourWhite 
    -- Arbitrary extension; maybe just 'error' out instead
    toEnum x :: Intx = base256 ::
  Integral int => (Word8 -> Word8 -> Word8 -> r) -> int -> rbase256 Rgb :: Word8 -> Word8 -> Word8 -> ColourRgb (x :: Intx(-) :: Num a => a -> a -> a-8)
    
    fromEnum Black   = 0
    fromEnum Red     = 1
    fromEnum Green   = 2
    fromEnum Yellow  = 3
    fromEnum Blue    = 4
    fromEnum Magenta = 5
    fromEnum Cyan    = 6
    fromEnum White   = 7
    -- Arbitrary extension; maybe just 'error' out instead
    fromEnum (Rgb r :: Word8r g :: Word8g b :: Word8b) = 8 (+) :: Num a => a -> a -> a+ unbase :: Integral int => int -> Word8 -> Word8 -> Word8 -> intunbase 256 r :: Word8r g :: Word8g b :: Word8b
 

-- | Types of highlighting supported by ANSI codes (and some extra styles).
data Highlight =
    Normal :: HighlightNormal
  | Bold :: HighlightBold
  | Dim :: HighlightDim
  | Underscore :: HighlightUnderscore
  | Blink :: HighlightBlink
  | ReverseVideo :: HighlightReverseVideo
  | Concealed :: HighlightConcealed
  | Foreground :: Colour -> HighlightForeground Colour
  | Background :: Colour -> HighlightBackground Colour
  -- The above styles are ANSI-supported, with the exception of the 'Rgb' constructor for 'Colour's.  Below are extra styles (e.g. for Html rendering).
  | Italic :: HighlightItalic
  deriving (D:Eq :: (a -> a -> Bool) -> (a -> a -> Bool) -> T:Eq aEq,D:Show ::
  (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> T:Show aShow,D:Read ::
  (Int -> ReadS a)
  -> ReadS [a]
  -> ReadPrec a
  -> ReadPrec [a]
  -> T:Read aRead)