@@ -16,6 +16,7 @@ import System.Console.Haskeline.Completion
16
16
import System.Console.Haskeline.Monads
17
17
18
18
import Data.List (transpose , unfoldr )
19
+ import Data.Maybe (fromMaybe , catMaybes )
19
20
20
21
useCompletion :: InsertMode -> Completion -> InsertMode
21
22
useCompletion im c = insertString r im
@@ -71,7 +72,7 @@ makePartialCompletion im completions = insertString partial im
71
72
pagingCompletion :: MonadReader Layout m => Key -> Prefs
72
73
-> [Completion ] -> Command m InsertMode InsertMode
73
74
pagingCompletion k prefs completions = \ im -> do
74
- ls <- asks $ makeLines ( map display completions)
75
+ ls <- asks $ makeLines completions
75
76
let pageAction = do
76
77
askFirst prefs (length completions) $
77
78
if completionPaging prefs
@@ -117,17 +118,26 @@ printPage ls = do
117
118
118
119
-----------------------------------------------
119
120
-- Splitting the list of completions into lines for paging.
120
- makeLines :: [String ] -> Layout -> [String ]
121
- makeLines ws layout = let
122
- minColPad = 2
121
+ makeLines :: [Completion ] -> Layout -> [String ]
122
+ makeLines cs layout = let
123
+ descM = description <$> cs
124
+ descs = fromMaybe [] <$> descM
125
+ disps = display <$> cs
126
+ singleColumnMode = not . null . catMaybes $ descM
127
+ minColPad = if singleColumnMode then 8 else 2
123
128
printWidth = width layout
124
- maxWidth = min printWidth (maximum (map (gsWidth . stringToGraphemes) ws) + minColPad)
125
- numCols = printWidth `div` maxWidth
129
+ maxWidth = min printWidth (maximum (map (gsWidth . stringToGraphemes) disps) + minColPad)
130
+ numCols = if singleColumnMode then 1 else printWidth `div` maxWidth
131
+ ws = if singleColumnMode then padLines maxWidth disps descs else disps
126
132
ls = if maxWidth >= printWidth
127
133
then map (: [] ) ws
128
134
else splitIntoGroups numCols ws
129
135
in map (padWords maxWidth) ls
130
136
137
+ padLines :: Int -> [String ] -> [String ] -> [String ]
138
+ padLines wid = zipWith (\ x y -> x ++ replicate (wid - widthOf x) ' ' ++ y)
139
+ where widthOf = gsWidth . stringToGraphemes
140
+
131
141
-- Add spaces to the end of each word so that it takes up the given visual width.
132
142
-- Don't pad the word in the last column, since printing a space in the last column
133
143
-- causes a line wrap on some terminals.
0 commit comments