Skip to content

Commit 0d73e92

Browse files
committed
Portage.Dependency.Print: Improve some formatting
Signed-off-by: hololeap <[email protected]>
1 parent 3fcf4df commit 0d73e92

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/Portage/Dependency/Print.hs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import Portage.Use
1313

1414
import Portage.PackageId
1515

16+
import Data.Default.Class
17+
import Data.Maybe (catMaybes)
1618
import Hackport.Pretty
1719

1820
import Portage.Dependency.Types
@@ -62,20 +64,31 @@ showDepend (DependAtom (Atom pn range dattr))
6264
DRange lb InfinityB -> dispLBound pn lb <> dispDAttr dattr
6365
-- TODO: handle >=foo-0 special case
6466
-- TODO: handle =foo-x.y.* special case
65-
DRange lb ub -> showDepend (DependAtom (Atom pn (DRange lb InfinityB) dattr))
66-
<> " "
67-
<> showDepend (DependAtom (Atom pn (DRange ZeroB ub) dattr))
67+
DRange lb ub -> showDepend (DependAtom (Atom pn (DRange lb InfinityB) dattr))
68+
<+> showDepend (DependAtom (Atom pn (DRange ZeroB ub) def))
6869
DExact v -> "~" <> pretty pn <-> pretty v { versionRevision = 0 } <> dispDAttr dattr
6970

70-
showDepend (DependIfUse u td fd) = valign $ vcat [td_doc, fd_doc]
71+
showDepend (DependIfUse u td fd) = valign $ vcat $ catMaybes [td_doc, fd_doc]
7172
where td_doc
72-
| is_empty_dependency td = emptyDoc
73-
| otherwise = pretty u <> "?" <> sp <> sparens (showDepend td)
73+
| is_empty_dependency td = Nothing
74+
| otherwise = Just $ vcat
75+
[ pretty u <> "?" <+> "("
76+
, indent 1 (emptyDoc <> showDepend td)
77+
, ")"
78+
]
7479
fd_doc
75-
| is_empty_dependency fd = emptyDoc
76-
| otherwise = "!" <> pretty u <> "?" <> sp <> sparens (showDepend fd)
77-
showDepend (DependAnyOf deps) = "||" <> sp <> sparens (vcat $ map showDependInAnyOf deps)
78-
showDepend (DependAllOf deps) = valign $ vcat $ map showDepend deps
80+
| is_empty_dependency fd = Nothing
81+
| otherwise = Just $ vcat
82+
[ "!" <> pretty u <> "?" <+> "("
83+
, indent 1 (emptyDoc <> showDepend fd)
84+
, ")"
85+
]
86+
showDepend (DependAnyOf deps) = vcat $
87+
[ "||" <+> "("
88+
, indent 1 (vcat (map showDependInAnyOf deps))
89+
, ")"
90+
]
91+
showDepend (DependAllOf deps) = vcat $ map showDepend deps
7992

8093
-- needs special grouping
8194
showDependInAnyOf :: Dependency -> Doc ann

0 commit comments

Comments
 (0)