Split into category packages; module github.com/ZacharyZhang-NY/MujicaUI
This commit is contained in:
1822 files changed
+24568
-21314
No files matched your search
@@ -7,7 +7,10 @@ import (
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
mujica "mujicaui"
|
||||
"github.com/ZacharyZhang-NY/MujicaUI/core"
|
||||
"github.com/ZacharyZhang-NY/MujicaUI/data"
|
||||
"github.com/ZacharyZhang-NY/MujicaUI/git"
|
||||
"github.com/ZacharyZhang-NY/MujicaUI/input"
|
||||
)
|
||||
|
||||
var gitDemoTime = time.Date(2026, 10, 5, 9, 30, 0, 0, time.UTC)
|
||||
@@ -15,11 +18,11 @@ var gitDemoTime = time.Date(2026, 10, 5, 9, 30, 0, 0, time.UTC)
|
||||
const gitDemoOld = "package court\n\nimport \"fmt\"\n\n// Greet welcomes a guest.\nfunc Greet(name string) {\n\tfmt.Println(\"Welcome,\", name)\n}\n\nfunc Leave() {}\n\nfunc Dance() {}\n\nfunc Bow() {}\n"
|
||||
const gitDemoNew = "package court\n\nimport \"fmt\"\n\n// Greet welcomes a guest by title.\nfunc Greet(title, name string) {\n\tfmt.Println(\"Welcome,\", title, name)\n}\n\nfunc Leave() {}\n\nfunc Dance() {}\n\nfunc Bow() {}\n\nfunc Curtsy() {}\n"
|
||||
|
||||
func gitDemoCommits(n int) []mujica.Commit {
|
||||
out := make([]mujica.Commit, n)
|
||||
func gitDemoCommits(n int) []git.Commit {
|
||||
out := make([]git.Commit, n)
|
||||
authors := []string{"Sakiko", "Mutsumi", "Uika", "Umiri", "Nyamu"}
|
||||
for i := range out {
|
||||
out[i] = mujica.Commit{Hash: fmt.Sprintf("%016x%024x", uint64(n-i)*0x9E3779B97F4A7C15, n-i), Author: authors[i%5],
|
||||
out[i] = git.Commit{Hash: fmt.Sprintf("%016x%024x", uint64(n-i)*0x9E3779B97F4A7C15, n-i), Author: authors[i%5],
|
||||
When: gitDemoTime.Add(-time.Duration(i) * 37 * time.Minute), Subject: fmt.Sprintf("Chapter %d of the chronicle", n-i)}
|
||||
if i+1 < n {
|
||||
out[i].Parents = []string{fmt.Sprintf("%016x%024x", uint64(n-i-1)*0x9E3779B97F4A7C15, n-i-1)}
|
||||
@@ -31,8 +34,8 @@ func gitDemoCommits(n int) []mujica.Commit {
|
||||
return out
|
||||
}
|
||||
|
||||
func gitDemoGraph() []mujica.Commit {
|
||||
cs := []mujica.Commit{
|
||||
func gitDemoGraph() []git.Commit {
|
||||
cs := []git.Commit{
|
||||
{Hash: "e7", Parents: []string{"e5", "f3"}, Subject: "Merge branch 'feature/lanes'", Refs: []string{"main"}},
|
||||
{Hash: "f3", Parents: []string{"f2"}, Subject: "Color lanes by branch"},
|
||||
{Hash: "e5", Parents: []string{"e4", "h1"}, Subject: "Merge hotfix"},
|
||||
@@ -51,8 +54,8 @@ func gitDemoGraph() []mujica.Commit {
|
||||
return cs
|
||||
}
|
||||
|
||||
func gitDemoBranches() []mujica.Branch {
|
||||
return []mujica.Branch{
|
||||
func gitDemoBranches() []git.Branch {
|
||||
return []git.Branch{
|
||||
{Name: "main", Current: true, Upstream: "origin/main", Ahead: 2, Behind: 1},
|
||||
{Name: "feature/lanes", Upstream: "origin/feature/lanes", Ahead: 5},
|
||||
{Name: "fix/blame"},
|
||||
@@ -64,7 +67,7 @@ func gitDemoBranches() []mujica.Branch {
|
||||
|
||||
func gitDiffViewerDemo(c *ui.Context, log func(string)) {
|
||||
type state struct {
|
||||
viewer mujica.DiffViewerState
|
||||
viewer git.DiffViewerState
|
||||
split, plain bool
|
||||
context float64
|
||||
}
|
||||
@@ -78,7 +81,7 @@ func gitDiffViewerDemo(c *ui.Context, log func(string)) {
|
||||
if s.plain {
|
||||
lang = ""
|
||||
}
|
||||
mujica.DiffViewer(c, &s.viewer, gitDemoOld, gitDemoNew, mujica.DiffViewerOptions{SideBySide: s.split, Context: int(s.context), Language: lang}).Height(380)
|
||||
git.DiffViewer(c, &s.viewer, gitDemoOld, gitDemoNew, git.DiffViewerOptions{SideBySide: s.split, Context: int(s.context), Language: lang}).Height(380)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -93,19 +96,19 @@ func gitInlineDiffDemo(c *ui.Context, log func(string)) {
|
||||
navigationDemo(c, func() {
|
||||
navigationCheck(c, &s.mono, "Monospace", log)
|
||||
}, func() {
|
||||
if mujica.TextInput(c, &s.from, mujica.TextInputOptions{Label: "Old line"}).Changed() {
|
||||
if input.TextInput(c, &s.from, input.TextInputOptions{Label: "Old line"}).Changed() {
|
||||
log("Old: " + s.from)
|
||||
}
|
||||
if mujica.TextInput(c, &s.to, mujica.TextInputOptions{Label: "New line"}).Changed() {
|
||||
if input.TextInput(c, &s.to, input.TextInputOptions{Label: "New line"}).Changed() {
|
||||
log("New: " + s.to)
|
||||
}
|
||||
mujica.InlineDiff(c, s.from, s.to, mujica.InlineDiffOptions{Mono: s.mono})
|
||||
git.InlineDiff(c, s.from, s.to, git.InlineDiffOptions{Mono: s.mono})
|
||||
})
|
||||
}
|
||||
|
||||
func gitThreeWayMergeDemo(c *ui.Context, log func(string)) {
|
||||
type state struct {
|
||||
merge mujica.ThreeWayMergeState
|
||||
merge git.ThreeWayMergeState
|
||||
disabled bool
|
||||
}
|
||||
s := ui.Local(c.Root(), "303", func() state { return state{} })
|
||||
@@ -115,19 +118,19 @@ func gitThreeWayMergeDemo(c *ui.Context, log func(string)) {
|
||||
navigationDemo(c, func() {
|
||||
navigationCheck(c, &s.disabled, "Disabled", log)
|
||||
}, func() {
|
||||
r := mujica.ThreeWayMerge(c, &s.merge, base, ours, theirs, mujica.ThreeWayMergeOptions{Disabled: s.disabled})
|
||||
r := git.ThreeWayMerge(c, &s.merge, base, ours, theirs, git.ThreeWayMergeOptions{Disabled: s.disabled})
|
||||
r.Element.Height(360)
|
||||
if r.Changed() {
|
||||
done, total := s.merge.Resolved()
|
||||
log(fmt.Sprintf("Changed: %d of %d resolved", done, total))
|
||||
}
|
||||
ui.Text(c, s.merge.Result()).Font("monospace").TextColor(mujica.Tokens(c).TextMuted)
|
||||
ui.Text(c, s.merge.Result()).Font("monospace").TextColor(core.Tokens(c).TextMuted)
|
||||
})
|
||||
}
|
||||
|
||||
func gitConflictResolverDemo(c *ui.Context, log func(string)) {
|
||||
type state struct {
|
||||
res mujica.ConflictResolverState
|
||||
res git.ConflictResolverState
|
||||
disabled bool
|
||||
}
|
||||
s := ui.Local(c.Root(), "304", func() state { return state{} })
|
||||
@@ -135,7 +138,7 @@ func gitConflictResolverDemo(c *ui.Context, log func(string)) {
|
||||
navigationDemo(c, func() {
|
||||
navigationCheck(c, &s.disabled, "Disabled", log)
|
||||
}, func() {
|
||||
if mujica.ConflictResolver(c, &s.res, text, mujica.ConflictResolverOptions{Disabled: s.disabled}).Changed() {
|
||||
if git.ConflictResolver(c, &s.res, text, git.ConflictResolverOptions{Disabled: s.disabled}).Changed() {
|
||||
done, total := s.res.Resolved()
|
||||
log(fmt.Sprintf("Changed: %d of %d resolved", done, total))
|
||||
}
|
||||
@@ -144,23 +147,23 @@ func gitConflictResolverDemo(c *ui.Context, log func(string)) {
|
||||
|
||||
func gitChangesListDemo(c *ui.Context, log func(string)) {
|
||||
type state struct {
|
||||
list mujica.ChangesListState
|
||||
files []mujica.ChangedFile
|
||||
list git.ChangesListState
|
||||
files []git.ChangedFile
|
||||
disabled bool
|
||||
}
|
||||
s := ui.Local(c.Root(), "305", func() state {
|
||||
return state{files: []mujica.ChangedFile{
|
||||
{Path: "commit_graph.go", Status: mujica.GitAdded, Staged: true},
|
||||
{Path: "internal/git.go", Status: mujica.GitModified},
|
||||
{Path: "docs/old.md", Status: mujica.GitDeleted},
|
||||
{Path: "notes.txt", Status: mujica.GitUntracked},
|
||||
{Path: "icons/svg/tag.svg", Status: mujica.GitRenamed},
|
||||
return state{files: []git.ChangedFile{
|
||||
{Path: "commit_graph.go", Status: git.GitAdded, Staged: true},
|
||||
{Path: "internal/git.go", Status: git.GitModified},
|
||||
{Path: "docs/old.md", Status: git.GitDeleted},
|
||||
{Path: "notes.txt", Status: git.GitUntracked},
|
||||
{Path: "icons/svg/tag.svg", Status: git.GitRenamed},
|
||||
}}
|
||||
})
|
||||
navigationDemo(c, func() {
|
||||
navigationCheck(c, &s.disabled, "Disabled", log)
|
||||
}, func() {
|
||||
r := mujica.ChangesList(c, &s.list, s.files, mujica.ChangesListOptions{Disabled: s.disabled})
|
||||
r := git.ChangesList(c, &s.list, s.files, git.ChangesListOptions{Disabled: s.disabled})
|
||||
r.Element.Height(320)
|
||||
if a, path, ok := r.Action(); ok {
|
||||
log("Action: " + a + " " + path)
|
||||
@@ -173,8 +176,8 @@ func gitChangesListDemo(c *ui.Context, log func(string)) {
|
||||
}
|
||||
|
||||
// gitStage applies a stage action to a copy of files.
|
||||
func gitStage(files []mujica.ChangedFile, action, path string) []mujica.ChangedFile {
|
||||
out := append([]mujica.ChangedFile(nil), files...)
|
||||
func gitStage(files []git.ChangedFile, action, path string) []git.ChangedFile {
|
||||
out := append([]git.ChangedFile(nil), files...)
|
||||
for i := range out {
|
||||
switch {
|
||||
case action == "stage_all":
|
||||
@@ -190,14 +193,14 @@ func gitStage(files []mujica.ChangedFile, action, path string) []mujica.ChangedF
|
||||
|
||||
func gitCommitInputDemo(c *ui.Context, log func(string)) {
|
||||
type state struct {
|
||||
msg mujica.CommitMessage
|
||||
msg git.CommitMessage
|
||||
busy, disabled bool
|
||||
until time.Time
|
||||
}
|
||||
s := ui.Local(c.Root(), "306", func() state { return state{} })
|
||||
if s.busy && c.Now().After(s.until) {
|
||||
s.busy = false
|
||||
s.msg = mujica.CommitMessage{}
|
||||
s.msg = git.CommitMessage{}
|
||||
log("Committed")
|
||||
}
|
||||
if s.busy {
|
||||
@@ -206,7 +209,7 @@ func gitCommitInputDemo(c *ui.Context, log func(string)) {
|
||||
navigationDemo(c, func() {
|
||||
navigationCheck(c, &s.disabled, "Disabled", log)
|
||||
}, func() {
|
||||
r := mujica.CommitInput(c, &s.msg, mujica.CommitInputOptions{Busy: s.busy, Disabled: s.disabled})
|
||||
r := git.CommitInput(c, &s.msg, git.CommitInputOptions{Busy: s.busy, Disabled: s.disabled})
|
||||
if r.Committed() || r.Amended() {
|
||||
log(fmt.Sprintf("Submit: amend=%v title=%q", r.Amended(), s.msg.Title))
|
||||
s.busy, s.until = true, c.Now().Add(1200*time.Millisecond)
|
||||
@@ -216,7 +219,7 @@ func gitCommitInputDemo(c *ui.Context, log func(string)) {
|
||||
|
||||
func gitCommitGraphDemo(c *ui.Context, log func(string)) {
|
||||
type state struct {
|
||||
graph mujica.CommitGraphState
|
||||
graph git.CommitGraphState
|
||||
big bool
|
||||
}
|
||||
s := ui.Local(c.Root(), "307", func() state { return state{} })
|
||||
@@ -228,7 +231,7 @@ func gitCommitGraphDemo(c *ui.Context, log func(string)) {
|
||||
if s.big {
|
||||
commits = big
|
||||
}
|
||||
r := mujica.CommitGraph(c, &s.graph, commits, mujica.CommitGraphOptions{})
|
||||
r := git.CommitGraph(c, &s.graph, commits, git.CommitGraphOptions{})
|
||||
r.Element.Height(380)
|
||||
if hash, ok := s.graph.List.Selected(); ok && (r.Changed() || r.Submitted()) {
|
||||
log(fmt.Sprintf("Selected %s, open=%v", hash[:min(7, len(hash))], r.Submitted()))
|
||||
@@ -238,7 +241,7 @@ func gitCommitGraphDemo(c *ui.Context, log func(string)) {
|
||||
|
||||
func gitCommitListDemo(c *ui.Context, log func(string)) {
|
||||
type state struct {
|
||||
list mujica.ListState[string]
|
||||
list data.ListState[string]
|
||||
loading bool
|
||||
}
|
||||
s := ui.Local(c.Root(), "308", func() state { return state{} })
|
||||
@@ -246,11 +249,11 @@ func gitCommitListDemo(c *ui.Context, log func(string)) {
|
||||
navigationDemo(c, func() {
|
||||
navigationCheck(c, &s.loading, "Loading more", log)
|
||||
}, func() {
|
||||
st := mujica.DataReady
|
||||
st := data.DataReady
|
||||
if s.loading {
|
||||
st = mujica.DataLoadingMore
|
||||
st = data.DataLoadingMore
|
||||
}
|
||||
r := mujica.CommitList(c, &s.list, commits, mujica.CommitListOptions{Status: st})
|
||||
r := git.CommitList(c, &s.list, commits, git.CommitListOptions{Status: st})
|
||||
r.Element.Height(360)
|
||||
if hash, ok := s.list.Selected(); ok && (r.Changed() || r.Submitted()) {
|
||||
log(fmt.Sprintf("Selected %s, open=%v", hash[:7], r.Submitted()))
|
||||
@@ -262,29 +265,29 @@ func gitBranchSelectorDemo(c *ui.Context, log func(string)) {
|
||||
type state struct {
|
||||
branch string
|
||||
create, disabled bool
|
||||
branches []mujica.Branch
|
||||
branches []git.Branch
|
||||
}
|
||||
s := ui.Local(c.Root(), "309", func() state { return state{branch: "main", create: true, branches: gitDemoBranches()} })
|
||||
navigationDemo(c, func() {
|
||||
navigationCheck(c, &s.create, "Allow create", log)
|
||||
navigationCheck(c, &s.disabled, "Disabled", log)
|
||||
}, func() {
|
||||
r := mujica.BranchSelector(c, &s.branch, s.branches, mujica.BranchSelectorOptions{AllowCreate: s.create, Disabled: s.disabled})
|
||||
r := git.BranchSelector(c, &s.branch, s.branches, git.BranchSelectorOptions{AllowCreate: s.create, Disabled: s.disabled})
|
||||
if r.Changed() {
|
||||
log("Changed: " + s.branch)
|
||||
}
|
||||
if name, ok := r.Created(); ok {
|
||||
log("Create: " + name)
|
||||
s.branches = append(append([]mujica.Branch(nil), s.branches...), mujica.Branch{Name: name})
|
||||
s.branches = append(append([]git.Branch(nil), s.branches...), git.Branch{Name: name})
|
||||
s.branch = name
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func gitBranchListDemo(c *ui.Context, log func(string)) {
|
||||
s := ui.Local(c.Root(), "310", func() mujica.ListState[string] { return mujica.ListState[string]{} })
|
||||
actions := []mujica.GitAction{{ID: "checkout", Label: "Check out", Icon: "git-branch"}, {ID: "delete", Label: "Delete", Icon: "trash-2"}}
|
||||
r := mujica.BranchList(c, s, gitDemoBranches(), mujica.BranchListOptions{Actions: actions})
|
||||
s := ui.Local(c.Root(), "310", func() data.ListState[string] { return data.ListState[string]{} })
|
||||
actions := []git.GitAction{{ID: "checkout", Label: "Check out", Icon: "git-branch"}, {ID: "delete", Label: "Delete", Icon: "trash-2"}}
|
||||
r := git.BranchList(c, s, gitDemoBranches(), git.BranchListOptions{Actions: actions})
|
||||
r.Element.Height(300)
|
||||
if a, name, ok := r.Action(); ok {
|
||||
log("Action: " + a + " " + name)
|
||||
@@ -295,13 +298,13 @@ func gitBranchListDemo(c *ui.Context, log func(string)) {
|
||||
}
|
||||
|
||||
func gitTagListDemo(c *ui.Context, log func(string)) {
|
||||
s := ui.Local(c.Root(), "311", func() mujica.ListState[string] { return mujica.ListState[string]{} })
|
||||
tags := []mujica.GitTag{
|
||||
s := ui.Local(c.Root(), "311", func() data.ListState[string] { return data.ListState[string]{} })
|
||||
tags := []git.GitTag{
|
||||
{Name: "v1.1.0", Target: "9e3779b97f4a7c15", Annotation: "Five hundred components"},
|
||||
{Name: "v1.0.0", Target: "3c6ef372fe94f82a", Annotation: "The first hundred"},
|
||||
{Name: "nightly", Target: "daa66d2c7ddf743f"},
|
||||
}
|
||||
r := mujica.TagList(c, s, tags, mujica.TagListOptions{})
|
||||
r := git.TagList(c, s, tags, git.TagListOptions{})
|
||||
r.Element.Height(220)
|
||||
if _, hash, ok := r.Action(); ok {
|
||||
log("Jump to " + hash[:7])
|
||||
@@ -313,22 +316,22 @@ func gitTagListDemo(c *ui.Context, log func(string)) {
|
||||
|
||||
func gitStashListDemo(c *ui.Context, log func(string)) {
|
||||
type state struct {
|
||||
list mujica.ListState[string]
|
||||
stashes []mujica.Stash
|
||||
list data.ListState[string]
|
||||
stashes []git.Stash
|
||||
}
|
||||
s := ui.Local(c.Root(), "312", func() state {
|
||||
return state{stashes: []mujica.Stash{
|
||||
return state{stashes: []git.Stash{
|
||||
{Ref: "stash@{0}", Message: "WIP on main: lane colors", Branch: "main"},
|
||||
{Ref: "stash@{1}", Message: "Try serif headings", Branch: "feature/type"},
|
||||
{Ref: "stash@{2}", Message: "Blame hover experiment", Branch: "fix/blame"},
|
||||
}}
|
||||
})
|
||||
r := mujica.StashList(c, &s.list, s.stashes, mujica.StashListOptions{})
|
||||
r := git.StashList(c, &s.list, s.stashes, git.StashListOptions{})
|
||||
r.Element.Height(240)
|
||||
if a, ref, ok := r.Action(); ok {
|
||||
log("Action: " + a + " " + ref)
|
||||
if a != "apply" {
|
||||
var keep []mujica.Stash
|
||||
var keep []git.Stash
|
||||
for _, st := range s.stashes {
|
||||
if st.Ref != ref {
|
||||
keep = append(keep, st)
|
||||
@@ -340,23 +343,23 @@ func gitStashListDemo(c *ui.Context, log func(string)) {
|
||||
}
|
||||
|
||||
func gitBlameViewDemo(c *ui.Context, log func(string)) {
|
||||
s := ui.Local(c.Root(), "313", func() mujica.BlameViewState { return mujica.BlameViewState{} })
|
||||
var lines []mujica.BlameLine
|
||||
s := ui.Local(c.Root(), "313", func() git.BlameViewState { return git.BlameViewState{} })
|
||||
var lines []git.BlameLine
|
||||
for i, l := range strings.Split(strings.TrimSuffix(gitDemoNew, "\n"), "\n") {
|
||||
who := []mujica.BlameLine{
|
||||
who := []git.BlameLine{
|
||||
{Hash: "9e3779b97f4a7c15", Author: "Sakiko", When: gitDemoTime, Summary: "Create the court package"},
|
||||
{Hash: "3c6ef372fe94f82a", Author: "Uika", When: gitDemoTime.Add(-48 * time.Hour), Summary: "Greet guests by title"},
|
||||
}[min(i/4%2, 1)]
|
||||
who.Text = l
|
||||
lines = append(lines, who)
|
||||
}
|
||||
mujica.BlameView(c, s, lines, mujica.BlameViewOptions{Language: "go"}).Height(380)
|
||||
ui.Text(c, "Hover the left column for commit details.").TextColor(mujica.Tokens(c).TextMuted)
|
||||
git.BlameView(c, s, lines, git.BlameViewOptions{Language: "go"}).Height(380)
|
||||
ui.Text(c, "Hover the left column for commit details.").TextColor(core.Tokens(c).TextMuted)
|
||||
}
|
||||
|
||||
func gitFileHistoryDemo(c *ui.Context, log func(string)) {
|
||||
s := ui.Local(c.Root(), "314", func() mujica.ListState[string] { return mujica.ListState[string]{} })
|
||||
r := mujica.FileHistory(c, s, "court/greet.go", gitDemoCommits(12), mujica.FileHistoryOptions{})
|
||||
s := ui.Local(c.Root(), "314", func() data.ListState[string] { return data.ListState[string]{} })
|
||||
r := git.FileHistory(c, s, "court/greet.go", gitDemoCommits(12), git.FileHistoryOptions{})
|
||||
r.Element.Height(360)
|
||||
if _, hash, ok := r.Action(); ok {
|
||||
log("Diff at " + hash[:7])
|
||||
|
||||
Reference in new issue
Block a user