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
@@ -4,12 +4,12 @@ var gitPages = []page{
|
||||
{
|
||||
ID: "301", Name: "DiffViewer", ZhName: "差异查看器 比较 diff", Category: "Git",
|
||||
Demo: gitDiffViewerDemo,
|
||||
Code: `var state mujica.DiffViewerState
|
||||
Code: `var state git.DiffViewerState
|
||||
from := "func main() {\n\tprintln(\"hi\")\n}\n"
|
||||
to := "func main() {\n\tprintln(\"hello\")\n}\n"
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
mujica.DiffViewer(c, &state, from, to, mujica.DiffViewerOptions{Language: "go", SideBySide: true}).Height(240)
|
||||
core.Use(c, core.Settings{})
|
||||
git.DiffViewer(c, &state, from, to, git.DiffViewerOptions{Language: "go", SideBySide: true}).Height(240)
|
||||
}
|
||||
ui.Render(view, 400, 300, 1)`,
|
||||
Keys: "Tab focuses the list; arrows and Page Up/Down scroll. Fold buttons take Tab; Enter or Space shows the hidden lines.",
|
||||
@@ -18,8 +18,8 @@ ui.Render(view, 400, 300, 1)`,
|
||||
ID: "302", Name: "InlineDiff", ZhName: "行内差异 词级差异", Category: "Git",
|
||||
Demo: gitInlineDiffDemo,
|
||||
Code: `view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
mujica.InlineDiff(c, "The court meets at noon", "The court meets at dusk", mujica.InlineDiffOptions{})
|
||||
core.Use(c, core.Settings{})
|
||||
git.InlineDiff(c, "The court meets at noon", "The court meets at dusk", git.InlineDiffOptions{})
|
||||
}
|
||||
ui.Render(view, 400, 300, 1)`,
|
||||
Keys: "Not focusable; each line is read with its full text.",
|
||||
@@ -27,11 +27,11 @@ ui.Render(view, 400, 300, 1)`,
|
||||
{
|
||||
ID: "303", Name: "ThreeWayMerge", ZhName: "三方合并 合并冲突", Category: "Git",
|
||||
Demo: gitThreeWayMergeDemo,
|
||||
Code: `var state mujica.ThreeWayMergeState
|
||||
Code: `var state git.ThreeWayMergeState
|
||||
base, local, remote := "a\nb\nc", "a\nB1\nc", "a\nB2\nc"
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
r := mujica.ThreeWayMerge(c, &state, base, local, remote, mujica.ThreeWayMergeOptions{})
|
||||
core.Use(c, core.Settings{})
|
||||
r := git.ThreeWayMerge(c, &state, base, local, remote, git.ThreeWayMergeOptions{})
|
||||
r.Element.Height(280)
|
||||
if done, total := state.Resolved(); r.Changed() && done == total {
|
||||
_ = state.Result() // write the merged file
|
||||
@@ -43,11 +43,11 @@ ui.Render(view, 400, 300, 1)`,
|
||||
{
|
||||
ID: "304", Name: "ConflictResolver", ZhName: "冲突解决 冲突标记", Category: "Git",
|
||||
Demo: gitConflictResolverDemo,
|
||||
Code: `var state mujica.ConflictResolverState
|
||||
Code: `var state git.ConflictResolverState
|
||||
text := "a\n<<<<<<< HEAD\nmine\n=======\ntheirs\n>>>>>>> feature\nb"
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
if mujica.ConflictResolver(c, &state, text, mujica.ConflictResolverOptions{}).Changed() {
|
||||
core.Use(c, core.Settings{})
|
||||
if git.ConflictResolver(c, &state, text, git.ConflictResolverOptions{}).Changed() {
|
||||
_ = state.Result() // save the file once every block is resolved
|
||||
}
|
||||
}
|
||||
@@ -57,14 +57,14 @@ ui.Render(view, 400, 300, 1)`,
|
||||
{
|
||||
ID: "305", Name: "ChangesList", ZhName: "更改列表 暂存 未暂存", Category: "Git",
|
||||
Demo: gitChangesListDemo,
|
||||
Code: `var state mujica.ChangesListState
|
||||
files := []mujica.ChangedFile{
|
||||
{Path: "main.go", Status: mujica.GitModified, Staged: true},
|
||||
{Path: "notes.txt", Status: mujica.GitUntracked},
|
||||
Code: `var state git.ChangesListState
|
||||
files := []git.ChangedFile{
|
||||
{Path: "main.go", Status: git.GitModified, Staged: true},
|
||||
{Path: "notes.txt", Status: git.GitUntracked},
|
||||
}
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
r := mujica.ChangesList(c, &state, files, mujica.ChangesListOptions{})
|
||||
core.Use(c, core.Settings{})
|
||||
r := git.ChangesList(c, &state, files, git.ChangesListOptions{})
|
||||
r.Element.Height(240)
|
||||
if action, path, ok := r.Action(); ok {
|
||||
_, _ = action, path // run git add or git restore --staged
|
||||
@@ -76,11 +76,11 @@ ui.Render(view, 400, 300, 1)`,
|
||||
{
|
||||
ID: "306", Name: "CommitInput", ZhName: "提交输入 提交信息", Category: "Git",
|
||||
Demo: gitCommitInputDemo,
|
||||
Code: `msg := mujica.CommitMessage{}
|
||||
Code: `msg := git.CommitMessage{}
|
||||
busy := false
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
r := mujica.CommitInput(c, &msg, mujica.CommitInputOptions{Busy: busy})
|
||||
core.Use(c, core.Settings{})
|
||||
r := git.CommitInput(c, &msg, git.CommitInputOptions{Busy: busy})
|
||||
if r.Committed() || r.Amended() {
|
||||
busy = true // run git commit, then clear busy
|
||||
}
|
||||
@@ -91,16 +91,16 @@ ui.Render(view, 400, 300, 1)`,
|
||||
{
|
||||
ID: "307", Name: "CommitGraph", ZhName: "提交图谱 泳道 分支图", Category: "Git",
|
||||
Demo: gitCommitGraphDemo,
|
||||
Code: `var state mujica.CommitGraphState
|
||||
commits := []mujica.Commit{
|
||||
Code: `var state git.CommitGraphState
|
||||
commits := []git.Commit{
|
||||
{Hash: "c3", Parents: []string{"c2", "b1"}, Subject: "Merge branch", Refs: []string{"main"}},
|
||||
{Hash: "b1", Parents: []string{"c1"}, Subject: "Feature"},
|
||||
{Hash: "c2", Parents: []string{"c1"}, Subject: "Fix"},
|
||||
{Hash: "c1", Subject: "Initial commit"},
|
||||
}
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
mujica.CommitGraph(c, &state, commits, mujica.CommitGraphOptions{}).Element.Height(240)
|
||||
core.Use(c, core.Settings{})
|
||||
git.CommitGraph(c, &state, commits, git.CommitGraphOptions{}).Element.Height(240)
|
||||
}
|
||||
ui.Render(view, 400, 300, 1)`,
|
||||
Keys: "Up/Down/Home/End choose a commit; typing jumps by subject; Enter opens it.",
|
||||
@@ -108,11 +108,11 @@ ui.Render(view, 400, 300, 1)`,
|
||||
{
|
||||
ID: "308", Name: "CommitList", ZhName: "提交列表 提交历史", Category: "Git",
|
||||
Demo: gitCommitListDemo,
|
||||
Code: `var state mujica.ListState[string]
|
||||
commits := []mujica.Commit{{Hash: "a1b2c3d4", Author: "Sakiko", When: time.Now(), Subject: "Add the commit list"}}
|
||||
Code: `var state data.ListState[string]
|
||||
commits := []git.Commit{{Hash: "a1b2c3d4", Author: "Sakiko", When: time.Now(), Subject: "Add the commit list"}}
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
r := mujica.CommitList(c, &state, commits, mujica.CommitListOptions{})
|
||||
core.Use(c, core.Settings{})
|
||||
r := git.CommitList(c, &state, commits, git.CommitListOptions{})
|
||||
r.Element.Height(240)
|
||||
if hash, ok := state.Selected(); ok && r.Submitted() {
|
||||
_ = hash // show the commit
|
||||
@@ -125,10 +125,10 @@ ui.Render(view, 400, 300, 1)`,
|
||||
ID: "309", Name: "BranchSelector", ZhName: "分支选择器 切换分支", Category: "Git",
|
||||
Demo: gitBranchSelectorDemo,
|
||||
Code: `branch := "main"
|
||||
branches := []mujica.Branch{{Name: "main", Current: true}, {Name: "origin/main", Remote: true}}
|
||||
branches := []git.Branch{{Name: "main", Current: true}, {Name: "origin/main", Remote: true}}
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
r := mujica.BranchSelector(c, &branch, branches, mujica.BranchSelectorOptions{AllowCreate: true})
|
||||
core.Use(c, core.Settings{})
|
||||
r := git.BranchSelector(c, &branch, branches, git.BranchSelectorOptions{AllowCreate: true})
|
||||
if name, ok := r.Created(); ok {
|
||||
_ = name // run git switch -c name
|
||||
}
|
||||
@@ -139,12 +139,12 @@ ui.Render(view, 400, 300, 1)`,
|
||||
{
|
||||
ID: "310", Name: "BranchList", ZhName: "分支列表 上游 领先落后", Category: "Git",
|
||||
Demo: gitBranchListDemo,
|
||||
Code: `var state mujica.ListState[string]
|
||||
branches := []mujica.Branch{{Name: "main", Current: true, Upstream: "origin/main", Ahead: 2}}
|
||||
actions := []mujica.GitAction{{ID: "delete", Label: "Delete", Icon: "trash-2"}}
|
||||
Code: `var state data.ListState[string]
|
||||
branches := []git.Branch{{Name: "main", Current: true, Upstream: "origin/main", Ahead: 2}}
|
||||
actions := []git.GitAction{{ID: "delete", Label: "Delete", Icon: "trash-2"}}
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
r := mujica.BranchList(c, &state, branches, mujica.BranchListOptions{Actions: actions})
|
||||
core.Use(c, core.Settings{})
|
||||
r := git.BranchList(c, &state, branches, git.BranchListOptions{Actions: actions})
|
||||
r.Element.Height(200)
|
||||
if action, name, ok := r.Action(); ok {
|
||||
_, _ = action, name // run the action on the branch
|
||||
@@ -156,11 +156,11 @@ ui.Render(view, 400, 300, 1)`,
|
||||
{
|
||||
ID: "311", Name: "TagList", ZhName: "标签列表 tag", Category: "Git",
|
||||
Demo: gitTagListDemo,
|
||||
Code: `var state mujica.ListState[string]
|
||||
tags := []mujica.GitTag{{Name: "v1.1.0", Target: "a1b2c3d4", Annotation: "Release"}}
|
||||
Code: `var state data.ListState[string]
|
||||
tags := []git.GitTag{{Name: "v1.1.0", Target: "a1b2c3d4", Annotation: "Release"}}
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
r := mujica.TagList(c, &state, tags, mujica.TagListOptions{})
|
||||
core.Use(c, core.Settings{})
|
||||
r := git.TagList(c, &state, tags, git.TagListOptions{})
|
||||
r.Element.Height(200)
|
||||
if _, hash, ok := r.Action(); ok {
|
||||
_ = hash // show the tagged commit
|
||||
@@ -172,11 +172,11 @@ ui.Render(view, 400, 300, 1)`,
|
||||
{
|
||||
ID: "312", Name: "StashList", ZhName: "贮藏列表 stash", Category: "Git",
|
||||
Demo: gitStashListDemo,
|
||||
Code: `var state mujica.ListState[string]
|
||||
stashes := []mujica.Stash{{Ref: "stash@{0}", Message: "WIP on main", Branch: "main"}}
|
||||
Code: `var state data.ListState[string]
|
||||
stashes := []git.Stash{{Ref: "stash@{0}", Message: "WIP on main", Branch: "main"}}
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
r := mujica.StashList(c, &state, stashes, mujica.StashListOptions{})
|
||||
core.Use(c, core.Settings{})
|
||||
r := git.StashList(c, &state, stashes, git.StashListOptions{})
|
||||
r.Element.Height(200)
|
||||
if action, ref, ok := r.Action(); ok {
|
||||
_, _ = action, ref // run git stash apply, pop or drop
|
||||
@@ -188,14 +188,14 @@ ui.Render(view, 400, 300, 1)`,
|
||||
{
|
||||
ID: "313", Name: "BlameView", ZhName: "逐行追溯 blame 作者", Category: "Git",
|
||||
Demo: gitBlameViewDemo,
|
||||
Code: `var state mujica.BlameViewState
|
||||
lines := []mujica.BlameLine{
|
||||
Code: `var state git.BlameViewState
|
||||
lines := []git.BlameLine{
|
||||
{Hash: "a1b2c3d4", Author: "Sakiko", When: time.Now(), Summary: "Add main", Text: "package main"},
|
||||
{Hash: "a1b2c3d4", Author: "Sakiko", When: time.Now(), Summary: "Add main", Text: "func main() {}"},
|
||||
}
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
mujica.BlameView(c, &state, lines, mujica.BlameViewOptions{Language: "go"}).Height(240)
|
||||
core.Use(c, core.Settings{})
|
||||
git.BlameView(c, &state, lines, git.BlameViewOptions{Language: "go"}).Height(240)
|
||||
}
|
||||
ui.Render(view, 400, 300, 1)`,
|
||||
Keys: "Tab focuses the code; arrows scroll; typing jumps to a line starting with the text. Hover the left column for details.",
|
||||
@@ -203,11 +203,11 @@ ui.Render(view, 400, 300, 1)`,
|
||||
{
|
||||
ID: "314", Name: "FileHistory", ZhName: "文件历史 单文件提交", Category: "Git",
|
||||
Demo: gitFileHistoryDemo,
|
||||
Code: `var state mujica.ListState[string]
|
||||
commits := []mujica.Commit{{Hash: "a1b2c3d4", Author: "Sakiko", When: time.Now(), Subject: "Edit main.go"}}
|
||||
Code: `var state data.ListState[string]
|
||||
commits := []git.Commit{{Hash: "a1b2c3d4", Author: "Sakiko", When: time.Now(), Subject: "Edit main.go"}}
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
r := mujica.FileHistory(c, &state, "main.go", commits, mujica.FileHistoryOptions{})
|
||||
core.Use(c, core.Settings{})
|
||||
r := git.FileHistory(c, &state, "main.go", commits, git.FileHistoryOptions{})
|
||||
r.Element.Height(240)
|
||||
if _, hash, ok := r.Action(); ok {
|
||||
_ = hash // open the diff of main.go at hash
|
||||
@@ -219,11 +219,11 @@ ui.Render(view, 400, 300, 1)`,
|
||||
{
|
||||
ID: "315", Name: "PullRequestCard", ZhName: "拉取请求卡片 合并请求 PR", Category: "Git",
|
||||
Demo: gitPullRequestCardDemo,
|
||||
Code: `pr := mujica.PullRequest{Number: 42, Title: "Add git components", Author: "Sakiko", Head: "feature", Base: "main",
|
||||
ChecksPassed: 3, Reviewers: []mujica.Reviewer{{Name: "Uika", State: mujica.ReviewApproved}}, Added: 120, Deleted: 8, Files: 6}
|
||||
Code: `pr := git.PullRequest{Number: 42, Title: "Add git components", Author: "Sakiko", Head: "feature", Base: "main",
|
||||
ChecksPassed: 3, Reviewers: []git.Reviewer{{Name: "Uika", State: git.ReviewApproved}}, Added: 120, Deleted: 8, Files: 6}
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
if mujica.PullRequestCard(c, pr, mujica.PullRequestCardOptions{}).Changed() {
|
||||
core.Use(c, core.Settings{})
|
||||
if git.PullRequestCard(c, pr, git.PullRequestCardOptions{}).Changed() {
|
||||
// open the pull request
|
||||
}
|
||||
}
|
||||
@@ -233,15 +233,15 @@ ui.Render(view, 400, 300, 1)`,
|
||||
{
|
||||
ID: "316", Name: "ReviewComment", ZhName: "评审评论 代码评审", Category: "Git",
|
||||
Demo: gitReviewCommentDemo,
|
||||
Code: `thread := mujica.ReviewThread{File: "main.go", Line: 12, Messages: []mujica.ReviewMessage{
|
||||
Code: `thread := git.ReviewThread{File: "main.go", Line: 12, Messages: []git.ReviewMessage{
|
||||
{Author: "Uika", When: time.Now(), Body: "Can this return early?"},
|
||||
}}
|
||||
draft := ""
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
r := mujica.ReviewComment(c, thread, &draft, mujica.ReviewCommentOptions{})
|
||||
core.Use(c, core.Settings{})
|
||||
r := git.ReviewComment(c, thread, &draft, git.ReviewCommentOptions{})
|
||||
if text, ok := r.Replied(); ok {
|
||||
thread.Messages = append(thread.Messages, mujica.ReviewMessage{Author: "Sakiko", When: time.Now(), Body: text})
|
||||
thread.Messages = append(thread.Messages, git.ReviewMessage{Author: "Sakiko", When: time.Now(), Body: text})
|
||||
}
|
||||
if r.Resolved() || r.Reopened() {
|
||||
thread.Resolved = !thread.Resolved
|
||||
@@ -254,8 +254,8 @@ ui.Render(view, 400, 300, 1)`,
|
||||
ID: "317", Name: "DiffStat", ZhName: "差异统计 增删行数", Category: "Git",
|
||||
Demo: gitDiffStatDemo,
|
||||
Code: `view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
mujica.DiffStat(c, 120, 8, mujica.DiffStatOptions{})
|
||||
core.Use(c, core.Settings{})
|
||||
git.DiffStat(c, 120, 8, git.DiffStatOptions{})
|
||||
}
|
||||
ui.Render(view, 400, 300, 1)`,
|
||||
Keys: "Not focusable; read as additions and deletions.",
|
||||
@@ -264,8 +264,8 @@ ui.Render(view, 400, 300, 1)`,
|
||||
ID: "318", Name: "GitStatusBadge", ZhName: "Git 状态标记 文件状态", Category: "Git",
|
||||
Demo: gitStatusBadgeDemo,
|
||||
Code: `view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
mujica.GitStatusBadge(c, mujica.GitModified, mujica.GitStatusBadgeOptions{ShowLabel: true})
|
||||
core.Use(c, core.Settings{})
|
||||
git.GitStatusBadge(c, git.GitModified, git.GitStatusBadgeOptions{ShowLabel: true})
|
||||
}
|
||||
ui.Render(view, 400, 300, 1)`,
|
||||
Keys: "Not focusable; each badge is read by its status name.",
|
||||
@@ -274,10 +274,10 @@ ui.Render(view, 400, 300, 1)`,
|
||||
ID: "319", Name: "CommandBlock", ZhName: "命令块 终端输出 退出码", Category: "Git",
|
||||
Demo: gitCommandBlockDemo,
|
||||
Code: `open := true
|
||||
run := mujica.CommandRun{Command: "go test ./...", Output: "\x1b[32mok\x1b[0m example 0.4s", Duration: 400 * time.Millisecond}
|
||||
run := agent.CommandRun{Command: "go test ./...", Output: "\x1b[32mok\x1b[0m example 0.4s", Duration: 400 * time.Millisecond}
|
||||
view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
r := mujica.CommandBlock(c, run, &open, mujica.CommandBlockOptions{})
|
||||
core.Use(c, core.Settings{})
|
||||
r := git.CommandBlock(c, run, &open, git.CommandBlockOptions{})
|
||||
if what, ok := r.Copied(); ok {
|
||||
_ = what // "command" or "output" is on the clipboard
|
||||
}
|
||||
@@ -289,8 +289,8 @@ ui.Render(view, 400, 300, 1)`,
|
||||
ID: "320", Name: "AnsiText", ZhName: "ANSI 文本 终端颜色", Category: "Git",
|
||||
Demo: gitAnsiTextDemo,
|
||||
Code: `view := func(c *ui.Context) {
|
||||
mujica.Use(c, mujica.Settings{})
|
||||
mujica.AnsiText(c, "\x1b[1;32mPASS\x1b[0m 12 tests\n\x1b[31mFAIL\x1b[0m 1 test", mujica.AnsiTextOptions{})
|
||||
core.Use(c, core.Settings{})
|
||||
git.AnsiText(c, "\x1b[1;32mPASS\x1b[0m 12 tests\n\x1b[31mFAIL\x1b[0m 1 test", git.AnsiTextOptions{})
|
||||
}
|
||||
ui.Render(view, 400, 300, 1)`,
|
||||
Keys: "Not focusable; shows the text with its styles.",
|
||||
|
||||
Reference in new issue
Block a user