module Vgrep.Environment.Config where
import Control.Lens
import Data.Maybe
import Graphics.Vty.Image
import System.Environment
data Config = Config
{ _colors :: Colors
, _tabstop :: Int
, _editor :: String
} deriving (Eq, Show)
data Colors = Colors
{ _lineNumbers :: Attr
, _lineNumbersHl :: Attr
, _normal :: Attr
, _normalHl :: Attr
, _fileHeaders :: Attr
, _selected :: Attr
} deriving (Eq, Show)
makeLenses ''Config
makeLenses ''Colors
defaultConfig :: Config
defaultConfig = Config
{ _colors = Colors
{ _lineNumbers = defAttr `withForeColor` blue
, _lineNumbersHl = defAttr `withForeColor` blue
`withStyle` bold
, _normal = defAttr
, _normalHl = defAttr `withStyle` bold
, _fileHeaders = defAttr `withBackColor` green
, _selected = defAttr `withStyle` standout }
, _tabstop = 8
, _editor = "vi" }
withConfiguredEditor :: Config -> IO Config
withConfiguredEditor config = do
let defaultEditor = view editor config
configuredEditor <- lookupEnv "EDITOR"
pure config { _editor = fromMaybe defaultEditor configuredEditor }