From cc8c0c8a11605b02bb9e15b5775f1c53da8bd668 Mon Sep 17 00:00:00 2001 From: leonardotrapani Date: Sun, 1 Feb 2026 13:21:10 +0100 Subject: [PATCH] implement editLanguage function in TUI with model compatibility warning --- internal/tui/configure_language.go | 76 +++++++++++++++++++++++++++++- progress.txt | 10 ++++ tasks/prd.jsonc | 2 +- 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/internal/tui/configure_language.go b/internal/tui/configure_language.go index c719be6..a9e40c9 100644 --- a/internal/tui/configure_language.go +++ b/internal/tui/configure_language.go @@ -1,11 +1,85 @@ package tui import ( + "fmt" + + "github.com/charmbracelet/huh" "github.com/leonardotrapani/hyprvoice/internal/config" + "github.com/leonardotrapani/hyprvoice/internal/language" + "github.com/leonardotrapani/hyprvoice/internal/provider" ) // editLanguage allows the user to select the global transcription language func editLanguage(cfg *config.Config) error { - // implementation in task 5 + // no model-specific warnings for global language selection + languageOptions := getLanguageOptions(nil) + + selectedLanguage := cfg.General.Language + + form := huh.NewForm( + huh.NewGroup( + huh.NewSelect[string](). + Title("Language"). + Description("Select language for transcription (applies globally)"). + Options(languageOptions...). + Filtering(true). + Value(&selectedLanguage), + ), + ).WithTheme(getTheme()) + + if err := form.Run(); err != nil { + return err + } + + // check if current transcription model supports the selected language + if selectedLanguage != "" && cfg.Transcription.Provider != "" && cfg.Transcription.Model != "" { + registryName := mapConfigProviderToRegistry(cfg.Transcription.Provider) + model, err := provider.GetModel(registryName, cfg.Transcription.Model) + if err == nil && !model.SupportsLanguage(selectedLanguage) { + langName := language.FromCode(selectedLanguage).Name + if langName == "" { + langName = selectedLanguage + } + + fmt.Println() + fmt.Println(StyleWarning.Render("Language-Model Compatibility Warning")) + fmt.Printf("Your current model '%s' does not support %s.\n", model.Name, langName) + fmt.Println() + fmt.Println(StyleMuted.Render("You can:")) + fmt.Println(StyleMuted.Render(" - Keep this language and change the model later")) + fmt.Println(StyleMuted.Render(" - Use 'Auto-detect' for language")) + fmt.Println(StyleMuted.Render(" - Choose a different language")) + fmt.Println() + + var action string + actionForm := huh.NewForm( + huh.NewGroup( + huh.NewSelect[string](). + Title("What would you like to do?"). + Options( + huh.NewOption("Keep this language (change model later)", "keep"), + huh.NewOption("Use Auto-detect instead", "auto"), + huh.NewOption("Choose a different language", "retry"), + ). + Value(&action), + ), + ).WithTheme(getTheme()) + + if err := actionForm.Run(); err != nil { + return err + } + + switch action { + case "auto": + selectedLanguage = "" + case "retry": + return editLanguage(cfg) + case "keep": + // proceed with incompatible language + } + } + } + + cfg.General.Language = selectedLanguage return nil } diff --git a/progress.txt b/progress.txt index bea5a80..d07c265 100644 --- a/progress.txt +++ b/progress.txt @@ -536,4 +536,14 @@ Started: Sun Feb 1 12:22:47 AM CET 2026 - Shows "Language (Auto-detect)" when empty, "Language ({name})" when set - Added case SectionLanguage in runEditExisting switch calling editLanguage() - Created stub configure_language.go with editLanguage() function (implementation in Task 5) +- All tests passing, typecheck passes + +### Task 5: Create editLanguage function in TUI +- Implemented `editLanguage(cfg *config.Config)` in configure_language.go +- Uses `getLanguageOptions(nil)` for 58 options (57 languages + Auto-detect) +- huh.NewSelect with `.Filtering(true)` for searchable language picker +- Saves selected language to `cfg.General.Language` +- Checks if current transcription model supports selected language via `provider.GetModel()` + `model.SupportsLanguage()` +- Shows warning dialog with 3 options: keep incompatible language, use auto-detect, or choose different language +- Recursive retry flow if user chooses "Choose a different language" - All tests passing, typecheck passes \ No newline at end of file diff --git a/tasks/prd.jsonc b/tasks/prd.jsonc index 7785601..cbe0adb 100644 --- a/tasks/prd.jsonc +++ b/tasks/prd.jsonc @@ -81,7 +81,7 @@ "Warning shown if current model doesn't support selected language", "Typecheck passes" ], - "passes": false + "passes": true }, { "title": "Remove language from transcription edit flow",