From 9650802789831e5c7d02ef8655b697b9f08b07c8 Mon Sep 17 00:00:00 2001 From: shaoying Date: Fri, 29 Jan 2021 23:14:47 +0800 Subject: [PATCH] opt inner.go --- core/code/code.shy | 26 +++++++++ core/code/inner.go | 131 +++++++++++++++++++++------------------------ core/code/vimer.go | 34 +++--------- init.go | 6 +-- 4 files changed, 97 insertions(+), 100 deletions(-) diff --git a/core/code/code.shy b/core/code/code.shy index b9a92f91..4a56d122 100644 --- a/core/code/code.shy +++ b/core/code/code.shy @@ -20,3 +20,29 @@ field "命令" web.code.sh field "脚本" web.code.shy field "后端" web.code.go field "前端" web.code.js + +return + +inner.go +vimer.go +favor.go +bench.go +pprof.go + +install.go +compile.go +autogen.go +publish.go +upgrade.go + +c.go +sh.go +shy.go +go.go +js.go + +code.go +code.shy +csdn.go +github.go +pack.go diff --git a/core/code/inner.go b/core/code/inner.go index 61bce188..15683b81 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -3,15 +3,45 @@ package code import ( ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/cli" + "github.com/shylinux/icebergs/base/ctx" "github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/nfs" - "github.com/shylinux/icebergs/base/web" kit "github.com/shylinux/toolkits" "path" "strings" ) +func _inner_ext(name string) string { + return strings.ToLower(kit.Select(path.Base(name), strings.TrimPrefix(path.Ext(name), "."))) +} +func _inner_list(m *ice.Message, ext, file, dir string, arg ...string) { + if m.Warn(!m.Right(dir, file), ice.ErrNotRight, path.Join(dir, file)) { + return // 没有权限 + } + if m.Cmdy(mdb.RENDER, ext, file, dir, arg); m.Result() != "" { + return // 解析成功 + } + + if m.Conf(INNER, kit.Keys(kit.META_SOURCE, ext)) == "true" { + m.Cmdy(nfs.CAT, path.Join(dir, file)) + } +} +func _inner_show(m *ice.Message, ext, file, dir string, arg ...string) { + if m.Warn(!m.Right(dir, file), ice.ErrNotRight, path.Join(dir, file)) { + return // 没有权限 + } + if m.Cmdy(mdb.ENGINE, ext, file, dir, arg); m.Result() != "" { + return // 执行成功 + } + + if ls := kit.Simple(m.Confv(INNER, kit.Keym("show", ext))); len(ls) > 0 { + m.Option(cli.CMD_DIR, dir) + m.Cmdy(cli.SYSTEM, ls, file) + m.Set(ice.MSG_APPEND) + } +} + const ( COMMENT = "comment" KEYWORD = "keyword" @@ -25,77 +55,39 @@ const ( SUFFIX = "suffix" ) -func _inner_ext(name string) string { - return strings.ToLower(kit.Select(path.Base(name), strings.TrimPrefix(path.Ext(name), "."))) -} -func _inner_list(m *ice.Message, ext, file, dir string, arg ...string) { - if strings.HasPrefix("http", dir) { - m.Cmdy(web.SPIDE, web.SPIDE_DEV, web.SPIDE_RAW, web.SPIDE_GET, dir+file) - return - } - - if m.Warn(!m.Right(dir, file), ice.ErrNotRight, path.Join(dir, file)) { - return // 没有权限 - } - if m.Cmdy(mdb.RENDER, ext, file, dir, arg); m.Result() != "" { - return // 解析成功 - } - - if m.Conf(INNER, kit.Keys(kit.META_SOURCE, ext)) == "true" { - if m.Cmdy(nfs.CAT, path.Join(dir, file)); m.Result() != "" { - return - } - } - m.Echo(path.Join(dir, file)) -} -func _inner_show(m *ice.Message, ext, file, dir string, arg ...string) { - if m.Warn(!m.Right(dir, file), ice.ErrNotRight, path.Join(dir, file)) { - return // 没有权限 - } - if m.Cmdy(mdb.ENGINE, ext, file, dir, arg); m.Result() != "" { - return // 执行成功 - } - - if ls := kit.Simple(m.Confv(INNER, kit.Keys("meta.show", ext))); len(ls) > 0 { - m.Cmdy(cli.SYSTEM, ls, path.Join(dir, file)).Set(ice.MSG_APPEND) - } -} - const INNER = "inner" func init() { Index.Merge(&ice.Context{ Commands: map[string]*ice.Command{ - INNER: {Name: "inner path=src/ file=main.go line=1 auto project searchShow", Help: "源代码", Meta: kit.Dict( + INNER: {Name: "inner path=src/ file=main.go line=1 auto", Help: "源代码", Meta: kit.Dict( "display", "/plugin/local/code/inner.js", "style", "editor", - "trans", kit.Dict("project", "项目"), ), Action: map[string]*ice.Action{ mdb.PLUGIN: {Name: "plugin", Help: "插件", Hand: func(m *ice.Message, arg ...string) { if m.Cmdy(mdb.PLUGIN, arg); m.Result() == "" { - if m.Echo(m.Conf(INNER, kit.Keys("meta.plug", arg[0]))); m.Result() == "" { - m.Echo("{}") - } + m.Echo(kit.Select("{}", m.Conf(INNER, kit.Keym("plug", arg[0])))) } }}, - mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { - _inner_list(m, arg[0], arg[1], arg[2], arg[3:]...) - }}, - mdb.ENGINE: {Name: "engine", Help: "引擎", Hand: func(m *ice.Message, arg ...string) { - _inner_show(m, arg[0], arg[1], arg[2], arg[3:]...) + mdb.ENGINE: {Name: "engine", Help: "运行", Hand: func(m *ice.Message, arg ...string) { + _inner_show(m, arg[0], arg[1], arg[2]) }}, mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { - m.Option(cli.CMD_DIR, kit.Select("src", arg, 2)) + m.Option(cli.CMD_DIR, arg[2]) + m.Option(nfs.DIR_ROOT, arg[2]) m.Cmdy(mdb.SEARCH, arg[:2], "file,line,text") }}, - FAVOR: {Name: "favor insert", Help: "收藏"}, - mdb.INPUTS: {Name: "favor inputs", Help: "补全"}, - nfs.DIR: {Name: "dir", Help: "目录"}, - - "searchShow": {Name: "searchShow", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { - }}, - "project": {Name: "project", Help: "项目", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(nfs.DIR, kit.Select("./", arg, 0)) + FAVOR: {Name: "favor", Help: "收藏"}, + ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) { + if arg[0] == "run" { + if arg = kit.Split(strings.Join(arg[1:], " ")); !m.Warn(!m.Right(arg)) { + if m.Cmdy(arg); len(m.Appendv(ice.MSG_APPEND)) == 0 && len(m.Resultv()) == 0 { + m.Cmdy(cli.SYSTEM, arg) + } + } + return + } + m.Cmdy(ctx.COMMAND, arg[0]) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) < 2 { @@ -109,15 +101,14 @@ func init() { INNER: {Name: "inner", Help: "源代码", Value: kit.Data( "source", kit.Dict( "s", "true", "S", "true", - "license", "true", "makefile", "true", "shy", "true", "py", "true", "csv", "true", "json", "true", "css", "true", "html", "true", "txt", "true", "url", "true", "log", "true", "err", "true", - "md", "true", "conf", "true", "toml", "true", - "ini", "true", + "md", "true", "license", "true", "makefile", "true", + "ini", "true", "conf", "true", "toml", "true", ), "plug", kit.Dict( "s", kit.Dict( @@ -131,22 +122,10 @@ func init() { PREFIX, kit.Dict("//", COMMENT), KEYWORD, kit.Dict(), ), - "makefile", kit.Dict( - PREFIX, kit.Dict("#", COMMENT), - SUFFIX, kit.Dict(":", COMMENT), - KEYWORD, kit.Dict( - "ifeq", KEYWORD, - "ifneq", KEYWORD, - "else", KEYWORD, - "endif", KEYWORD, - ), - ), "py", kit.Dict( PREFIX, kit.Dict("#", COMMENT), KEYWORD, kit.Dict("print", KEYWORD), ), - "csv", kit.Dict("display", true), - "json", kit.Dict("link", true), "html", kit.Dict( SPLIT, kit.Dict( "space", " ", @@ -162,6 +141,16 @@ func init() { ), "md", kit.Dict(), + "makefile", kit.Dict( + PREFIX, kit.Dict("#", COMMENT), + SUFFIX, kit.Dict(":", COMMENT), + KEYWORD, kit.Dict( + "ifeq", KEYWORD, + "ifneq", KEYWORD, + "else", KEYWORD, + "endif", KEYWORD, + ), + ), ), "show", kit.Dict( "py", []string{"python"}, diff --git a/core/code/vimer.go b/core/code/vimer.go index 8e612c2c..22dd76b8 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -1,11 +1,7 @@ package code import ( - "strings" - ice "github.com/shylinux/icebergs" - "github.com/shylinux/icebergs/base/cli" - "github.com/shylinux/icebergs/base/ctx" "github.com/shylinux/icebergs/base/nfs" kit "github.com/shylinux/toolkits" @@ -15,27 +11,13 @@ import ( const VIMER = "vimer" func init() { - Index.Merge(&ice.Context{ - Commands: map[string]*ice.Command{ - VIMER: {Name: "vimer path=src/ file=main.go line=1 刷新:button=auto save project searchShow", Help: "编辑器", Meta: kit.Dict( - "display", "/plugin/local/code/vimer.js", "style", "editor", - "trans", kit.Dict("display", "运行", "project", "项目", "search", "搜索"), - ), Action: map[string]*ice.Action{ - "searchShow": {Name: "searchShow", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { - }}, - nfs.SAVE: {Name: "save type file path", Help: "保存", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(nfs.SAVE, path.Join(m.Option(kit.MDB_PATH), m.Option(kit.MDB_FILE))) - }}, - ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) { - if arg = kit.Split(strings.Join(arg, " ")); !m.Warn(!m.Right(arg)) { - if m.Cmdy(arg); len(m.Appendv(ice.MSG_APPEND)) == 0 && len(m.Resultv()) == 0 { - m.Cmdy(cli.SYSTEM, arg) - } - } - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Cmdy(INNER, arg) + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + VIMER: {Name: "vimer path=src/ file=main.go line=1 刷新:button=auto save", Help: "编辑器", Meta: kit.Dict( + "display", "/plugin/local/code/vimer.js", "style", "editor", + ), Action: map[string]*ice.Action{ + nfs.SAVE: {Name: "save type file path", Help: "保存", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(nfs.SAVE, path.Join(m.Option(kit.MDB_PATH), m.Option(kit.MDB_FILE))) }}, - }, - }) + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Cmdy(INNER, arg) }}, + }}) } diff --git a/init.go b/init.go index e710da60..66f337bb 100644 --- a/init.go +++ b/init.go @@ -95,9 +95,9 @@ var Index = &Context{Name: "ice", Help: "冰山模块", "^_^ 欢迎使用冰山框架 ^_^", "^_^ Welcome to Icebergs World ^_^", "", - "Report: shylinuxc@gmail.com", - "Public: https://shylinux.com", - "Source: https://github.com/shylinux/icebergs", + "report: shylinuxc@gmail.com", + "server: https://shylinux.com", + "source: https://github.com/shylinux/icebergs", "", }, }},