add language picker dropdown to TUI with filtering and model compatibility warnings
This commit is contained in:
@@ -125,13 +125,17 @@ func editTranscription(cfg *config.Config, configuredProviders []string) ([]stri
|
||||
modelDesc = fmt.Sprintf("Currently: %s", cfg.Transcription.Model)
|
||||
}
|
||||
|
||||
language := cfg.Transcription.Language
|
||||
selectedLanguage := cfg.Transcription.Language
|
||||
|
||||
langDesc := "ISO-639-1 code (e.g., 'en', 'es', 'fr') or empty for auto-detect"
|
||||
if cfg.Transcription.Language != "" {
|
||||
langDesc = fmt.Sprintf("Currently: %s. %s", cfg.Transcription.Language, langDesc)
|
||||
// get current model for language compatibility warnings
|
||||
var currentModel *provider.Model
|
||||
registryName := mapConfigProviderToRegistry(selectedProvider)
|
||||
if m, err := provider.GetModel(registryName, selectedModel); err == nil {
|
||||
currentModel = m
|
||||
}
|
||||
|
||||
languageOptions := getLanguageOptions(currentModel)
|
||||
|
||||
modelForm := huh.NewForm(
|
||||
huh.NewGroup(
|
||||
huh.NewSelect[string]().
|
||||
@@ -139,11 +143,12 @@ func editTranscription(cfg *config.Config, configuredProviders []string) ([]stri
|
||||
Description(modelDesc).
|
||||
Options(modelOptions...).
|
||||
Value(&selectedModel),
|
||||
huh.NewInput().
|
||||
huh.NewSelect[string]().
|
||||
Title("Language").
|
||||
Description(langDesc).
|
||||
Placeholder("auto-detect").
|
||||
Value(&language),
|
||||
Description("Select language for transcription").
|
||||
Options(languageOptions...).
|
||||
Filtering(true).
|
||||
Value(&selectedLanguage),
|
||||
),
|
||||
).WithTheme(getTheme())
|
||||
|
||||
@@ -203,7 +208,7 @@ func editTranscription(cfg *config.Config, configuredProviders []string) ([]stri
|
||||
}
|
||||
|
||||
cfg.Transcription.Model = selectedModel
|
||||
cfg.Transcription.Language = language
|
||||
cfg.Transcription.Language = selectedLanguage
|
||||
|
||||
return configuredProviders, nil
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -286,3 +286,15 @@ Started: Sun Feb 1 12:22:47 AM CET 2026
|
||||
- Added download confirmation dialog after selecting uninstalled model
|
||||
- Download shows progress percentage (10%, 20%, ...)
|
||||
- All tests passing, typecheck passes
|
||||
|
||||
### Task 29: Add language picker to TUI using language package
|
||||
- Created `internal/tui/languages.go` with `getLanguageOptions()` function
|
||||
- Takes optional `*provider.Model` to show compatibility warnings for non-supported languages
|
||||
- First option is "Auto-detect (Recommended)" with empty value
|
||||
- Languages formatted as "Name - NativeName (code)" when native name differs
|
||||
- English-only models (*.en) show "(not supported by current model)" for non-English languages
|
||||
- Updated `editTranscription()` to use `huh.NewSelect` with `Filtering(true)` instead of text input
|
||||
- Pass current model to `getLanguageOptions()` for compatibility warnings
|
||||
- Language code saved to config, not display name
|
||||
- All 57 languages + Auto = 58 options total
|
||||
- All tests passing, typecheck passes
|
||||
+1
-1
@@ -689,7 +689,7 @@
|
||||
"Selecting language saves the Code to config",
|
||||
"Typecheck passes"
|
||||
],
|
||||
"passes": false
|
||||
"passes": true
|
||||
},
|
||||
{
|
||||
"title": "Add TUI validation for language-model compatibility on save",
|
||||
|
||||
Reference in New Issue
Block a user