For speech preferences, make sure the selected module is spoken. Also reorder so grouping is more similar to Cthulhu.

This commit is contained in:
Storm Dragon committed 2026-11-15 16:03:54 -05:00
1 parent 6168e541cd
commit 87f57912ca
16 files changed
+143 -46

No files matched your search

+1
View File
@@ -108,6 +108,7 @@ func new_application(ctx context.Context, source Source, keyboards Keyboards, vo
a.ui.gridSettings = func() config.InternalUI { return a.settings.live.InternalUI }
a.ui.previewSpelling = a.preview_spelling
a.ui.previewSpeech, a.ui.restoreSpeech = a.preview_menu_speech, a.restore_speech_preview
a.ui.deferSpeech = a.defer_preview_speech
a.ui.discoverChoices, a.ui.saveSettings = options.SettingsChoices, a.save_menu_settings
a.speechResults = make(chan speechChangeResult, 1)
a.preview.results = make(chan speechPreviewResult, 1)
@@ -63,6 +63,9 @@ func TestRogueMenuSelectionNamedReadProfileAndShellExit(t *testing.T) {
t.Fatal(got)
}
base := a.overrideCurrent.underlying.settings.live.Presentation.Speech.Rate
for _, id := range quickToRate {
a.handle_command(id)
}
a.handle_command(command.NextQuickValue)
rate := a.settings.live.Presentation.Speech.Rate
if rate == base {
@@ -360,6 +363,9 @@ func TestOverridesSuspendPerTerminalAndClearOnlyOnFreshShell(t *testing.T) {
override_read(t, a, override_screen(1, "ninjam"))
a.select_override("ninjam")
override_read(t, a, override_screen(1, "ninjam"))
for _, id := range quickToRate {
a.handle_command(id)
}
a.handle_command(command.NextQuickValue)
appRate := a.settings.live.Presentation.Speech.Rate
override_read(t, a, override_screen(2, "other terminal"))
@@ -474,6 +480,9 @@ func TestApplicationProfileReloadAndDefaultInheritance(t *testing.T) {
override_read(t, a, override_screen(1, "ninjam"))
a.select_override("ninjam")
override_read(t, a, override_screen(1, "ninjam"))
for _, id := range quickToRate {
a.handle_command(id)
}
a.handle_command(command.NextQuickValue)
savedRate := a.settings.live.Presentation.Speech.Rate
a.save_settings()
+3
View File
@@ -243,6 +243,9 @@ func TestAttributeSessionToggleQuickSaveAndFreshStartup(t *testing.T) {
handle(input.Decision{Command: command.ToggleAttributes})
// Every quick command reapplies configuration; it must
// preserve the session override and still save the default.
for _, id := range quickToRate {
handle(input.Decision{Command: id})
}
handle(input.Decision{Command: command.NextQuickValue})
handle(input.Decision{Command: command.SaveSettings})
}
+12 -2
View File
@@ -57,6 +57,7 @@ type internalUI struct {
previewSpelling func(config.Reading)
previewSpeech func(config.Speech)
restoreSpeech func()
deferSpeech func(string) bool
speechOverride *config.Speech
testSpeech func(context.Context, config.Speech, config.Speech) error
cancelTest context.CancelFunc
@@ -135,7 +136,16 @@ func (ui *internalUI) close() {
if err := ui.keys.Capture(false); err != nil {
slog.Error("release internal UI capture", "error", err, "at", time.Now())
}
ui.voice.Say(i18n.Format("{0} closed", i18n.T(name)))
ui.say(i18n.Format("{0} closed", i18n.T(name)))
}
// say holds an announcement while a voice preview is switching connections;
// closing the old connection would otherwise cut it off.
func (ui *internalUI) say(text string) {
if ui.deferSpeech != nil && ui.deferSpeech(text) {
return
}
ui.voice.Say(text)
}
func (ui *internalUI) post(update uiUpdate) {
@@ -228,7 +238,7 @@ func (ui *internalUI) handle(key interaction.Key) {
return
}
if result.Speech != "" {
ui.voice.Say(result.Speech)
ui.say(result.Speech)
}
if result.Action != "" && ui.action != nil {
ui.action(result.Action, ui.session)
+15 -10
View File
@@ -69,18 +69,12 @@ func TestSettingsMenuCancelSaveAndReopen(t *testing.T) {
if !ui.active || voice.messages[len(voice.messages)-1] != "Fenrir Menu. Presentation tab" {
t.Fatal(ui.active, voice.messages)
}
ui.handle(interaction.Key{Name: "tab"})
ui.handle(interaction.Key{Name: "tab"})
tab_to_control(t, ui, "speech.rate")
ui.handle(interaction.Key{Name: "up"})
if action == "escape" {
ui.handle(interaction.Key{Name: "escape"})
} else {
for range 13 {
ui.handle(interaction.Key{Name: "tab"})
}
if action == "cancel" {
ui.handle(interaction.Key{Name: "tab"})
}
tab_to_control(t, ui, map[string]string{"save": "ok", "cancel": "cancel"}[action])
ui.handle(interaction.Key{Name: "enter"})
if action == "save" {
finish_persistence(t, a, false)
@@ -102,8 +96,7 @@ func TestSettingsMenuCancelSaveAndReopen(t *testing.T) {
}
ui.open_settings(config.Defaults(), path)
receive_ui(t, ui)
ui.handle(interaction.Key{Name: "tab"})
ui.handle(interaction.Key{Name: "tab"})
tab_to_control(t, ui, "speech.rate")
if ui.session.Values()["presentation.speech.rate"].Number != float64(want) {
t.Fatal("reopen did not reload settings")
}
@@ -354,3 +347,15 @@ func TestMenuAbortsOnTerminalChange(t *testing.T) {
t.Fatal("terminal change did not announce closure", voice.messages)
}
}
// tab_to_control moves focus with Tab, as a user would, until id is focused.
func tab_to_control(t *testing.T, ui *internalUI, id string) {
t.Helper()
for range 64 {
if control, ok := ui.session.Focused_control(); ok && control.ID == id {
return
}
ui.handle(interaction.Key{Name: "tab"})
}
t.Fatalf("control %s not reached with Tab", id)
}
+2 -3
View File
@@ -18,8 +18,7 @@ func admit_menu_save(t *testing.T, a *application) {
t.Helper()
a.open_settings()
receive_ui(t, a.ui)
a.ui.handle(interaction.Key{Name: "tab"})
a.ui.handle(interaction.Key{Name: "tab"})
tab_to_control(t, a.ui, "speech.rate")
a.ui.handle(interaction.Key{Name: "right"}) // Rate 24 -> 25.
a.ui.action("save", a.ui.session)
if !a.saver.busy || a.ui.session != nil {
@@ -113,7 +112,7 @@ func TestMenuCommitPreservesNewerOverridesAndCoordinatesSaves(t *testing.T) {
persistence_reply(t, persistence_request(a, "RESET"), true)
a.save_settings() // Cannot replace the pending menu snapshot.
persistence_reply(t, persistence_request(a, "SET speech#pitch=0.8;keyboard#word_echo=True"), false)
for _, id := range []command.ID{command.NextQuickValue, command.PreviousQuickValue, command.ProgressMonitor, command.Mute, command.AutoRead} {
for _, id := range append(quickToRate, command.NextQuickValue, command.PreviousQuickValue, command.ProgressMonitor, command.Mute, command.AutoRead) {
a.handle_input(input.Decision{Command: id})
}
// Returning rate to its old value still counts as a later adjustment.
+1 -1
View File
@@ -85,7 +85,7 @@ func new_quick_settings(driverID string) *quickSettings {
category.Entries = append(category.Entries, entry)
}
if section.ID == "presentation.speech" {
ranks := map[string]int{"rate": 0, "pitch": 1, "volume": 2, "module": 3, "language": 4, "voice": 5}
ranks := map[string]int{"module": 0, "language": 1, "voice": 2, "rate": 3, "pitch": 4, "volume": 5}
sort.SliceStable(category.Entries, func(i, j int) bool {
return ranks[strings.TrimPrefix(category.Entries[i].ID, "presentation.speech.")] < ranks[strings.TrimPrefix(category.Entries[j].ID, "presentation.speech.")]
})
+34 -14
View File
@@ -43,7 +43,12 @@ func TestQuickSpeechSelectionAdjustmentAndBounds(t *testing.T) {
id command.ID
want string
}{
{command.CurrentQuickEntry, "speech rate 80"},
{command.CurrentQuickEntry, "Speech Dispatcher module default"},
{command.NextQuickEntry, "speech language default"},
{command.NextQuickEntry, "speech voice default"},
{command.CurrentQuickValue, "speech voice default"},
{command.NextQuickValue, "speech voice default"},
{command.NextQuickEntry, "speech rate 80"},
{command.NextQuickValue, "90"},
{command.NextQuickValue, "100"},
{command.NextQuickValue, "100"},
@@ -53,15 +58,13 @@ func TestQuickSpeechSelectionAdjustmentAndBounds(t *testing.T) {
{command.NextQuickEntry, "speech volume 100"},
{command.PreviousQuickValue, "90"},
{command.NextQuickEntry, "Speech Dispatcher module default"},
{command.NextQuickEntry, "speech language default"},
{command.NextQuickEntry, "speech voice default"},
{command.CurrentQuickValue, "speech voice default"},
{command.NextQuickValue, "speech voice default"},
{command.NextQuickEntry, "speech rate 100"},
{command.PreviousQuickEntry, "speech voice default"},
{command.PreviousQuickEntry, "speech language default"},
{command.PreviousQuickEntry, "Speech Dispatcher module default"},
{command.PreviousQuickEntry, "speech volume 90"},
{command.PreviousQuickEntry, "speech pitch -10"},
{command.PreviousQuickEntry, "speech rate 100"},
{command.PreviousQuickEntry, "speech voice default"},
{command.NextQuickEntry, "speech rate 100"},
{command.NextQuickEntry, "speech pitch -10"},
{command.NextQuickEntry, "speech volume 90"},
} {
if !menu.command(testCase.id, &settings, voice) || voice.messages[len(voice.messages)-1] != testCase.want {
t.Fatal(testCase, voice.messages)
@@ -116,7 +119,7 @@ func TestQuickChangesSurviveMenuCancelAndExplicitSaveThenQuit(t *testing.T) {
defer cancel()
keys.poll = func(_ bool, handle func(input.Decision)) error {
keys.poll = nil
for _, id := range []command.ID{command.NextQuickValue, command.NextQuickEntry, command.PreviousQuickValue, command.AutoRead, command.ToggleTracking, command.SaveSettings, command.Quit} {
for _, id := range append(quickToRate, command.NextQuickValue, command.NextQuickEntry, command.PreviousQuickValue, command.AutoRead, command.ToggleTracking, command.SaveSettings, command.Quit) {
handle(input.Decision{Command: id, Interrupt: true})
}
return nil
@@ -139,6 +142,7 @@ func TestQuickChangesSurviveMenuCancelAndExplicitSaveThenQuit(t *testing.T) {
// Opening the full menu reflects unsaved quick adjustments; cancelling
// it leaves the running values and the existing disk file intact.
menu := new_quick_settings("speech-dispatcher")
quick_select_rate(menu, &base, voice)
menu.command(command.NextQuickValue, &base, voice)
ui := new_internal_ui(context.Background(), keys, voice)
ui.open_settings(base, path, base)
@@ -192,6 +196,9 @@ func TestSessionMuteDoesNotPersistAcrossRestart(t *testing.T) {
t.Fatal("session mute did not toggle", voice.muted)
}
if trial.save {
for _, id := range quickToRate {
handle(input.Decision{Command: id})
}
handle(input.Decision{Command: command.NextQuickValue})
handle(input.Decision{Command: command.SaveSettings})
}
@@ -255,6 +262,9 @@ func TestSessionAutomaticReadingDoesNotPersistAcrossRestart(t *testing.T) {
t.Fatal(voice.messages)
}
if trial.save {
for _, id := range quickToRate {
handle(input.Decision{Command: id})
}
handle(input.Decision{Command: command.NextQuickValue})
handle(input.Decision{Command: command.SaveSettings})
}
@@ -294,6 +304,7 @@ func TestSaveFailureKeepsRunningQuickSettings(t *testing.T) {
settings := config.Defaults()
voice := &fakeVoice{}
menu := new_quick_settings("speech-dispatcher")
quick_select_rate(menu, &settings, voice)
menu.command(command.NextQuickValue, &settings, voice)
saver := &settingsSaver{results: make(chan error, 1)}
saver.save(context.Background(), filepath.Join(path, "settings.toml"), settings)
@@ -319,7 +330,7 @@ func TestQuickCategoriesRememberSelectionAndWrap(t *testing.T) {
id command.ID
want string
}{
{command.NextQuickEntry, "speech pitch 0"},
{command.NextQuickEntry, "speech language default"},
{command.NextQuickCategory, "Reading. Punctuation level some"},
{command.NextQuickValue, "most"},
{command.NextQuickValue, "all"},
@@ -331,10 +342,10 @@ func TestQuickCategoriesRememberSelectionAndWrap(t *testing.T) {
{command.NextQuickCategory, "Keyboard. Character echo checked"},
{command.NextQuickValue, "unchecked"},
{command.PreviousQuickEntry, "Echo on CapsLock unchecked"},
{command.NextQuickCategory, "Speech. speech pitch 0"},
{command.NextQuickCategory, "Speech. speech language default"},
{command.PreviousQuickCategory, "Keyboard. Echo on CapsLock unchecked"},
{command.PreviousQuickCategory, "Reading. Indentation none"},
{command.PreviousQuickCategory, "Speech. speech pitch 0"},
{command.PreviousQuickCategory, "Speech. speech language default"},
{command.PreviousQuickCategory, "Keyboard. Echo on CapsLock unchecked"},
} {
menu.command(trial.id, &settings, voice)
@@ -342,7 +353,7 @@ func TestQuickCategoriesRememberSelectionAndWrap(t *testing.T) {
t.Fatalf("%s: got %q, want %q", trial.id, got, trial.want)
}
}
if menu := new_quick_settings("speech-dispatcher"); !menu.command(command.CurrentQuickEntry, &settings, voice) || voice.messages[len(voice.messages)-1] != "speech rate 0" {
if menu := new_quick_settings("speech-dispatcher"); !menu.command(command.CurrentQuickEntry, &settings, voice) || voice.messages[len(voice.messages)-1] != "Speech Dispatcher module default" {
t.Fatal("new session did not reset selection", voice.messages)
}
}
@@ -477,3 +488,12 @@ func TestQuickEchoAppliesLiveWithAutomaticReadingOff(t *testing.T) {
}
}
}
// quickToRate reaches rate past the module, language and voice entries.
var quickToRate = []command.ID{command.NextQuickEntry, command.NextQuickEntry, command.NextQuickEntry}
func quick_select_rate(menu *quickSettings, settings *config.Settings, voice Speaker) {
for _, id := range quickToRate {
menu.command(id, settings, voice)
}
}
+1 -1
View File
@@ -71,7 +71,7 @@ func TestMenuRemoteAndQuickSavePreserveNextLaunchChoices(t *testing.T) {
t.Fatal("remote assignment changed unrelated session state")
}
}
for _, id := range []command.ID{command.NextQuickValue, command.SaveSettings, command.Quit} {
for _, id := range append(quickToRate, command.NextQuickValue, command.SaveSettings, command.Quit) {
a.handle_input(input.Decision{Command: id})
}
if err := a.loop(nil); err != nil || ctx.Err() != nil {
+15
View File
@@ -21,6 +21,7 @@ type speechPreview struct {
selection config.Speech
parameters speech.Parameters
queued *config.Speech
announce string
idle []func()
results chan speechPreviewResult
}
@@ -98,6 +99,10 @@ func (a *application) speech_preview_result(result speechPreviewResult) {
if preview.busy {
return
}
if announce := preview.announce; announce != "" {
preview.announce = ""
a.voice.Say(announce)
}
if same_speech_selection(preview.selection, a.settings.live.Presentation.Speech) &&
preview.parameters == speech_parameters(a.settings.live) {
preview.active = false
@@ -137,3 +142,13 @@ func (a *application) after_speech_preview(run func()) bool {
a.preview.idle = append(a.preview.idle, run)
return true
}
// defer_preview_speech keeps only the newest menu announcement until the
// candidate connection is speaking.
func (a *application) defer_preview_speech(text string) bool {
if !a.preview.busy {
return false
}
a.preview.announce = text
return true
}
+29 -2
View File
@@ -135,8 +135,7 @@ func TestMenuRateChangeIsHeardAndEscapeRestoresIt(t *testing.T) {
live := speech_parameters(a.settings.live)
a.open_settings()
receive_ui(t, a.ui)
a.ui.handle(interaction.Key{Name: "tab"})
a.ui.handle(interaction.Key{Name: "tab"})
tab_to_control(t, a.ui, "speech.rate")
a.ui.handle(interaction.Key{Name: "right"})
if len(voice.parameters) == 0 || voice.parameters[len(voice.parameters)-1].Rate != live.Rate+1 {
t.Fatal("menu rate change was not previewed", voice.parameters, live)
@@ -146,3 +145,31 @@ func TestMenuRateChangeIsHeardAndEscapeRestoresIt(t *testing.T) {
t.Fatal("escape did not restore the live voice", got, live)
}
}
func TestMenuAnnouncementWaitsForPreviewedVoice(t *testing.T) {
a, voice, _, prepared := preview_application(t)
selected := a.settings.live.Presentation.Speech
selected.Module = "fixture"
a.preview_menu_speech(selected)
<-prepared
a.ui.say("old announcement")
a.ui.say("Speech Dispatcher module combo box fixture")
for _, message := range voice.messages {
if message == "Speech Dispatcher module combo box fixture" {
t.Fatal("announcement reached the connection being replaced")
}
}
finish_preview(t, a, voice)
if got := voice.messages[len(voice.messages)-1]; got != "Speech Dispatcher module combo box fixture" {
t.Fatal("announcement not spoken with the new voice", voice.messages)
}
for _, message := range voice.messages {
if message == "old announcement" {
t.Fatal("superseded announcement was spoken")
}
}
a.ui.say("next")
if got := voice.messages[len(voice.messages)-1]; got != "next" {
t.Fatal("idle announcement was held", voice.messages)
}
}
+2 -3
View File
@@ -187,6 +187,7 @@ func TestMenuSelectionFailurePreservesDiskAndCommittedSaveSurvivesClose(t *testi
}
<-started
a.ui.close()
quick_select_rate(a.quick, &a.settings.live, a.voice)
a.quick.command(command.NextQuickValue, &a.settings.live, a.voice)
close(release)
finish_persistence(t, a, failed)
@@ -258,9 +259,7 @@ func TestQuickVoiceCancelSaveAndStaleFeedback(t *testing.T) {
}}}
started, release := make(chan struct{}), make(chan struct{})
a.prepareSpeech = func(config.Speech) (speech.Transport, error) { close(started); <-release; return &preparedVoice{}, nil }
for range 3 {
a.quick.command(command.NextQuickEntry, &a.settings.live, a.voice)
}
// The module is the first speech entry.
a.quick.command(command.NextQuickValue, &a.settings.live, a.voice)
<-started
// Focus handoff invalidates presentation, not the admitted setting change.
+2 -1
View File
@@ -135,7 +135,8 @@ func TestQuickVoiceProfilePreservesLaterNumericAdjustment(t *testing.T) {
menu.command(command.NextQuickEntry, &settings, voice)
}
menu.command(command.NextQuickValue, &settings, voice)
menu.command(command.NextQuickEntry, &settings, voice) // wraps to rate
menu.command(command.NextQuickEntry, &settings, voice) // wraps to the module
quick_select_rate(menu, &settings, voice)
menu.command(command.NextQuickValue, &settings, voice)
complete(nil, true)
if settings.Presentation.Speech.Rate != 10 || settings.Presentation.Speech.Volume != 80 {
+1 -1
View File
@@ -131,13 +131,13 @@ type Sound struct {
}
type Speech struct {
Enabled bool `toml:"enabled" label:"Speech enabled"`
Rate int `toml:"rate" label:"Rate" min:"-100" max:"100" step:"1" quick:"speech rate"`
Driver string `toml:"driver" label:"Driver" choices:"speech-driver"`
HardwareDevice string `toml:"hardware_device" label:"Serial port" speech:"serial"`
HardwareBaudRate int `toml:"hardware_baud_rate" label:"Baud rate" choices:"speech-baud" speech:"serial"`
Module string `toml:"module" label:"Speech Dispatcher module" choices:"speech-module" quick:"Speech Dispatcher module" speech:"modules"`
Language string `toml:"language" label:"Speech language" choices:"speech-language" quick:"speech language" speech:"voices"`
Voice string `toml:"voice" label:"Speech voice" choices:"speech-voice" quick:"speech voice" speech:"voices"`
Rate int `toml:"rate" label:"Rate" min:"-100" max:"100" step:"1" quick:"speech rate"`
Pitch int `toml:"pitch" label:"Pitch" min:"-100" max:"100" step:"1" quick:"speech pitch"`
Volume int `toml:"volume" label:"Volume" min:"-100" max:"100" step:"1" quick:"speech volume"`
}
+1 -2
View File
@@ -24,8 +24,7 @@ func TestApplicationSettingsOnlyExposeRestorableControls(t *testing.T) {
if _, exists := values["presentation.speech.voice"]; !exists {
t.Fatal("voice control missing")
}
session.Handle(interaction.Key{Name: "tab"})
session.Handle(interaction.Key{Name: "tab"})
tab_to_control(t, session, "speech.rate")
session.Handle(interaction.Key{Name: "up"})
saved, err := Application_settings(session, base)
if err != nil || saved.Presentation.Speech.Rate != base.Presentation.Speech.Rate+10 || saved.Keyboard.Layout != base.Keyboard.Layout {
+15 -6
View File
@@ -47,7 +47,7 @@ func TestSettingsFormCoversSchemaAndReturnsIsolatedDraft(t *testing.T) {
}
session.Handle(interaction.Key{Name: "tab"})
session.Handle(interaction.Key{Name: "space"})
session.Handle(interaction.Key{Name: "tab"})
tab_to_control(t, session, "speech.rate")
session.Handle(interaction.Key{Name: "up"})
draft, err := Settings(session, base)
if err != nil {
@@ -79,8 +79,7 @@ func TestSpeechRateArrowSteps(t *testing.T) {
if err != nil {
t.Fatal(err)
}
session.Handle(interaction.Key{Name: "tab"}) // Speech enabled.
session.Handle(interaction.Key{Name: "tab"}) // Rate.
tab_to_control(t, session, "speech.rate")
result := session.Handle(interaction.Key{Name: trial.key})
if want := "Rate " + strconv.Itoa(trial.want); result.Speech != want {
t.Fatalf("application=%v, rate=%d, key=%s: speech=%q, want %q", application, trial.start, trial.key, result.Speech, want)
@@ -272,9 +271,7 @@ func TestConstrainedChoicesKeepStableIDsAndIgnoreTextEditing(t *testing.T) {
if err != nil {
t.Fatal(err)
}
for range 3 {
session.Handle(interaction.Key{Name: "tab"})
}
tab_to_control(t, session, "speech.driver")
session.Handle(interaction.Key{Ctrl: true, Text: "a"})
session.Handle(interaction.Key{Text: "invented-driver"})
session.Handle(interaction.Key{Name: "tab"})
@@ -345,3 +342,15 @@ func TestInternalUIOptionsAndApplicationIsolation(t *testing.T) {
}
}
}
// tab_to_control moves focus with Tab, as a user would, until id is focused.
func tab_to_control(t *testing.T, session *interaction.Session, id string) {
t.Helper()
for range 64 {
if control, ok := session.Focused_control(); ok && control.ID == id {
return
}
session.Handle(interaction.Key{Name: "tab"})
}
t.Fatalf("control %s not reached with Tab", id)
}