mirror of https://github.com/Hilbis/Hilbish
fix: percentages in completion entries causing a problem in the completion menus
parent
7de835fab4
commit
387d7d2243
|
@ -138,6 +138,8 @@ menu is open.
|
||||||
- `hilbish.dataDir` now has tilde (`~`) expanded.
|
- `hilbish.dataDir` now has tilde (`~`) expanded.
|
||||||
- Arrow keys now work on Windows terminals.
|
- Arrow keys now work on Windows terminals.
|
||||||
- Escape codes now work.
|
- Escape codes now work.
|
||||||
|
- Escape percentage symbols in completion entries, so you will no longer see
|
||||||
|
an error of missing format variable
|
||||||
|
|
||||||
## [1.2.0] - 2022-03-17
|
## [1.2.0] - 2022-03-17
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -99,7 +99,7 @@ func (g *CompletionGroup) writeGrid(rl *Instance) (comp string) {
|
||||||
|
|
||||||
// If group title, print it and adjust offset.
|
// If group title, print it and adjust offset.
|
||||||
if g.Name != "" {
|
if g.Name != "" {
|
||||||
comp += fmt.Sprintf("%s%s%s %s\n", BOLD, YELLOW, g.Name, RESET)
|
comp += fmt.Sprintf("%s%s%s %s\n", BOLD, YELLOW, fmtEscape(g.Name), RESET)
|
||||||
rl.tcUsedY++
|
rl.tcUsedY++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ func (g *CompletionGroup) writeGrid(rl *Instance) (comp string) {
|
||||||
comp += seqInvert
|
comp += seqInvert
|
||||||
}
|
}
|
||||||
|
|
||||||
comp += fmt.Sprintf("%-"+cellWidth+"s %s", g.Suggestions[i], seqReset)
|
comp += fmt.Sprintf("%-"+cellWidth+"s %s", fmtEscape(g.Suggestions[i]), seqReset)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always add a newline to the group if the end if not punctuated with one
|
// Always add a newline to the group if the end if not punctuated with one
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package readline
|
package readline
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
// CompletionGroup - A group/category of items offered to completion, with its own
|
// CompletionGroup - A group/category of items offered to completion, with its own
|
||||||
// name, descriptions and completion display format/type.
|
// name, descriptions and completion display format/type.
|
||||||
// The output, if there are multiple groups available for a given completion input,
|
// The output, if there are multiple groups available for a given completion input,
|
||||||
|
@ -285,3 +287,7 @@ func (g *CompletionGroup) goLastCell() {
|
||||||
g.tcPosX = 0
|
g.tcPosX = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fmtEscape(s string) string {
|
||||||
|
return strings.Replace(s, "%", "%%", -1)
|
||||||
|
}
|
||||||
|
|
|
@ -206,12 +206,12 @@ func (g *CompletionGroup) writeList(rl *Instance) (comp string) {
|
||||||
if len(item) > maxLength {
|
if len(item) > maxLength {
|
||||||
item = item[:maxLength-3] + "..."
|
item = item[:maxLength-3] + "..."
|
||||||
}
|
}
|
||||||
sugg := fmt.Sprintf("\r%s%-"+cellWidth+"s", highlight(y, 0), item)
|
sugg := fmt.Sprintf("\r%s%-"+cellWidth+"s", highlight(y, 0), fmtEscape(item))
|
||||||
|
|
||||||
// Alt suggestion
|
// Alt suggestion
|
||||||
alt, ok := g.Aliases[item]
|
alt, ok := g.Aliases[item]
|
||||||
if ok {
|
if ok {
|
||||||
alt = fmt.Sprintf(" %s%"+cellWidthAlt+"s", highlight(y, 1), alt)
|
alt = fmt.Sprintf(" %s%"+cellWidthAlt+"s", highlight(y, 1), fmtEscape(alt))
|
||||||
} else {
|
} else {
|
||||||
// Else, make an empty cell
|
// Else, make an empty cell
|
||||||
alt = strings.Repeat(" ", maxLengthAlt+1) // + 2 to keep account of spaces
|
alt = strings.Repeat(" ", maxLengthAlt+1) // + 2 to keep account of spaces
|
||||||
|
|
|
@ -76,7 +76,7 @@ func (g *CompletionGroup) writeMap(rl *Instance) (comp string) {
|
||||||
|
|
||||||
if g.Name != "" {
|
if g.Name != "" {
|
||||||
// Print group title (changes with line returns depending on type)
|
// Print group title (changes with line returns depending on type)
|
||||||
comp += fmt.Sprintf("%s%s%s %s\n", BOLD, YELLOW, g.Name, RESET)
|
comp += fmt.Sprintf("%s%s%s %s\n", BOLD, YELLOW, fmtEscape(g.Name), RESET)
|
||||||
rl.tcUsedY++
|
rl.tcUsedY++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ func (g *CompletionGroup) writeMap(rl *Instance) (comp string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
comp += fmt.Sprintf("\r%-"+cellWidth+"s %s %-"+itemWidth+"s %s\n",
|
comp += fmt.Sprintf("\r%-"+cellWidth+"s %s %-"+itemWidth+"s %s\n",
|
||||||
description, highlight(y), item, seqReset)
|
description, highlight(y), fmtEscape(item), seqReset)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the equivalent of this group's size to final screen clearing
|
// Add the equivalent of this group's size to final screen clearing
|
||||||
|
|
Loading…
Reference in New Issue