module BishBosh.UI.PrintObject (
PrintObject(..),
boardTag,
configurationTag,
fenTag,
gameTag,
helpTag,
movesTag,
pgnTag,
range,
autoComplete
) where
import qualified Control.Arrow
import qualified Control.DeepSeq
import qualified Data.Char
import qualified Data.List
import qualified Data.List.Extra
boardTag :: String
boardTag = "board"
configurationTag :: String
configurationTag = "configuration"
fenTag :: String
fenTag = "fen"
gameTag :: String
gameTag = "game"
helpTag :: String
helpTag = "help"
movesTag :: String
movesTag = "moves"
pgnTag :: String
pgnTag = "pgn"
data PrintObject
= Board
| Configuration
| FEN
| Game
| Help
| Moves
| PGN
deriving Eq
instance Control.DeepSeq.NFData PrintObject where
rnf _ = ()
instance Show PrintObject where
showsPrec _ printObject = showString $ case printObject of
Board -> boardTag
Configuration -> configurationTag
FEN -> fenTag
Game -> gameTag
Help -> helpTag
Moves -> movesTag
PGN -> pgnTag
instance Read PrintObject where
readsPrec _ s = case Control.Arrow.first Data.List.Extra.lower `map` lex s of
[("board", remainder)] -> [(Board, remainder)]
[("configuration", remainder)] -> [(Configuration, remainder)]
[("fen", remainder)] -> [(FEN, remainder)]
[("game", remainder)] -> [(Game, remainder)]
[("help", remainder)] -> [(Help, remainder)]
[("moves", remainder)] -> [(Moves, remainder)]
[("pgn", remainder)] -> [(PGN, remainder)]
_ -> []
range :: [PrintObject]
range = [Board, Configuration, FEN, Game, Help, Moves, PGN]
autoComplete :: ShowS
autoComplete = uncurry (++) . Control.Arrow.first (
\word -> case [
tag |
tag <- [
boardTag,
configurationTag,
fenTag,
gameTag,
helpTag,
movesTag
],
Data.List.Extra.lower word `Data.List.isPrefixOf` Data.List.Extra.lower tag
] of
[tag] -> tag
_ -> word
) . break Data.Char.isSpace . Data.List.Extra.trimStart