diff --git a/base/ctx/command.go b/base/ctx/command.go index 3d8cfb79..e2cb8d9b 100644 --- a/base/ctx/command.go +++ b/base/ctx/command.go @@ -9,6 +9,10 @@ import ( ) func _command_list(m *ice.Message, name string) { + if strings.HasPrefix(name, "can.") { + m.Push(mdb.INDEX, name) + return + } if name == "" { // 命令列表 for k, v := range m.Source().Commands { if k[0] == '/' || k[0] == '_' { diff --git a/base/mdb/engine.go b/base/mdb/engine.go index d5f8d62b..4216650e 100644 --- a/base/mdb/engine.go +++ b/base/mdb/engine.go @@ -17,10 +17,10 @@ func init() { }}, }, HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 1 { - m.OptionCB(SELECT, func(fields []string, value map[string]interface{}) { - m.Cmdy(kit.Keys(value[TEXT], value[NAME]), - m.CommandKey(), arg[0], arg[1], kit.Select("", arg, 2), kit.Slice(arg, 3)) + m.Cmdy(SELECT, m.PrefixKey(), "", HASH, m.Config(SHORT), arg, func(value map[string]interface{}) { + m.Cmdy(kit.Keys(value[TEXT], value[NAME]), m.CommandKey(), arg[0], arg[1], kit.Select("", arg, 2), kit.Slice(arg, 3)) }) + return } if HashSelect(m, arg...); len(arg) == 0 { m.Sort(TYPE) diff --git a/base/mdb/hash.go b/base/mdb/hash.go index e462a723..9c112867 100644 --- a/base/mdb/hash.go +++ b/base/mdb/hash.go @@ -64,6 +64,8 @@ func _hash_select(m *ice.Message, prefix, chain, field, value string) { switch val = kit.GetMeta(val); cb := m.OptionCB(SELECT).(type) { case func(fields []string, value map[string]interface{}): cb(fields, val) + case func(value map[string]interface{}): + cb(val) default: if m.OptionFields() == DETAIL { m.Push(DETAIL, val) diff --git a/base/mdb/plugin.go b/base/mdb/plugin.go index f3f6056b..4bf81961 100644 --- a/base/mdb/plugin.go +++ b/base/mdb/plugin.go @@ -9,7 +9,7 @@ const PLUGIN = "plugin" func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ - PLUGIN: {Name: "plugin", Help: "插件", Value: kit.Data(SHORT, TYPE, FIELD, "time,type,name,text")}, + PLUGIN: {Name: PLUGIN, Help: "插件", Value: kit.Data(SHORT, TYPE, FIELD, "time,type,name,text")}, }, Commands: map[string]*ice.Command{ PLUGIN: {Name: "plugin type name text auto", Help: "插件", Action: map[string]*ice.Action{ CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) { @@ -17,10 +17,10 @@ func init() { }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 1 { - m.OptionCB(SELECT, func(fields []string, value map[string]interface{}) { - m.Cmdy(kit.Keys(value[TEXT], value[NAME]), - m.CommandKey(), arg[0], arg[1], kit.Select("", arg, 2), kit.Slice(arg, 3)) + m.Cmdy(SELECT, m.PrefixKey(), "", HASH, m.Config(SHORT), arg, func(value map[string]interface{}) { + m.Cmdy(kit.Keys(value[TEXT], value[NAME]), m.CommandKey(), arg[0], arg[1], kit.Select("", arg, 2), kit.Slice(arg, 3)) }) + return } if HashSelect(m, arg...); len(arg) == 0 { m.Sort(TYPE) diff --git a/base/mdb/render.go b/base/mdb/render.go index 7e66ffbf..bc0b66fa 100644 --- a/base/mdb/render.go +++ b/base/mdb/render.go @@ -9,7 +9,7 @@ const RENDER = "render" func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ - RENDER: {Name: "render", Help: "渲染", Value: kit.Data(SHORT, TYPE, FIELD, "time,type,name,text")}, + RENDER: {Name: RENDER, Help: "渲染", Value: kit.Data(SHORT, TYPE, FIELD, "time,type,name,text")}, }, Commands: map[string]*ice.Command{ RENDER: {Name: "render type name text auto", Help: "渲染", Action: map[string]*ice.Action{ CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) { @@ -17,10 +17,10 @@ func init() { }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 1 { - m.OptionCB(SELECT, func(fields []string, value map[string]interface{}) { - m.Cmdy(kit.Keys(value[TEXT], value[NAME]), - m.CommandKey(), arg[0], arg[1], kit.Select("", arg, 2), kit.Slice(arg, 3)) + m.Cmdy(SELECT, m.PrefixKey(), "", HASH, m.Config(SHORT), arg, func(value map[string]interface{}) { + m.Cmdy(kit.Keys(value[TEXT], value[NAME]), m.CommandKey(), arg[0], arg[1], kit.Select("", arg, 2), kit.Slice(arg, 3)) }) + return } if HashSelect(m, arg...); len(arg) == 0 { m.Sort(TYPE) diff --git a/base/mdb/search.go b/base/mdb/search.go index 82157519..72389a29 100644 --- a/base/mdb/search.go +++ b/base/mdb/search.go @@ -9,26 +9,23 @@ const SEARCH = "search" func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ - SEARCH: {Name: "search", Help: "搜索", Value: kit.Data(SHORT, TYPE, FIELD, "time,type,name,text")}, + SEARCH: {Name: SEARCH, Help: "搜索", Value: kit.Data(SHORT, TYPE, FIELD, "time,type,name,text")}, }, Commands: map[string]*ice.Command{ - SEARCH: {Name: "search type word text auto", Help: "搜索", Action: map[string]*ice.Action{ + SEARCH: {Name: "search type name text auto", Help: "搜索", Action: map[string]*ice.Action{ CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(INSERT, m.PrefixKey(), "", HASH, m.OptionSimple("type,name,text")) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - msg := m.Spawn(c) if len(arg) > 1 { - msg.OptionCB(SELECT, func(fields []string, value map[string]interface{}) { + m.Cmdy(SELECT, m.PrefixKey(), "", HASH, m.Config(SHORT), arg, func(value map[string]interface{}) { m.OptionFields(kit.Select("ctx,cmd,type,name,text", kit.Select(m.OptionFields()))) - m.Cmdy(kit.Keys(value[TEXT], value[NAME]), m.CommandKey(), arg[0], arg[1], kit.Select("", arg, 2)) + m.Cmdy(kit.Keys(value[TEXT], value[NAME]), m.CommandKey(), arg[0], arg[1], kit.Select("", arg, 2), kit.Slice(arg, 3)) }) + return } - if HashSelect(msg, arg...); len(arg) == 0 { - m.Copy(msg).Sort(TYPE) - } else if len(arg) == 1 { - m.Copy(msg) + if HashSelect(m, arg...); len(arg) == 0 { + m.Sort(TYPE) } - m.StatusTimeCount() }}, }}) } diff --git a/base/nfs/cat.go b/base/nfs/cat.go index ba2e43d1..4e3216ad 100644 --- a/base/nfs/cat.go +++ b/base/nfs/cat.go @@ -151,6 +151,7 @@ func init() { HTML, ice.TRUE, CSS, ice.TRUE, JS, ice.TRUE, GO, ice.TRUE, SH, ice.TRUE, CSV, ice.TRUE, JSON, ice.TRUE, "md", ice.TRUE, "shy", ice.TRUE, "makefile", ice.TRUE, "license", ice.TRUE, "conf", ice.TRUE, "yaml", ice.TRUE, "yml", ice.TRUE, + "py", ice.TRUE, ), )}, }, Commands: map[string]*ice.Command{ diff --git a/core/code/autogen.go b/core/code/autogen.go index d0541b11..b92a47ca 100644 --- a/core/code/autogen.go +++ b/core/code/autogen.go @@ -178,6 +178,8 @@ func init() { _autogen_script(m, p) _autogen_source(m, m.Option(mdb.ZONE), m.Option(mdb.NAME)) } + m.Option(nfs.FILE, path.Join(m.Option(mdb.ZONE), kit.Keys(m.Option(mdb.NAME), GO))) + m.Debug("what %v", m.FormatMeta()) }}, ssh.SCRIPT: {Name: "script", Help: "脚本:生成 etc/miss.sh", Hand: func(m *ice.Message, arg ...string) { _autogen_miss(m) diff --git a/core/code/c.go b/core/code/c.go index b92ca8a2..a7e9917e 100644 --- a/core/code/c.go +++ b/core/code/c.go @@ -51,29 +51,19 @@ const C = "c" func init() { Index.Register(&ice.Context{Name: C, Help: "系统", Commands: map[string]*ice.Command{ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - for _, cmd := range []string{mdb.PLUGIN, mdb.RENDER, mdb.ENGINE, mdb.SEARCH} { + for _, cmd := range []string{mdb.SEARCH, mdb.ENGINE, mdb.RENDER, mdb.PLUGIN} { for _, k := range []string{H, C, CC} { m.Cmd(cmd, mdb.CREATE, k, m.Prefix(C)) } } - for _, cmd := range []string{mdb.PLUGIN, mdb.RENDER, mdb.SEARCH} { + for _, cmd := range []string{mdb.SEARCH, mdb.RENDER, mdb.PLUGIN} { for _, k := range []string{MAN1, MAN2, MAN3, MAN8} { m.Cmd(cmd, mdb.CREATE, k, m.Prefix(MAN)) } } - LoadPlug(m, C) - LoadPlug(m, MAN) + LoadPlug(m, C, MAN) }}, C: {Name: C, Help: "系统", Action: ice.MergeAction(map[string]*ice.Action{ - 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) { - m.Copy(msg) - return - } - m.Cmdy(cli.SYSTEM, ice.PWD+name) - }}, mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { if arg[0] == mdb.FOREACH { return @@ -85,11 +75,17 @@ func init() { _go_find(m, kit.Select(MAIN, arg, 1), arg[2]) _go_grep(m, kit.Select(MAIN, arg, 1), arg[2]) }}, + 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) { + m.Copy(msg) + return + } + m.Echo(m.Cmd(cli.SYSTEM, ice.PWD+name).Append(cli.CMD_OUT)) + }}, }, PlugAction())}, MAN: {Name: MAN, Help: "手册", Action: ice.MergeAction(map[string]*ice.Action{ - mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { - m.Echo(_c_help(m, strings.TrimPrefix(arg[0], MAN), strings.TrimSuffix(arg[1], ice.PT+arg[0]))) - }}, mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { if arg[0] == mdb.FOREACH { return @@ -100,12 +96,14 @@ func init() { } } }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { + m.Echo(_c_help(m, strings.TrimPrefix(arg[0], MAN), strings.TrimSuffix(arg[1], ice.PT+arg[0]))) + }}, }, PlugAction())}, }, Configs: map[string]*ice.Config{ C: {Name: C, Help: "系统", Value: kit.Data(PLUG, kit.Dict( SPLIT, kit.Dict("space", " ", "operator", "{[(.,:;!|<>)]}"), - PREFIX, kit.Dict("//", COMMENT, "/*", COMMENT, "*", COMMENT), - PREPARE, kit.Dict( + PREFIX, kit.Dict("//", COMMENT, "/*", COMMENT, "*", COMMENT), PREPARE, kit.Dict( KEYWORD, kit.Simple( "#include", "#define", diff --git a/core/code/compile.go b/core/code/compile.go index a2acc090..9c612b6a 100644 --- a/core/code/compile.go +++ b/core/code/compile.go @@ -61,7 +61,8 @@ func init() { // 执行编译 _autogen_version(m.Spawn()) m.Optionv(cli.CMD_ENV, kit.Simple(m.Configv(cli.ENV), cli.GOOS, goos, cli.GOARCH, arch)) - if msg := m.Cmd(cli.SYSTEM, m.Configv(GO), "-o", file, main, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO); !cli.IsSuccess(msg) { + // if msg := m.Cmd(cli.SYSTEM, m.Configv(GO), "-o", file, main, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO); !cli.IsSuccess(msg) { + if msg := m.Cmd(cli.SYSTEM, m.Configv(GO), "-v", "-o", file, main, ice.SRC_VERSION_GO); !cli.IsSuccess(msg) { m.Copy(msg) return } diff --git a/core/code/go.go b/core/code/go.go index 231731d6..f32af265 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -61,6 +61,72 @@ func _go_grep(m *ice.Message, key string, dir string) { m.PushSearch(value) }) } +func _go_exec(m *ice.Message, arg ...string) { + if key, ok := ice.Info.File[path.Join(arg[2], arg[1])]; ok && key != "" { + m.Cmdy(cli.SYSTEM, GO, ice.RUN, ice.SRC_MAIN_GO, key) + } else if m.Option(cli.CMD_DIR, arg[2]); strings.HasSuffix(arg[1], "_test.go") { + m.Cmdy(cli.SYSTEM, GO, "test", "-v", ice.PWD+arg[1]) + } else { + m.Cmdy(cli.SYSTEM, GO, ice.RUN, ice.PWD+arg[1]) + } + m.SetAppend() +} +func _go_show(m *ice.Message, arg ...string) { + if key, ok := ice.Info.File[path.Join(arg[2], arg[1])]; ok && key != "" { + m.ProcessCommand(key, kit.Simple()) + } else { + m.ProcessCommand("web.wiki.word", kit.Simple(strings.ReplaceAll(path.Join(arg[2], arg[1]), ".go", ".shy"))) + } +} +func _mod_show(m *ice.Message, file string) { + const ( + MODULE = "module" + REQUIRE = "require" + REPLACE = "replace" + VERSION = "version" + ) + + block := "" + require := map[string]string{} + replace := map[string]string{} + m.Cmd(nfs.CAT, file, func(line string) { + ls := kit.Split(line) + switch { + case strings.HasPrefix(line, MODULE): + require[ls[1]] = "" + replace[ls[1]] = ice.PWD + return + case strings.HasPrefix(line, REQUIRE+" ("): + block = REQUIRE + return + case strings.HasPrefix(line, REPLACE+" ("): + block = REPLACE + return + case strings.HasPrefix(line, ")"): + block = "" + return + case strings.HasPrefix(line, REQUIRE): + require[ls[1]] = ls[2] + case strings.HasPrefix(line, REPLACE): + replace[ls[1]] = ls[3] + } + if block == "" || len(ls) < 2 { + return + } + switch block { + case REQUIRE: + require[ls[0]] = ls[1] + case REPLACE: + replace[ls[0]] = ls[2] + } + }) + for k, v := range require { + m.Push(REQUIRE, k) + m.Push(VERSION, v) + m.Push(REPLACE, kit.Select("", replace[k])) + } + m.Sort(REPLACE) +} const ( TAGS = ".tags" @@ -81,36 +147,31 @@ func init() { LoadPlug(m, GO, MOD, SUM, PROTO) for _, k := range []string{GO, MOD, SUM, PROTO, GODOC} { - m.Cmd(mdb.PLUGIN, mdb.CREATE, k, m.Prefix(k)) m.Cmd(mdb.RENDER, mdb.CREATE, k, m.Prefix(k)) + m.Cmd(mdb.PLUGIN, mdb.CREATE, k, m.Prefix(k)) } }}, - GODOC: {Name: GODOC, Help: "文档", Action: ice.MergeAction(map[string]*ice.Action{ + GODOC: {Name: "godoc", Help: "文档", Action: ice.MergeAction(map[string]*ice.Action{ mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { - m.Option(cli.CMD_DIR, arg[2]) - m.Echo(m.Cmdx(cli.SYSTEM, GO, "doc", strings.TrimSuffix(arg[1], ice.PT+arg[0]))) + m.Cmdy(cli.SYSTEM, GO, "doc", strings.TrimSuffix(arg[1], ice.PT+arg[0]), kit.Dict(cli.CMD_DIR, arg[2])).SetAppend() }}, }, PlugAction())}, - PROTO: {Name: PROTO, Help: "协议", Action: PlugAction()}, - SUM: {Name: SUM, Help: "版本", Action: PlugAction()}, - MOD: {Name: MOD, Help: "模块", Action: PlugAction()}, - GO: {Name: GO, Help: "后端", Action: ice.MergeAction(map[string]*ice.Action{ + PROTO: {Name: "proto", Help: "协议", Action: PlugAction()}, + SUM: {Name: "sum", Help: "版本", Action: PlugAction()}, + MOD: {Name: "mod", Help: "模块", Action: ice.MergeAction(map[string]*ice.Action{ + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _mod_show(m, path.Join(arg[2], arg[1])) }}, + }, PlugAction())}, + GO: {Name: "go", Help: "后端", Action: ice.MergeAction(map[string]*ice.Action{ mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { - if arg[0] == mdb.FOREACH { - return - } - _go_tags(m, kit.Select(MAIN, arg, 1)) - _go_help(m, kit.Select(MAIN, arg, 1)) - // _go_find(m, kit.Select(MAIN, arg, 1), arg[2]) - // _go_grep(m, kit.Select(MAIN, arg, 1), arg[2]) - }}, - mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { - if m.Option(cli.CMD_DIR, arg[2]); strings.HasSuffix(arg[1], "_test.go") { - m.Cmdy(cli.SYSTEM, GO, "test", "-v", ice.PWD+arg[1]) - } else { - m.Cmdy(cli.SYSTEM, GO, "run", ice.PWD+arg[1]) + if arg[0] == GO { + _go_tags(m, kit.Select(MAIN, arg, 1)) + _go_help(m, kit.Select(MAIN, arg, 1)) + // _go_find(m, kit.Select(MAIN, arg, 1), arg[2]) + // _go_grep(m, kit.Select(MAIN, arg, 1), arg[2]) } }}, + mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _go_exec(m, arg...) }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _go_show(m, arg...) }}, }, PlugAction())}, }, Configs: map[string]*ice.Config{ PROTO: {Name: PROTO, Help: "协议", Value: kit.Data(PLUG, kit.Dict( diff --git a/core/code/inner.go b/core/code/inner.go index 69e57c3b..6892dd8e 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -42,6 +42,22 @@ func _inner_show(m *ice.Message, ext, file, dir string, arg ...string) { return // 解析成功 } } +func _inner_make(m *ice.Message, msg *ice.Message) { + for _, line := range strings.Split(msg.Append(cli.CMD_ERR), ice.NL) { + if strings.Contains(line, ice.DF) { + if ls := strings.SplitN(line, ice.DF, 4); len(ls) > 3 { + m.Push(nfs.FILE, strings.TrimPrefix(ls[0], m.Option(nfs.PATH))) + m.Push(nfs.LINE, ls[1]) + m.Push(mdb.TEXT, ls[3]) + } + } + } + if m.Length() == 0 { + m.Echo(msg.Append(cli.CMD_OUT)) + m.Echo(msg.Append(cli.CMD_ERR)) + } + m.StatusTime() +} func LoadPlug(m *ice.Message, language ...string) { for _, language := range language { @@ -56,9 +72,9 @@ func LoadPlug(m *ice.Message, language ...string) { func PlugAction(fields ...string) map[string]*ice.Action { return ice.SelectAction(map[string]*ice.Action{ - mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { m.Echo(m.Config(PLUG)) }}, - mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }}, mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }}, + mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { m.Echo(m.Config(PLUG)) }}, }, fields...) } @@ -118,21 +134,7 @@ func init() { m.StatusTimeCount(mdb.INDEX, 0) }}, cli.MAKE: {Name: "make", Help: "构建", Hand: func(m *ice.Message, arg ...string) { - msg := m.Cmd(cli.SYSTEM, cli.MAKE, arg) - for _, line := range strings.Split(msg.Append(cli.CMD_ERR), ice.NL) { - if strings.Contains(line, ice.DF) { - if ls := strings.SplitN(line, ice.DF, 4); len(ls) > 3 { - m.Push(nfs.FILE, strings.TrimPrefix(ls[0], m.Option(nfs.PATH))) - m.Push(nfs.LINE, ls[1]) - m.Push(mdb.TEXT, ls[3]) - } - } - } - if m.Length() == 0 { - m.Echo(msg.Append(cli.CMD_OUT)) - m.Echo(msg.Append(cli.CMD_ERR)) - } - m.StatusTime() + _inner_make(m, m.Cmd(cli.SYSTEM, cli.MAKE, arg)) }}, mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { switch arg[0] { diff --git a/core/code/js.go b/core/code/js.go index 6006f9f0..a59f1161 100644 --- a/core/code/js.go +++ b/core/code/js.go @@ -1,6 +1,8 @@ package code import ( + "path" + ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/mdb" @@ -20,7 +22,7 @@ const VUE = "vue" func init() { Index.Register(&ice.Context{Name: JS, Help: "前端", Commands: map[string]*ice.Command{ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - for _, cmd := range []string{mdb.PLUGIN, mdb.RENDER, mdb.ENGINE, mdb.SEARCH} { + for _, cmd := range []string{mdb.SEARCH, mdb.ENGINE, mdb.RENDER, mdb.PLUGIN} { m.Cmd(cmd, mdb.CREATE, JSON, m.Prefix(JS)) m.Cmd(cmd, mdb.CREATE, VUE, m.Prefix(JS)) m.Cmd(cmd, mdb.CREATE, JS, m.Prefix(JS)) @@ -28,12 +30,7 @@ func init() { } LoadPlug(m, JS) }}, - JS: {Name: JS, Help: "前端", Action: ice.MergeAction(map[string]*ice.Action{ - mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { - m.Option(cli.CMD_DIR, arg[2]) - m.Cmdy(cli.SYSTEM, NODE, arg[1]) - m.Set(ice.MSG_APPEND) - }}, + JS: {Name: "js", Help: "前端", Action: ice.MergeAction(map[string]*ice.Action{ mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { if arg[0] == mdb.FOREACH { return @@ -41,6 +38,19 @@ func init() { _go_find(m, kit.Select(MAIN, arg, 1), arg[2]) _go_grep(m, kit.Select(MAIN, arg, 1), arg[2]) }}, + mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(cli.SYSTEM, NODE, arg[1], kit.Dict(cli.CMD_DIR, arg[2])).SetAppend() + }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { + if key, ok := ice.Info.File[kit.Replace(path.Join(arg[2], arg[1]), ".js", ".go")]; ok && key != "" { + m.Display(path.Join(web.SHARE_LOCAL, path.Join(arg[2], arg[1]))) + m.ProcessCommand(key, kit.Simple()) + } else { + m.Display(path.Join(web.SHARE_LOCAL, path.Join(arg[2], arg[1]))) + m.ProcessCommand("can.code.inner.plugin", kit.Simple()) + // m.ProcessCommand("web.wiki.word", kit.Simple(strings.ReplaceAll(path.Join(arg[2], arg[1]), ".go", ".shy"))) + } + }}, }, PlugAction())}, NODE: {Name: "node auto download", Help: "前端", Action: map[string]*ice.Action{ web.DOWNLOAD: {Name: "download", Help: "下载", Hand: func(m *ice.Message, arg ...string) { @@ -53,40 +63,16 @@ func init() { )}, JS: {Name: JS, Help: "js", Value: kit.Data(PLUG, kit.Dict( SPLIT, kit.Dict("space", " \t", "operator", "{[(&.,;!|<>)]}"), - PREFIX, kit.Dict("//", COMMENT, "/*", COMMENT, "*", COMMENT), - PREPARE, kit.Dict( + PREFIX, kit.Dict("//", COMMENT, "/*", COMMENT, "*", COMMENT), PREPARE, kit.Dict( KEYWORD, kit.Simple( - "import", - "from", - "export", + "import", "from", "export", - "var", - "new", - "delete", - "typeof", - "const", - "function", + "var", "new", "delete", "typeof", "const", "function", - "if", - "else", - "for", - "while", - "break", - "continue", - "switch", - "case", - "default", - "return", - "try", - "throw", - "catch", - "finally", + "if", "else", "for", "while", "break", "continue", "switch", "case", "default", + "return", "try", "throw", "catch", "finally", - "can", - "sub", - "msg", - "res", - "target", + "can", "sub", "msg", "res", "target", ), FUNCTION, kit.Simple( "window", diff --git a/core/code/python.go b/core/code/python.go index 7c9d2131..a7f60f54 100644 --- a/core/code/python.go +++ b/core/code/python.go @@ -3,6 +3,7 @@ package code import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/cli" + "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" kit "shylinux.com/x/toolkits" ) @@ -16,6 +17,9 @@ func init() { PYTHON, "python", "pip", "pip", )}, }, Commands: map[string]*ice.Command{ + ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Cmd(mdb.ENGINE, mdb.CREATE, mdb.TYPE, "py", mdb.NAME, m.Prefix(PYTHON)) + }}, PYTHON: {Name: "python path auto order build download", Help: "脚本命令", Action: ice.MergeAction(map[string]*ice.Action{ ice.RUN: {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(cli.SYSTEM, m.Config(PYTHON), arg) diff --git a/core/code/sh.go b/core/code/sh.go index 97cc6a62..6cbb9785 100644 --- a/core/code/sh.go +++ b/core/code/sh.go @@ -12,17 +12,12 @@ const SH = "sh" func init() { Index.Register(&ice.Context{Name: SH, Help: "命令", Commands: map[string]*ice.Command{ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - for _, cmd := range []string{mdb.PLUGIN, mdb.RENDER, mdb.ENGINE, mdb.SEARCH} { + for _, cmd := range []string{mdb.SEARCH, mdb.ENGINE, mdb.RENDER, mdb.PLUGIN} { m.Cmd(cmd, mdb.CREATE, SH, m.Prefix(SH)) } LoadPlug(m, SH) }}, SH: {Name: SH, Help: "命令", Action: ice.MergeAction(map[string]*ice.Action{ - mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { - m.Option(cli.CMD_DIR, arg[2]) - m.Cmdy(cli.SYSTEM, SH, arg[1]) - m.Set(ice.MSG_APPEND) - }}, mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { if arg[0] == mdb.FOREACH { return @@ -33,6 +28,9 @@ func init() { _go_find(m, kit.Select(MAIN, arg, 1), arg[2]) _go_grep(m, kit.Select(MAIN, arg, 1), arg[2]) }}, + mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(cli.SYSTEM, SH, arg[1], kit.Dict(cli.CMD_DIR, arg[2])).SetAppend() + }}, MAN: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_c_help(m, arg[0], arg[1])) }}, diff --git a/core/code/shy.go b/core/code/shy.go index c82e21a1..d6bc698d 100644 --- a/core/code/shy.go +++ b/core/code/shy.go @@ -14,7 +14,7 @@ const SHY = "shy" func init() { Index.Register(&ice.Context{Name: SHY, Help: "脚本", Commands: map[string]*ice.Command{ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - for _, cmd := range []string{mdb.SEARCH, mdb.PLUGIN, mdb.RENDER, mdb.ENGINE} { + for _, cmd := range []string{mdb.SEARCH, mdb.ENGINE, mdb.RENDER, mdb.PLUGIN} { m.Cmd(cmd, mdb.CREATE, SHY, m.Prefix(SHY)) } LoadPlug(m, SHY) @@ -26,30 +26,22 @@ func init() { _go_grep(m, kit.Select(MAIN, arg, 1), arg[2]) } }}, - mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { - m.ProcessCommand() - m.Cmdy("web.wiki.word", path.Join(arg[2], arg[1])) - }}, mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(nfs.SOURCE, path.Join(arg[2], arg[1])) + m.Cmdy(nfs.SOURCE, path.Join(arg[2], arg[1]), kit.Dict(ice.MSG_ALIAS, m.Confv("web.wiki.word", kit.Keym(mdb.ALIAS)))) + }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { + m.ProcessCommand("web.wiki.word", kit.Simple(path.Join(arg[2], arg[1]))) }}, }, PlugAction())}, }, Configs: map[string]*ice.Config{ SHY: {Name: SHY, Help: "脚本", Value: kit.Data(PLUG, kit.Dict( - PREFIX, kit.Dict("# ", COMMENT), - PREPARE, kit.Dict( + PREFIX, kit.Dict("# ", COMMENT), PREPARE, kit.Dict( KEYWORD, kit.Simple( - "title", - "premenu", - "chapter", - "section", - "source", - "refer", - "field", - "spark", + "source", "return", + "title", "premenu", "chapter", "section", + "refer", "spark", "field", + "chart", "label", "chain", "image", - "label", - "chain", ), ), KEYWORD, kit.Dict(), ))}, diff --git a/core/code/vimer.go b/core/code/vimer.go index d0c246e3..befa5faa 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -22,11 +22,16 @@ func init() { m.Cmdy(AUTOGEN, mdb.CREATE, arg) }}, COMPILE: {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) { - if m.Cmdy(COMPILE, ice.SRC_MAIN_GO); cli.IsSuccess(m) { - m.Cmd(COMPILE, ice.SRC_MAIN_GO, ice.BIN_ICE_BIN) - m.Cmd(ice.EXIT, "1") + defer m.ProcessInner() + if msg := m.Cmd(COMPILE, ice.SRC_MAIN_GO); !cli.IsSuccess(msg) { + _inner_make(m, msg) + return } - m.ProcessInner() + if msg := m.Cmd(COMPILE, ice.SRC_MAIN_GO, ice.BIN_ICE_BIN); !cli.IsSuccess(msg) { + _inner_make(m, msg) + return + } + m.Go(func() { m.Sleep("1s", ice.EXIT, "1") }) }}, BINPACK: {Name: "binpack", Help: "打包", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(AUTOGEN, BINPACK) diff --git a/info.go b/info.go index 50bf397b..81b5aadd 100644 --- a/info.go +++ b/info.go @@ -33,6 +33,7 @@ var Info = struct { names map[string]interface{} render map[string]func(*Message, string, ...interface{}) string Log func(m *Message, p, l, s string) + File map[string]string }{ Help: ` ^_^ 欢迎使用冰山框架 ^_^ @@ -45,6 +46,7 @@ source: https://shylinux.com/x/icebergs Pack: map[string][]byte{}, names: map[string]interface{}{}, render: map[string]func(*Message, string, ...interface{}) string{}, + File: map[string]string{}, } func Dump(w io.Writer, name string, cb func(string)) bool { diff --git a/init.go b/init.go index a6ce57c7..c9f24a12 100644 --- a/init.go +++ b/init.go @@ -113,7 +113,9 @@ func Run(arg ...string) string { os.Exit(kit.Int(Pulse.Option(EXIT))) } default: - if Pulse.Cmdy(arg); Pulse.Result() == "" { + Pulse.Cmd(INIT) + defer Pulse.Cmd(EXIT) + if Pulse.Cmdy(arg); strings.TrimSpace(Pulse.Result()) == "" { Pulse.Table() } Pulse.Sleep30ms() diff --git a/render.go b/render.go index 54e07ccf..56dbc882 100644 --- a/render.go +++ b/render.go @@ -150,6 +150,9 @@ func (m *Message) PushDownload(key string, arg ...interface{}) { // [name] file } func (m *Message) PushAction(list ...interface{}) *Message { + if len(m.meta[MSG_APPEND]) == 0 { + return m + } m.Set(MSG_APPEND, ACTION) m.Table(func(index int, value map[string]string, head []string) { m.PushButton(list...)