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
+10
-22
@@ -6,44 +6,32 @@
|
||||
package emoji
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"git.stormux.org/storm/fenrir/internal/interaction"
|
||||
commonemoji "git.stormux.org/storm/screenreader-common/emoji"
|
||||
)
|
||||
|
||||
const MenuTitle = "Emoji Menu"
|
||||
|
||||
// New_session builds an independent draft. Search is local to each category;
|
||||
// NewSession builds an independent draft. Search is local to each category;
|
||||
// the first All tab searches the complete catalog.
|
||||
func New_session() (*interaction.Session, error) {
|
||||
func NewSession() (*interaction.Session, error) {
|
||||
form := interaction.Form{Type: interaction.TabForm, Title: MenuTitle}
|
||||
var all []interaction.Choice
|
||||
sharedCategories := commonemoji.Categories()
|
||||
addTab := func(id, label string, choices []interaction.Choice) {
|
||||
form.Tabs = append(form.Tabs, interaction.Tab{ID: id, Label: label, Controls: []interaction.Control{{
|
||||
ID: "emoji", Label: "Emoji", Kind: interaction.Grid, Choices: choices, Columns: 6, Action: "copy_emoji",
|
||||
}}})
|
||||
}
|
||||
for _, category := range sharedCategories {
|
||||
choices := make([]interaction.Choice, len(category.Entries))
|
||||
for index, entry := range category.Entries {
|
||||
for _, tab := range commonemoji.PickerTabs() {
|
||||
choices := make([]interaction.Choice, len(tab.Entries))
|
||||
for index, entry := range tab.Entries {
|
||||
choices[index] = interaction.Choice{ID: entry.ID, Label: entry.Label}
|
||||
}
|
||||
all = append(all, choices...)
|
||||
addTab(category.ID, category.Label, choices)
|
||||
form.Tabs = append(form.Tabs, interaction.Tab{ID: tab.ID, Label: tab.Label, Controls: []interaction.Control{{
|
||||
ID: "emoji", Label: "Emoji", Kind: interaction.Grid, Choices: choices, Columns: commonemoji.PickerColumns, Action: "copy_emoji",
|
||||
}}})
|
||||
}
|
||||
sort.SliceStable(all, func(i, j int) bool { return all[i].Label < all[j].Label })
|
||||
form.Tabs = append([]interaction.Tab{{ID: "all", Label: "All", Controls: []interaction.Control{{
|
||||
ID: "emoji", Label: "Emoji", Kind: interaction.Grid, Choices: all, Columns: 6, Action: "copy_emoji",
|
||||
}}}}, form.Tabs...)
|
||||
return interaction.New_session(form)
|
||||
return interaction.NewSession(form)
|
||||
}
|
||||
|
||||
// Selection returns the selected Unicode sequence and readable name. It never
|
||||
// returns a selection from another tab or from an empty search.
|
||||
func Selection(session *interaction.Session) (string, string, bool) {
|
||||
control, ok := session.Focused_control()
|
||||
control, ok := session.FocusedControl()
|
||||
if !ok || control.Kind != interaction.Grid || control.Selected < 0 || control.Selected >= len(control.Choices) {
|
||||
return "", "", false
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCategorySelectionAndIndependentSearches(t *testing.T) {
|
||||
session, err := New_session()
|
||||
session, err := NewSession()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -42,12 +42,12 @@ func TestCategorySelectionAndIndependentSearches(t *testing.T) {
|
||||
if value, _, _ := Selection(session); value != "🇯🇵" {
|
||||
t.Fatal("All search/selection not retained", value)
|
||||
}
|
||||
other, err := New_session()
|
||||
other, err := NewSession()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
other.Handle(interaction.Key{Name: "tab"})
|
||||
control, controlOK := other.Focused_control()
|
||||
control, controlOK := other.FocusedControl()
|
||||
value, _, selectionOK := Selection(other)
|
||||
if !controlOK || control.Text != "" || !selectionOK || value == "🇯🇵" {
|
||||
t.Fatal("new session inherited previous search")
|
||||
@@ -57,7 +57,7 @@ func TestCategorySelectionAndIndependentSearches(t *testing.T) {
|
||||
func TestBundledTranslationSearchPreservesEmoji(t *testing.T) {
|
||||
previous := i18n.Use(i18n.New(t.TempDir(), "de"))
|
||||
t.Cleanup(func() { i18n.Use(previous) })
|
||||
session, err := New_session()
|
||||
session, err := NewSession()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func TestExpandedCatalogCategoriesAndUniqueEmojiIDs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestKissMarkSearch(t *testing.T) {
|
||||
session, err := New_session()
|
||||
session, err := NewSession()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func TestKissMarkSearch(t *testing.T) {
|
||||
}
|
||||
previous := i18n.Use(i18n.New(t.TempDir(), "de"))
|
||||
t.Cleanup(func() { i18n.Use(previous) })
|
||||
localized, err := New_session()
|
||||
localized, err := NewSession()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func TestKissMarkSearch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewCategoryNavigation(t *testing.T) {
|
||||
session, err := New_session()
|
||||
session, err := NewSession()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user