Use common v0.8.0 UI, transport, and translation APIs
This commit is contained in:
1 parent
317303adb7
commit
92fd479336
344 files changed
+4102
-4973
No files matched your search
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
func TestApplicationSettingsOnlyExposeRestorableControls(t *testing.T) {
|
||||
base := config.Defaults()
|
||||
session, err := New_application_session(base, nil, "Ninjam application settings")
|
||||
session, err := NewApplicationSession(base, nil, "Ninjam application settings")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -24,9 +24,9 @@ func TestApplicationSettingsOnlyExposeRestorableControls(t *testing.T) {
|
||||
if _, exists := values["presentation.speech.voice"]; !exists {
|
||||
t.Fatal("voice control missing")
|
||||
}
|
||||
tab_to_control(t, session, "speech.rate")
|
||||
tabToControl(t, session, "speech.rate")
|
||||
session.Handle(interaction.Key{Name: "up"})
|
||||
saved, err := Application_settings(session, base)
|
||||
saved, err := ApplicationSettings(session, base)
|
||||
if err != nil || saved.Presentation.Speech.Rate != base.Presentation.Speech.Rate+10 || saved.Keyboard.Layout != base.Keyboard.Layout {
|
||||
t.Fatal(saved, err)
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ type Discovery struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
// Discover_choices runs only in a worker, never on the input loop.
|
||||
func Discover_choices(settings config.Settings) Discovery {
|
||||
driver, err := speech.Find_driver(settings.Presentation.Speech.Driver)
|
||||
// DiscoverChoices runs only in a worker, never on the input loop.
|
||||
func DiscoverChoices(settings config.Settings) Discovery {
|
||||
driver, err := speech.FindDriver(settings.Presentation.Speech.Driver)
|
||||
if err == nil {
|
||||
err = driver.Availability()
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func (d Discovery) Choices(settings config.Settings) Choices {
|
||||
for _, module := range d.Catalog.Modules {
|
||||
modules = append(modules, config.Choice{ID: module, Label: module})
|
||||
}
|
||||
result["presentation.speech.module"] = preserve_choice(modules, selected.Module, d.Err)
|
||||
result["presentation.speech.module"] = preserveChoice(modules, selected.Module, d.Err)
|
||||
voices := d.Catalog.Voices[selected.Module]
|
||||
err := d.Err
|
||||
if moduleErr := d.Catalog.Errors[selected.Module]; moduleErr != nil {
|
||||
@@ -60,10 +60,10 @@ func (d Discovery) Choices(settings config.Settings) Choices {
|
||||
seen[voice.Language] = true
|
||||
}
|
||||
}
|
||||
result["presentation.speech.language"] = preserve_choice(languages, selected.Language, err)
|
||||
result["presentation.speech.language"] = preserveChoice(languages, selected.Language, err)
|
||||
filtered := voices
|
||||
if selected.Language != "" {
|
||||
filtered = speech.Language_voices(voices, selected.Language)
|
||||
filtered = speech.LanguageVoices(voices, selected.Language)
|
||||
} else {
|
||||
espeak := strings.Contains(strings.ToLower(selected.Module), "espeak")
|
||||
if selected.Module == "" {
|
||||
@@ -75,7 +75,7 @@ func (d Discovery) Choices(settings config.Settings) Choices {
|
||||
}
|
||||
}
|
||||
if espeak {
|
||||
filtered = speech.Language_voices(voices, "")
|
||||
filtered = speech.LanguageVoices(voices, "")
|
||||
}
|
||||
}
|
||||
voiceChoices := []config.Choice{{ID: "", Label: "default"}}
|
||||
@@ -88,11 +88,11 @@ func (d Discovery) Choices(settings config.Settings) Choices {
|
||||
voiceChoices = append(voiceChoices, config.Choice{ID: voice.Name, Label: voice.Name})
|
||||
}
|
||||
}
|
||||
result["presentation.speech.voice"] = preserve_choice(voiceChoices, selected.Voice, err)
|
||||
result["presentation.speech.voice"] = preserveChoice(voiceChoices, selected.Voice, err)
|
||||
return result
|
||||
}
|
||||
|
||||
func preserve_choice(choices []config.Choice, saved string, err error) []config.Choice {
|
||||
func preserveChoice(choices []config.Choice, saved string, err error) []config.Choice {
|
||||
if err != nil {
|
||||
choices[0].Unavailable = err.Error()
|
||||
}
|
||||
@@ -106,10 +106,10 @@ func preserve_choice(choices []config.Choice, saved string, err error) []config.
|
||||
return append(choices, config.Choice{ID: saved, Label: saved, Unavailable: reason})
|
||||
}
|
||||
|
||||
// Refresh_speech updates driver visibility and dependent choices. Driver changes
|
||||
// RefreshSpeech updates driver visibility and dependent choices. Driver changes
|
||||
// keep hidden edits; module/language changes clear their dependent selections.
|
||||
// The result tells the host when a different driver's catalog may be needed.
|
||||
func (d Discovery) Refresh_speech(session *interaction.Session, previous *config.Settings) bool {
|
||||
func (d Discovery) RefreshSpeech(session *interaction.Session, previous *config.Settings) bool {
|
||||
next := *previous
|
||||
values := session.Values()
|
||||
for path, target := range map[string]*string{
|
||||
@@ -132,11 +132,11 @@ func (d Discovery) Refresh_speech(session *interaction.Session, previous *config
|
||||
driverChanged := next.Presentation.Speech.Driver != previous.Presentation.Speech.Driver
|
||||
*previous = next
|
||||
if driverChanged {
|
||||
driver, _ := speech.Find_driver(next.Presentation.Speech.Driver)
|
||||
session.Set_hidden("presentation", "speech.test", !driver.Hardware)
|
||||
driver, _ := speech.FindDriver(next.Presentation.Speech.Driver)
|
||||
session.SetHidden("presentation", "speech.test", !driver.Hardware)
|
||||
for _, definition := range config.Definitions() {
|
||||
if definition.SpeechCapability != "" {
|
||||
session.Set_hidden("presentation", strings.TrimPrefix(definition.Path, "presentation."), !definition.Available(next))
|
||||
session.SetHidden("presentation", strings.TrimPrefix(definition.Path, "presentation."), !definition.Available(next))
|
||||
}
|
||||
}
|
||||
// Keep each backend's hidden selections intact while another driver is
|
||||
@@ -152,27 +152,27 @@ func (d Discovery) Refresh_speech(session *interaction.Session, previous *config
|
||||
next.Presentation.Speech.Voice = ""
|
||||
choices := d.Choices(next)
|
||||
if moduleChanged {
|
||||
session.Replace_choices("presentation", "speech.language", interaction_choices(choices["presentation.speech.language"]), "")
|
||||
session.ReplaceChoices("presentation", "speech.language", interactionChoices(choices["presentation.speech.language"]), "")
|
||||
}
|
||||
session.Replace_choices("presentation", "speech.voice", interaction_choices(choices["presentation.speech.voice"]), "")
|
||||
session.ReplaceChoices("presentation", "speech.voice", interactionChoices(choices["presentation.speech.voice"]), "")
|
||||
*previous = next
|
||||
return false
|
||||
}
|
||||
|
||||
// Refresh_catalog applies a worker result to the current selector draft. It
|
||||
// RefreshCatalog applies a worker result to the current selector draft. It
|
||||
// never moves focus or resets a selection made while discovery was pending.
|
||||
func (d Discovery) Refresh_catalog(session *interaction.Session, selected config.Settings) {
|
||||
func (d Discovery) RefreshCatalog(session *interaction.Session, selected config.Settings) {
|
||||
choices := d.Choices(selected)
|
||||
for path, value := range map[string]string{
|
||||
"presentation.speech.module": selected.Presentation.Speech.Module,
|
||||
"presentation.speech.language": selected.Presentation.Speech.Language,
|
||||
"presentation.speech.voice": selected.Presentation.Speech.Voice,
|
||||
} {
|
||||
session.Replace_choices("presentation", strings.TrimPrefix(path, "presentation."), interaction_choices(choices[path]), value)
|
||||
session.ReplaceChoices("presentation", strings.TrimPrefix(path, "presentation."), interactionChoices(choices[path]), value)
|
||||
}
|
||||
}
|
||||
|
||||
func interaction_choices(choices []config.Choice) []interaction.Choice {
|
||||
func interactionChoices(choices []config.Choice) []interaction.Choice {
|
||||
result := make([]interaction.Choice, 0, len(choices))
|
||||
for _, choice := range choices {
|
||||
result = append(result, interaction.Choice{ID: choice.ID, Label: choice.Label, Unavailable: choice.Unavailable})
|
||||
|
||||
@@ -33,12 +33,12 @@ func TestModuleDiscoveryAndOfflinePreservation(t *testing.T) {
|
||||
base := config.Defaults()
|
||||
base.Presentation.Speech.Module = "saved-module"
|
||||
t.Setenv("SPEECHD_ADDRESS", "unix_socket:"+filepath.Join(t.TempDir(), "missing.sock"))
|
||||
offline := Discover_choices(base).Choices(base)
|
||||
offline := DiscoverChoices(base).Choices(base)
|
||||
choices := offline["presentation.speech.module"]
|
||||
if len(choices) != 2 || choices[1].ID != "saved-module" || choices[1].Unavailable == "" {
|
||||
t.Fatal(choices)
|
||||
}
|
||||
session, err := New_session(base, nil, offline)
|
||||
session, err := NewSession(base, nil, offline)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -69,7 +69,7 @@ func TestModuleDiscoveryAndOfflinePreservation(t *testing.T) {
|
||||
done <- request
|
||||
}()
|
||||
t.Setenv("SPEECHD_ADDRESS", "unix_socket:"+path)
|
||||
online := Discover_choices(base).Choices(base)["presentation.speech.module"]
|
||||
online := DiscoverChoices(base).Choices(base)["presentation.speech.module"]
|
||||
if request := <-done; request != "LIST OUTPUT_MODULES\r\n" {
|
||||
t.Fatal(request)
|
||||
}
|
||||
@@ -96,19 +96,19 @@ func TestDependentSpeechChoicesKeepSavedVoicesAndFilterEspeak(t *testing.T) {
|
||||
if got := choices["presentation.speech.voice"]; len(got) != 4 || got[3].ID != "German" || got[3].Unavailable != "" {
|
||||
t.Fatal("valid saved voice lost", got)
|
||||
}
|
||||
session, err := New_session(base, nil, choices)
|
||||
session, err := NewSession(base, nil, choices)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
previous := base
|
||||
session.Replace_choices("presentation", "speech.language", interaction_choices(choices["presentation.speech.language"]), "de")
|
||||
discovery.Refresh_speech(session, &previous)
|
||||
session.ReplaceChoices("presentation", "speech.language", interactionChoices(choices["presentation.speech.language"]), "de")
|
||||
discovery.RefreshSpeech(session, &previous)
|
||||
values := session.Values()
|
||||
if got := values["presentation.speech.voice"]; len(got.Choices) != 2 || got.Choices[1].ID != "German" || got.Selected != 0 {
|
||||
t.Fatal(got)
|
||||
}
|
||||
session.Replace_choices("presentation", "speech.module", interaction_choices(choices["presentation.speech.module"]), "fixture")
|
||||
discovery.Refresh_speech(session, &previous)
|
||||
session.ReplaceChoices("presentation", "speech.module", interactionChoices(choices["presentation.speech.module"]), "fixture")
|
||||
discovery.RefreshSpeech(session, &previous)
|
||||
values = session.Values()
|
||||
if values["presentation.speech.language"].Selected != 0 || values["presentation.speech.voice"].Selected != 0 || len(values["presentation.speech.voice"].Choices) != 2 {
|
||||
t.Fatal(values)
|
||||
@@ -121,7 +121,7 @@ func TestDependentSpeechChoicesKeepSavedVoicesAndFilterEspeak(t *testing.T) {
|
||||
t.Fatal(path, got)
|
||||
}
|
||||
}
|
||||
session, err = New_session(base, nil, offline)
|
||||
session, err = NewSession(base, nil, offline)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func TestHardwareDriverChangesHideDispatcherChoicesAndPreserveDevice(t *testing.
|
||||
base.Presentation.Speech.Language = "en"
|
||||
base.Presentation.Speech.Voice = "Fixture Voice"
|
||||
discovery := Discovery{Driver: "speech-dispatcher", Catalog: speech.Catalog{Modules: []string{"fixture"}, Voices: map[string][]speech.Voice{"fixture": {{Name: "Fixture Voice", Language: "en"}}}}}
|
||||
session, err := New_session(base, nil, discovery.Choices(base))
|
||||
session, err := NewSession(base, nil, discovery.Choices(base))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -151,8 +151,8 @@ func TestHardwareDriverChangesHideDispatcherChoicesAndPreserveDevice(t *testing.
|
||||
choices = definition.Choices(base)
|
||||
}
|
||||
}
|
||||
session.Replace_choices("presentation", "speech.driver", interaction_choices(choices), id)
|
||||
discovery.Refresh_speech(session, &previous)
|
||||
session.ReplaceChoices("presentation", "speech.driver", interactionChoices(choices), id)
|
||||
discovery.RefreshSpeech(session, &previous)
|
||||
draft, err := Settings(session, base)
|
||||
if err != nil {
|
||||
t.Fatal(id, err)
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
"git.stormux.org/storm/fenrir/internal/interaction"
|
||||
)
|
||||
|
||||
func focus_setting(t *testing.T, session *interaction.Session, id string) {
|
||||
func focusSetting(t *testing.T, session *interaction.Session, id string) {
|
||||
t.Helper()
|
||||
for range 100 {
|
||||
if control, ok := session.Focused_control(); ok && control.ID == id {
|
||||
if control, ok := session.FocusedControl(); ok && control.ID == id {
|
||||
return
|
||||
}
|
||||
session.Handle(interaction.Key{Name: "tab"})
|
||||
@@ -23,7 +23,7 @@ func focus_setting(t *testing.T, session *interaction.Session, id string) {
|
||||
|
||||
func TestHardwareControlsUpdateImmediatelyAndKeepDraftEdits(t *testing.T) {
|
||||
base := config.Defaults()
|
||||
session, err := New_session(base, nil)
|
||||
session, err := NewSession(base, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -34,25 +34,25 @@ func TestHardwareControlsUpdateImmediatelyAndKeepDraftEdits(t *testing.T) {
|
||||
t.Fatal("hardware control initially visible", path)
|
||||
}
|
||||
}
|
||||
focus_setting(t, session, "speech.driver")
|
||||
focusSetting(t, session, "speech.driver")
|
||||
session.Handle(interaction.Key{Name: "down"})
|
||||
if !discovery.Refresh_speech(session, &previous) {
|
||||
if !discovery.RefreshSpeech(session, &previous) {
|
||||
t.Fatal("driver change not detected")
|
||||
}
|
||||
if control, _ := session.Focused_control(); control.ID != "speech.driver" {
|
||||
if control, _ := session.FocusedControl(); control.ID != "speech.driver" {
|
||||
t.Fatal("driver change moved focus", control)
|
||||
}
|
||||
focus_setting(t, session, "speech.hardware_device")
|
||||
focusSetting(t, session, "speech.hardware_device")
|
||||
session.Handle(interaction.Key{Text: "/dev/fixture-synth"})
|
||||
focus_setting(t, session, "speech.hardware_baud_rate")
|
||||
focusSetting(t, session, "speech.hardware_baud_rate")
|
||||
session.Handle(interaction.Key{Name: "end"})
|
||||
draft, err := Settings(session, base)
|
||||
if err != nil || draft.Presentation.Speech.HardwareDevice != "/dev/fixture-synth" || draft.Presentation.Speech.HardwareBaudRate != 115200 {
|
||||
t.Fatal(draft, err)
|
||||
}
|
||||
focus_setting(t, session, "speech.driver")
|
||||
focusSetting(t, session, "speech.driver")
|
||||
session.Handle(interaction.Key{Name: "down"})
|
||||
discovery.Refresh_speech(session, &previous)
|
||||
discovery.RefreshSpeech(session, &previous)
|
||||
for _, path := range []string{"presentation.speech.hardware_device", "presentation.speech.hardware_baud_rate", "presentation.speech.module", "presentation.speech.language", "presentation.speech.voice"} {
|
||||
if !session.Values()[path].Hidden {
|
||||
t.Fatal("irrelevant USB control visible", path)
|
||||
@@ -62,13 +62,13 @@ func TestHardwareControlsUpdateImmediatelyAndKeepDraftEdits(t *testing.T) {
|
||||
t.Fatal("USB test button hidden")
|
||||
}
|
||||
session.Handle(interaction.Key{Name: "up"})
|
||||
discovery.Refresh_speech(session, &previous)
|
||||
discovery.RefreshSpeech(session, &previous)
|
||||
draft, err = Settings(session, base)
|
||||
if err != nil || draft.Presentation.Speech.HardwareDevice != "/dev/fixture-synth" || draft.Presentation.Speech.HardwareBaudRate != 115200 {
|
||||
t.Fatal("driver round trip lost edits", draft, err)
|
||||
}
|
||||
session.Handle(interaction.Key{Name: "home"})
|
||||
discovery.Refresh_speech(session, &previous)
|
||||
discovery.RefreshSpeech(session, &previous)
|
||||
if !session.Values()["presentation.speech.test"].Hidden || session.Values()["presentation.speech.module"].Hidden {
|
||||
t.Fatal("Speech Dispatcher controls not restored")
|
||||
}
|
||||
@@ -79,15 +79,15 @@ func TestEveryHardwareFormCanSavePortAndTypedBaud(t *testing.T) {
|
||||
base := config.Defaults()
|
||||
base.Presentation.Speech.Driver = driver
|
||||
base.Presentation.Speech.HardwareDevice = "/dev/fixture-original"
|
||||
session, err := New_session(base, nil)
|
||||
session, err := NewSession(base, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if driver != "dectalk-usb" {
|
||||
focus_setting(t, session, "speech.hardware_device")
|
||||
focusSetting(t, session, "speech.hardware_device")
|
||||
session.Handle(interaction.Key{Ctrl: true, Text: "a"})
|
||||
session.Handle(interaction.Key{Text: "/dev/fixture-updated"})
|
||||
focus_setting(t, session, "speech.hardware_baud_rate")
|
||||
focusSetting(t, session, "speech.hardware_baud_rate")
|
||||
session.Handle(interaction.Key{Name: "home"})
|
||||
session.Handle(interaction.Key{Name: "down"})
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ var modifierOptions = []modifierOption{
|
||||
{name: "KEY_META", Label: "Super"},
|
||||
}
|
||||
|
||||
func reader_names(settings config.Settings) []string {
|
||||
func readerNames(settings config.Settings) []string {
|
||||
if settings.Keyboard.FenrirKeys != nil {
|
||||
return settings.Keyboard.FenrirKeys
|
||||
}
|
||||
@@ -35,16 +35,16 @@ func reader_names(settings config.Settings) []string {
|
||||
default:
|
||||
names = []string{"KEY_KP0", "KEY_INSERT", "KEY_META"}
|
||||
}
|
||||
available, err := input.Available_fenrir_keys(names, settings.General.ScriptKeys)
|
||||
available, err := input.AvailableFenrirKeys(names, settings.General.ScriptKeys)
|
||||
if err != nil {
|
||||
return []string{}
|
||||
}
|
||||
return available
|
||||
}
|
||||
|
||||
func modifier_checked(names []string, name string) bool {
|
||||
keys, _ := input.Modifier_codes(names)
|
||||
option, _ := input.Modifier_codes([]string{name})
|
||||
func modifierChecked(names []string, name string) bool {
|
||||
keys, _ := input.ModifierCodes(names)
|
||||
option, _ := input.ModifierCodes([]string{name})
|
||||
for key := range option {
|
||||
if keys[key] {
|
||||
return true
|
||||
@@ -53,13 +53,13 @@ func modifier_checked(names []string, name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func modifier_controls(settings config.Settings) []interaction.Control {
|
||||
func modifierControls(settings config.Settings) []interaction.Control {
|
||||
var controls []interaction.Control
|
||||
for _, role := range []struct {
|
||||
id, Label string
|
||||
names []string
|
||||
}{
|
||||
{id: "fenrir_key.", Label: "Fenrir keys", names: reader_names(settings)},
|
||||
{id: "fenrir_key.", Label: "Fenrir keys", names: readerNames(settings)},
|
||||
{id: "script_key.", Label: "Script keys", names: settings.General.ScriptKeys},
|
||||
} {
|
||||
options := slices.Clone(modifierOptions)
|
||||
@@ -67,13 +67,13 @@ func modifier_controls(settings config.Settings) []interaction.Control {
|
||||
options = append(options, modifierOption{name: "KEY_COMPOSE", Label: "Compose"})
|
||||
}
|
||||
for _, option := range options {
|
||||
controls = append(controls, interaction.Control{ID: role.id + option.name, Label: option.Label, Group: role.Label, Kind: interaction.CheckBox, Checked: modifier_checked(role.names, option.name)})
|
||||
controls = append(controls, interaction.Control{ID: role.id + option.name, Label: option.Label, Group: role.Label, Kind: interaction.CheckBox, Checked: modifierChecked(role.names, option.name)})
|
||||
}
|
||||
}
|
||||
return controls
|
||||
}
|
||||
|
||||
func selected_modifiers(values map[string]interaction.Control, prefix string, names []string, options []modifierOption) ([]string, bool, error) {
|
||||
func selectedModifiers(values map[string]interaction.Control, prefix string, names []string, options []modifierOption) ([]string, bool, error) {
|
||||
selected := slices.Clone(names)
|
||||
changed := false
|
||||
for _, option := range options {
|
||||
@@ -81,7 +81,7 @@ func selected_modifiers(values map[string]interaction.Control, prefix string, na
|
||||
if !ok {
|
||||
return nil, false, fmt.Errorf("missing modifier checkbox %s", option.name)
|
||||
}
|
||||
if control.Checked == modifier_checked(names, option.name) {
|
||||
if control.Checked == modifierChecked(names, option.name) {
|
||||
continue
|
||||
}
|
||||
changed = true
|
||||
@@ -89,21 +89,21 @@ func selected_modifiers(values map[string]interaction.Control, prefix string, na
|
||||
selected = append(selected, option.name)
|
||||
continue
|
||||
}
|
||||
selected = slices.DeleteFunc(selected, func(name string) bool { return modifier_checked([]string{name}, option.name) })
|
||||
selected = slices.DeleteFunc(selected, func(name string) bool { return modifierChecked([]string{name}, option.name) })
|
||||
}
|
||||
return selected, changed, nil
|
||||
}
|
||||
|
||||
func modifier_settings(values map[string]interaction.Control, base *config.Settings) error {
|
||||
reader, changed, err := selected_modifiers(values, "fenrir_key.", reader_names(*base), modifierOptions)
|
||||
func modifierSettings(values map[string]interaction.Control, base *config.Settings) error {
|
||||
reader, changed, err := selectedModifiers(values, "fenrir_key.", readerNames(*base), modifierOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
scripts, _, err := selected_modifiers(values, "script_key.", base.General.ScriptKeys, append(slices.Clone(modifierOptions), modifierOption{name: "KEY_COMPOSE", Label: "Compose"}))
|
||||
scripts, _, err := selectedModifiers(values, "script_key.", base.General.ScriptKeys, append(slices.Clone(modifierOptions), modifierOption{name: "KEY_COMPOSE", Label: "Compose"}))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := input.Validate_modifier_keys(reader, scripts); err != nil {
|
||||
if err := input.ValidateModifierKeys(reader, scripts); err != nil {
|
||||
return err
|
||||
}
|
||||
if changed {
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
"git.stormux.org/storm/fenrir/internal/interaction"
|
||||
)
|
||||
|
||||
func focus_modifier(t *testing.T, s *interaction.Session, id string) {
|
||||
func focusModifier(t *testing.T, s *interaction.Session, id string) {
|
||||
t.Helper()
|
||||
for range 40 {
|
||||
if control, ok := s.Focused_control(); ok && control.ID == id {
|
||||
if control, ok := s.FocusedControl(); ok && control.ID == id {
|
||||
return
|
||||
}
|
||||
s.Handle(interaction.Key{Name: "tab"})
|
||||
@@ -29,7 +29,7 @@ func TestModifierCheckboxesRejectConflictAndSaveSelections(t *testing.T) {
|
||||
base.Keyboard.Devices = []string{}
|
||||
base.Keyboard.FenrirKeys = []string{key}
|
||||
base.General.ScriptKeys = []string{"KEY_COMPOSE", "KEY_F9"}
|
||||
session, err := New_session(base, []string{"keyboard"})
|
||||
session, err := NewSession(base, []string{"keyboard"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -39,12 +39,12 @@ func TestModifierCheckboxesRejectConflictAndSaveSelections(t *testing.T) {
|
||||
t.Fatal(control)
|
||||
}
|
||||
}
|
||||
focus_modifier(t, session, "script_key."+key)
|
||||
focusModifier(t, session, "script_key."+key)
|
||||
session.Handle(interaction.Key{Name: "space"})
|
||||
if _, err := Settings(session, base); err == nil {
|
||||
t.Fatal("overlapping checkbox roles saved", key)
|
||||
}
|
||||
focus_modifier(t, session, "fenrir_key."+key)
|
||||
focusModifier(t, session, "fenrir_key."+key)
|
||||
session.Handle(interaction.Key{Name: "space"})
|
||||
if _, err := Settings(session, base); err == nil {
|
||||
t.Fatal("all reader keys unchecked accepted")
|
||||
@@ -53,17 +53,17 @@ func TestModifierCheckboxesRejectConflictAndSaveSelections(t *testing.T) {
|
||||
if key == replacement {
|
||||
replacement = "KEY_CAPSLOCK"
|
||||
}
|
||||
focus_modifier(t, session, "fenrir_key."+replacement)
|
||||
focusModifier(t, session, "fenrir_key."+replacement)
|
||||
session.Handle(interaction.Key{Name: "space"})
|
||||
draft, err := Settings(session, base)
|
||||
if err != nil || !modifier_checked(draft.General.ScriptKeys, key) || !modifier_checked(draft.Keyboard.FenrirKeys, replacement) || modifier_checked(draft.Keyboard.FenrirKeys, key) {
|
||||
if err != nil || !modifierChecked(draft.General.ScriptKeys, key) || !modifierChecked(draft.Keyboard.FenrirKeys, replacement) || modifierChecked(draft.Keyboard.FenrirKeys, key) {
|
||||
t.Fatal(draft.Keyboard, draft.General, err)
|
||||
}
|
||||
if !reflect.DeepEqual(base.Keyboard.FenrirKeys, []string{key}) || len(base.General.ScriptKeys) != 2 {
|
||||
t.Fatal("draft changed original")
|
||||
}
|
||||
path := filepath.Join(t.TempDir(), "settings.toml")
|
||||
doc, err := config.Open_document(path, base)
|
||||
doc, err := config.OpenDocument(path, base)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func TestModifierCheckboxesRejectConflictAndSaveSelections(t *testing.T) {
|
||||
if err != nil || !reflect.DeepEqual(saved.Keyboard.FenrirKeys, draft.Keyboard.FenrirKeys) || !reflect.DeepEqual(saved.General.ScriptKeys, draft.General.ScriptKeys) {
|
||||
t.Fatal(saved.Keyboard, saved.General, err)
|
||||
}
|
||||
if !modifier_checked(saved.General.ScriptKeys, "KEY_F9") {
|
||||
if !modifierChecked(saved.General.ScriptKeys, "KEY_F9") {
|
||||
t.Fatal("custom script key lost")
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ func TestModifierCheckboxesPreserveSideSpecificSuperAndDefaults(t *testing.T) {
|
||||
base.Keyboard.Devices = []string{}
|
||||
base.Keyboard.FenrirKeys = []string{"KEY_RIGHTMETA"}
|
||||
base.General.ScriptKeys = []string{"KEY_LEFTMETA"}
|
||||
session, err := New_session(base, []string{"keyboard"})
|
||||
session, err := NewSession(base, []string{"keyboard"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func TestModifierCheckboxesPreserveSideSpecificSuperAndDefaults(t *testing.T) {
|
||||
base = config.Defaults()
|
||||
base.Keyboard.Devices = []string{}
|
||||
base.General.ScriptKeys = []string{"KEY_META", "KEY_COMPOSE"}
|
||||
session, err = New_session(base, []string{"keyboard"})
|
||||
session, err = NewSession(base, []string{"keyboard"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -37,31 +37,31 @@ type Choices map[string][]config.Choice
|
||||
|
||||
const MenuTitle = "Fenrir Menu"
|
||||
|
||||
func New_session(settings config.Settings, order []string, discovered ...Choices) (*interaction.Session, error) {
|
||||
return new_session(settings, order, MenuTitle, false, discovered...)
|
||||
func NewSession(settings config.Settings, order []string, discovered ...Choices) (*interaction.Session, error) {
|
||||
return newSession(settings, order, MenuTitle, false, discovered...)
|
||||
}
|
||||
|
||||
func New_application_session(settings config.Settings, order []string, title string, discovered ...Choices) (*interaction.Session, error) {
|
||||
return new_session(settings, order, title, true, discovered...)
|
||||
func NewApplicationSession(settings config.Settings, order []string, title string, discovered ...Choices) (*interaction.Session, error) {
|
||||
return newSession(settings, order, title, true, discovered...)
|
||||
}
|
||||
|
||||
func new_session(settings config.Settings, order []string, title string, application bool, discovered ...Choices) (*interaction.Session, error) {
|
||||
func newSession(settings config.Settings, order []string, title string, application bool, discovered ...Choices) (*interaction.Session, error) {
|
||||
if err := settings.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
form := interaction.Form{Type: interaction.TabForm, Title: title}
|
||||
for _, section := range config.Ordered_sections(config.Sections(), order) {
|
||||
for _, section := range config.OrderedSections(config.Sections(), order) {
|
||||
if section.Label == "" {
|
||||
continue
|
||||
}
|
||||
tab := interaction.Tab{ID: section.ID, Label: section.Label}
|
||||
var append_section func(config.Section, string) error
|
||||
append_section = func(section config.Section, group string) error {
|
||||
var appendSection func(config.Section, string) error
|
||||
appendSection = func(section config.Section, group string) error {
|
||||
for _, definition := range section.Settings {
|
||||
if application && !config.Application_setting(definition.Path) {
|
||||
if application && !config.ApplicationSetting(definition.Path) {
|
||||
continue
|
||||
}
|
||||
control, err := make_control(definition, settings, discovered)
|
||||
control, err := makeControl(definition, settings, discovered)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -69,25 +69,25 @@ func new_session(settings config.Settings, order []string, title string, applica
|
||||
control.Group = group
|
||||
tab.Controls = append(tab.Controls, control)
|
||||
}
|
||||
for _, child := range config.Ordered_sections(section.Sections, order) {
|
||||
for _, child := range config.OrderedSections(section.Sections, order) {
|
||||
label := child.Label
|
||||
if group != "" {
|
||||
label = group + ". " + label
|
||||
}
|
||||
if err := append_section(child, label); err != nil {
|
||||
if err := appendSection(child, label); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if section.ID == "keyboard" && !application {
|
||||
tab.Controls = append(tab.Controls, modifier_controls(settings)...)
|
||||
tab.Controls = append(tab.Controls, modifierControls(settings)...)
|
||||
}
|
||||
if section.ID == "presentation.speech" {
|
||||
driver, _ := speech.Find_driver(settings.Presentation.Speech.Driver)
|
||||
driver, _ := speech.FindDriver(settings.Presentation.Speech.Driver)
|
||||
tab.Controls = append(tab.Controls, interaction.Control{ID: "speech.test", Label: "Test synthesizer", Group: "Speech", Kind: interaction.Button, Action: "test-synthesizer", Hidden: !driver.Hardware})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err := append_section(section, ""); err != nil {
|
||||
if err := appendSection(section, ""); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(tab.Controls) == 0 {
|
||||
@@ -103,10 +103,10 @@ func new_session(settings config.Settings, order []string, title string, applica
|
||||
interaction.Control{ID: "cancel", Label: "Cancel", Kind: interaction.Button, Action: "cancel"})
|
||||
form.Tabs = append(form.Tabs, profiles)
|
||||
}
|
||||
return interaction.New_session(form)
|
||||
return interaction.NewSession(form)
|
||||
}
|
||||
|
||||
func make_control(definition config.Definition, settings config.Settings, discovered []Choices) (interaction.Control, error) {
|
||||
func makeControl(definition config.Definition, settings config.Settings, discovered []Choices) (interaction.Control, error) {
|
||||
control := interaction.Control{Label: definition.Label, Hidden: !definition.Available(settings)}
|
||||
value := definition.Value(settings)
|
||||
if definition.ChoiceSource != "" {
|
||||
@@ -164,14 +164,14 @@ func make_control(definition config.Definition, settings config.Settings, discov
|
||||
}
|
||||
|
||||
func Settings(session *interaction.Session, base config.Settings) (config.Settings, error) {
|
||||
return settings_values(session, base, false)
|
||||
return settingsValues(session, base, false)
|
||||
}
|
||||
|
||||
func Application_settings(session *interaction.Session, base config.Settings) (config.Settings, error) {
|
||||
return settings_values(session, base, true)
|
||||
func ApplicationSettings(session *interaction.Session, base config.Settings) (config.Settings, error) {
|
||||
return settingsValues(session, base, true)
|
||||
}
|
||||
|
||||
func settings_values(session *interaction.Session, base config.Settings, application bool) (config.Settings, error) {
|
||||
func settingsValues(session *interaction.Session, base config.Settings, application bool) (config.Settings, error) {
|
||||
values := session.Values()
|
||||
// Visibility follows the form's selected driver, including unsaved switches.
|
||||
driver, hasDriver := values["presentation.speech.driver"]
|
||||
@@ -182,7 +182,7 @@ func settings_values(session *interaction.Session, base config.Settings, applica
|
||||
base.Presentation.Speech.Driver = driver.Choices[driver.Selected].ID
|
||||
}
|
||||
for _, definition := range config.Definitions() {
|
||||
if !definition.Available(base) || (application && !config.Application_setting(definition.Path)) {
|
||||
if !definition.Available(base) || (application && !config.ApplicationSetting(definition.Path)) {
|
||||
continue
|
||||
}
|
||||
control, ok := values[definition.Path]
|
||||
@@ -230,7 +230,7 @@ func settings_values(session *interaction.Session, base config.Settings, applica
|
||||
}
|
||||
}
|
||||
if !application {
|
||||
if err := modifier_settings(values, &base); err != nil {
|
||||
if err := modifierSettings(values, &base); err != nil {
|
||||
return config.Settings{}, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
func TestSettingsFormCoversSchemaAndReturnsIsolatedDraft(t *testing.T) {
|
||||
base := config.Defaults()
|
||||
base.Keyboard.Devices = []string{"/dev/input/event-test"}
|
||||
session, err := New_session(base, []string{"presentation", "presentation.speech", "presentation.sound"})
|
||||
session, err := NewSession(base, []string{"presentation", "presentation.speech", "presentation.sound"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -50,7 +50,7 @@ func TestSettingsFormCoversSchemaAndReturnsIsolatedDraft(t *testing.T) {
|
||||
}
|
||||
session.Handle(interaction.Key{Name: "tab"})
|
||||
session.Handle(interaction.Key{Name: "space"})
|
||||
tab_to_control(t, session, "speech.rate")
|
||||
tabToControl(t, session, "speech.rate")
|
||||
session.Handle(interaction.Key{Name: "up"})
|
||||
draft, err := Settings(session, base)
|
||||
if err != nil {
|
||||
@@ -78,18 +78,18 @@ func TestSpeechRateArrowSteps(t *testing.T) {
|
||||
} {
|
||||
base := config.Defaults()
|
||||
base.Presentation.Speech.Rate = trial.start
|
||||
session, err := new_session(base, []string{"presentation"}, MenuTitle, application)
|
||||
session, err := newSession(base, []string{"presentation"}, MenuTitle, application)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tab_to_control(t, session, "speech.rate")
|
||||
tabToControl(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)
|
||||
}
|
||||
var draft config.Settings
|
||||
if application {
|
||||
draft, err = Application_settings(session, base)
|
||||
draft, err = ApplicationSettings(session, base)
|
||||
} else {
|
||||
draft, err = Settings(session, base)
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func TestSpeechRateArrowSteps(t *testing.T) {
|
||||
|
||||
func TestReadingModeIsConstrainedAndSavedInDraft(t *testing.T) {
|
||||
base := config.Defaults()
|
||||
session, err := New_session(base, []string{"reading"})
|
||||
session, err := NewSession(base, []string{"reading"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func TestCapitalCheckboxesRoundTripIndependently(t *testing.T) {
|
||||
base.Reading.RaisePitchForCapitals = choices&1 != 0
|
||||
base.Reading.BeepForCapitals = choices&2 != 0
|
||||
base.Reading.SayCapForCapitals = choices&4 != 0
|
||||
session, err := New_session(base, []string{"reading"})
|
||||
session, err := NewSession(base, []string{"reading"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -150,7 +150,7 @@ func TestCapitalCheckboxesRoundTripIndependently(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInvalidDeviceEntryDoesNotSubmit(t *testing.T) {
|
||||
session, err := New_session(config.Defaults(), []string{"keyboard"})
|
||||
session, err := NewSession(config.Defaults(), []string{"keyboard"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func TestKeyboardLayoutComboBox(t *testing.T) {
|
||||
for _, saved := range []string{"desktop", "laptop", "/tmp/custom.toml"} {
|
||||
base := config.Defaults()
|
||||
base.Keyboard.Layout = saved
|
||||
session, err := New_session(base, []string{"keyboard"})
|
||||
session, err := NewSession(base, []string{"keyboard"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -197,7 +197,7 @@ func TestKeyboardLayoutComboBox(t *testing.T) {
|
||||
|
||||
func TestKeyboardEchoCheckboxesSaveIndependently(t *testing.T) {
|
||||
base := config.Defaults()
|
||||
session, err := New_session(base, []string{"keyboard"})
|
||||
session, err := NewSession(base, []string{"keyboard"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -221,7 +221,7 @@ func TestKeyboardEchoCheckboxesSaveIndependently(t *testing.T) {
|
||||
func TestClipboardSyncCheckboxPreservesAdvancedSettings(t *testing.T) {
|
||||
base := config.Defaults()
|
||||
base.Clipboard.SyncDisplay, base.Clipboard.ExportPath, base.Clipboard.NumberOfClipboards = ":42", "/tmp/fixture-clipboard", 3
|
||||
session, err := New_session(base, []string{"clipboard"})
|
||||
session, err := NewSession(base, []string{"clipboard"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -237,7 +237,7 @@ func TestClipboardSyncCheckboxPreservesAdvancedSettings(t *testing.T) {
|
||||
|
||||
func TestPresentationGroupsFollowSchemaAndFileOrder(t *testing.T) {
|
||||
base := config.Defaults()
|
||||
session, err := New_session(base, []string{"reading", "presentation", "presentation.sound", "presentation.speech"})
|
||||
session, err := NewSession(base, []string{"reading", "presentation", "presentation.sound", "presentation.speech"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -268,13 +268,13 @@ func TestConstrainedChoicesKeepStableIDsAndIgnoreTextEditing(t *testing.T) {
|
||||
base := config.Defaults()
|
||||
base.Presentation.Speech.Module = "fixture-module"
|
||||
base.Keyboard.Devices = []string{}
|
||||
session, err := New_session(base, nil, Choices{"presentation.speech.module": {
|
||||
session, err := NewSession(base, nil, Choices{"presentation.speech.module": {
|
||||
{ID: "", Label: "default"}, {ID: "fixture-module", Label: "Fixture module", Unavailable: "fixture server offline"},
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tab_to_control(t, session, "speech.driver")
|
||||
tabToControl(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"})
|
||||
@@ -296,7 +296,7 @@ func TestSoundChoicesPreserveUnavailableThemeAndFileOnlyDevice(t *testing.T) {
|
||||
base := config.Defaults()
|
||||
base.Presentation.Sound.Theme = "missing-fixture-theme"
|
||||
base.Presentation.Sound.Device = "plughw:CARD=Generic,DEV=0"
|
||||
session, err := New_session(base, []string{"presentation", "presentation.sound"})
|
||||
session, err := NewSession(base, []string{"presentation", "presentation.sound"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -315,7 +315,7 @@ func TestSoundChoicesPreserveUnavailableThemeAndFileOnlyDevice(t *testing.T) {
|
||||
|
||||
func TestInternalUIOptionsAndApplicationIsolation(t *testing.T) {
|
||||
base := config.Defaults()
|
||||
session, err := New_session(base, []string{"internal_ui"})
|
||||
session, err := NewSession(base, []string{"internal_ui"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -335,7 +335,7 @@ func TestInternalUIOptionsAndApplicationIsolation(t *testing.T) {
|
||||
t.Fatal("options did not save independently", draft.InternalUI)
|
||||
}
|
||||
}
|
||||
application, err := New_application_session(base, nil, "Application settings")
|
||||
application, err := NewApplicationSession(base, nil, "Application settings")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -346,11 +346,11 @@ 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) {
|
||||
// tabToControl moves focus with Tab, as a user would, until id is focused.
|
||||
func tabToControl(t *testing.T, session *interaction.Session, id string) {
|
||||
t.Helper()
|
||||
for range 64 {
|
||||
if control, ok := session.Focused_control(); ok && control.ID == id {
|
||||
if control, ok := session.FocusedControl(); ok && control.ID == id {
|
||||
return
|
||||
}
|
||||
session.Handle(interaction.Key{Name: "tab"})
|
||||
|
||||
Reference in new issue
Block a user