1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 00:12:29 +03:00

Simplify showLine.

This commit is contained in:
Rob Rix 2016-04-25 14:59:00 -04:00
parent 7628d15a73
commit 237558fbed

View File

@ -117,11 +117,9 @@ instance Eq PrettyDiff where
instance Show PrettyDiff where
show (PrettyDiff sources lines) = ('\n':) =<< (showLine (fromMaybe 0 (maximum (fmap length <$> shownLines))) <$> catMaybes shownLines)
where shownLines = toBoth <$> lines
showLine n line = case runJoin line of
This before -> pad n before " | "
That after -> showString (replicate n ' ') (showString " | " after)
These before after -> pad n before (showString " | " after)
showLine n line = let (before, after) = fromThese (replicate n ' ') (replicate n ' ') (runJoin (pad n <$> line)) in
before ++ " | " ++ after
showDiff diff = stripNewlines . toList . Source.slice (getRange diff)
stripNewlines = filter (/= '\n')
pad n string = showString (take n string) . showString (replicate (max 0 (n - length string)) ' ')
pad n string = showString (take n string) (showString (replicate (max 0 (n - length string)) ' ') "")
toBoth them = showDiff <$> them `applyThese` modifyJoin (uncurry These) sources