add language picker dropdown to TUI with filtering and model compatibility warnings

This commit is contained in:
leonardotrapani
2026-02-01 01:32:02 +01:00
parent 973643a698
commit 3af88e30c9
4 changed files with 67 additions and 10 deletions
+40
View File
@@ -0,0 +1,40 @@
package tui
import (
"fmt"
"github.com/charmbracelet/huh"
"github.com/leonardotrapani/hyprvoice/internal/language"
"github.com/leonardotrapani/hyprvoice/internal/provider"
)
// getLanguageOptions returns language options for the dropdown
// if currentModel is provided, languages unsupported by that model will be marked
func getLanguageOptions(currentModel *provider.Model) []huh.Option[string] {
var options []huh.Option[string]
// auto-detect is always first and recommended
options = append(options, huh.NewOption("Auto-detect (Recommended)", ""))
// add all languages
for _, lang := range language.List() {
label := formatLanguageLabel(lang)
// add warning if model doesn't support this language
if currentModel != nil && !currentModel.SupportsLanguage(lang.Code) {
label += " (not supported by current model)"
}
options = append(options, huh.NewOption(label, lang.Code))
}
return options
}
// formatLanguageLabel formats a language for display
func formatLanguageLabel(lang language.Language) string {
if lang.Name == lang.NativeName || lang.NativeName == "" {
return fmt.Sprintf("%s (%s)", lang.Name, lang.Code)
}
return fmt.Sprintf("%s - %s (%s)", lang.Name, lang.NativeName, lang.Code)
}