From d93e5b56ad26d88b97b7b7c813a476fe845c5186 Mon Sep 17 00:00:00 2001 From: shylinux Date: Sat, 3 Sep 2022 16:43:13 +0800 Subject: [PATCH] opt some --- base/ctx/command.go | 47 +++++++++++++++++++++++++++++++++++++------ base/gdb/gdb.go | 1 + base/mdb/list.go | 7 +++++-- core/code/c.go | 29 ++++++++++++++++++++++---- core/code/go.go | 5 ++++- core/code/inner.go | 31 +++++++++++++++++++++++++++- core/code/install.go | 12 +++++++++++ core/code/xterm.go | 11 ++++++++++ misc/git/count.go | 3 +++ misc/git/server.go | 5 ++++- misc/node/compile.shy | 2 +- type.go | 1 + 12 files changed, 138 insertions(+), 16 deletions(-) diff --git a/base/ctx/command.go b/base/ctx/command.go index 8faf2490..88164495 100644 --- a/base/ctx/command.go +++ b/base/ctx/command.go @@ -116,12 +116,25 @@ func CmdAction(args ...ice.Any) ice.Actions { } }}, ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { - if len(arg) > 3 && arg[1] == ACTION && arg[2] == CONFIG && arg[3] == "reset" { - m.Cmd(CONFIG, "reset", arg[0]) - return - } - if len(arg) > 3 && arg[1] == ACTION && arg[2] == CONFIG && arg[3] == "select" { - m.Cmdy(CONFIG, arg[0]) + if len(arg) > 3 && arg[1] == ACTION && arg[2] == CONFIG { + switch arg[3] { + case "select": + m.Cmdy(CONFIG, arg[0]) + case "reset": + m.Cmd(CONFIG, "reset", arg[0]) + case "help": + if file := strings.ReplaceAll(GetCmdFile(m, arg[0]), ".go", ".shy"); nfs.ExistsFile(m, file) { + m.ProcessStory("web.wiki.word", file) + } + case "script": + if file := strings.ReplaceAll(GetCmdFile(m, arg[0]), ".go", ".js"); nfs.ExistsFile(m, file) { + m.ProcessStory("web.code.inner", file) + } + case "source": + if file := GetCmdFile(m, arg[0]); nfs.ExistsFile(m, file) { + m.ProcessStory("web.code.inner", file) + } + } return } if !PodCmd(m, arg) && aaa.Right(m, arg) { @@ -173,6 +186,14 @@ func AddFileCmd(dir, key string) { ice.Info.File[FileCmd(dir)] = key } func GetFileCmd(dir string) string { + if strings.HasPrefix(dir, "usr/") { + p := ice.Pulse.Cmdx("cli.system", "git", "config", "remote.origin.url", kit.Dict("cmd_dir", path.Dir(dir))) + p = strings.Replace(strings.TrimSpace(p), "https://", "/require/", 1) + dir = path.Join(p, strings.Join(strings.Split(dir, "/")[2:], "/")) + } + if strings.HasPrefix(dir, ".ish/pluged/") { + dir = strings.Replace(dir, ".ish/pluged/", "/require/", 1) + } if strings.HasPrefix(dir, "require/") { dir = "/" + dir } @@ -192,3 +213,17 @@ func GetFileCmd(dir string) string { } return "" } +func GetCmdFile(m *ice.Message, cmds string) (file string) { + m.Search(cmds, func(key string, cmd *ice.Command) { + if cmd.RawHand == nil { + file = kit.Split(kit.FileLine(cmd.Hand, 100), ":")[0] + } else { + for k, v := range ice.Info.File { + if v == cmds { + file = strings.Replace(k, "/require/", ".ish/pluged/", 1) + } + } + } + }) + return +} diff --git a/base/gdb/gdb.go b/base/gdb/gdb.go index 7a4fa4b5..5b0d1f3b 100644 --- a/base/gdb/gdb.go +++ b/base/gdb/gdb.go @@ -56,6 +56,7 @@ func (f *Frame) Close(m *ice.Message, arg ...string) bool { return true } +const DEBUG = "debug" const GDB = "gdb" var Index = &ice.Context{Name: GDB, Help: "事件模块", Commands: ice.Commands{ diff --git a/base/mdb/list.go b/base/mdb/list.go index c820645c..62bb54e5 100644 --- a/base/mdb/list.go +++ b/base/mdb/list.go @@ -31,7 +31,11 @@ func _list_insert(m *ice.Message, prefix, chain string, arg ...string) { defer Lock(m, prefix, chain)() m.Logs(INSERT, KEY, path.Join(prefix, chain), arg[0], arg[1]) - m.Echo("%d", Grow(m, prefix, chain, kit.Dict(arg))) + if m.Optionv(TARGET) != nil && m.Option(TARGET) != "" { + m.Echo("%d", Grow(m, prefix, chain, kit.Dict(arg, TARGET, m.Optionv(TARGET)))) + } else { + m.Echo("%d", Grow(m, prefix, chain, kit.Dict(arg))) + } } func _list_modify(m *ice.Message, prefix, chain string, field, value string, arg ...string) { defer Lock(m, prefix, chain)() @@ -262,7 +266,6 @@ func Grows(m *ice.Message, prefix string, chain Any, match string, value string, m.Option(CACHE_OFFEND, -begin-limit) } } - return miss.Grows(path.Join(prefix, kit.Keys(chain)), cache, kit.Int(kit.Select("0", strings.TrimPrefix(m.Option(CACHE_OFFEND), "-"))), kit.Int(kit.Select("10", m.Option(CACHE_LIMIT))), diff --git a/core/code/c.go b/core/code/c.go index d12f4b2a..7c9ed8e4 100644 --- a/core/code/c.go +++ b/core/code/c.go @@ -56,16 +56,18 @@ func init() { m.Cmd(cmd, mdb.CREATE, k, m.PrefixKey()) } } - LoadPlug(m, C) + LoadPlug(m, H, C) }}, mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { - m.Option(cli.CMD_DIR, arg[2]) name := strings.TrimSuffix(arg[1], path.Ext(arg[1])) + ".bin" - if msg := m.Cmd(cli.SYSTEM, "gcc", arg[1], "-o", name); !cli.IsSuccess(msg) { + if msg := m.Cmd(cli.SYSTEM, "gcc", arg[1], "-o", name, kit.Dict(cli.CMD_DIR, arg[2])); !cli.IsSuccess(msg) { m.Copy(msg) return } - m.Echo(m.Cmd(cli.SYSTEM, nfs.PWD+name).Append(cli.CMD_OUT)) + m.Echo(m.Cmd(cli.SYSTEM, path.Join(arg[2], name)).Append(cli.CMD_OUT)) + }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { + TagsList(m, "ctags", "--excmd=number", "--sort=no", "-f", "-", path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE))) }}, mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { if arg[0] == mdb.FOREACH { @@ -104,6 +106,7 @@ func init() { }, PlugAction())}, }, Configs: ice.Configs{ C: {Name: C, Help: "系统", Value: kit.Data(PLUG, kit.Dict( + mdb.RENDER, kit.Dict(), SPLIT, kit.Dict("space", " ", "operator", "{[(.,:;!|<>)]}"), PREFIX, kit.Dict("//", COMMENT, "/* ", COMMENT, "* ", COMMENT), PREPARE, kit.Dict( KEYWORD, kit.Simple( @@ -169,3 +172,21 @@ func init() { ))}, }}, nil) } + +func TagsList(m *ice.Message, cmds ...string) { + for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, cmds), ice.NL) { + if strings.HasPrefix(l, "!_") { + continue + } + ls := strings.Split(l, ice.TB) + if len(ls) < 2 { + continue + } + switch ls[3] { + case "w": + continue + } + m.PushRecord(kit.Dict(mdb.TYPE, ls[3], mdb.NAME, ls[0], nfs.LINE, strings.TrimSuffix(ls[2], ";\""))) + } + m.Sort(nfs.LINE).StatusTimeCount() +} diff --git a/core/code/go.go b/core/code/go.go index 624c1bf1..940afe35 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -162,8 +162,10 @@ func _go_show(m *ice.Message, arg ...string) { } else { if key := ctx.GetFileCmd(path.Join(arg[2], arg[1])); key != "" { ctx.ProcessCommand(m, key, kit.Simple()) + } else if p := strings.ReplaceAll(path.Join(arg[2], arg[1]), ".go", ".shy"); nfs.ExistsFile(m, p) { + ctx.ProcessCommand(m, "web.wiki.word", kit.Simple(p)) } else { - ctx.ProcessCommand(m, "web.wiki.word", kit.Simple(strings.ReplaceAll(path.Join(arg[2], arg[1]), ".go", ".shy"))) + TagsList(m, "gotags", path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE))) } } } @@ -279,6 +281,7 @@ func init() { ), KEYWORD, kit.Dict(), ))}, GO: {Name: GO, Help: "后端", Value: kit.Data(PLUG, kit.Dict( + mdb.RENDER, kit.Dict(), SPLIT, kit.Dict("space", "\t ", "operator", "{[(&.,:;!|<>)]}"), PREFIX, kit.Dict("// ", COMMENT, "/*", COMMENT, "* ", COMMENT), PREPARE, kit.Dict( KEYWORD, kit.Simple( diff --git a/core/code/inner.go b/core/code/inner.go index 5976e38a..693d70ff 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -1,6 +1,7 @@ package code import ( + "bufio" "path" "strings" @@ -58,6 +59,32 @@ func _inner_make(m *ice.Message, msg *ice.Message) { } m.StatusTime() } +func _inner_tags(m *ice.Message, path string, value string) { + for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, "grep", "^"+value+"\\>", "tags", kit.Dict(cli.CMD_DIR, m.Option(nfs.PATH))), ice.NL) { + ls := strings.SplitN(l, ice.TB, 2) + if len(ls) < 2 { + continue + } + + ls = strings.SplitN(ls[1], ice.TB, 2) + file := ls[0] + ls = strings.SplitN(ls[1], ";\"", 2) + text := strings.TrimSuffix(strings.TrimPrefix(ls[0], "/^"), "$/") + line := kit.Int(text) + + f, e := nfs.OpenFile(m, kit.Path(path, file)) + m.Assert(e) + defer f.Close() + + bio := bufio.NewScanner(f) + for i := 1; bio.Scan(); i++ { + if i == line || bio.Text() == text { + m.PushRecord(kit.Dict(nfs.PATH, path, nfs.FILE, strings.TrimPrefix(file, nfs.PWD), nfs.LINE, kit.Format(i))) + return + } + } + } +} func LoadPlug(m *ice.Message, language ...string) { for _, language := range language { @@ -164,7 +191,9 @@ func init() { } }}, - nfs.TAGS: {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) {}}, + nfs.TAGS: {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) { + _inner_tags(m, m.Option(nfs.PATH), arg[0]) + }}, nfs.GREP: {Name: "grep", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.GREP, m.Option(nfs.PATH), arg[0]) m.StatusTimeCount(mdb.INDEX, 0) diff --git a/core/code/install.go b/core/code/install.go index dfac0088..47327342 100644 --- a/core/code/install.go +++ b/core/code/install.go @@ -8,6 +8,7 @@ import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/cli" + "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/gdb" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" @@ -203,6 +204,17 @@ func init() { cli.STOP: {Name: "stop", Help: "停止", Hand: func(m *ice.Message, arg ...string) { _install_stop(m, arg...) }}, + gdb.DEBUG: {Name: "debug", Help: "调试", Hand: func(m *ice.Message, arg ...string) { + if cmd := "web.code.xterm"; len(arg) > 0 && arg[0] == ice.RUN { + if len(arg) > 2 && arg[1] == ctx.ACTION && arg[2] == mdb.CREATE { + arg = append(arg, mdb.TYPE, "gdb") + } + m.Cmdy(cmd, arg[1:]) + } else { + m.Cmdy(ctx.COMMAND, cmd) + m.ProcessField(m.ActionKey(), ice.RUN) + } + }}, nfs.TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) { _install_trash(m, arg...) }}, diff --git a/core/code/xterm.go b/core/code/xterm.go index d830e807..f2a46c62 100644 --- a/core/code/xterm.go +++ b/core/code/xterm.go @@ -118,3 +118,14 @@ func init() { }}, }) } + +func ProcessXterm(m *ice.Message, bin string, arg ...string) { + if cmd := "web.code.xterm"; len(arg) > 0 && arg[0] == ice.RUN { + if len(arg) > 2 && arg[1] == ctx.ACTION && arg[2] == mdb.CREATE { + arg = append(arg, mdb.TYPE, bin) + } + m.Cmdy(cmd, arg[1:]) + } else { + m.Cmdy(ctx.COMMAND, cmd).ProcessField(m.ActionKey(), ice.RUN) + } +} diff --git a/misc/git/count.go b/misc/git/count.go index e05e8d1c..659693ad 100644 --- a/misc/git/count.go +++ b/misc/git/count.go @@ -34,6 +34,9 @@ func init() { if strings.Contains(file, "var/") { return } + if strings.Contains(file, "tags") { + return + } switch kit.Ext(file) { case "sum", "log": return diff --git a/misc/git/server.go b/misc/git/server.go index 9f97c911..b8ee87d9 100644 --- a/misc/git/server.go +++ b/misc/git/server.go @@ -23,7 +23,10 @@ import ( func _server_rewrite(m *ice.Message, p string, r *http.Request) { if ua := r.Header.Get(web.UserAgent); strings.HasPrefix(ua, "Mozilla") { - r.URL.Path = strings.Replace(r.URL.Path, "/x/", "/chat/pod/", 1) + ls := kit.Split(r.URL.Path, "/") + r.URL = kit.ParseURL(kit.MergeURL("/chat/cmd/web.code.inner", "path", "usr/"+ls[1]+"/", "file", path.Join(ls[2:]...))) + + // r.URL.Path = strings.Replace(r.URL.Path, "/x/", "/chat/pod/", 1) m.Info("rewrite %v -> %v", p, r.URL.Path) // 访问服务 } else { diff --git a/misc/node/compile.shy b/misc/node/compile.shy index c5f90c19..b54b924c 100644 --- a/misc/node/compile.shy +++ b/misc/node/compile.shy @@ -9,4 +9,4 @@ field web.code.node.compile shell ` wget https://mirrors.tencent.com/nodejs-release/v16.15.1/node-v16.15.1-linux-x64.tar.xz tar xvf node-v16.15.1-linux-x64.tar.xz && cd node-v16.15.1-linux-x64 -` +`Á diff --git a/type.go b/type.go index e1ec95dd..7cf2705c 100644 --- a/type.go +++ b/type.go @@ -46,6 +46,7 @@ type Command struct { Help string Actions Actions Hand Handler + RawHand Any List List Meta Map }