feat: add argument description to UI when suggestions are available

Signed-off-by: cpendery <cpendery@vt.edu>
This commit is contained in:
cpendery
2023-09-12 22:07:11 -04:00
parent b8bafd6354
commit 59f810fb2b
2 changed files with 42 additions and 1 deletions
+25
View File
@@ -0,0 +1,25 @@
package suggestions
import "github.com/charmbracelet/lipgloss"
var SuggestionWithDescriptionBorder = lipgloss.Border{
Top: "─",
Bottom: "─",
Left: "│",
Right: "│",
TopLeft: "┌",
TopRight: "┐",
BottomLeft: "├",
BottomRight: "┤",
}
var ArgumentDescriptionBorder = lipgloss.Border{
Top: "",
Bottom: "─",
Left: "│",
Right: "│",
TopLeft: "",
TopRight: "",
BottomLeft: "└",
BottomRight: "┘",
}
+17 -1
View File
@@ -132,10 +132,15 @@ func pageSuggestions(suggestions []autocomplete.Suggestion, cursorLocation int)
}
func (m Model) renderSuggestions(width int) string {
suggestionBorder := lipgloss.NormalBorder()
if m.argDescription != "" {
suggestionBorder = SuggestionWithDescriptionBorder
}
var style = lipgloss.NewStyle().
Bold(true).
Width(width).
BorderStyle(lipgloss.NormalBorder()).
BorderStyle(suggestionBorder).
BorderForeground(lipgloss.Color("63"))
m.suggestions = pageSuggestions(m.suggestions, m.cursor)
@@ -145,6 +150,17 @@ func (m Model) renderSuggestions(width int) string {
r[idx] = m.renderSuggestion(suggestion.Name, idx, m.cursor, width)
}
if m.argDescription != "" {
descriptionStyle := lipgloss.NewStyle().
Width(width).
Border(ArgumentDescriptionBorder, false, true, true, true).
BorderForeground(lipgloss.Color("63"))
return lipgloss.JoinVertical(
lipgloss.Left,
style.Render(strings.Join(r, "\n")),
descriptionStyle.Render(m.argDescription))
}
return style.Render(strings.Join(r, "\n"))
}