[Git][ghc/ghc][master] [hadrian] Fix multiline synopsis rendering

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Sat Jun 3 20:50:01 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
f7744e8e by Andrey Mokhov at 2023-06-03T16:49:44-04:00
[hadrian] Fix multiline synopsis rendering

- - - - -


1 changed file:

- hadrian/src/Hadrian/Utilities.hs


Changes:

=====================================
hadrian/src/Hadrian/Utilities.hs
=====================================
@@ -574,22 +574,36 @@ renderCreateFileLink linkTarget link' = do
     where
         link = unifyPath link'
 
+-- | Render a multiline string, prefixing the first line with a header.
+renderMultiLineString :: String -> String -> [String]
+renderMultiLineString header string =
+    [ linePrefix index ++ line | (index, line) <- zip [0..] (lines string) ]
+  where
+    linePrefix :: Int -> String
+    linePrefix index
+        | index == 0 = header
+        | otherwise  = replicate (length header) ' '
+
+-- | Render a (possibly multiline) synopsis, making sure it ends with a dot.
+renderSynopsis :: String -> String -> [String]
+renderSynopsis header synopsis
+    | null synopsis = []
+    | otherwise = renderMultiLineString header (endWithADot synopsis)
+  where
+    endWithADot :: String -> String
+    endWithADot s = dropWhileEnd isPunctuation s ++ "."
+
 -- | Render the successful build of a program.
 renderProgram :: String -> String -> String -> String
 renderProgram name bin synopsis = renderBox $
-    [ "Successfully built program " ++ name
-    , "Executable: " ++ bin ] ++
-    [ "Program synopsis: " ++ endWithADot synopsis | not (null synopsis) ]
+    [ "Successfully built program " ++ name, "Executable: " ++ bin ] ++
+    renderSynopsis "Program synopsis: " synopsis
 
 -- | Render the successful build of a library.
 renderLibrary :: String -> String -> String -> String
 renderLibrary name lib synopsis = renderBox $
-    [ "Successfully built library " ++ name
-    , "Library: " ++ lib ] ++
-    [ "Library synopsis: " ++ endWithADot synopsis | not (null synopsis) ]
-
-endWithADot :: String -> String
-endWithADot s = dropWhileEnd isPunctuation s ++ "."
+    [ "Successfully built library " ++ name, "Library: " ++ lib ] ++
+    renderSynopsis "Library synopsis: " synopsis
 
 -- | Render the given set of lines in an ASCII box. The minimum width and
 -- whether to use Unicode symbols are hardcoded in the function's body.



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f7744e8e48362879ba4fae226763cfc7db1bdecb

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f7744e8e48362879ba4fae226763cfc7db1bdecb
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230603/51ab6eeb/attachment-0001.html>


More information about the ghc-commits mailing list