From 15a3f015c78f0f2b4017cebf9523e952592962e0 Mon Sep 17 00:00:00 2001 From: shy Date: Wed, 11 Oct 2023 11:52:47 +0800 Subject: [PATCH] opt git --- base/aaa/role.go | 2 +- base/aaa/totp.go | 2 +- base/base.go | 2 +- base/cli/readelf.go | 1 - base/cli/runtime.go | 9 +- base/ctx/command.go | 2 +- base/ctx/context.go | 1 - base/ctx/display.go | 3 + base/mdb/hash.go | 5 +- base/mdb/zone.go | 2 +- base/nfs/dir.go | 4 +- base/nfs/pack.go | 2 +- base/tcp/host.go | 2 +- base/web/dream.go | 3 - base/web/option.go | 3 +- base/web/route.go | 1 - base/web/serve.go | 5 +- base/web/spide.go | 13 +- conf.go | 7 +- core/chat/flows.go | 2 +- core/chat/icons.go | 1 - core/chat/search.go | 2 +- core/code/css.go | 1 - core/code/go.go | 3 +- core/code/inner.go | 2 +- core/code/install.go | 2 +- core/code/vimer.go | 1 - core/core.go | 2 +- core/mall/asset.go | 2 +- core/wiki/data.go | 2 +- info.go | 4 +- misc/alpha/alpha.go | 2 +- misc/bash/run.go | 2 +- misc/chrome/daemon.go | 2 +- misc/git/configs.go | 17 +- misc/git/count.go | 91 ++++++++--- misc/git/git.go | 8 - misc/git/repos.go | 354 ++++++++++++++++-------------------------- misc/git/search.go | 19 ++- misc/git/service.go | 4 +- misc/git/status.go | 22 +-- misc/git/total.go | 11 +- misc/git/trend.go | 3 +- misc/tmux/buffer.go | 2 +- render.go | 5 +- type.go | 8 +- 46 files changed, 303 insertions(+), 340 deletions(-) diff --git a/base/aaa/role.go b/base/aaa/role.go index 679443fb..9c8d16f1 100644 --- a/base/aaa/role.go +++ b/base/aaa/role.go @@ -44,7 +44,7 @@ func _role_list(m *ice.Message, role string) *ice.Message { m.Push(ROLE, kit.Value(value, mdb.NAME)).Push(mdb.ZONE, BLACK).Push(mdb.KEY, k).Push(mdb.STATUS, v) }) }) - return m.Sort(mdb.KEY).StatusTimeCount() + return m.Sort(mdb.KEY) } const ( diff --git a/base/aaa/totp.go b/base/aaa/totp.go index fd104a79..79bcec9c 100644 --- a/base/aaa/totp.go +++ b/base/aaa/totp.go @@ -61,7 +61,7 @@ func init() { } }) if len(arg) == 0 { - m.PushAction(mdb.REMOVE).Action(mdb.CREATE, mdb.PRUNES).StatusTimeCount() + m.PushAction(mdb.REMOVE).Action(mdb.CREATE, mdb.PRUNES) } }}, }) diff --git a/base/base.go b/base/base.go index 90ce245f..8b8b111b 100644 --- a/base/base.go +++ b/base/base.go @@ -1,4 +1,4 @@ -package shy +package base import ( _ "shylinux.com/x/icebergs/base/aaa" diff --git a/base/cli/readelf.go b/base/cli/readelf.go index 979bc9fa..265e2185 100644 --- a/base/cli/readelf.go +++ b/base/cli/readelf.go @@ -37,7 +37,6 @@ func init() { kit.If(i%16 == 0, func() { m.Push("addr", kit.Format("%04x", i)) }) m.Push(kit.Format("%02x", i%16), kit.Format("%02x", buf[i])) } - m.StatusTimeCount() } }}, }) diff --git a/base/cli/runtime.go b/base/cli/runtime.go index 64f2a842..f8030476 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -191,7 +191,7 @@ func init() { } ctx.DisplayStorySpide(m.Options(nfs.DIR_ROOT, nfs.PS), lex.PREFIX, kit.Fields(ctx.ACTION, m.ActionKey())) kit.For(ice.Info.Route, func(k, v string) { m.Push(nfs.PATH, k).Push(nfs.FILE, v) }) - m.Sort(nfs.PATH).StatusTimeCount() + m.Sort(nfs.PATH) }}, CLI: {Hand: func(m *ice.Message, arg ...string) { if len(arg) > 1 { @@ -200,22 +200,21 @@ func init() { } ctx.DisplayStorySpide(m.Options(nfs.DIR_ROOT, "ice."), lex.PREFIX, kit.Fields(ctx.ACTION, m.ActionKey()), mdb.FIELD, mdb.NAME, lex.SPLIT, nfs.PT) kit.For(ice.Info.File, func(k, v string) { m.Push(nfs.FILE, k).Push(mdb.NAME, v) }) - m.Sort(mdb.NAME).StatusTimeCount() + m.Sort(mdb.NAME) }}, CMD: {Hand: func(m *ice.Message, arg ...string) { m.OptionFields(ctx.INDEX, mdb.NAME, mdb.HELP, nfs.FILE) - m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND).StatusTimeCount() + m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND) }}, MOD: {Hand: func(m *ice.Message, arg ...string) { kit.For(ice.Info.Gomod, func(k string, v string) { m.Push(nfs.MODULE, k).Push(nfs.VERSION, v) }) - m.StatusTimeCount() }}, ENV: {Hand: func(m *ice.Message, arg ...string) { kit.For(os.Environ(), func(v string) { ls := strings.SplitN(v, mdb.EQ, 2) m.Push(mdb.NAME, ls[0]).Push(mdb.VALUE, ls[1]) }) - m.StatusTimeCount().Sort(mdb.NAME) + m.Sort(mdb.NAME) }}, nfs.PATH: {Hand: func(m *ice.Message, arg ...string) { kit.For(_path_split(os.Getenv(PATH)), func(p string) { m.Push(nfs.PATH, p) }) diff --git a/base/ctx/command.go b/base/ctx/command.go index e3d34685..c0232700 100644 --- a/base/ctx/command.go +++ b/base/ctx/command.go @@ -93,7 +93,7 @@ func init() { }}, }, aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 { - m.Cmdy("", mdb.SEARCH, COMMAND, ice.OptionFields(INDEX)).Action(mdb.EXPORT).StatusTimeCount() + m.Cmdy("", mdb.SEARCH, COMMAND, ice.OptionFields(INDEX)).Action(mdb.EXPORT) DisplayStory(m.Options(nfs.DIR_ROOT, "ice."), "spide.js?split=.") } else { kit.For(arg, func(k string) { _command_list(m, k) }) diff --git a/base/ctx/context.go b/base/ctx/context.go index f51567a7..61e12051 100644 --- a/base/ctx/context.go +++ b/base/ctx/context.go @@ -16,7 +16,6 @@ func _context_list(m *ice.Message, sub *ice.Context, name string) { } m.Push(mdb.NAME, s.Prefix()).Push(mdb.HELP, s.Help) }) - m.StatusTimeCount() } const CONTEXT = "context" diff --git a/base/ctx/display.go b/base/ctx/display.go index e5ea453f..2e6f30a0 100644 --- a/base/ctx/display.go +++ b/base/ctx/display.go @@ -52,6 +52,9 @@ func DisplayLocal(m displayMessage, file string, arg ...ice.Any) displayMessage kit.If(isLocalFile(file), func() { file = path.Join(ice.PLUGIN_LOCAL, file) }) return DisplayBase(m, file, arg...) } +func DisplayLocalInner(m displayMessage, arg ...ice.Any) displayMessage { + return DisplayLocal(m, "code/inner.js", arg...) +} func DisplayBase(m displayMessage, file string, arg ...ice.Any) displayMessage { m.Option(ice.MSG_DISPLAY, kit.MergeURL(kit.Select(kit.ExtChange(file, nfs.JS), file, strings.Contains(file, mdb.QS)), arg...)) return m diff --git a/base/mdb/hash.go b/base/mdb/hash.go index 9ea894fa..a18fb993 100644 --- a/base/mdb/hash.go +++ b/base/mdb/hash.go @@ -223,10 +223,9 @@ func HashSelect(m *ice.Message, arg ...string) *ice.Message { kit.If(sort != UNIQ, func() { m.Sort(sort) }) }) if m.PushAction(Config(m, ACTION), REMOVE); !m.FieldsIsDetail() { - return m.Action(CREATE, PRUNES).StatusTimeCount() - } else { - return m.StatusTime() + return m.Action(CREATE, PRUNES) } + return m } func HashPrunes(m *ice.Message, cb func(Map) bool) *ice.Message { expire := kit.Select(m.Time("-"+kit.Select(DAYS, Config(m, EXPIRE))), m.Option("before")) diff --git a/base/mdb/zone.go b/base/mdb/zone.go index f0cd1650..a35a4799 100644 --- a/base/mdb/zone.go +++ b/base/mdb/zone.go @@ -231,7 +231,7 @@ func ZoneSelect(m *ice.Message, arg ...string) *ice.Message { arg = kit.Slice(arg, 0, 2) m.Fields(len(arg), kit.Select(kit.Fields(TIME, Config(m, SHORT), COUNT), Config(m, FIELD)), ZoneField(m)) if m.Cmdy(SELECT, m.PrefixKey(), "", ZONE, arg, logs.FileLineMeta(-1)); len(arg) == 0 { - m.Sort(ZoneShort(m)).PushAction(Config(m, ACTION), REMOVE).Action(CREATE).StatusTimeCount() + m.Sort(ZoneShort(m)).PushAction(Config(m, ACTION), REMOVE).Action(CREATE) } else if len(arg) == 1 { m.Action(INSERT).StatusTimeCountTotal(_zone_meta(m, m.PrefixKey(), kit.Keys(HASH, HashSelectField(m, arg[0], HASH)), COUNT)) } diff --git a/base/nfs/dir.go b/base/nfs/dir.go index 7c0a1fe9..2ea77472 100644 --- a/base/nfs/dir.go +++ b/base/nfs/dir.go @@ -139,11 +139,12 @@ const ( PWD = "./" SRC = "src/" BIN = "bin/" + VAR = "var/" USR = "usr/" USR_PORTAL = ice.USR_PORTAL USR_PUBLISH = ice.USR_PUBLISH - USR_LOCAL_WORK = ice.USR_LOCAL_WORK USR_ICEBERGS = ice.USR_ICEBERGS + USR_LOCAL_WORK = ice.USR_LOCAL_WORK SRC_DOCUMENT = ice.SRC_DOCUMENT SRC_TEMPLATE = ice.SRC_TEMPLATE REQUIRE = "/require/" @@ -202,6 +203,7 @@ func init() { fields := kit.Split(kit.Select(kit.Select(DIR_DEF_FIELDS, m.OptionFields()), kit.Join(kit.Slice(arg, 1)))) size, _ := _dir_list(m, root, dir, 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), regexp.MustCompile(m.Option(DIR_REG)), fields) // m.Status(mdb.TIME, last, mdb.COUNT, kit.Split(m.FormatSize())[0], SIZE, kit.FmtSize(size), m.OptionSimple(DIR_ROOT), kit.MDB_COST, m.FormatCost()) + kit.If(m.Option(DIR_ROOT), func() { m.Option(DIR_ROOT, path.Join(m.Option(DIR_ROOT))+PS) }) m.StatusTimeCount(SIZE, kit.FmtSize(size), m.OptionSimple(DIR_ROOT)) }}, }) diff --git a/base/nfs/pack.go b/base/nfs/pack.go index ff2b6763..57be3ca4 100644 --- a/base/nfs/pack.go +++ b/base/nfs/pack.go @@ -62,7 +62,7 @@ func init() { m.Push(PATH, path.Join(p, s.Name())+kit.Select("", PS, s.IsDir())) m.Push(SIZE, kit.FmtSize(s.Size())) }) - m.PushAction(mdb.REMOVE).StatusTimeCount() + m.PushAction(mdb.REMOVE) } }}, }) diff --git a/base/tcp/host.go b/base/tcp/host.go index 4f56a11c..9150b62a 100644 --- a/base/tcp/host.go +++ b/base/tcp/host.go @@ -32,7 +32,7 @@ func _host_list(m *ice.Message, name string) { if len(m.Appendv(aaa.IP)) == 0 { m.Push(mdb.INDEX, -1).Push(mdb.NAME, LOCALHOST).Push(aaa.IP, "127.0.0.1").Push("mask", "255.0.0.0").Push("hard", "") } - m.SortInt(mdb.INDEX).StatusTimeCount() + m.SortInt(mdb.INDEX) } const ( diff --git a/base/web/dream.go b/base/web/dream.go index c3d349a3..ba7d8a71 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -233,14 +233,12 @@ func init() { }) return nil }) - m.StatusTimeCount() }}, nfs.CAT: {Name: "cat file*", Help: "文件", Hand: func(m *ice.Message, arg ...string) { mdb.HashSelect(m.Spawn()).Table(func(value ice.Maps) { m.Push(mdb.NAME, value[mdb.NAME]) m.Push(mdb.TEXT, m.Cmdx(SPACE, value[mdb.NAME], nfs.CAT, m.Option(nfs.FILE))) }) - m.StatusTimeCount() }}, ice.CMD: {Name: "cmd cmd*", Help: "命令", Hand: func(m *ice.Message, arg ...string) { GoToast(m, "", func(toast func(string, int, int)) []string { @@ -252,7 +250,6 @@ func init() { }) return nil }) - m.StatusTimeCount() }}, cli.START: {Hand: func(m *ice.Message, arg ...string) { gdb.Event(m, DREAM_START, arg) diff --git a/base/web/option.go b/base/web/option.go index d12721ce..8f132e54 100644 --- a/base/web/option.go +++ b/base/web/option.go @@ -104,7 +104,7 @@ func PushStream(m *ice.Message) *ice.Message { func init() { ice.Info.PushStream = PushStream } func init() { ice.Info.PushNotice = PushNotice } -func Toast(m *ice.Message, text string, arg ...ice.Any) { // [title [duration [progress]]] +func Toast(m *ice.Message, text string, arg ...ice.Any) *ice.Message { // [title [duration [progress]]] if len(arg) > 1 { switch val := arg[1].(type) { case string: @@ -116,6 +116,7 @@ func Toast(m *ice.Message, text string, arg ...ice.Any) { // [title [duration [p kit.If(len(arg) == 0, func() { arg = append(arg, m.PrefixKey()) }) kit.If(len(arg) > 0, func() { arg[0] = kit.Select(m.PrefixKey(), arg[0]) }) PushNoticeToast(m, text, arg) + return m } func toastContent(m *ice.Message, state string) string { return kit.Join([]string{map[string]string{ice.PROCESS: "🕑", ice.FAILURE: "❌", ice.SUCCESS: "✅"}[state], state, m.ActionKey()}, " ") diff --git a/base/web/route.go b/base/web/route.go index 2b84e1ad..bc8db1f2 100644 --- a/base/web/route.go +++ b/base/web/route.go @@ -35,7 +35,6 @@ func _route_match(m *ice.Message, space string, cb func(ice.Maps, int, []ice.Map for i, item := range list { cb(item, i, list) } - m.StatusTimeCount() } func _route_toast(m *ice.Message, space string, args ...string) { GoToast(m, "", func(toast func(string, int, int)) (list []string) { diff --git a/base/web/serve.go b/base/web/serve.go index 05c07453..1af3b122 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -121,9 +121,12 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response kit.If(strings.TrimPrefix(r.URL.Path, key), func(p string) { m.Optionv(ice.MSG_CMDS, strings.Split(p, nfs.PS)) }) }) m.W.Header().Add(strings.ReplaceAll(ice.LOG_TRACEID, ".", "-"), m.Option(ice.LOG_TRACEID)) - defer func() { Render(m, m.Option(ice.MSG_OUTPUT), kit.List(m.Optionv(ice.MSG_ARGS))...) }() + defer func() { + Render(m, m.Option(ice.MSG_OUTPUT), kit.List(m.Optionv(ice.MSG_ARGS))...) + }() if cmds, ok := _serve_auth(m, key, kit.Simple(m.Optionv(ice.MSG_CMDS)), w, r); ok { defer func() { + kit.If(m.Option(ice.MSG_STATUS) == "", func() { m.StatusTimeCount() }) m.Cost(kit.Format("%s: /chat/cmd/%s/%s %v", r.Method, m.Option(ice.MSG_INDEX), path.Join(cmds...), m.FormatSize())) }() m.Option(ice.MSG_OPTS, kit.Simple(m.Optionv(ice.MSG_OPTION), func(k string) bool { return !strings.HasPrefix(k, ice.MSG_SESSID) })) diff --git a/base/web/spide.go b/base/web/spide.go index dd977129..aa8d6cbe 100644 --- a/base/web/spide.go +++ b/base/web/spide.go @@ -365,13 +365,11 @@ func init() { } func HostPort(m *ice.Message, host, port string) string { - if host == "" { - host = kit.ParseURL(UserHost(m)).Hostname() - } - if port == "80" { - return kit.Format("http://%s", host) - } else if port == "443" { + kit.If(host == "", func() { host = kit.ParseURL(UserHost(m)).Hostname() }) + if port == "443" { return kit.Format("https://%s", host) + } else if port == "80" || port == "" { + return kit.Format("http://%s", host) } else { return kit.Format("http://%s:%s", host, port) } @@ -394,3 +392,6 @@ func SpideDelete(m *ice.Message, arg ...ice.Any) ice.Any { func SpideSave(m *ice.Message, file, link string, cb func(count int, total int, value int)) *ice.Message { return m.Cmd(Prefix(SPIDE), ice.DEV, SPIDE_SAVE, file, http.MethodGet, link, cb) } +func SpideOrigin(m *ice.Message, name string) string { + return m.Cmdv("web.spide", name, CLIENT_ORIGIN) +} diff --git a/conf.go b/conf.go index f8740bcd..1691e1af 100644 --- a/conf.go +++ b/conf.go @@ -282,8 +282,11 @@ const ( // CTX CTX_SERVE = "serve" CTX_CLOSE = "close" - CTX_INIT = "_init" - CTX_EXIT = "_exit" + CTX_INIT = "_init" + CTX_EXIT = "_exit" + CTX_ICONS = "_icons" + CTX_TRANS = "_trans" + CTX_TITLE = "_title" ) const ( // LOG LOG_CMDS = "cmds" diff --git a/core/chat/flows.go b/core/chat/flows.go index 344c0b27..b443c7ff 100644 --- a/core/chat/flows.go +++ b/core/chat/flows.go @@ -33,7 +33,7 @@ func init() { } else { m.Fields(len(arg)-1, mdb.Config(m, mdb.FIELDS), mdb.DETAIL) m.Cmdy(mdb.SELECT, m.PrefixKey(), kit.KeyHash(arg[0]), mdb.HASH, arg[1:]) - m.PushAction(mdb.PLUGIN, mdb.DELETE).StatusTimeCount() + m.PushAction(mdb.PLUGIN, mdb.DELETE) } m.Display("") }}, diff --git a/core/chat/icons.go b/core/chat/icons.go index a5daff8c..97f94432 100644 --- a/core/chat/icons.go +++ b/core/chat/icons.go @@ -22,7 +22,6 @@ func init() { m.Push(mdb.NAME, name).Push(mdb.ICON, kit.Format(``, name)) } }) - m.StatusTimeCount() }}, }) } diff --git a/core/chat/search.go b/core/chat/search.go index 18955a89..90cfc3e9 100644 --- a/core/chat/search.go +++ b/core/chat/search.go @@ -13,7 +13,7 @@ func init() { SEARCH: {Actions: ice.MergeActions(ice.Actions{ cli.OPENS: {Hand: func(m *ice.Message, arg ...string) { cli.Opens(m, arg...) }}, }, web.ApiAction()), Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(web.Space(m, m.Option(ice.POD)), "mdb.search", arg).StatusTimeCount() + m.Cmdy(web.Space(m, m.Option(ice.POD)), "mdb.search", arg) }}, }) } diff --git a/core/code/css.go b/core/code/css.go index 7958d022..49b75d3d 100644 --- a/core/code/css.go +++ b/core/code/css.go @@ -50,7 +50,6 @@ func _css_show(m *ice.Message, arg ...string) { }) _css_stat(m, "stats.key", stats_key) _css_stat(m, "stats.value", stats_value) - m.StatusTimeCount() } func _css_exec(m *ice.Message, arg ...string) { if arg[2] == ice.USR_VOLCANOS { diff --git a/core/code/go.go b/core/code/go.go index 2c40f667..010ef322 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -94,12 +94,11 @@ func _mod_show(m *ice.Message, file string) { } }) kit.For(require, func(k, v string) { m.Push(REQUIRE, k).Push(VERSION, v).Push(REPLACE, kit.Select("", replace[k])) }) - m.StatusTimeCount() } func _sum_show(m *ice.Message, file string) { m.Cmdy(nfs.CAT, file, func(ls []string, line string) { m.Push(nfs.REPOS, ls[0]).Push(nfs.VERSION, ls[1]).Push(mdb.HASH, ls[2]) - }).StatusTimeCount() + }) } const ( diff --git a/core/code/inner.go b/core/code/inner.go index 0f1986f7..ea909577 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -174,5 +174,5 @@ func TagsList(m *ice.Message, cmds ...string) { } m.PushRecord(kit.Dict(mdb.TYPE, ls[3], mdb.NAME, ls[0], nfs.LINE, strings.TrimSuffix(ls[2], ";\""))) } - m.Sort(nfs.LINE).StatusTimeCount() + m.Sort(nfs.LINE) } diff --git a/core/code/install.go b/core/code/install.go index 4d1caea7..571c7097 100644 --- a/core/code/install.go +++ b/core/code/install.go @@ -158,7 +158,7 @@ func _install_service(m *ice.Message, arg ...string) { } } }) - m.Set(tcp.PORT).Table(func(value ice.Maps) { m.Push(tcp.PORT, path.Base(value[nfs.DIR])) }).StatusTimeCount() + m.Set(tcp.PORT).Table(func(value ice.Maps) { m.Push(tcp.PORT, path.Base(value[nfs.DIR])) }) } const ( diff --git a/core/code/vimer.go b/core/code/vimer.go index 785dbd68..88a72cc1 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -21,7 +21,6 @@ import ( ) func _vimer_make(m *ice.Message, dir string, msg *ice.Message) { - defer m.StatusTimeCount() for _, line := range strings.Split(msg.Append(cli.CMD_ERR), lex.NL) { if !strings.Contains(line, nfs.DF) { continue diff --git a/core/core.go b/core/core.go index 9e64e5e2..4ae40d7b 100644 --- a/core/core.go +++ b/core/core.go @@ -1,4 +1,4 @@ -package shy +package core import ( _ "shylinux.com/x/icebergs/core/chat" diff --git a/core/mall/asset.go b/core/mall/asset.go index 727d1f90..acf2c548 100644 --- a/core/mall/asset.go +++ b/core/mall/asset.go @@ -66,7 +66,7 @@ func init() { )}, }, Commands: ice.Commands{ ASSET: {Name: "asset account id auto spend trans bonus", Help: "资产", Meta: kit.Dict( - "_trans", kit.Dict(ACCOUNT, "账户", AMOUNT, "金额", FROM, "转出", TO, "转入", "time", "时间", "name", "商家", "text", "备注"), + ice.CTX_TRANS, kit.Dict(ACCOUNT, "账户", AMOUNT, "金额", FROM, "转出", TO, "转入", "time", "时间", "name", "商家", "text", "备注"), ), Actions: ice.MergeActions(ice.Actions{ SPEND: {Name: "spend account name amount time@date text", Help: "支出", Hand: func(m *ice.Message, arg ...string) { _sub_amount(m, arg) diff --git a/core/wiki/data.go b/core/wiki/data.go index 4d002c31..5daac36b 100644 --- a/core/wiki/data.go +++ b/core/wiki/data.go @@ -35,7 +35,7 @@ func init() { if kit.Ext(arg[0]) == nfs.JSON { ctx.DisplayStoryJSON(m.Cmdy(nfs.CAT, arg[0])) } else { - CSV(m, m.Cmdx(nfs.CAT, arg[0])).StatusTimeCount() + CSV(m, m.Cmdx(nfs.CAT, arg[0])) } }) }}, diff --git a/info.go b/info.go index a5589656..c73749b2 100644 --- a/info.go +++ b/info.go @@ -150,8 +150,8 @@ func MergeActions(arg ...Any) Actions { h.Hand = func(m *Message, arg ...string) { m.Cmdy(from, k, arg) } } if help := kit.Split(v.Help, " ::"); len(help) > 0 { - if kit.Value(_cmd.Meta, kit.Keys("_trans", strings.TrimPrefix(k, "_")), help[0]); len(help) > 1 { - kit.Value(_cmd.Meta, kit.Keys("_title", k), help[1]) + if kit.Value(_cmd.Meta, kit.Keys(CTX_TRANS, strings.TrimPrefix(k, "_")), help[0]); len(help) > 1 { + kit.Value(_cmd.Meta, kit.Keys(CTX_TITLE, k), help[1]) } } kit.If(len(v.List) > 0, func() { _cmd.Meta[k] = v.List }) diff --git a/misc/alpha/alpha.go b/misc/alpha/alpha.go index 73b6e381..99f84648 100644 --- a/misc/alpha/alpha.go +++ b/misc/alpha/alpha.go @@ -63,7 +63,7 @@ func (s alpha) List(m *ice.Message, arg ...string) { } wiki.CSV(m.Message.Spawn(), m.Cmdx(cli.SYSTEM, "grep", "-rih", arg[1], mdb.Config(m, mdb.STORE)), kit.Split(mdb.Config(m, mdb.FIELD))...).Table(func(value ice.Maps) { kit.If(m.FieldsIsDetail(), func() { m.PushDetail(value, mdb.Config(m, mdb.FIELD)) }, func() { m.PushRecord(value, mdb.Config(m, mdb.FIELD)) }) - }).StatusTimeCount() + }) } func init() { ice.Cmd("web.wiki.alpha.alpha", alpha{}) } diff --git a/misc/bash/run.go b/misc/bash/run.go index b9222b8c..b849803c 100644 --- a/misc/bash/run.go +++ b/misc/bash/run.go @@ -16,7 +16,7 @@ import ( func _run_action(m *ice.Message, cmd *ice.Command, script string, arg ...string) { list, args := []string{}, []string{} - kit.For(cmd.Meta["_trans"], func(k string, v string) { + kit.For(cmd.Meta[ice.CTX_TRANS], func(k string, v string) { list = append(list, k) args = append(args, kit.Format(` %s)`, k)) kit.For(cmd.Meta[k], func(index int, value ice.Map) { diff --git a/misc/chrome/daemon.go b/misc/chrome/daemon.go index 4039ee40..95b28c85 100644 --- a/misc/chrome/daemon.go +++ b/misc/chrome/daemon.go @@ -37,7 +37,7 @@ func (s daemon) Inputs(m *ice.Message, arg ...string) { } func (s daemon) List(m *ice.Message, arg ...string) { if len(arg) < 3 || arg[0] == "" || arg[1] == "" { - s.send(m, arg).StatusTimeCount() + s.send(m, arg) } else { s.send(m, arg[:2], "user.jumps", arg[2]) } diff --git a/misc/git/configs.go b/misc/git/configs.go index 352a0e2a..18cd5f58 100644 --- a/misc/git/configs.go +++ b/misc/git/configs.go @@ -7,10 +7,10 @@ import ( kit "shylinux.com/x/toolkits" ) -func _configs_set(m *ice.Message, k, v string) string { return _git_cmds(m, CONFIG, "--global", k, v) } -func _configs_get(m *ice.Message, k string) string { return _git_cmds(m, CONFIG, "--global", k) } +func _configs_set(m *ice.Message, k, v string) string { return _git_cmds(m, CONFIG, GLOBAL, k, v) } +func _configs_get(m *ice.Message, k string) string { return _git_cmds(m, CONFIG, GLOBAL, k) } func _configs_list(m *ice.Message) *ice.Message { - kit.SplitKV(mdb.EQ, lex.NL, _configs_get(m, "--list"), func(text string, ls []string) { + kit.SplitKV(mdb.EQ, lex.NL, _configs_get(m, LIST), func(text string, ls []string) { m.Push(mdb.NAME, ls[0]).Push(mdb.VALUE, ls[1]).PushButton(mdb.REMOVE) }) return mdb.HashSelectValue(m, func(value ice.Maps) { @@ -21,6 +21,10 @@ func _configs_list(m *ice.Message) *ice.Message { const ( USER_EMAIL = "user.email" USER_NAME = "user.name" + + GLOBAL = "--global" + UNSET = "--unset" + LIST = "--list" ) const CONFIGS = "configs" @@ -38,7 +42,7 @@ func init() { }}, mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) { mdb.HashCreate(m.Spawn(), m.OptionSimple(mdb.NAME, mdb.VALUE)) - _configs_set(m, "--unset", m.Option(mdb.NAME)) + _configs_set(m, UNSET, m.Option(mdb.NAME)) }}, mdb.MODIFY: {Hand: func(m *ice.Message, arg ...string) { if arg[0] == mdb.VALUE { @@ -52,11 +56,10 @@ func init() { "core", kit.Dict("quotepath", "false"), "color", kit.Dict("ui", "always"), ))), Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 { - _configs_list(m).Action(mdb.CREATE, ice.INIT).StatusTimeCount() + _configs_list(m).Action(mdb.CREATE, ice.INIT) return - } else if len(arg) > 1 { - m.Echo(_configs_set(m, arg[0], arg[1])) } + kit.If(len(arg) > 1, func() { _configs_set(m, arg[0], arg[1]) }) m.Echo(_configs_get(m, arg[0])) }}, }) diff --git a/misc/git/count.go b/misc/git/count.go index 7b79976a..b0c419be 100644 --- a/misc/git/count.go +++ b/misc/git/count.go @@ -5,6 +5,7 @@ import ( "strings" ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/lex" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" @@ -17,25 +18,36 @@ func _count_count(m *ice.Message, arg []string, cb func(string)) { return } nfs.DirDeepAll(m, "", arg[0], func(value ice.Maps) { - file := value[nfs.PATH] - for _, p := range []string{"node_modules/", "bin/", "var/", "tags"} { - if strings.Contains(file, p) { - return - } - } - switch kit.Ext(file) { - case "sum", "log": + if file := value[nfs.PATH]; kit.Contains(file, nfs.BIN, nfs.VAR, "node_modules/") { return + } else if kit.IsIn(kit.Ext(file), "tags", "sum", "log") { + return + } else { + cb(file) } - cb(file) }, nfs.PATH) } const COUNT = "count" func init() { + const ( + FILES = "files" + LINES = "lines" + ) Index.MergeCommands(ice.Commands{ - COUNT: {Name: "count path auto count order tags", Help: "代码行", Actions: ice.Actions{ + COUNT: {Name: "count path@key auto order count package tags", Help: "代码行", Actions: ice.Actions{ + mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(nfs.DIR, path.Dir(kit.Select(nfs.PWD, arg[1]))).CutTo(nfs.PATH, arg[0]) + }}, + cli.ORDER: {Help: "排行", Hand: func(m *ice.Message, arg ...string) { + files := map[string]int{} + _count_count(m, arg, func(file string) { + m.Cmdy(nfs.CAT, file, func(text string) { files[strings.TrimPrefix(file, arg[0])]++ }) + }) + kit.For(files, func(k string, v int) { m.Push(FILES, k).Push(LINES, v) }) + m.SortIntR(LINES) + }}, COUNT: {Help: "计数", Hand: func(m *ice.Message, arg ...string) { files, lines := map[string]int{}, map[string]int{} _count_count(m, arg, func(file string) { @@ -50,22 +62,61 @@ func init() { lines["_func"]++ } } - lines[mdb.TOTAL]++ lines[kit.Ext(file)]++ + lines[mdb.TOTAL]++ }) }) - kit.For(lines, func(k string, v int) { m.Push(mdb.TYPE, k).Push("files", files[k]).Push("lines", lines[k]) }) - m.SortIntR("lines").StatusTimeCount() + kit.For(lines, func(k string, v int) { m.Push(mdb.TYPE, k).Push(FILES, files[k]).Push(LINES, lines[k]) }) + m.SortIntR(LINES) }}, - "order": {Help: "排行", Hand: func(m *ice.Message, arg ...string) { - files := map[string]int{} + code.PACKAGE: {Help: "依赖", Hand: func(m *ice.Message, arg ...string) { + list := map[string]map[string]int{} + ls := map[string]int{} + pkg, block := "", false + add := func(mod string) { + if _, ok := list[pkg]; !ok { + list[pkg] = map[string]int{} + } + kit.If(mod, func() { list[pkg][mod]++; ls[mod]++ }) + } _count_count(m, arg, func(file string) { - m.Cmdy(nfs.CAT, file, func(text string) { files[strings.TrimPrefix(file, arg[0])]++ }) + m.Cmdy(nfs.CAT, file, func(text string) { + if kit.Ext(file) == code.GO { + switch { + case strings.HasPrefix(text, "package "): + pkg = kit.Split(text)[1] + case strings.HasPrefix(text, "import ("): + block = true + case strings.HasPrefix(text, "import "): + add(kit.Select("", kit.Split(text), -1)) + case strings.HasPrefix(text, ")"): + block = false + default: + kit.If(block, func() { add(kit.Select("", kit.Split(text), -1)) }) + } + } + }) }) - kit.For(files, func(k string, v int) { m.Push("files", k).Push("lines", v) }) - m.SortIntR("lines").StatusTimeCount() + m.Appendv(ice.MSG_APPEND, []string{code.PACKAGE, mdb.COUNT}) + kit.For(ls, func(key string, value int) { + if !strings.Contains(key, "shylinux.com") { + return + } + count := 0 + m.Push(code.PACKAGE, key) + kit.For(kit.SortedKey(list), func(k string) { + if n := list[k][key]; n == 0 { + m.Push(k, "") + } else { + m.Push(k, n) + count++ + } + }) + m.Push(mdb.COUNT, count) + }) + m.SortIntR(mdb.COUNT) }}, - "tags": {Help: "索引", Hand: func(m *ice.Message, arg ...string) { + nfs.TAGS: {Help: "索引", Hand: func(m *ice.Message, arg ...string) { count := map[string]int{} m.Cmd(nfs.CAT, path.Join(arg[0], nfs.TAGS), func(line string) { if ls := strings.SplitN(line, lex.TB, 3); len(ls) < 3 { @@ -77,7 +128,7 @@ func init() { } }) kit.For(count, func(k string, v int) { m.Push(mdb.TYPE, k).Push(mdb.COUNT, v) }) - m.SortIntR(mdb.COUNT).StatusTimeCount() + m.SortIntR(mdb.COUNT) }}, }, Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.DIR, arg) }}, }) diff --git a/misc/git/git.go b/misc/git/git.go index 69ad36e0..161e524e 100644 --- a/misc/git/git.go +++ b/misc/git/git.go @@ -1,23 +1,15 @@ package git import ( - "path" - ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/cli" - "shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/core/code" kit "shylinux.com/x/toolkits" ) -func _git_dir(arg ...string) string { return path.Join(path.Join(arg...), ".git") } func _git_cmd(m *ice.Message, arg ...string) *ice.Message { return m.Cmd(cli.SYSTEM, GIT, arg) } func _git_cmds(m *ice.Message, arg ...string) string { return _git_cmd(m, arg...).Results() } -func _git_tags(m *ice.Message) string { return _git_cmds(m, "describe", "--tags") } -func _git_diff(m *ice.Message) string { return _git_cmds(m, DIFF, "--shortstat") } -func _git_status(m *ice.Message) string { return _git_cmds(m, STATUS, "-sb") } -func _git_remote(m *ice.Message) string { return _git_cmds(m, nfs.REMOTE, "get-url", nfs.ORIGIN) } const GIT = "git" diff --git a/misc/git/repos.go b/misc/git/repos.go index e7bab76a..74104878 100644 --- a/misc/git/repos.go +++ b/misc/git/repos.go @@ -21,6 +21,7 @@ import ( "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/web" + "shylinux.com/x/icebergs/base/web/html" "shylinux.com/x/icebergs/core/code" kit "shylinux.com/x/toolkits" ) @@ -31,7 +32,7 @@ func _repos_insert(m *ice.Message, p string) { if head, err := repos.Head(); err == nil { args = append(args, BRANCH, head.Name().Short()) if commit, err := repos.CommitObject(head.Hash()); err == nil { - args = append(args, mdb.TIME, commit.Author.When.Format(ice.MOD_TIME), COMMENT, strings.TrimSuffix(commit.Message, lex.NL)) + args = append(args, mdb.TIME, commit.Author.When.Format(ice.MOD_TIME), MESSAGE, strings.TrimSuffix(commit.Message, lex.NL)) } } if refer := _repos_recent(m, repos); refer != nil { @@ -56,6 +57,14 @@ func _repos_origin(m *ice.Message, repos *git.Repository) string { return "" } } +func _repos_remote(m *ice.Message, remote string) string { + if remote == "" { + return "" + } else if insteadof := mdb.Config(m, INSTEADOF); insteadof != "" { + remote = insteadof + path.Base(remote) + } + return remote +} func _repos_recent(m *ice.Message, repos *git.Repository) (r *plumbing.Reference) { max := 0 if iter, err := repos.Tags(); err == nil { @@ -102,15 +111,13 @@ func _repos_each(m *ice.Message, title string, cb func(*git.Repository, ice.Maps msg.Table(func(value ice.Maps) { toast(value[REPOS], count, total) if err := cb(_repos_open(m, value[REPOS]), value); err != nil && err != git.NoErrAlreadyUpToDate { - web.Toast(m, err.Error(), "error: "+value[REPOS], "", "3s") + web.Toast(m, err.Error(), "error: "+value[REPOS], "", "3s").Sleep3s() list = append(list, value[REPOS]) - m.Sleep3s() } count++ }) return }) - } func _repos_each_origin(m *ice.Message, title string, cb func(*git.Repository, string, *http.BasicAuth, ice.Maps) error) { _repos_each(m, "", func(repos *git.Repository, value ice.Maps) error { @@ -134,8 +141,7 @@ func _repos_credentials(m *ice.Message) map[string]*url.URL { } func _repos_auth(m *ice.Message, origin string) *http.BasicAuth { list := _repos_credentials(m) - origin = _repos_remote(m, origin) - if u, ok := list[kit.ParseURL(origin).Host]; !ok { + if u, ok := list[kit.ParseURL(_repos_remote(m, origin)).Host]; !ok { return nil } else if password, ok := u.User.Password(); !ok { return nil @@ -144,7 +150,6 @@ func _repos_auth(m *ice.Message, origin string) *http.BasicAuth { return &http.BasicAuth{Username: u.User.Username(), Password: password} } } - func _repos_path(m *ice.Message, p string, arg ...string) string { if p == path.Base(kit.Path("")) { return kit.Path("", arg...) @@ -156,12 +161,12 @@ func _repos_path(m *ice.Message, p string, arg ...string) string { return p } } + func _repos_branch(m *ice.Message, repos *git.Repository) error { iter, err := repos.Branches() if err != nil { return err } - defer m.StatusTimeCount() iter.ForEach(func(refer *plumbing.Reference) error { if commit, err := repos.CommitObject(refer.Hash()); err == nil { m.Push(mdb.TIME, commit.Author.When.Format(ice.MOD_TIME)) @@ -173,21 +178,12 @@ func _repos_branch(m *ice.Message, repos *git.Repository) error { }) return nil } -func _repos_remote(m *ice.Message, remote string) string { - if remote == "" { - return "" - } else if insteadof := mdb.Config(m, INSTEADOF); insteadof != "" { - remote = insteadof + path.Base(remote) - } - return remote -} func _repos_log(m *ice.Message, hash plumbing.Hash, repos *git.Repository) error { iter, err := repos.Log(&git.LogOptions{From: hash}) if err != nil { return err } limit := 30 - defer m.StatusTimeCount() m.Push(mdb.TIME, m.Time()).Push(COMMIT, INDEX) m.Push(aaa.USERNAME, m.Option(ice.MSG_USERNAME)) m.Push(mdb.TEXT, "add some") @@ -210,6 +206,21 @@ func _repos_log(m *ice.Message, hash plumbing.Hash, repos *git.Repository) error return nil }) } +func _repos_tag(m *ice.Message, tags string) string { + if tags == "" { + return "v0.0.1" + } + ls := kit.Split(strings.TrimPrefix(kit.Split(tags, "-")[0], "v"), nfs.PT) + if v := kit.Int(ls[2]); v < 9 { + return kit.Format("v%v.%v.%v", ls[0], ls[1], v+1) + } else if v := kit.Int(ls[1]); v < 9 { + return kit.Format("v%v.%v.0", ls[0], v+1) + } else if v := kit.Int(ls[0]); v < 9 { + return kit.Format("v%v.0.0", v+1) + } else { + return "v0.0.1" + } +} func _repos_status(m *ice.Message, p string, repos *git.Repository) error { work, err := repos.Worktree() if err != nil { @@ -219,22 +230,17 @@ func _repos_status(m *ice.Message, p string, repos *git.Repository) error { if err != nil { return err } - defer m.StatusTimeCount() for k, v := range status { if kit.IsIn(k, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO, ice.ETC_LOCAL_SHY) { continue - } else if kit.IsIn(kit.Ext(k), "swp", "swo") || kit.IsIn(kit.Split(k, nfs.PS)[0], ice.BIN, ice.VAR, ice.USR) && !strings.HasPrefix(k, ice.USR_LOCAL_EXPORT) { + } else if kit.IsIn(kit.Ext(k), "swp", "swo") || kit.HasPrefix(k, nfs.BIN, nfs.VAR, nfs.USR) && !strings.HasPrefix(k, ice.USR_LOCAL_EXPORT) { continue } - if m.Push(REPOS, p).Push(STATUS, string(v.Worktree)+string(v.Staging)).Push(nfs.FILE, k); m.Option(ice.MSG_MODE) == mdb.ZONE { - ls := nfs.SplitPath(m, kit.Path(_repos_path(m, p), k)) - m.Push(nfs.PATH, ls[0]).Push(mdb.TEXT, string(v.Worktree)+string(v.Staging)+lex.SP+ls[0]+ls[1]) - } - switch v.Worktree { + switch m.Push(REPOS, p).Push(STATUS, string(v.Worktree)+string(v.Staging)).Push(nfs.FILE, k); v.Worktree { case git.Untracked: m.PushButton(ADD, nfs.TRASH) default: - m.PushButton(COMMIT, CHECKOUT) + m.PushButton(COMMIT) } } if p == path.Base(kit.Path("")) { @@ -282,21 +288,18 @@ func _repos_stats(m *ice.Message, repos *git.Repository, h string) error { } func _repos_inner(m *ice.Message, _repos_path func(m *ice.Message, p string, arg ...string) string, arg ...string) { if len(arg) == 0 || arg[0] != ctx.RUN { - arg = []string{path.Join(arg[:3]...) + nfs.PS, kit.Select("README.md", arg, 3)} + arg = []string{path.Join(arg[:3]...) + nfs.PS, kit.Select(ice.README_MD, arg, 3)} } else if kit.Select("", arg, 1) != ctx.ACTION { if ls := kit.Split(path.Join(m.Option(nfs.DIR_ROOT), arg[1]), nfs.PS); len(ls) < 2 || ls[2] == INDEX { if repos := _repos_open(m, ls[0]); len(arg) < 3 { - // m.Cmdy(nfs.DIR, nfs.PWD, kit.Dict(nfs.DIR_ROOT, _repos_path(m, ls[0]))) if work, err := repos.Worktree(); err == nil { if status, err := work.Status(); err == nil { for k := range status { m.Push(nfs.PATH, k) - // m.Echo(k) } } } } else { - m.Cmdy(nfs.CAT, _repos_path(m, ls[0], arg[2])) if refer, err := repos.Head(); err == nil { if commit, err := repos.CommitObject(refer.Hash()); err == nil { if file, err := commit.File(arg[2]); !m.Warn(err) { @@ -316,20 +319,14 @@ func _repos_inner(m *ice.Message, _repos_path func(m *ice.Message, p string, arg } } } + m.Cmdy(nfs.CAT, _repos_path(m, ls[0], arg[2])) } } else if commit, err := _repos_open(m, ls[0]).CommitObject(plumbing.NewHash(ls[2])); m.Warn(err) { return } else if len(arg) < 3 { - if iter, err := commit.Files(); !m.Warn(err) { - iter.ForEach(func(file *object.File) error { - // m.Push(nfs.PATH, file.Name) - return nil - }) - } if stats, err := commit.Stats(); err == nil { for _, stat := range stats { m.Push(nfs.PATH, stat.Name) - // m.Echo(stat.Name) } } } else { @@ -356,113 +353,60 @@ func _repos_inner(m *ice.Message, _repos_path func(m *ice.Message, p string, arg } } } - ctx.DisplayLocal(m, "code/inner.js", "style", "output") + ctx.DisplayLocalInner(m, ctx.STYLE, html.OUTPUT) return } ctx.ProcessField(m, "", arg, arg...) } -func _repos_total(m *ice.Message, p string, repos *git.Repository, stats map[string]int) *time.Time { - iter, err := repos.Log(&git.LogOptions{}) - if err != nil { - return nil - } - from, cmts, adds, dels := time.Now(), 0, 0, 0 - iter.ForEach(func(commit *object.Commit) error { - from, cmts = commit.Author.When, cmts+1 - if stats, err := commit.Stats(); err == nil { - for _, stat := range stats { - adds, dels = adds+stat.Addition, dels+stat.Deletion - } - } - return nil - }) - days := kit.Int(time.Now().Sub(from) / time.Hour / 24) - m.Push(REPOS, p).Push("from", from.Format(ice.MOD_TIME)).Push("days", days) - m.Push("commits", cmts).Push("adds", adds).Push("dels", dels).Push("rest", adds-dels) - stats["cmts"] += cmts - stats["adds"] += adds - stats["dels"] += dels - stats["rest"] += adds - dels - if days > stats["days"] { - stats["days"] = days - return &from - } - return nil -} func _repos_cmd(m *ice.Message, p string, arg ...string) *ice.Message { return m.Copy(_git_cmd(m.Options(cli.CMD_DIR, _repos_path(m, p)), arg...)) } -func _status_tag(m *ice.Message, tags string) string { - if tags == "" { - return "v0.0.1" - } - ls := kit.Split(strings.TrimPrefix(kit.Split(tags, "-")[0], "v"), nfs.PT) - if v := kit.Int(ls[2]); v < 9 { - return kit.Format("v%v.%v.%v", ls[0], ls[1], v+1) - } else if v := kit.Int(ls[1]); v < 9 { - return kit.Format("v%v.%v.0", ls[0], v+1) - } else if v := kit.Int(ls[0]); v < 9 { - return kit.Format("v%v.0.0", v+1) - } else { - return "v0.0.1" - } -} const ( - INIT = "init" - CLONE = "clone" - PULL = "pull" - PUSH = "push" - LOG = "log" - TAG = "tag" - ADD = "add" - STASH = "stash" - CONFIG = "config" - COMMIT = "commit" - BRANCH = "branch" - CHECKOUT = "checkout" - - REMOTE = "remote" - ORIGIN = "origin" - MASTER = "master" - INDEX = "index" - INSTEADOF = "insteadof" + CLONE = "clone" + PULL = "pull" + PUSH = "push" + LOG = "log" + TAG = "tag" + ADD = "add" + COMMIT = "commit" ) const ( - GITEA = "gitea" - OAUTH = "oauth" - DIFF = "diff" - OPT = "opt" - FIX = "fix" - + BRANCH = "branch" + MASTER = "master" + REMOTE = "remote" + ORIGIN = "origin" + CONFIG = "config" + INDEX = "index" TAGS = "tags" VERSION = "version" - COMMENT = "comment" + FORWORD = "forword" + MESSAGE = "message" + AUTHOR = "author" + WHEN = "when" ) const REPOS = "repos" func init() { cache := ice.USR_REQUIRE web.Index.MergeCommands(ice.Commands{ - web.PP(ice.REQUIRE): {Name: "/require/shylinux.com/x/volcanos/proto.js", Actions: ice.MergeActions(ice.Actions{ + web.PP(ice.REQUIRE): {Name: "/require/shylinux.com/x/volcanos@v0.0.1/proto.js", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { kit.If(cli.SystemFind(m, code.GO), func() { cache = code.GoCache(m) }) }}, }), Hand: func(m *ice.Message, arg ...string) { if len(arg) < 4 { m.RenderStatusBadRequest() - } else if path.Join(arg[:3]...) == ice.Info.Make.Module && nfs.Exists(m, path.Join(arg[3:]...)) { + } else if ls := kit.Split(arg[2], mdb.AT); path.Join(arg[:3]...) == ice.Info.Make.Module && nfs.Exists(m, path.Join(arg[3:]...)) { m.RenderDownload(path.Join(arg[3:]...)) - } else if p := path.Join(nfs.USR, kit.Split(arg[2], mdb.AT)[0], path.Join(arg[3:]...)); nfs.Exists(m, p) && kit.Select("", kit.Split(arg[2], mdb.AT), 1) == ice.Info.Gomod[path.Join(arg[0], arg[1], kit.Split(arg[2], mdb.AT)[0])] { + } else if p := path.Join(nfs.USR, ls[0], path.Join(arg[3:]...)); nfs.Exists(m, p) && kit.Select("", ls, 1) == ice.Info.Gomod[path.Join(arg[0], arg[1], ls[0])] { m.RenderDownload(p) } else { if p = path.Join(cache, path.Join(arg...)); !nfs.Exists(m, p) { if p = path.Join(ice.USR_REQUIRE, path.Join(arg...)); !nfs.Exists(m, p) { - ls := strings.SplitN(path.Join(arg[:3]...), mdb.AT, 2) - _, err := git.PlainClone(path.Join(ice.USR_REQUIRE, path.Join(arg[:3]...)), false, &git.CloneOptions{ - URL: "https://" + ls[0], Depth: 1, ReferenceName: plumbing.NewTagReferenceName(kit.Select(ice.Info.Gomod[ls[0]], ls, 1)), - }) - if m.Warn(err) { + if m.Warn(kit.Lasterr(git.PlainClone(path.Join(ice.USR_REQUIRE, path.Join(arg[:3]...)), false, &git.CloneOptions{ + URL: ice.HTTPS + "://" + ls[0], Depth: 1, ReferenceName: plumbing.NewTagReferenceName(kit.Select(ice.Info.Gomod[ls[0]], ls, 1)), + }))) { return } } @@ -493,22 +437,58 @@ func init() { _git_cmd(m, CONFIG, "--global", "url."+m.Option(REMOTE)+".insteadof", strings.TrimSuffix(ice.Info.Make.Remote, path.Base(ice.Info.Make.Remote))) } }}, + INIT: {Name: "init origin* path", Hand: func(m *ice.Message, arg ...string) { + m.Cmd(nfs.DEFS, kit.Path(".git/config"), kit.Format(nfs.Template(m, CONFIG), m.Option(ORIGIN))) + git.PlainInit(m.Option(nfs.PATH), false) + _repos_insert(m, kit.Path("")) + m.ProcessRefresh() + }}, + REMOTE: {Hand: func(m *ice.Message, arg ...string) { + repos := _repos_open(m, kit.Select(path.Base(kit.Path("")), kit.Select(m.Option(REPOS), arg, 0))) + if _remote, err := repos.Remote(ORIGIN); err == nil { + m.Push(REMOTE, kit.Select("", _remote.Config().URLs, 0)) + } + if refer := _repos_recent(m, repos); refer != nil { + m.Push(VERSION, refer.Name().Short()) + m.Push(FORWORD, _repos_forword(m, repos, refer.Hash().String())) + } + if refer, err := repos.Head(); err == nil { + m.Push(BRANCH, refer.Name().Short()) + m.Push(mdb.HASH, refer.Hash().String()) + if commit, err := repos.CommitObject(refer.Hash()); err == nil { + m.Push(aaa.EMAIL, commit.Author.Email) + m.Push(AUTHOR, commit.Author.Name) + m.Push(WHEN, commit.Author.When) + m.Push(MESSAGE, commit.Message) + } + } + }}, + "remoteURL": {Hand: func(m *ice.Message, arg ...string) { + m.Echo(_repos_remote(m, _repos_origin(m, _repos_open(m, path.Base(kit.Path("")))))) + }}, mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { switch arg[0] { - case COMMENT: + case MESSAGE: ls := kit.Split(m.Option(nfs.FILE), " /") + m.Push(arg[0], kit.Select("", ls, -2)) m.Push(arg[0], kit.Join(kit.Slice(ls, -1), nfs.PS)) m.Push(arg[0], kit.Join(kit.Slice(ls, -2), nfs.PS)) m.Push(arg[0], m.Option(nfs.FILE)) case VERSION: - m.Push(arg[0], _status_tag(m, m.Option(TAGS))) + m.Push(arg[0], _repos_tag(m, m.Option(TAGS))) + } + }}, + mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) { + if !m.Warn(m.Option(REPOS), ice.ErrNotValid, REPOS) { + nfs.Trash(m, _repos_path(m, m.Option(REPOS))) + mdb.HashRemove(m, m.Option(REPOS)) } }}, CLONE: {Name: "clone origin* branch name path", Help: "克隆", Hand: func(m *ice.Message, arg ...string) { m.OptionDefault(mdb.NAME, path.Base(m.Option(ORIGIN))) m.OptionDefault(nfs.PATH, path.Join(nfs.USR, m.Option(mdb.NAME))) defer m.Cmdy(nfs.DIR, m.Option(nfs.PATH)) - if nfs.Exists(m, _git_dir(m.Option(nfs.PATH))) { + if nfs.Exists(m, path.Join(m.Option(nfs.PATH), ".git")) { return } defer web.ToastProcess(m)() @@ -516,12 +496,6 @@ func init() { _repos_insert(m, m.Option(nfs.PATH)) } }}, - INIT: {Name: "clone origin* path", Hand: func(m *ice.Message, arg ...string) { - m.Cmd(nfs.DEFS, kit.Path(".git/config"), kit.Format(nfs.Template(m, "config"), m.Option(ORIGIN))) - git.PlainInit(m.Option(nfs.PATH), false) - _repos_insert(m, kit.Path("")) - m.ProcessRefresh() - }}, PULL: {Help: "下载", Hand: func(m *ice.Message, arg ...string) { _repos_each_origin(m, "", func(repos *git.Repository, remoteURL string, auth *http.BasicAuth, value ice.Maps) error { if work, err := repos.Worktree(); err != nil { @@ -533,58 +507,15 @@ func init() { }}, PUSH: {Help: "上传", Hand: func(m *ice.Message, arg ...string) { _repos_each_origin(m, "", func(repos *git.Repository, remoteURL string, auth *http.BasicAuth, value ice.Maps) error { - _git_cmd(m.Spawn(kit.Dict(cli.CMD_DIR, value[nfs.PATH])), PUSH, "--tags") + defer _git_cmd(m.Spawn(kit.Dict(cli.CMD_DIR, value[nfs.PATH])), PUSH, "--tags") return repos.Push(&git.PushOptions{RemoteURL: remoteURL, Auth: auth, FollowTags: true}) }) }}, - LOG: {Hand: func(m *ice.Message, arg ...string) { - repos := _repos_open(m, kit.Select(m.Option(REPOS), arg, 0)) - if branch, err := repos.Branch(kit.Select(m.Option(BRANCH), arg, 1)); !m.Warn(err) { - if refer, err := repos.Reference(branch.Merge, true); !m.Warn(err) { - _repos_log(m, refer.Hash(), repos) - } - } - }}, - TAG: {Name: "tag version", Hand: func(m *ice.Message, arg ...string) { - repos := _repos_open(m, m.Option(REPOS)) - if refer, err := repos.Head(); !m.Warn(err) { - kit.If(m.Option(VERSION) == "", func() { m.Option(VERSION, _status_tag(m, m.Option(TAGS))) }) - _, err := repos.CreateTag(m.Option(VERSION), refer.Hash(), &git.CreateTagOptions{}) - m.Warn(err) - } - }}, - ADD: {Hand: func(m *ice.Message, arg ...string) { - if work, err := _repos_open(m, m.Option(REPOS)).Worktree(); !m.Warn(err) { - _, err := work.Add(m.Option(nfs.FILE)) - m.Warn(err) - } - }}, - STASH: {Hand: func(m *ice.Message, arg ...string) { - _repos_cmd(m, kit.Select(m.Option(REPOS), arg, 0), STASH) - }}, - CHECKOUT: {Help: "恢复", Hand: func(m *ice.Message, arg ...string) { - _git_cmd(m.Options(nfs.DIR_ROOT, mdb.HashSelectField(m, m.Option(REPOS), nfs.PATH)), CHECKOUT, m.Option(nfs.FILE)) - }}, - COMMIT: {Name: "commit actions=add,fix,opt message*=some", Help: "提交", Hand: func(m *ice.Message, arg ...string) { - if work, err := _repos_open(m, m.Option(REPOS)).Worktree(); !m.Warn(err) { - opt := &git.CommitOptions{All: true} - if cfg, err := config.LoadConfig(config.GlobalScope); err == nil { - if cfg.Author.Email == "" || cfg.Author.Name == "" { - opt.Author = &object.Signature{When: time.Now(), - Name: kit.Select(m.Option(ice.MSG_USERNAME), mdb.Config(m, aaa.USERNAME)), - Email: kit.Select(m.Option(ice.MSG_USERNAME)+"@shylinux.com", mdb.Config(m, aaa.EMAIL)), - } - } - } - _, err := work.Commit(m.Option("actions")+lex.SP+m.Option("message"), opt) - m.Warn(err) - } - }}, STATUS: {Help: "状态", Hand: func(m *ice.Message, arg ...string) { if repos := kit.Select(m.Option(REPOS), arg, 0); repos != "" { _repos_status(m, repos, _repos_open(m, repos)) } else { - last, password, list := "", "", _repos_credentials(m) + last := "" _repos_each(m, "", func(repos *git.Repository, value ice.Maps) error { if refer, err := repos.Head(); err == nil { if commit, err := repos.CommitObject(refer.Hash()); err == nil { @@ -599,6 +530,7 @@ func init() { remote = kit.Select(remote, _repos_origin(m, repos)) } remote = _repos_remote(m, remote) + password, list := "", _repos_credentials(m) if u, ok := list[kit.ParseURL(remote).Host]; ok { password, _ = u.User.Password() } @@ -609,52 +541,9 @@ func init() { ) } }}, - TOTAL: {Hand: func(m *ice.Message, arg ...string) { - stats := map[string]int{} - if repos := kit.Select(m.Option(REPOS), arg, 0); repos == "" { - var from *time.Time - _repos_each(m, "", func(repos *git.Repository, value ice.Maps) error { - if kit.IsIn(value[REPOS], "go-git", "go-qrcode", "websocket", "webview", "wubi-dict", "word-dict") { - return nil - } - t := _repos_total(m, value[REPOS], repos, stats) - kit.If(t != nil, func() { from = t }) - return nil - }) - m.Push(REPOS, TOTAL) - m.Push("from", from.Format(ice.MOD_TIME)) - m.Push("days", stats["days"]) - m.Push("commits", stats["cmts"]) - m.Push("adds", stats["adds"]) - m.Push("dels", stats["dels"]) - m.Push("rest", stats["rest"]) - m.SortIntR("rest") - } else { - _repos_total(m, repos, _repos_open(m, repos), stats) - } - m.StatusTimeCount() - }}, - "remoteURL": {Hand: func(m *ice.Message, arg ...string) { - m.Echo(_repos_remote(m, _repos_origin(m, _repos_open(m, path.Base(kit.Path("")))))) - }}, - REMOTE: {Hand: func(m *ice.Message, arg ...string) { - repos := _repos_open(m, kit.Select(path.Base(kit.Path("")), kit.Select(m.Option(REPOS), arg, 0))) - if _remote, err := repos.Remote(ORIGIN); err == nil { - m.Push(REMOTE, kit.Select("", _remote.Config().URLs, 0)) - } - if refer := _repos_recent(m, repos); refer != nil { - m.Push(nfs.VERSION, refer.Name().Short()) - m.Push("forword", _repos_forword(m, repos, refer.Hash().String())) - } - if refer, err := repos.Head(); err == nil { - m.Push(BRANCH, refer.Name().Short()) - m.Push(mdb.HASH, refer.Hash().String()) - if commit, err := repos.CommitObject(refer.Hash()); err == nil { - m.Push(aaa.EMAIL, commit.Author.Email) - m.Push("author", commit.Author.Name) - m.Push("when", commit.Author.When) - m.Push("message", commit.Message) - } + ADD: {Hand: func(m *ice.Message, arg ...string) { + if work, err := _repos_open(m, m.Option(REPOS)).Worktree(); !m.Warn(err) { + m.Warn(kit.Lasterr(work.Add(m.Option(nfs.FILE)))) } }}, nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { @@ -662,18 +551,42 @@ func init() { nfs.Trash(m, _repos_path(m, m.Option(REPOS), m.Option(nfs.FILE))) } }}, - mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) { - if !m.Warn(m.Option(REPOS), ice.ErrNotValid, REPOS) { - nfs.Trash(m, _repos_path(m, m.Option(REPOS))) - mdb.HashRemove(m, m.Option(REPOS)) + COMMIT: {Name: "commit actions=add,fix,opt message*=some", Help: "提交", Hand: func(m *ice.Message, arg ...string) { + if work, err := _repos_open(m, m.Option(REPOS)).Worktree(); !m.Warn(err) { + opt := &git.CommitOptions{All: true} + if cfg, err := config.LoadConfig(config.GlobalScope); err == nil { + if cfg.Author.Email == "" || cfg.Author.Name == "" { + opt.Author = &object.Signature{When: time.Now(), + Name: kit.Select(m.Option(ice.MSG_USERNAME), mdb.Config(m, aaa.USERNAME)), + Email: kit.Select(m.Option(ice.MSG_USERNAME)+mdb.AT+"shylinux.com", mdb.Config(m, aaa.EMAIL)), + } + } + } + m.Warn(kit.Lasterr(work.Commit(m.Option("actions")+lex.SP+m.Option(MESSAGE), opt))) } }}, + LOG: {Hand: func(m *ice.Message, arg ...string) { + repos := _repos_open(m, kit.Select(m.Option(REPOS), arg, 0)) + if branch, err := repos.Branch(kit.Select(m.Option(BRANCH), arg, 1)); !m.Warn(err) { + if refer, err := repos.Reference(branch.Merge, true); !m.Warn(err) { + _repos_log(m, refer.Hash(), repos) + } + } + }}, + TAG: {Name: "tag version", Hand: func(m *ice.Message, arg ...string) { + repos := _repos_open(m, m.Option(REPOS)) + if refer, err := repos.Head(); !m.Warn(err) { + kit.If(m.Option(VERSION) == "", func() { m.Option(VERSION, _repos_tag(m, m.Option(TAGS))) }) + m.Warn(kit.Lasterr(repos.CreateTag(m.Option(VERSION), refer.Hash(), &git.CreateTagOptions{}))) + } + }}, + code.INNER: {Hand: func(m *ice.Message, arg ...string) { _repos_inner(m, _repos_path, arg...) }}, web.DREAM_CREATE: {Hand: func(m *ice.Message, arg ...string) { kit.If(m.Option(REPOS), func(p string) { p = strings.Split(p, mdb.QS)[0] kit.If(!strings.Contains(p, "://"), func() { p = web.UserHost(m) + "/x/" + p }) - kit.If(ice.Info.System == cli.LINUX, func() { p = strings.Replace(p, "https", "http", 1) }) - web.Toast(m, "clone "+p) + kit.If(ice.Info.System == cli.LINUX, func() { p = strings.Replace(p, ice.HTTPS, ice.HTTP, 1) }) + web.Toast(m, CLONE+" "+p) m.Cmd("", CLONE, ORIGIN, p, nfs.PATH, m.Option(cli.CMD_DIR), ice.Maps{cli.CMD_DIR: ""}) }) }}, @@ -689,8 +602,7 @@ func init() { m.PushButton(kit.Dict(m.CommandKey(), "源码")) }}, web.DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) { web.DreamProcess(m, []string{}, arg...) }}, - code.INNER: {Hand: func(m *ice.Message, arg ...string) { _repos_inner(m, _repos_path, arg...) }}, - }, aaa.RoleAction(REMOTE), web.DreamAction(), mdb.HashAction(mdb.SHORT, REPOS, mdb.FIELD, "time,repos,branch,version,comment,origin"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) { + }, aaa.RoleAction(REMOTE), web.DreamAction(), mdb.HashAction(mdb.SHORT, REPOS, mdb.FIELD, "time,repos,branch,version,message,origin"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 { mdb.HashSelect(m, arg...).Sort(REPOS).PushAction(STATUS, mdb.REMOVE).Action(STATUS, PULL, PUSH, CLONE) } else if len(arg) == 1 { diff --git a/misc/git/search.go b/misc/git/search.go index 9f4acac5..a0e3e4bd 100644 --- a/misc/git/search.go +++ b/misc/git/search.go @@ -17,8 +17,8 @@ import ( func init() { const ( - REPOS_SEARCH = "/api/v1/repos/search" EXPLORE_REPOS = "/explore/repos" + REPOS_SEARCH = "/api/v1/repos/search" ) const ( WEB_SPIDE = "web.spide" @@ -39,12 +39,12 @@ func init() { HTML_URL: {Help: "源码", Hand: func(m *ice.Message, arg ...string) { m.ProcessOpen(m.Option(HTML_URL)) }}, WEBSITE: {Help: "官网", Hand: func(m *ice.Message, arg ...string) { m.ProcessOpen(m.Option(WEBSITE)) }}, ORIGIN: {Help: "平台", Hand: func(m *ice.Message, arg ...string) { - m.ProcessOpen(m.Cmdv(WEB_SPIDE, kit.Select(m.Option(REPOS), arg, 0), web.CLIENT_ORIGIN) + EXPLORE_REPOS) + m.ProcessOpen(web.SpideOrigin(m, kit.Select(m.Option(REPOS), arg, 0)) + EXPLORE_REPOS) }}, web.DREAM_INPUTS: {Hand: func(m *ice.Message, arg ...string) { kit.If(arg[0] == REPOS, func() { m.Cmds("", nfs.REPOS).Table(func(value ice.Maps) { - m.Push(nfs.REPOS, value["html_url"]).Push(nfs.VERSION, "").Push(mdb.TIME, value["updated_at"]) + m.Push(nfs.REPOS, value[HTML_URL]).Push(nfs.VERSION, "").Push(mdb.TIME, value[UPDATED_AT]) }) }) }}, @@ -53,16 +53,15 @@ func init() { m.Cmdy(WEB_SPIDE).RenameAppend(web.CLIENT_NAME, REPOS, web.CLIENT_URL, ORIGIN).Cut("time,repos,origin") return } - kit.For(kit.Value(kit.UnMarshal(m.Cmdx(WEB_SPIDE, arg[0], web.SPIDE_RAW, http.MethodGet, REPOS_SEARCH, "q", kit.Select("", arg, 1), "sort", "updated", "order", "desc", "page", "1", "limit", "30")), mdb.DATA), func(value ice.Map) { + kit.For(kit.Value(kit.UnMarshal(m.Cmdx(WEB_SPIDE, arg[0], web.SPIDE_RAW, http.MethodGet, REPOS_SEARCH, + "q", kit.Select("", arg, 1), mdb.SORT, "updated", mdb.ORDER, "desc", mdb.PAGE, "1", mdb.LIMIT, "30")), mdb.DATA), func(value ice.Map) { value[nfs.SIZE] = kit.FmtSize(kit.Int(value[nfs.SIZE]) * 1000) if t, e := time.Parse(time.RFC3339, kit.Format(value[UPDATED_AT])); e == nil { value[UPDATED_AT] = t.Format("01-02 15:04") } - m.Push("", value, []string{ - aaa.AVATAR_URL, mdb.NAME, aaa.LANGUAGE, - "forks_count", "stars_count", "watchers_count", - nfs.SIZE, UPDATED_AT, DESCRIPTION, - CLONE_URL, HTML_URL, WEBSITE, + m.Push("", value, []string{aaa.AVATAR_URL, mdb.NAME, DESCRIPTION, + aaa.LANGUAGE, "forks_count", "stars_count", "watchers_count", + nfs.SIZE, UPDATED_AT, CLONE_URL, HTML_URL, WEBSITE, }) button := []ice.Any{} kit.If(!kit.IsIn(kit.Format(value[mdb.NAME]), ice.ICEBERGS, ice.VOLCANOS), func() { button = append(button, cli.START) }) @@ -70,7 +69,7 @@ func init() { kit.For([]string{HTML_URL, WEBSITE}, func(key string) { kit.If(kit.Format(value[key]), func() { button = append(button, key) }) }) m.PushButton(button...) }) - m.RenameAppend(CLONE_URL, REPOS).Action(ORIGIN).StatusTimeCount().Display("") + m.RenameAppend(CLONE_URL, REPOS).Action(ORIGIN).Display("") }}, }) } diff --git a/misc/git/service.go b/misc/git/service.go index adec74be..3f300942 100644 --- a/misc/git/service.go +++ b/misc/git/service.go @@ -110,7 +110,7 @@ func init() { if len(arg) == 0 { return } else if arg[0] == ice.LIST { - m.Cmd(Prefix(SERVICE), func(value ice.Maps) { m.Push(nfs.REPOS, web.MergeLink(m, "/x/"+kit.Keys(value[nfs.REPOS], GIT))) }) + m.Cmd(Prefix(SERVICE), func(value ice.Maps) { m.Push(nfs.REPOS, _service_link(m, value[nfs.REPOS])) }) m.Sort(nfs.REPOS) return } else if m.RenderVoid(); m.Option("go-get") == "1" { @@ -157,7 +157,7 @@ func init() { web.DREAM_INPUTS: {Hand: func(m *ice.Message, arg ...string) { kit.If(arg[0] == REPOS, func() { mdb.HashSelect(m).Sort(REPOS).Cut("repos,version,time") }) }}, - }, web.DreamAction(), mdb.HashAction(mdb.SHORT, REPOS, mdb.FIELD, "time,repos,branch,version,comment"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) { + }, web.DreamAction(), mdb.HashAction(mdb.SHORT, REPOS, mdb.FIELD, "time,repos,branch,version,message"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 { mdb.HashSelect(m, arg...).Table(func(value ice.Maps) { m.Push(nfs.SIZE, kit.Split(m.Cmdx(cli.SYSTEM, "du", "-sh", path.Join(ice.USR_LOCAL_REPOS, value[REPOS])))[0]) diff --git a/misc/git/status.go b/misc/git/status.go index 5a0981be..a87c1d19 100644 --- a/misc/git/status.go +++ b/misc/git/status.go @@ -17,6 +17,14 @@ import ( kit "shylinux.com/x/toolkits" ) +const ( + INIT = "init" + DIFF = "diff" + INSTEADOF = "insteadof" + OAUTH = "oauth" + GITEA = "gitea" +) + const STATUS = "status" func init() { @@ -39,24 +47,18 @@ func init() { } } }}, + INIT: {Name: "init origin*", Help: "初始化", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(REPOS, INIT) }}, CONFIGS: {Name: "configs email* username* token", Help: "配置", Hand: func(m *ice.Message, arg ...string) { m.Cmd(nfs.DEFS, kit.HomePath(".gitconfig"), kit.Format(nfs.Template(m, "gitconfig"), m.Option(aaa.USERNAME), m.Option(aaa.EMAIL))) kit.If(m.Option(web.TOKEN), func() { m.Cmd(web.TOKEN, "set") }) mdb.Config(m, aaa.USERNAME, m.Option(aaa.USERNAME)) mdb.Config(m, aaa.EMAIL, m.Option(aaa.EMAIL)) }}, - INIT: {Name: "init origin", Help: "初始化", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(REPOS, INIT) - }}, - INSTEADOF: {Name: "insteadof remote", Help: "代理", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(REPOS, INSTEADOF, arg) - }}, + INSTEADOF: {Name: "insteadof remote", Help: "代理", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(REPOS, INSTEADOF, arg) }}, OAUTH: {Help: "授权", Hand: func(m *ice.Message, arg ...string) { m.ProcessOpen(kit.MergeURL2(kit.Select(ice.Info.Make.Domain, m.Cmdx(REPOS, "remoteURL")), web.ChatCmdPath(m, web.TOKEN, "gen"), tcp.HOST, m.Option(ice.MSG_USERWEB))) }}, - GITEA: {Help: "资源", Hand: func(m *ice.Message, arg ...string) { - m.ProcessOpen(m.Cmdv("web.spide", ice.HUB, web.CLIENT_URL)) - }}, + GITEA: {Help: "资源", Hand: func(m *ice.Message, arg ...string) { m.ProcessOpen(m.Cmdv("web.spide", ice.HUB, web.CLIENT_URL)) }}, web.DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) { if !kit.IsIn(m.Option(mdb.TYPE), web.WORKER, web.SERVER) { return @@ -66,7 +68,7 @@ func init() { } text := []string{} for _, line := range kit.Split(m.Cmdx(web.SPACE, m.Option(mdb.NAME), cli.SYSTEM, GIT, DIFF, "--shortstat"), mdb.FS, mdb.FS) { - if list := kit.Split(line); strings.Contains(line, "file") { + if list := kit.Split(line); strings.Contains(line, nfs.FILE) { text = append(text, list[0]+" file") } else if strings.Contains(line, "ins") { text = append(text, list[0]+" +++") diff --git a/misc/git/total.go b/misc/git/total.go index 00af927b..1c4fd1df 100644 --- a/misc/git/total.go +++ b/misc/git/total.go @@ -12,6 +12,7 @@ import ( "shylinux.com/x/icebergs/base/lex" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" + "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" "shylinux.com/x/toolkits/logs" "shylinux.com/x/toolkits/task" @@ -46,6 +47,7 @@ func init() { m.StatusTimeCount(m.AppendSimple(FROM)) return } + defer web.ToastProcess(m)() from, days, commit, adds, dels, rest := "", 0, 0, 0, 0, 0 TableGo(ReposList(m.Spawn()), func(value ice.Maps, lock *task.Lock) { msg := m.Cmd("_sum", value[nfs.PATH], mdb.TOTAL, "10000") @@ -60,20 +62,19 @@ func init() { m.Push(REPOS, value[REPOS]).Copy(msg) }) m.Push(REPOS, mdb.TOTAL).Push(TAGS, "v3.0.0").Push(FROM, from).Push(DAYS, days).Push(COMMIT, commit).Push(ADDS, adds).Push(DELS, dels).Push(REST, rest) - m.SortIntR(REST).StatusTimeCount() + m.SortIntR(REST) }}, "_sum": {Name: "_sum [path] [total] [count|date] args...", Help: "统计量", Hand: func(m *ice.Message, arg ...string) { - m.Options(nfs.CAT_CONTENT, "") - m.Options(nfs.DIR_ROOT, "") + m.Options(nfs.DIR_ROOT, "", nfs.CAT_CONTENT, "") if len(arg) > 0 { - if nfs.Exists(m, _git_dir(arg[0])) || nfs.Exists(m, path.Join(arg[0], "refs/heads/")) { + if nfs.Exists(m, path.Join(arg[0], ".git")) || nfs.Exists(m, path.Join(arg[0], "refs/heads/")) { m.Option(cli.CMD_DIR, arg[0]) arg = arg[1:] } } total := false kit.If(len(arg) > 0 && arg[0] == mdb.TOTAL, func() { total, arg = true, arg[1:] }) - args := []string{"log", "--shortstat", "--pretty=commit: %H %ad %n%s", "--date=iso", "--reverse"} + args := []string{LOG, "--shortstat", "--pretty=commit: %H %ad %n%s", "--date=iso", "--reverse"} if len(arg) > 0 { arg[0] += kit.Select("", " 00:00:00", strings.Contains(arg[0], "-") && !strings.Contains(arg[0], nfs.DF)) args = append(args, kit.Select("-n", "--since", strings.Contains(arg[0], "-"))) diff --git a/misc/git/trend.go b/misc/git/trend.go index bd838824..67ab4f82 100644 --- a/misc/git/trend.go +++ b/misc/git/trend.go @@ -19,8 +19,7 @@ func init() { m.Cmdy("", code.INNER, m.Option(REPOS), MASTER, m.Option(mdb.HASH), m.Cmdv(REPOS, m.Option(REPOS), MASTER, m.Option(mdb.HASH), nfs.FILE)) }}, code.INNER: {Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(REPOS, code.INNER, arg) - ctx.DisplayLocal(m, "code/inner.js", ctx.STYLE, html.FLOAT) + ctx.DisplayLocalInner(m.Cmdy(REPOS, code.INNER, arg), ctx.STYLE, html.FLOAT) }}, }, Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 { diff --git a/misc/tmux/buffer.go b/misc/tmux/buffer.go index 8fc48beb..150ccf88 100644 --- a/misc/tmux/buffer.go +++ b/misc/tmux/buffer.go @@ -50,7 +50,7 @@ func init() { m.Push(mdb.VALUE, ls[2][1:len(ls[2])-1]) } } - m.StatusTimeCount().PushAction(mdb.REMOVE).Action(mdb.CREATE) + m.PushAction(mdb.REMOVE).Action(mdb.CREATE) }}, TEXT: {Name: "text auto text:textarea", Help: "文本", Hand: func(m *ice.Message, arg ...string) { kit.If(len(arg) > 0, func() { _tmux_cmd(m, SET_BUFFER, arg[0]) }) diff --git a/render.go b/render.go index 95112451..c3d202e8 100644 --- a/render.go +++ b/render.go @@ -21,6 +21,7 @@ func Render(m *Message, cmd string, args ...Any) string { if render, ok := Info.render[cmd]; ok { return render(m, args...) } + trans := kit.Value(m._cmd.Meta, CTX_TRANS) switch arg := kit.Simple(args...); cmd { case RENDER_BUTTON: list := []string{} @@ -33,7 +34,9 @@ func Render(m *Message, cmd string, args ...Any) string { list = append(list, k) break } - kit.For(kit.Split(k), func(k string) { list = append(list, kit.Format(``, k, k)) }) + kit.For(kit.Split(k), func(k string) { + list = append(list, kit.Format(``, k, kit.Select(k, kit.Value(trans, k), !m.IsEnglish()))) + }) case Map, Maps: kit.For(k, func(k, v string) { list = append(list, kit.Format(``, k, kit.Select(v, k, m.IsEnglish()))) diff --git a/type.go b/type.go index de1fc9bd..918d0171 100644 --- a/type.go +++ b/type.go @@ -162,11 +162,11 @@ func (c *Context) Merge(s *Context) *Context { kit.If(sub == SELECT, func() { cmd.Name = kit.Select(action.Name, cmd.Name) }) kit.If(sub == SELECT, func() { cmd.Help = kit.Select(action.Help, cmd.Help) }) if help := kit.Split(action.Help, " ::"); len(help) > 0 { - if kit.Value(cmd.Meta, kit.Keys("_trans", strings.TrimPrefix(sub, "_")), help[0]); len(help) > 1 { - kit.Value(cmd.Meta, kit.Keys("_title", sub), help[1]) + if kit.Value(cmd.Meta, kit.Keys(CTX_TRANS, strings.TrimPrefix(sub, "_")), help[0]); len(help) > 1 { + kit.Value(cmd.Meta, kit.Keys(CTX_TITLE, sub), help[1]) } } - kit.Value(cmd.Meta, kit.Keys("_icons", sub), action.Icon) + kit.Value(cmd.Meta, kit.Keys(CTX_ICONS, sub), action.Icon) if action.Hand == nil { continue } @@ -401,7 +401,7 @@ func (m *Message) Design(action Any, help string, input ...Any) { k := kit.Format(action) if a, ok := m._cmd.Actions[k]; ok { m._cmd.Meta[k], a.List = list, list - kit.Value(m._cmd.Meta, kit.Keys("_trans", k), help) + kit.Value(m._cmd.Meta, kit.Keys(CTX_TRANS, k), help) } } func (m *Message) Actions(key string) *Action { return m._cmd.Actions[key] }