@@ -124,9 +124,7 @@ func (g *group) initCompletionsGrid(comps RawValues) {
124124 }
125125
126126 pairLength := g .longestValueDescribed (comps )
127- if pairLength > g .termWidth {
128- pairLength = g .termWidth
129- }
127+ pairLength = min (g .termWidth , pairLength )
130128
131129 maxColumns := g .termWidth / pairLength
132130 if g .list || maxColumns < 0 {
@@ -144,9 +142,9 @@ func (g *group) initCompletionAliased(domains []Candidate) {
144142 g .aliased = true
145143
146144 // Filter out all duplicates: group aliased completions together.
147- grid , descriptions := g .createDescribedRows (domains )
145+ grid , _ := g .createDescribedRows (domains )
148146 g .calculateMaxColumnWidths (grid )
149- g .wrapExcessAliases (grid , descriptions )
147+ g .wrapExcessAliases (grid )
150148
151149 g .maxY = len (g .rows )
152150 g .maxX = len (g .columnsWidth )
@@ -172,16 +170,14 @@ func (g *group) createDescribedRows(values []Candidate) ([][]Candidate, []string
172170 // Sorting helps with easier grids.
173171 for _ , description := range uniqueDescriptions {
174172 row := descriptionMap [description ]
175- // slices.Sort(row)
176- // slices.Reverse(row)
177173 rows = append (rows , row )
178174 }
179175
180176 return rows , uniqueDescriptions
181177}
182178
183179// Wraps all rows for which there are too many aliases to be displayed on a single one.
184- func (g * group ) wrapExcessAliases (grid [][]Candidate , descriptions [] string ) {
180+ func (g * group ) wrapExcessAliases (grid [][]Candidate ) {
185181 breakeven := 0
186182 maxColumns := len (g .columnsWidth )
187183
@@ -356,10 +352,7 @@ func (g *group) trimDisplay(comp Candidate, pad, col int) (candidate, padded str
356352 // Get the allowed length for this column.
357353 // The display can never be longer than terminal width.
358354 maxDisplayWidth := g .columnsWidth [col ] + 1
359-
360- if maxDisplayWidth > g .termWidth {
361- maxDisplayWidth = g .termWidth
362- }
355+ maxDisplayWidth = min (g .termWidth , maxDisplayWidth )
363356
364357 val = sanitizer .Replace (val )
365358
@@ -417,10 +410,7 @@ func (g *group) getPad(value Candidate, columnIndex int, desc bool) int {
417410 // to the terminal size: we are not really sure
418411 // of where offsets might be set in the code...
419412 column := columns [columnIndex ]
420- if column > g .termWidth - 1 {
421- column = g .termWidth - 1
422- }
423-
413+ column = min (g .termWidth - 1 , column )
424414 padding := column - valLen
425415
426416 if padding < 0 {
@@ -641,7 +631,7 @@ func createGrid(values []Candidate, rowCount, maxColumns int) [][]Candidate {
641631
642632 grid := make ([][]Candidate , rowCount )
643633
644- for i := 0 ; i < rowCount ; i ++ {
634+ for i := range rowCount {
645635 grid [i ] = createRow (values , maxColumns , i )
646636 }
647637
@@ -651,10 +641,7 @@ func createGrid(values []Candidate, rowCount, maxColumns int) [][]Candidate {
651641func createRow (domains []Candidate , maxColumns , rowIndex int ) []Candidate {
652642 rowStart := rowIndex * maxColumns
653643 rowEnd := (rowIndex + 1 ) * maxColumns
654-
655- if rowEnd > len (domains ) {
656- rowEnd = len (domains )
657- }
644+ rowEnd = min (len (domains ), rowEnd )
658645
659646 return domains [rowStart :rowEnd ]
660647}
0 commit comments