newtype DiffR a = DiffR {unDiffR :: Text}
deriving stock (Show)
type
let escaped = Text.replace "\"" "\\\"" content
in flip Text.snoc '"' . Text.cons '"' $ escaped
Text.stripEnd . Text.unlines
empty = DiffR Text.empty
deck = DiffR
add cardname categoryname cardCopies content =
let entry =
[ "A"
, quote $ toText cardname
, Text.pack . show . toNumber @Int $ cardCopies
, quote $ toText categoryname
]
in DiffR $ line [unDiffR content, Text.intercalate " " entry]
delete cardname content =
let entry =
Text.intercalate
" "
[ "D"
, quote $ toText cardname
]
in DiffR $ line [unDiffR content, entry]
hunk cardname changes content =
let header = Text.append ">> " (quote $ toText cardname)
hunks = line $ foldr (\ch acc -> Text.append " " (unDiffR ch) : acc ) mempty changes
in DiffR $ Text.unlines [Text.stripEnd $ unDiffR content, Text.empty, header, hunks]
move fromCategory toCategory count =
let entry =
Text.intercalate
" "
[ "M"
, Text.pack . show . toNumber @Int $ count
, quote $ toText fromCategory
, quote $ toText toCategory
]
in DiffR entry
deltaCopies delta categoryname =
let entry =
Text.intercalate
" "
[ Text.pack . show $ delta
, quote $ toText categoryname
]
in DiffR entry
unDiffR
evalMany