From 511204504cbbaa604cc018e5298958062ec2b991 Mon Sep 17 00:00:00 2001 From: harveyshao Date: Tue, 10 Jan 2023 21:42:28 +0800 Subject: [PATCH] add dark --- base/cli/qrcode.go | 4 ++-- base/web/render.go | 7 ++++--- core/code/vimer.go | 9 ++++++++- misc/git/repos.go | 32 ++++++++++++++++++++++++++++---- misc/git/server.go | 19 ++++++++++++++++++- 5 files changed, 60 insertions(+), 11 deletions(-) diff --git a/base/cli/qrcode.go b/base/cli/qrcode.go index ebc2517a..483dce90 100644 --- a/base/cli/qrcode.go +++ b/base/cli/qrcode.go @@ -126,8 +126,8 @@ func init() { } }}, }, Hand: func(m *ice.Message, arg ...string) { - m.Option(FG, kit.Select(kit.Select(BLUE, CYAN, m.Option(ice.TOPIC) == BLACK), arg, 1)) - m.Option(BG, kit.Select(kit.Select(WHITE, BLACK, m.Option(ice.TOPIC) == BLACK), arg, 2)) + m.Option(FG, kit.Select(kit.Select(CYAN, BLUE, m.Option(ice.TOPIC) == WHITE), arg, 1)) + m.Option(BG, kit.Select(kit.Select(BLACK, WHITE, m.Option(ice.TOPIC) == WHITE), arg, 2)) if m.IsCliUA() { _qrcode_cli(m, kit.Select(kit.Select(ice.Info.Make.Domain, ice.Info.Domain), arg, 0)) } else { diff --git a/base/web/render.go b/base/web/render.go index 289cec81..87674028 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -167,15 +167,16 @@ func RenderMain(m *ice.Message, pod, index string, arg ...ice.Any) *ice.Message func RenderCmd(m *ice.Message, cmd string, arg ...ice.Any) { RenderPodCmd(m, "", cmd, arg...) } +func RenderCmds(m *ice.Message, list ...ice.Any) { + m.Echo(kit.Renders(_cmd_template, ice.Maps{"version": renderVersion(m), "list": kit.Format(list)})).RenderResult() +} func RenderPodCmd(m *ice.Message, pod, cmd string, arg ...ice.Any) { msg := m.Cmd(Space(m, pod), ctx.COMMAND, kit.Select("web.wiki.word", cmd)) list := kit.Format(kit.List(kit.Dict(msg.AppendSimple(mdb.NAME, mdb.HELP), ctx.INDEX, cmd, ctx.ARGS, kit.Simple(arg), ctx.DISPLAY, m.Option(ice.MSG_DISPLAY), mdb.LIST, kit.UnMarshal(msg.Append(mdb.LIST)), mdb.META, kit.UnMarshal(msg.Append(mdb.META)), ))) - m.Echo(kit.Renders(_cmd_template, ice.Maps{ - "version": renderVersion(m), "list": list, - })).RenderResult() + m.Echo(kit.Renders(_cmd_template, ice.Maps{"version": renderVersion(m), "list": list})).RenderResult() } func renderVersion(m *ice.Message) string { if strings.Contains(m.R.URL.RawQuery, "debug=true") { diff --git a/core/code/vimer.go b/core/code/vimer.go index edc8d17b..8fd1720f 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -89,10 +89,17 @@ func init() { if m.Option(nfs.CONTENT) == "" { m.Option(nfs.CONTENT, m.Cmdx("", TEMPLATE)) } - switch m.Cmdy(nfs.SAVE, path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE))); m.Option(nfs.FILE) { + p := path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)) + switch m.Cmd(nfs.SAVE, p); m.Option(nfs.FILE) { case "proto.js", "page/index.css": m.Cmd("", DEVPACK) } + switch arg[0] { + case nfs.GO: + m.Cmd(cli.SYSTEM, "gofmt", "-w", p) + m.Cmd(cli.SYSTEM, "goimports", "-w", p) + m.Cmdy(nfs.CAT, p) + } }}, nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { nfs.Trash(m, arg[0]) }}, nfs.SCRIPT: {Name: "script file*=hi/hi.js", Help: "脚本", Hand: func(m *ice.Message, arg ...string) { diff --git a/misc/git/repos.go b/misc/git/repos.go index 2392eb28..e4f638e8 100644 --- a/misc/git/repos.go +++ b/misc/git/repos.go @@ -89,11 +89,17 @@ func _repos_commit(m *ice.Message, dir, branch string, cb func(*gogit.Commit, *g } } func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit.TreeEntry, *gogit.Repository) bool) { - if commit == cli.PWD { + if commit == cli.PWD && strings.HasPrefix(dir, ".git") { nfs.DirDeepAll(m, path.Dir(dir), file, nil, "time,line,path") m.Option(cli.CMD_DIR, path.Dir(dir)) m.Echo(_git_cmds(m, DIFF)) return + } else if commit == cli.PWD { + if repos, e := gogit.OpenRepository(dir); !m.Warn(e, ice.ErrNotFound, dir) { + if refer, e := repos.LookupReference(REFS_HEADS + branch); !m.Warn(e, ice.ErrNotFound, branch) { + commit = refer.Oid.String() + } + } } else if file == nfs.PWD { file = "" } @@ -114,10 +120,15 @@ func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit } if tree, e := repos.LookupTree(ci.TreeId()); !m.Warn(e, ice.ErrNotValid, ci.TreeId().String) { m.Logs(mdb.SELECT, REPOS, dir, BRANCH, branch, COMMIT, commit, "tree", tree.Oid.Short()) + m.Logs("what", file, file) tree.Walk(func(p string, v *gogit.TreeEntry) bool { if pp := path.Join(p, v.Name) + kit.Select("", ice.PS, v.Type == gogit.ObjectTree); strings.HasPrefix(pp, file) { + m.Logs("what", file, pp) if cb == nil { - if v.Type == gogit.ObjectTree { + m.Logs("what", file, pp) + if path.Dir(file) != path.Dir(pp) { + + } else if v.Type == gogit.ObjectTree { } else if id, ok := prev[pp]; ok && id == v.Oid.String() { if m.Option("_index") == web.CODE_INNER { @@ -130,13 +141,20 @@ func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit } delete(prev, pp) } else if cb(v, repos) { + m.Logs("what", file, pp) return true } } return false }) } - kit.Fetch(prev, func(pp, id string) { m.Push(mdb.HASH, id[:6]).Push(nfs.PATH, pp).Push(mdb.STATUS, "---") }) + kit.Fetch(prev, func(pp, id string) { + m.Logs("what", path.Dir(file), path.Dir(pp)) + if path.Dir(file) != path.Dir(pp) { + return + } + m.Push(mdb.HASH, id[:6]).Push(nfs.PATH, pp).Push(mdb.STATUS, "---") + }) if m.Sort(kit.Fields(mdb.STATUS, nfs.PATH), ice.STR_R, ice.STR); cb == nil { m.Option(cli.CMD_DIR, dir) m.Echo(_git_cmds(m, DIFF, ci.Oid.String()+"^", ci.Oid.String())) @@ -146,9 +164,15 @@ func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit }) } func _repos_cat(m *ice.Message, dir, branch, commit, file string) { - if commit == cli.PWD { + if commit == cli.PWD && strings.HasPrefix(dir, ".git") { m.Cmdy(nfs.CAT, path.Join(path.Dir(dir), file)) return + } else if commit == cli.PWD { + if repos, e := gogit.OpenRepository(dir); !m.Warn(e, ice.ErrNotFound, dir) { + if refer, e := repos.LookupReference(REFS_HEADS + branch); !m.Warn(e, ice.ErrNotFound, branch) { + commit = refer.Oid.String() + } + } } _repos_dir(m, dir, branch, commit, file, func(v *gogit.TreeEntry, repos *gogit.Repository) bool { if blob, e := repos.LookupBlob(v.Oid); e == nil { diff --git a/misc/git/server.go b/misc/git/server.go index 210359e8..91a1281e 100644 --- a/misc/git/server.go +++ b/misc/git/server.go @@ -92,7 +92,13 @@ const ( const SERVER = "server" func init() { - web.Index.MergeCommands(ice.Commands{"/x/": {Actions: aaa.WhiteAction(), Hand: func(m *ice.Message, arg ...string) { + web.Index.MergeCommands(ice.Commands{"/x/": {Actions: ice.MergeActions(ctx.CmdAction(), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) { + if !m.IsCliUA() { + web.RenderCmds(m, + kit.Dict(ctx.DISPLAY, "/plugin/local/code/repos.js", ctx.INDEX, "web.code.git.inner", ctx.ARGS, kit.List(strings.TrimSuffix(arg[0], ".git"), kit.Select("master", arg, 1), "pwd", kit.Select("README.md", path.Join(kit.Slice(arg, 2)...)))), + ) + return + } if m.RenderVoid(); m.Option("go-get") == "1" { p := _git_url(m, path.Join(arg...)) m.RenderResult(kit.Format(``, kit.Format(`%s git %s`, strings.TrimSuffix(strings.Split(p, "://")[1], ".git"), p))) @@ -115,6 +121,17 @@ func init() { m.Warn(_server_repos(m, arg...), ice.ErrNotValid) }}}) Index.MergeCommands(ice.Commands{ + "inner": {Name: "inner repos branch commit path auto", Help: "服务器", Actions: ice.MergeActions(ice.Actions{}), Hand: func(m *ice.Message, arg ...string) { + if m.Option(nfs.DIR_ROOT, ice.USR_LOCAL_REPOS); len(arg) == 0 { + } else if dir := path.Join(m.Option(nfs.DIR_ROOT), arg[0]); len(arg) == 1 { + } else if len(arg) == 2 { + } else if len(arg) == 3 || strings.HasSuffix(arg[3], "/") { + _repos_dir(m, dir, arg[1], arg[2], kit.Select("", arg, 3), nil) + } else { + m.Option("file", kit.Select("", arg, 3)) + _repos_cat(m, dir, arg[1], arg[2], kit.Select("", arg, 3)) + } + }}, SERVER: {Name: "server repos branch commit path auto create import", Help: "服务器", Actions: ice.MergeActions(ice.Actions{ mdb.CREATE: {Name: "create name*", Hand: func(m *ice.Message, arg ...string) { _repos_init(m, path.Join(ice.USR_LOCAL_REPOS, m.Option(mdb.NAME)))