{-# LANGUAGE RecordWildCards #-}

module Potato.Flow.Configuration where

import           Relude

import           Potato.Data.Text.Unicode

import           Data.Default
import qualified Text.Show

data PotatoConfiguration = PotatoConfiguration {
    PotatoConfiguration -> Bool
_potatoConfiguration_allowGraphemeClusters            :: Bool -- NOTE we don't support replacing grapheme clusters as this would require reverting past inputs
    -- TODO rename to disallow
    , PotatoConfiguration -> Maybe (Maybe Char)
_potatoConfiguration_allowOrReplaceUnicodeWideChars :: Maybe (Maybe Char) -- outer Maybe is if we disallow, inner Maybe is what we replace with
    , PotatoConfiguration -> Char -> Int8
_potatoConfiguration_unicodeWideCharFn              :: Char -> Int8
  }

instance Show PotatoConfiguration where
  show :: PotatoConfiguration -> String
show PotatoConfiguration {Bool
Maybe (Maybe Char)
Char -> Int8
_potatoConfiguration_unicodeWideCharFn :: Char -> Int8
_potatoConfiguration_allowOrReplaceUnicodeWideChars :: Maybe (Maybe Char)
_potatoConfiguration_allowGraphemeClusters :: Bool
_potatoConfiguration_unicodeWideCharFn :: PotatoConfiguration -> Char -> Int8
_potatoConfiguration_allowOrReplaceUnicodeWideChars :: PotatoConfiguration -> Maybe (Maybe Char)
_potatoConfiguration_allowGraphemeClusters :: PotatoConfiguration -> Bool
..} = String
"_potatoConfiguration_allowGraphemeClusters: " forall a. Semigroup a => a -> a -> a
<> forall b a. (Show a, IsString b) => a -> b
show Bool
_potatoConfiguration_allowGraphemeClusters forall a. Semigroup a => a -> a -> a
<> String
"\n_potatoConfiguration_allowOrReplaceUnicodeWideChars: " forall a. Semigroup a => a -> a -> a
<> forall b a. (Show a, IsString b) => a -> b
show Maybe (Maybe Char)
_potatoConfiguration_allowOrReplaceUnicodeWideChars

instance Default PotatoConfiguration where
  def :: PotatoConfiguration
def = PotatoConfiguration {
      _potatoConfiguration_allowGraphemeClusters :: Bool
_potatoConfiguration_allowGraphemeClusters = Bool
False
      --, _potatoConfiguration_allowOrReplaceUnicodeWideChars = Just (Just '☺')
      , _potatoConfiguration_allowOrReplaceUnicodeWideChars :: Maybe (Maybe Char)
_potatoConfiguration_allowOrReplaceUnicodeWideChars = forall a. Maybe a
Nothing
      -- NOTE getCharWidth is unsafely modified by vty on initialization based on the terminal config file
      , _potatoConfiguration_unicodeWideCharFn :: Char -> Int8
_potatoConfiguration_unicodeWideCharFn = Char -> Int8
getCharWidth
    }