Builds the help view from various sections pieces, truncating it if the view would otherwise wrap to two lines. Help view entries should come in as pairs, with the first being the key and the second being the help text.
(entries ...string)
| 176 | // would otherwise wrap to two lines. Help view entries should come in as pairs, |
| 177 | // with the first being the key and the second being the help text. |
| 178 | func (m stashModel) miniHelpView(entries ...string) string { |
| 179 | if len(entries) == 0 { |
| 180 | return "" |
| 181 | } |
| 182 | |
| 183 | var ( |
| 184 | truncationChar = subtleStyle.Render("…") |
| 185 | truncationWidth = ansi.PrintableRuneWidth(truncationChar) |
| 186 | ) |
| 187 | |
| 188 | var ( |
| 189 | next string |
| 190 | leftGutter = " " |
| 191 | maxWidth = m.common.width - |
| 192 | stashViewHorizontalPadding - |
| 193 | truncationWidth - |
| 194 | ansi.PrintableRuneWidth(leftGutter) |
| 195 | s = leftGutter |
| 196 | ) |
| 197 | |
| 198 | for i := 0; i < len(entries); i = i + 2 { |
| 199 | k := entries[i] |
| 200 | v := entries[i+1] |
| 201 | |
| 202 | k = grayFg(k) |
| 203 | v = midGrayFg(v) |
| 204 | |
| 205 | next = fmt.Sprintf("%s %s", k, v) |
| 206 | |
| 207 | if i < len(entries)-2 { |
| 208 | next += dividerDot.String() |
| 209 | } |
| 210 | |
| 211 | // Only this (and the following) help text items if we have the |
| 212 | // horizontal space |
| 213 | if ansi.PrintableRuneWidth(s)+ansi.PrintableRuneWidth(next) >= maxWidth { |
| 214 | s += truncationChar |
| 215 | break |
| 216 | } |
| 217 | |
| 218 | s += next |
| 219 | } |
| 220 | return s |
| 221 | } |
| 222 | |
| 223 | func (m stashModel) fullHelpView(groups ...[]string) string { |
| 224 | var tallestCol int |