diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2017-02-25 21:38:10 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2017-02-25 21:38:18 -0700 |
commit | efe0d114a6052431659419c4801424d1f2084875 (patch) | |
tree | 7ee856d122e8c584f6edbaf67977149085db8359 | |
parent | 709024c81ab8f00e081d7aa94097d0669fc3b095 (diff) | |
download | sscan-efe0d114a6052431659419c4801424d1f2084875.tar.gz |
align defnList better when AlignLeft
-rw-r--r-- | Brick/Widgets/DefnList.hs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Brick/Widgets/DefnList.hs b/Brick/Widgets/DefnList.hs index 090428f..6ce0f48 100644 --- a/Brick/Widgets/DefnList.hs +++ b/Brick/Widgets/DefnList.hs @@ -19,16 +19,20 @@ defnList align attr defns = vBox $ line <$> defns where line (label, content) = markup $ (T.pack label @@ labelAttr) <> (T.pack sep @@ V.defAttr) - <> (if align == AlignRight - then (T.pack (gap label content) @@ V.defAttr) - else mempty - ) + <> (T.pack (gap label content) @@ V.defAttr) <> (T.pack content @@ V.defAttr) - gap a b = take (maxWidth - length a - length b - length sep) $ - repeat ' ' + gap a b + | align == AlignRight = + take (maxWidth - length a - length b - length sep) $ + repeat ' ' + | align == AlignLeft = + take (maxLabelWidth - length a) $ + repeat ' ' + maxWidth = maximum $ map (\(x,y) -> length sep + length x + length y) defns + maxLabelWidth = maximum $ map (\(x,y) -> length x) defns sep = if align == AlignRight then ": " else ": " labelAttr = maybe V.defAttr id attr |