Skip to content

Commit

Permalink
Show multiline output by line
Browse files Browse the repository at this point in the history
Related: #71
  • Loading branch information
YAMAMOTO Yuji committed Aug 26, 2020
1 parent 854363b commit 4e504c0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Education/MakeMistakesToLearnHaskell/Exercise/Result.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ resultForUser diag code judge args input result =
msg =
Text.unlines $
[ Text.replicate 80 "="
, headerYourProgramsOutput <> Text.pack (show out) -- TODO: pretty print
, headerExpectedOutput <> Text.pack (show right)
, headerYourProgramsOutput <> formatOutput out
, headerExpectedOutput <> formatOutput right
] ++ messageFooter input args
in
if isSuccessful
Expand All @@ -44,6 +44,13 @@ resultForUser diag code judge args input result =
let textMsg = decodeUtf8 msg
in whenGhcError code textMsg $ diag code textMsg

where
formatOutput :: Text -> Text
formatOutput s =
case Text.lines s of
lns@(_firstLine : _secondLine : _leftLines) -> "\n" <> showLines lns
_other -> Text.pack $ show s


headerYourProgramsOutput, headerExpectedOutput, headerForInput, headerForArgs, headerForShowArg, headerForShowLine :: Text
headerYourProgramsOutput = "Your program's output: "
Expand Down Expand Up @@ -83,7 +90,14 @@ messageFooter input args =
showArg i (FilePath path content) =
headerForShowArg <> Text.pack (show i) <> ": file " <> Text.pack (show path) <> "\n" <> showContent content

showContent content = Text.unlines . map showLine $ Text.lines content

showContent :: Text -> Text
showContent = showLines . Text.lines


showLines :: [Text] -> Text
showLines = Text.unlines . map showLine
where
showLine line = headerForShowLine <> Text.pack (show line)


Expand Down

0 comments on commit 4e504c0

Please sign in to comment.