Split into category packages; module github.com/ZacharyZhang-NY/MujicaUI

This commit is contained in:
ZacharyZhang-NY committed 2026-10-05 16:18:48 -04:00
1 parent 5a7e921c7e
commit 22b53e9e9e
1822 files changed
+24568 -21314

No files matched your search

+23 -23
View File
@@ -6,27 +6,27 @@ import (
"github.com/egoist/mygo/ui"
mujica "mujicaui"
"github.com/ZacharyZhang-NY/MujicaUI/account"
)
type accountRecorderState struct {
palette, zen mujica.Shortcut
palette, zen account.Shortcut
disabled bool
}
var accountTaken = []mujica.ShortcutBinding{{Action: "Save", Shortcut: mujica.Shortcut{Mods: ui.Cmd, Key: ui.KeyS}}}
var accountTaken = []account.ShortcutBinding{{Action: "Save", Shortcut: account.Shortcut{Mods: ui.Cmd, Key: ui.KeyS}}}
func accountRecorderDemo(c *ui.Context, log func(string)) {
d := ui.Local(c.Root(), "465", func() accountRecorderState {
return accountRecorderState{palette: mujica.Shortcut{Mods: ui.Cmd | ui.Shift, Key: ui.KeyP}}
return accountRecorderState{palette: account.Shortcut{Mods: ui.Cmd | ui.Shift, Key: ui.KeyP}}
})
accountToggles(c, log, []string{"Disabled"}, &d.disabled)
ui.Text(c, "Cmd/Ctrl+S is taken by Save.")
for _, r := range []struct {
name string
v *mujica.Shortcut
v *account.Shortcut
}{{"Command palette", &d.palette}, {"Zen mode", &d.zen}} {
if mujica.ShortcutRecorder(c, r.v, mujica.ShortcutRecorderOptions{Label: r.name, Taken: accountTaken, Disabled: d.disabled}).Changed() {
if account.ShortcutRecorder(c, r.v, account.ShortcutRecorderOptions{Label: r.name, Taken: accountTaken, Disabled: d.disabled}).Changed() {
log(fmt.Sprintf("%s = %s", r.name, r.v.String()))
}
}
@@ -36,27 +36,27 @@ type accountShortcutsState struct{ query string }
func accountShortcutsDemo(c *ui.Context, log func(string)) {
d := ui.Local(c.Root(), "466", func() accountShortcutsState { return accountShortcutsState{} })
groups := []mujica.ShortcutGroup{
{Title: "General", Bindings: []mujica.ShortcutBinding{
{Action: "Command palette", Shortcut: mujica.Shortcut{Mods: ui.Cmd | ui.Shift, Key: ui.KeyP}},
{Action: "Settings", Shortcut: mujica.Shortcut{Mods: ui.Cmd, Key: ui.KeyComma}},
{Action: "Save", Shortcut: mujica.Shortcut{Mods: ui.Cmd, Key: ui.KeyS}},
groups := []account.ShortcutGroup{
{Title: "General", Bindings: []account.ShortcutBinding{
{Action: "Command palette", Shortcut: account.Shortcut{Mods: ui.Cmd | ui.Shift, Key: ui.KeyP}},
{Action: "Settings", Shortcut: account.Shortcut{Mods: ui.Cmd, Key: ui.KeyComma}},
{Action: "Save", Shortcut: account.Shortcut{Mods: ui.Cmd, Key: ui.KeyS}},
}},
{Title: "Editing", Bindings: []mujica.ShortcutBinding{
{Action: "Duplicate line", Shortcut: mujica.Shortcut{Mods: ui.Alt | ui.Shift, Key: ui.KeyDown}},
{Action: "Toggle comment", Shortcut: mujica.Shortcut{Mods: ui.Cmd, Key: ui.KeySlash}},
{Title: "Editing", Bindings: []account.ShortcutBinding{
{Action: "Duplicate line", Shortcut: account.Shortcut{Mods: ui.Alt | ui.Shift, Key: ui.KeyDown}},
{Action: "Toggle comment", Shortcut: account.Shortcut{Mods: ui.Cmd, Key: ui.KeySlash}},
{Action: "Zen mode"},
}},
}
before := d.query
ui.Box(c).Width(480).Children(func() { mujica.KeyboardShortcutsList(c, &d.query, groups, mujica.KeyboardShortcutsListOptions{}) })
ui.Box(c).Width(480).Children(func() { account.KeyboardShortcutsList(c, &d.query, groups, account.KeyboardShortcutsListOptions{}) })
if d.query != before {
log(fmt.Sprintf("search %q", d.query))
}
}
type accountLoginState struct {
form mujica.LoginFormState
form account.LoginFormState
disabled, reject bool
attempts int
}
@@ -71,7 +71,7 @@ func accountLoginDemo(c *ui.Context, log func(string)) {
default:
}
accountToggles(c, log, []string{"Disabled", "Server rejects"}, &d.disabled, &d.reject)
mujica.LoginForm(c, &d.form, mujica.LoginFormOptions{Disabled: d.disabled, OnSubmit: func(account, password string, remember bool) {
account.LoginForm(c, &d.form, account.LoginFormOptions{Disabled: d.disabled, OnSubmit: func(account, password string, remember bool) {
// Credentials stay in the caller's sign-in request.
d.attempts++
log(fmt.Sprintf("submit %q, remember %v", account, remember))
@@ -98,8 +98,8 @@ type accountOAuthState struct {
func accountOAuthDemo(c *ui.Context, log func(string)) {
d := ui.Local(c.Root(), "468", func() accountOAuthState { return accountOAuthState{} })
accountToggles(c, log, []string{"Disabled"}, &d.disabled)
providers := []mujica.OAuthProvider{{ID: "git", Name: "Git host"}, {ID: "sso", Name: "Company SSO"}, {ID: "mail", Name: "Email link"}}
if id, ok := mujica.OAuthButtons(c, providers, mujica.OAuthButtonsOptions{Pending: d.pending, Disabled: d.disabled}).Chosen(); ok {
providers := []account.OAuthProvider{{ID: "git", Name: "Git host"}, {ID: "sso", Name: "Company SSO"}, {ID: "mail", Name: "Email link"}}
if id, ok := account.OAuthButtons(c, providers, account.OAuthButtonsOptions{Pending: d.pending, Disabled: d.disabled}).Chosen(); ok {
d.pending = id
log("continue with " + id)
}
@@ -119,7 +119,7 @@ type accountTwoFactorState struct {
func accountTwoFactorDemo(c *ui.Context, log func(string)) {
d := ui.Local(c.Root(), "469", func() accountTwoFactorState { return accountTwoFactorState{} })
accountToggles(c, log, []string{"Disabled"}, &d.disabled)
r := mujica.TwoFactorInput(c, &d.code, mujica.TwoFactorInputOptions{ResendAt: d.resendAt, Error: d.err, Disabled: d.disabled})
r := account.TwoFactorInput(c, &d.code, account.TwoFactorInputOptions{ResendAt: d.resendAt, Error: d.err, Disabled: d.disabled})
if r.Completed() {
// The code is checked here and never logged.
d.err = ""
@@ -135,17 +135,17 @@ func accountTwoFactorDemo(c *ui.Context, log func(string)) {
}
type accountProfileState struct {
saved, edit mujica.Profile
saved, edit account.Profile
saving, disabled bool
}
func accountProfileDemo(c *ui.Context, log func(string)) {
d := ui.Local(c.Root(), "470", func() accountProfileState {
p := mujica.Profile{Name: "Sakiko Togawa", Bio: "Keyboard, Ave Mujica."}
p := account.Profile{Name: "Sakiko Togawa", Bio: "Keyboard, Ave Mujica."}
return accountProfileState{saved: p, edit: p}
})
accountToggles(c, log, []string{"Saving", "Disabled"}, &d.saving, &d.disabled)
r := mujica.ProfileEditor(c, &d.edit, mujica.ProfileEditorOptions{Saved: d.saved, Saving: d.saving, Disabled: d.disabled})
r := account.ProfileEditor(c, &d.edit, account.ProfileEditorOptions{Saved: d.saved, Saving: d.saving, Disabled: d.disabled})
if r.Save() {
d.saved = d.edit
log("saved")