@@ -126,8 +126,18 @@ impl Prompt {
126126 let selected_color = theme.get("ui.menu.selected");
127127 // completion
128128
129− let max_col = std::cmp::max(1, area.width / BASE_WIDTH);
130− let height = ((self.completion.len() as u16 + max_col - 1) / max_col)
129+ let max_len = self
130+ .completion
131+ .iter()
132+ .map(|(_, completion)| completion.len() as u16)
133+ .max()
134+ .unwrap_or(BASE_WIDTH)
135+ .max(BASE_WIDTH);
136+
137+ let cols = std::cmp::max(1, area.width / max_len);
138+ let col_width = (area.width - (cols)) / cols;
139+
140+ let height = ((self.completion.len() as u16 + cols - 1) / cols)
131141 .min(10) // at most 10 rows (or less)
132142 .min(area.height);
133143
@@ -147,7 +157,13 @@ impl Prompt {
147157 let mut row = 0;
148158 let mut col = 0;
149159
150− for (i, (_range, completion)) in self.completion.iter().enumerate() {
160+ // TODO: paginate
161+ for (i, (_range, completion)) in self
162+ .completion
163+ .iter()
164+ .enumerate()
165+ .take(height as usize * cols as usize)
166+ {
151167 let color = if Some(i) == self.selection {
152168 // Style::default().bg(Color::Rgb(104, 60, 232))
153169 selected_color // TODO: just invert bg
@@ -155,10 +171,10 @@ impl Prompt {
155171 text_color
156172 };
157173 surface.set_stringn(
158− area.x + 1 + col * BASE_WIDTH,
174+ area.x + col * (1 + col_width),
159175 area.y + row,
160176 &completion,
161− BASE_WIDTH as usize - 1,
177+ col_width.saturating_sub(1) as usize,
162178 color,
163179 );
164180 row += 1;
@@ -166,9 +182,6 @@ impl Prompt {
166182 row = 0;
167183 col += 1;
168184 }
169− if col > max_col {
170− break;
171− }
172185 }
173186 }
174187