module Data.GiveYouAHead where
import GiveYouAHead.Common
--Switch
data Switch = Off | On
deriving (Show , Read , Eq , Ord)
turnSwitch :: Switch -> Switch
turnSwitch On = Off
turnSwitch Off = On
--CommandMap
type CommandMap = [(Switch,String,String)]
findKey :: CommandMap -> String -> String
findKey [] key = key
findKey ((On,k,v):xs) key
| key == k = v
| otherwise = findKey xs key
findKey (_:xs) key = findKey xs key
delNewLine :: String -> String
delNewLine = concat.lines
getCmdMap :: FilePath -> IO CommandMap
getCmdMap fpath = do
src' <- readF fpath
let src = delNewLine src'
return (read src :: CommandMap)
changeSwitchStatus :: CommandMap
-> String
-> Int
-> CommandMap
changeSwitchStatus [] _ _ = []
changeSwitchStatus ((s,k,v):xs) key c
| key == k && c == 0 = (turnSwitch s,k,v):xs
| key == k && c /= 0 = (s,k,v):changeSwitchStatus xs key (c1)
| otherwise = (s,k,v):changeSwitchStatus xs key c
--Settings
data Settings = Settings
{
dfShell ::String,
dfFileName :: String,
sysShell ::String
} deriving (Read,Show)
getSettings :: FilePath
-> IO Settings
getSettings fPath = do
src <- readF fPath
return (read src :: Settings)