diff --git a/base/cli/runtime.go b/base/cli/runtime.go index 0f027bf1..6c7a9642 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -220,12 +220,6 @@ func init() { DISKINFO: {Name: "diskinfo", Help: "磁盘信息", Hand: func(m *ice.Message, arg ...string) { _runtime_diskinfo(m) }}, - "Terminal": {Name: "Terminal", Help: "终端", Hand: func(m *ice.Message, arg ...string) { - m.Cmd(SYSTEM, "open", "-a", "Terminal") - }}, - "Chrome": {Name: "Chrome", Help: "浏览器", Hand: func(m *ice.Message, arg ...string) { - m.Cmd(SYSTEM, "open", "-a", "Google Chrome") - }}, MAXPROCS: {Name: "maxprocs", Help: "最大并发", Hand: func(m *ice.Message, arg ...string) { if len(arg) > 0 { runtime.GOMAXPROCS(kit.Int(m.Conf(RUNTIME, kit.Keys(HOST, MAXPROCS), kit.Select("1", arg, 0)))) diff --git a/base/ctx/option.go b/base/ctx/option.go index 587ef8c7..3df9b286 100644 --- a/base/ctx/option.go +++ b/base/ctx/option.go @@ -47,7 +47,7 @@ func DisplayLocal(m *ice.Message, file string, arg ...ice.Any) *ice.Message { // if file == "" { file = path.Join(kit.PathName(2), kit.Keys(kit.FileName(2), ice.JS)) } - if !strings.HasPrefix(file, ice.HTTP) && !strings.HasPrefix(file, ice.PS) { + if !strings.HasPrefix(file, ice.PS) && !strings.HasPrefix(file, ice.HTTP) { file = path.Join(ice.PLUGIN_LOCAL, file) } return DisplayBase(m, file, arg...) diff --git a/base/web/spide.go b/base/web/spide.go index a71325c3..8bc25bb0 100644 --- a/base/web/spide.go +++ b/base/web/spide.go @@ -351,6 +351,7 @@ const ( CLIENT_URL = "client.url" LOGHEADERS = "logheaders" + HTTP = "http" FORM = "form" ADDRESS = "address" REQUEST = "request" diff --git a/core/code/js.go b/core/code/js.go index f86d41f2..f8080d7d 100644 --- a/core/code/js.go +++ b/core/code/js.go @@ -36,46 +36,46 @@ func _js_main_script(m *ice.Message, arg ...string) (res []string) { } func _js_parse(m *ice.Message, arg ...string) { - + } func _js_show(m *ice.Message, arg ...string) { - kind := "" - m.Cmd(nfs.CAT, path.Join(arg[2], arg[1]), func(text string, index int) { - ls := kit.Split(text, "\t ", ":,()") - if strings.HasPrefix(text, "Volcanos(") { - if kind = ls[2]; strings.Contains(text, "_init: ") { - m.Push("line", index+1) - m.Push("kind", kind) - m.Push("name", "_init") - m.Push("type", "function") - } - return - } - indent := 0 - for _, c := range text { - if c == '\t' { - indent++ - } else if c == ' ' { - indent++ - } else { - break - } - } - if len(ls) > 2 && ls[1] == ":" { - if indent > 1 { - return - } + kind := "" + m.Cmd(nfs.CAT, path.Join(arg[2], arg[1]), func(text string, index int) { + ls := kit.Split(text, "\t ", ":,()") + if strings.HasPrefix(text, "Volcanos(") { + if kind = ls[2]; strings.Contains(text, "_init: ") { m.Push("line", index+1) m.Push("kind", kind) - m.Push("name", ls[0]) - m.Push("type", ls[2]) + m.Push("name", "_init") + m.Push("type", "function") } - }) - m.StatusTimeCount() + return + } + indent := 0 + for _, c := range text { + if c == '\t' { + indent++ + } else if c == ' ' { + indent++ + } else { + break + } + } + if len(ls) > 2 && ls[1] == ":" { + if indent > 1 { + return + } + m.Push("line", index+1) + m.Push("kind", kind) + m.Push("name", ls[0]) + m.Push("type", ls[2]) + } + }) + m.StatusTimeCount() } func _js_exec(m *ice.Message, arg ...string) { if arg[2] == "usr/volcanos/" && strings.HasPrefix(arg[1], "plugin/local/") { - key := "web."+strings.ReplaceAll(strings.TrimSuffix(strings.TrimPrefix(arg[1], "plugin/local/"), ".js"), ice.PS, ice.PT) + key := "web." + strings.ReplaceAll(strings.TrimSuffix(strings.TrimPrefix(arg[1], "plugin/local/"), ".js"), ice.PS, ice.PT) ctx.ProcessCommand(m, kit.Select("can.plugin", key), kit.Simple()) return } @@ -103,7 +103,7 @@ func init() { switch m.Option(ctx.ACTION) { case nfs.SCRIPT: m.Push(nfs.PATH, strings.ReplaceAll(arg[1], ice.PT+kit.Ext(arg[1]), ice.PT+JS)) - m.Option(nfs.DIR_REG, `.*\.(sh|py|shy|js)$`) + m.Option(nfs.DIR_REG, kit.FileReg(nfs.SH, nfs.PY, nfs.SHY, nfs.JS)) nfs.DirDeepAll(m, ice.SRC, nfs.PWD, nil).Cut(nfs.PATH) } diff --git a/core/wiki/audio.go b/core/wiki/audio.go index 18233b62..ee3f73a5 100644 --- a/core/wiki/audio.go +++ b/core/wiki/audio.go @@ -2,16 +2,15 @@ package wiki import ( ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/nfs" ) + const AUDIO = "audio" func init() { Index.MergeCommands(ice.Commands{ - AUDIO: {Name: "audio path auto", Help: "音频", Actions: ice.MergeActions( - ), Hand: func(m *ice.Message, arg ...string) { - if len(arg) > 0 { - m.Echo("", arg[0]) - } - }}, + AUDIO: {Name: "audio url", Help: "音频", Actions: WordAction( + ``, nfs.PATH, ice.USR_LOCAL_IMAGE, + ), Hand: func(m *ice.Message, arg ...string) { _image_show(m, arg[0], arg[1:]...) }}, }) -} \ No newline at end of file +} diff --git a/core/wiki/brief.go b/core/wiki/brief.go index c7595a73..52acaaa3 100644 --- a/core/wiki/brief.go +++ b/core/wiki/brief.go @@ -2,18 +2,14 @@ package wiki import ( ice "shylinux.com/x/icebergs" - "shylinux.com/x/icebergs/base/nfs" - kit "shylinux.com/x/toolkits" ) const BRIEF = "brief" func init() { - Index.Merge(&ice.Context{Commands: ice.Commands{ - BRIEF: {Name: "brief text", Help: "摘要", Hand: func(m *ice.Message, arg ...string) { - _wiki_template(m, m.CommandKey(), "", arg[0], arg[1:]...) - }}, - }, Configs: ice.Configs{ - BRIEF: {Name: BRIEF, Help: "摘要", Value: kit.Data(nfs.TEMPLATE, `

{{.Option "text"}}

`)}, - }}) + Index.MergeCommands(ice.Commands{ + BRIEF: {Name: "brief text", Help: "摘要", Actions: WordAction( + `

{{.Option "text"}}

`, + ), Hand: func(m *ice.Message, arg ...string) { _wiki_template(m, "", arg[0], arg[1:]...) }}, + }) } diff --git a/core/wiki/chart.go b/core/wiki/chart.go index 59b8734f..4336e416 100644 --- a/core/wiki/chart.go +++ b/core/wiki/chart.go @@ -157,7 +157,7 @@ func _chart_show(m *ice.Message, kind, text string, arg ...string) { m.Option(HEIGHT, chart.GetHeight()) // 渲染引擎 - _wiki_template(m, CHART, "", text, arg...) + _wiki_template(m, "", text, arg...) defer m.Echo("") chart.Draw(m, 0, 0) m.RenderResult() diff --git a/core/wiki/data.go b/core/wiki/data.go index ebf3a836..8f4460d6 100644 --- a/core/wiki/data.go +++ b/core/wiki/data.go @@ -6,8 +6,6 @@ import ( "path" ice "shylinux.com/x/icebergs" - "shylinux.com/x/icebergs/base/ctx" - "shylinux.com/x/icebergs/base/lex" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" kit "shylinux.com/x/toolkits" @@ -30,17 +28,18 @@ func init() { nfs.PUSH: {Name: "push path record", Help: "添加", Hand: func(m *ice.Message, arg ...string) { m.Cmd(nfs.PUSH, path.Join(m.Config(nfs.PATH), arg[0]), kit.Join(arg[1:], ice.FS)+ice.NL) }}, - }, FileAction(nfs.PATH, ice.USR_LOCAL_EXPORT, lex.REGEXP, ".*\\.csv")), Hand: func(m *ice.Message, arg ...string) { - if !_wiki_list(m, m.CommandKey(), kit.Select(nfs.PWD, arg, 0)) { + }, WikiAction(ice.USR_LOCAL_EXPORT, nfs.CSV)), Hand: func(m *ice.Message, arg ...string) { + if !_wiki_list(m, arg...) { CSV(m, m.Cmd(nfs.CAT, arg[0]).Result()).StatusTimeCount() - ctx.DisplayLocal(m, "") } }}, }) } func FileAction(arg ...ice.Any) ice.Actions { return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(arg...), - nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(nfs.TRASH, path.Join(m.Config(nfs.PATH), m.Option(nfs.PATH))) }}, + nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { + m.Cmd(nfs.TRASH, path.Join(m.Config(nfs.PATH), m.Option(nfs.PATH))) + }}, nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) { m.Cmd(nfs.SAVE, arg[0], arg[1], kit.Dict(nfs.DIR_ROOT, m.Config(nfs.PATH))) }}, diff --git a/core/wiki/draw.go b/core/wiki/draw.go index b47be5bd..dadb1961 100644 --- a/core/wiki/draw.go +++ b/core/wiki/draw.go @@ -5,7 +5,6 @@ import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/ctx" - "shylinux.com/x/icebergs/base/lex" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" kit "shylinux.com/x/toolkits" @@ -14,10 +13,8 @@ import ( const DRAW = "draw" func init() { - Index.Merge(&ice.Context{Configs: ice.Configs{ - DRAW: {Name: DRAW, Help: "思维导图", Value: kit.Data(lex.REGEXP, ".*\\.svg")}, - }, Commands: ice.Commands{ - DRAW: {Name: "draw path=src/main.svg pid refresh:button=auto save edit actions", Help: "思维导图", Meta: kit.Dict(ice.DisplayLocal("")), Actions: ice.MergeActions(ice.Actions{ + Index.MergeCommands(ice.Commands{ + DRAW: {Name: "draw path=src/main.svg pid refresh:button=auto save edit actions", Help: "思维导图", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(mdb.RENDER, mdb.CREATE, mdb.TYPE, nfs.SVG, mdb.NAME, m.PrefixKey()) }}, @@ -27,12 +24,12 @@ func init() { m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }}, nfs.SAVE: {Name: "save", Help: "保存", Hand: func(m *ice.Message, arg ...string) { - _wiki_save(m, DRAW, arg[0], m.Option(nfs.CONTENT)) + _wiki_save(m, arg[0], m.Option(nfs.CONTENT)) }}, - }, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) { - if !_wiki_list(m, DRAW, kit.Select(nfs.PWD, arg, 0)) { - _wiki_show(m, DRAW, arg[0]) + }, WikiAction("", nfs.SVG), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) { + if !_wiki_list(m, kit.Select(nfs.PWD, arg, 0)) { + _wiki_show(m, arg[0]) } }}, - }}) + }) } diff --git a/core/wiki/feel.go b/core/wiki/feel.go index 682db0ba..1f232121 100644 --- a/core/wiki/feel.go +++ b/core/wiki/feel.go @@ -1,34 +1,18 @@ package wiki import ( - "path" - ice "shylinux.com/x/icebergs" - "shylinux.com/x/icebergs/base/lex" - "shylinux.com/x/icebergs/base/nfs" - "shylinux.com/x/icebergs/base/web" - kit "shylinux.com/x/toolkits" ) const FEEL = "feel" func init() { - Index.Merge(&ice.Context{Configs: ice.Configs{ - FEEL: {Name: FEEL, Help: "影音媒体", Value: kit.Data(nfs.PATH, ice.USR_LOCAL_IMAGE, lex.REGEXP, ".*.(png|PNG|jpg|JPG|jpeg|mp4|m4v|MOV|webm)")}, - }, Commands: ice.Commands{ - FEEL: {Name: "feel path auto record1 record upload prev next actions", Help: "影音媒体", Meta: kit.Dict(ice.DisplayLocal("")), Actions: ice.Actions{ - "record1": {Name: "record1", Help: "截图", Hand: func(m *ice.Message, arg ...string) { - }}, - "record": {Name: "record", Help: "录屏", Hand: func(m *ice.Message, arg ...string) { - }}, - web.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) { - _wiki_upload(m, m.CommandKey(), m.Option(nfs.PATH)) - }}, - nfs.TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) { - m.Cmd(nfs.TRASH, path.Join(m.Config(nfs.PATH), path.Join(arg...))) - }}, - }, Hand: func(m *ice.Message, arg ...string) { - _wiki_list(m, m.CommandKey(), kit.Select(nfs.PWD, arg, 0)) + Index.MergeCommands(ice.Commands{ + FEEL: {Name: "feel path auto record1 record upload prev next actions", Help: "影音媒体", Actions: ice.MergeActions(ice.Actions{ + "record1": {Name: "record1", Help: "截图", Hand: func(m *ice.Message, arg ...string) {}}, + "record": {Name: "record", Help: "录屏", Hand: func(m *ice.Message, arg ...string) {}}, + }, WikiAction(ice.USR_LOCAL_IMAGE, "png|PNG|jpg|JPG|jpeg|mp4|m4v|MOV|webm")), Hand: func(m *ice.Message, arg ...string) { + _wiki_list(m, arg...) }}, - }}) + }) } diff --git a/core/wiki/field.go b/core/wiki/field.go index f8651ed8..bd70e8e8 100644 --- a/core/wiki/field.go +++ b/core/wiki/field.go @@ -14,7 +14,7 @@ import ( func Parse(m *ice.Message, meta string, key string, arg ...string) (data ice.Any) { list := []string{} - for _, line := range kit.Split(strings.Join(arg, ice.SP), ice.NL) { + for _, line := range kit.SplitLine(strings.Join(arg, ice.SP)) { ls := kit.Split(line) for i := 0; i < len(ls); i++ { if strings.HasPrefix(ls[i], "# ") { @@ -24,7 +24,6 @@ func Parse(m *ice.Message, meta string, key string, arg ...string) (data ice.Any } list = append(list, ls...) } - switch data = kit.Parse(nil, "", list...); meta { case ice.MSG_OPTION: m.Option(key, data) @@ -34,17 +33,13 @@ func Parse(m *ice.Message, meta string, key string, arg ...string) (data ice.Any return data } func _field_show(m *ice.Message, name, text string, arg ...string) { - // 命令参数 meta, cmds := kit.Dict(), kit.Split(text) m.Search(cmds[0], func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) { if meta[FEATURE], meta[INPUTS] = kit.Dict(cmd.Meta), cmd.List; name == "" { name = cmd.Help } }) - if len(meta) == 0 { - return - } - if !aaa.Right(m.Spawn(), cmds[0]) { + if len(meta) == 0 || !aaa.Right(m.Spawn(), cmds[0]) { return } @@ -52,7 +47,6 @@ func _field_show(m *ice.Message, name, text string, arg ...string) { meta[mdb.NAME], meta[mdb.INDEX] = name, text msg := m.Spawn() - // 扩展参数 for i := 0; i < len(arg)-1; i += 2 { if strings.HasPrefix(arg[i], "opts.") { kit.Value(meta, arg[i], m.Option(arg[i], strings.TrimSpace(arg[i+1]))) @@ -65,59 +59,48 @@ func _field_show(m *ice.Message, name, text string, arg ...string) { } switch arg[i] { - case "content": - meta[arg[i]] = arg[i+1] - - case SPARK: - if arg[i+1][0] == '@' && nfs.ExistsFile(m, arg[i+1][1:]) { - msg.Cmdy(nfs.CAT, arg[i+1][1:]) - } else { - msg.Echo(strings.TrimSpace(arg[i+1])) - } - - kit.Value(meta, kit.Keys(FEATURE, "mode"), "simple") - if meta["msg"] = msg.FormatMeta(); text == "web.code.inner" { - meta["plug"] = kit.UnMarshal(m.Cmdx(mdb.PLUGIN, kit.Ext(name))) - kit.Value(meta, kit.Keys(FEATURE, "display"), "/plugin/local/code/inner.js") - kit.Value(meta, ARGS, kit.List(path.Dir(name)+ice.PS, path.Base(name))) - } - - case TABLE: - ls := kit.Split(arg[i+1], ice.NL, ice.NL, ice.NL) - head := kit.Split(ls[0]) - for _, l := range ls[1:] { - for i, v := range kit.Split(l) { - msg.Push(head[i], v) - } - } - meta["msg"] = msg.FormatMeta() - kit.Value(meta, kit.Keys(FEATURE, "mode"), "simple") - case ARGS: - args := kit.Simple(m.Optionv(arg[i])) - count := 0 kit.Fetch(meta[INPUTS], func(index int, value ice.Map) { if value[mdb.TYPE] != "button" { count++ } }) - - if len(args) > count { + if args := kit.Simple(m.Optionv(arg[i])); len(args) > count { list := meta[INPUTS].([]ice.Any) for i := count; i < len(args); i++ { list = append(list, kit.Dict(mdb.TYPE, "text", mdb.NAME, ARGS, mdb.VALUE, args[i])) } meta[INPUTS] = list } + case TABLE: + ls := kit.SplitLine(arg[i+1]) + head := kit.SplitWord(ls[0]) + for _, l := range ls[1:] { + for i, v := range kit.SplitWord(l) { + msg.Push(head[i], v) + } + } + kit.Value(meta, "msg", msg.FormatMeta(), kit.Keys(FEATURE, "mode"), "simple") + case SPARK: + if arg[i+1][0] == '@' && nfs.ExistsFile(m, arg[i+1][1:]) { + msg.Cmdy(nfs.CAT, arg[i+1][1:]) + } else { + msg.Echo(strings.TrimSpace(arg[i+1])) + } + kit.Value(meta, "msg", msg.FormatMeta(), kit.Keys(FEATURE, "mode"), "simple") + + if text == "web.code.inner" { + kit.Value(meta, kit.Keys(FEATURE, "display"), "/plugin/local/code/inner.js") + kit.Value(meta, "plug", kit.UnMarshal(m.Cmdx(mdb.PLUGIN, kit.Ext(name)))) + kit.Value(meta, ARGS, kit.List(path.Dir(name)+ice.PS, path.Base(name))) + } default: kit.Value(meta, kit.Keys(FEATURE, arg[i]), msg.Optionv(arg[i], arg[i+1])) } } m.Option(mdb.META, meta) - - // 渲染引擎 - _wiki_template(m, FIELD, name, text) + _wiki_template(m, name, text) } const ( @@ -128,27 +111,21 @@ const ( const FIELD = "field" func init() { - Index.Merge(&ice.Context{Commands: ice.Commands{ - FIELD: {Name: "field [name] cmd", Help: "插件", Actions: ice.MergeActions(ice.Actions{ - ice.RUN: {Name: "run", Help: "执行"}, - }, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) { - if arg = _name(m, arg); strings.Contains(arg[1], ice.NL) { - arg = kit.Simple(arg[0], "web.chat.div", "auto.cmd", "split", "opts.text", arg[1], arg[2:]) - } - if arg[1] == "args" { - arg = kit.Simple("", arg) - } - _field_show(m, arg[0], arg[1], arg[2:]...) - }}, - }, Configs: ice.Configs{ - FIELD: {Name: FIELD, Help: "插件", Value: kit.Data( - nfs.TEMPLATE, `
+ Index.MergeCommands(ice.Commands{ + FIELD: {Name: "field [name] cmd", Help: "插件", Actions: ice.MergeActions(WordAction(`
{{.Option "name"}}
-
`, - )}, - }}) +
`), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) { + if arg[1] == "args" { + arg = kit.Simple("", arg) + } + if arg = _name(m, arg); strings.Contains(arg[1], ice.NL) { + arg = kit.Simple(arg[0], "web.chat.div", "auto.cmd", "split", "opts.text", arg[1], arg[2:]) + } + _field_show(m, arg[0], arg[1], arg[2:]...) + }}, + }) } diff --git a/core/wiki/image.go b/core/wiki/image.go index 41018e2e..0a3941f5 100644 --- a/core/wiki/image.go +++ b/core/wiki/image.go @@ -1,16 +1,12 @@ package wiki import ( - "path" - ice "shylinux.com/x/icebergs" - "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" - kit "shylinux.com/x/toolkits" ) -func _image_show(m *ice.Message, text string) { - _wiki_template(m, IMAGE, "", _wiki_link(m, IMAGE, text)) +func _image_show(m *ice.Message, text string, arg ...string) { + _wiki_template(m, "", _wiki_link(m, text), arg...) } const ( @@ -22,25 +18,9 @@ const ( const IMAGE = "image" func init() { - Index.Merge(&ice.Context{Commands: ice.Commands{ - IMAGE: {Name: "image url height auto", Help: "图片", Actions: ice.Actions{ - ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { - m.Cmd(mdb.RENDER, mdb.CREATE, PNG, m.PrefixKey()) - }}, - mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { - _image_show(m, path.Join(arg[2], arg[1])) - }}, - }, Hand: func(m *ice.Message, arg ...string) { - if len(arg) == 0 { - return - } - m.Option("height", kit.Select("", arg, 1)) - _image_show(m, arg[0]) - }}, - }, Configs: ice.Configs{ - IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data( - nfs.TEMPLATE, ``, - nfs.PATH, ice.USR_LOCAL_IMAGE, - )}, - }}) + Index.MergeCommands(ice.Commands{ + IMAGE: {Name: "image url", Help: "图片", Actions: WordAction( + ``, nfs.PATH, ice.USR_LOCAL_IMAGE, + ), Hand: func(m *ice.Message, arg ...string) { _image_show(m, arg[0], arg[1:]...) }}, + }) } diff --git a/core/wiki/local.go b/core/wiki/local.go deleted file mode 100644 index 6ab78e54..00000000 --- a/core/wiki/local.go +++ /dev/null @@ -1,27 +0,0 @@ -package wiki - -import ( - ice "shylinux.com/x/icebergs" - "shylinux.com/x/icebergs/base/nfs" - kit "shylinux.com/x/toolkits" -) - -func _local_show(m *ice.Message, name, text string, arg ...string) { - m.Option(INPUT, m.Cmdx(nfs.CAT, text)) - _wiki_template(m, LOCAL, name, text, arg...) -} - -const LOCAL = "local" - -func init() { - Index.Merge(&ice.Context{Commands: ice.Commands{ - LOCAL: {Name: "local [name] file", Help: "文件", Hand: func(m *ice.Message, arg ...string) { - arg = _name(m, arg) - _local_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) - }}, - }, Configs: ice.Configs{ - LOCAL: {Name: LOCAL, Help: "文件", Value: kit.Data( - nfs.TEMPLATE, `{{range $index, $value := .Optionv "input"}}{{$value}}{{end}}`, - )}, - }}) -} diff --git a/core/wiki/order.go b/core/wiki/order.go index 4310e604..a5047d1e 100644 --- a/core/wiki/order.go +++ b/core/wiki/order.go @@ -5,25 +5,20 @@ import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/mdb" - "shylinux.com/x/icebergs/base/nfs" kit "shylinux.com/x/toolkits" ) func _order_show(m *ice.Message, text string, arg ...string) { m.Optionv(mdb.LIST, kit.Split(strings.TrimSpace(text), ice.NL)) - _wiki_template(m, ORDER, "", text, arg...) + _wiki_template(m, "", text, arg...) } const ORDER = "order" func init() { - Index.Merge(&ice.Context{Commands: ice.Commands{ - ORDER: {Name: "order `[item\n]...`", Help: "列表", Hand: func(m *ice.Message, arg ...string) { - _order_show(m, arg[0], arg[1:]...) - }}, - }, Configs: ice.Configs{ - ORDER: {Name: ORDER, Help: "列表", Value: kit.Data( - nfs.TEMPLATE, ``, - )}, - }}) + Index.MergeCommands(ice.Commands{ + ORDER: {Name: "order text", Help: "列表", Actions: WordAction( + ``, + ), Hand: func(m *ice.Message, arg ...string) { _order_show(m, arg[0], arg[1:]...) }}, + }) } diff --git a/core/wiki/parse.go b/core/wiki/parse.go index 45ef32c6..8b81e7f9 100644 --- a/core/wiki/parse.go +++ b/core/wiki/parse.go @@ -19,7 +19,7 @@ import ( const PARSE = "parse" func init() { - Index.Merge(&ice.Context{Commands: ice.Commands{ + Index.MergeCommands(ice.Commands{ PARSE: {Name: "parse type=auto,base64,json,http,form,time,list auto text", Help: "解析", Hand: func(m *ice.Message, arg ...string) { if len(arg) < 2 { return @@ -28,8 +28,8 @@ func init() { if arg[1] = strings.TrimSpace(arg[1]); arg[0] == ice.AUTO { if strings.HasPrefix(arg[1], "{") || strings.HasPrefix(arg[1], "[") { arg[0] = nfs.JSON - } else if strings.HasPrefix(arg[1], ice.HTTP) { - arg[0] = ice.HTTP + } else if strings.HasPrefix(arg[1], web.HTTP) { + arg[0] = web.HTTP } else if strings.Contains(arg[1], "=") { arg[0] = web.FORM } else if _, e := strconv.ParseInt(arg[1], 10, 64); e == nil { @@ -41,15 +41,12 @@ func init() { switch m.OptionFields(mdb.DETAIL); arg[0] { case "base64": - buf, err := base64.StdEncoding.DecodeString(arg[1]) - if err == nil { + if buf, err := base64.StdEncoding.DecodeString(arg[1]); err == nil { m.Echo(hex.EncodeToString(buf)) } - case nfs.JSON: m.Echo(kit.Formats(kit.UnMarshal(arg[1]))) - - case ice.HTTP: + case web.HTTP: u, _ := url.Parse(arg[1]) m.Push(tcp.PROTO, u.Scheme) m.Push(tcp.HOST, u.Host) @@ -60,25 +57,20 @@ func init() { } } m.EchoQRCode(arg[1]) - case web.FORM: - for _, v := range kit.Split(arg[1], "&", "&", "&") { - ls := kit.Split(v, "=", "=", "=") - key, _ := url.QueryUnescape(ls[0]) - value, _ := url.QueryUnescape(kit.Select("", ls, 1)) - m.Push(key, value) + for _, v := range strings.Split(arg[1], "&") { + ls := strings.Split(v, ice.EQ) + m.Push(kit.QueryUnescape(ls[0]), kit.QueryUnescape(kit.Select("", ls, 1))) } - case mdb.TIME: if i, e := strconv.ParseInt(arg[1], 10, 64); e == nil { m.Echo(time.Unix(i, 0).Format(ice.MOD_TIME)) } - case mdb.LIST: for i, v := range kit.Split(arg[1]) { m.Push(kit.Format(i), v) } } }}, - }}) + }) } diff --git a/core/wiki/refer.go b/core/wiki/refer.go index 693dc447..872cfd07 100644 --- a/core/wiki/refer.go +++ b/core/wiki/refer.go @@ -1,41 +1,33 @@ package wiki import ( - "net/url" "path" - "strings" ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/mdb" - "shylinux.com/x/icebergs/base/nfs" kit "shylinux.com/x/toolkits" ) func _refer_show(m *ice.Message, text string, arg ...string) { list := [][]string{} - for _, v := range kit.Split(strings.TrimSpace(text), ice.NL, ice.NL) { - if ls := kit.Split(v, " ", " "); len(ls) == 1 { - p, _ := url.QueryUnescape(ls[0]) + for _, v := range kit.SplitLine(text) { + if ls := kit.SplitWord(v); len(ls) == 1 { + p := kit.QueryUnescape(ls[0]) list = append(list, []string{kit.Select(ls[0], path.Base(p)), ls[0], p}) } else { - p, _ := url.QueryUnescape(ls[1]) - list = append(list, append(ls, p)) + list = append(list, append(ls, kit.QueryUnescape(ls[1]))) } } m.Optionv(mdb.LIST, list) - _wiki_template(m, REFER, "", text, arg...) + _wiki_template(m, "", text, arg...) } const REFER = "refer" func init() { - Index.Merge(&ice.Context{Commands: ice.Commands{ - REFER: {Name: "refer `[[name] url\n]...`", Help: "参考", Hand: func(m *ice.Message, arg ...string) { - _refer_show(m, arg[0], arg[1:]...) - }}, - }, Configs: ice.Configs{ - REFER: {Name: REFER, Help: "参考", Value: kit.Data( - nfs.TEMPLATE, ``, - )}, - }}) + Index.MergeCommands(ice.Commands{ + REFER: {Name: "refer text", Help: "参考", Actions: WordAction( + ``, + ), Hand: func(m *ice.Message, arg ...string) { _refer_show(m, arg[0], arg[1:]...) }}, + }) } diff --git a/core/wiki/shell.go b/core/wiki/shell.go deleted file mode 100644 index 06b94df6..00000000 --- a/core/wiki/shell.go +++ /dev/null @@ -1,39 +0,0 @@ -package wiki - -import ( - ice "shylinux.com/x/icebergs" - "shylinux.com/x/icebergs/base/cli" - "shylinux.com/x/icebergs/base/nfs" - kit "shylinux.com/x/toolkits" -) - -func _shell_show(m *ice.Message, name, text string, arg ...string) { - m.Option(OUTPUT, cli.SystemCmds(m, m.Option(INPUT, text))) - _wiki_template(m, SHELL, name, text, arg...) -} - -const ( - INPUT = "input" - OUTPUT = "output" -) -const SHELL = "shell" - -func init() { - Index.Merge(&ice.Context{Commands: ice.Commands{ - SHELL: {Name: "shell [name] cmd", Help: "命令", Hand: func(m *ice.Message, arg ...string) { - if len(arg) == 1 { - m.Cmdy(SPARK, SHELL, arg) - } else { - m.Cmdy(SPARK, arg) - } - return - arg = _name(m, arg) - _shell_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) - }}, - }, Configs: ice.Configs{ - SHELL: {Name: SHELL, Help: "命令", Value: kit.Data( - nfs.TEMPLATE, `$ {{.Option "input"}} # {{.Option "name"}} -{{.Option "output"}}`, - )}, - }}) -} diff --git a/core/wiki/spark.go b/core/wiki/spark.go index 6c5b7d80..d4901c13 100644 --- a/core/wiki/spark.go +++ b/core/wiki/spark.go @@ -9,41 +9,37 @@ import ( kit "shylinux.com/x/toolkits" ) -func _spark_show(m *ice.Message, name, text string, arg ...string) { - for i := 0; i < len(arg); i += 2 { - m.Option(arg[i], arg[i+1]) +func _spark_show(m *ice.Message, name, text string, arg ...string) *ice.Message { + if _option(m, m.CommandKey(), name, text, arg...); name == "" { + return _wiki_template(m, name, text, arg...) } - if name == "" { - _wiki_template(m, SPARK, name, text, arg...) - return - } - - prompt := kit.Select(name+"> ", m.Config(kit.Keys(ssh.PROMPT, name))) m.Echo(`
`, name, m.Option("style")) defer m.Echo("
") switch name { case "inner", "field": - m.Echo(text) - return + return m.Echo(text) } - for _, l := range strings.Split(text, ice.NL) { + prompt := kit.Select(name+"> ", m.Config(kit.Keys(ssh.PROMPT, name))) + for _, l := range kit.SplitLine(text) { m.Echo(Format("div", Format("label", prompt), Format("span", l))) } + return m } const ( PROMPT = "prompt" BREAK = "break" + SHELL = "shell" ) const SPARK = "spark" func init() { - Index.Merge(&ice.Context{Commands: ice.Commands{ - SPARK: {Name: "spark [name] text auto field:text value:text", Help: "段落", Actions: ice.Actions{ + Index.MergeCommands(ice.Commands{ + SPARK: {Name: "spark [name] text auto field:text value:text", Help: "段落", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { ice.AddRender(ice.RENDER_SCRIPT, func(m *ice.Message, cmd string, args ...ice.Any) string { arg := kit.Simple(args...) @@ -57,19 +53,10 @@ func init() { arg = []string{SHELL, arg[0]} } list := []string{kit.Format(`
`, arg[0])} - for _, l := range strings.Split(strings.Join(arg[1:], ice.NL), ice.NL) { - list = append(list, "
") - switch arg[0] { - case SHELL: - list = append(list, Format("label", "$ ")) - default: - list = append(list, Format("label", "> ")) - } - list = append(list, Format("span", l)) - list = append(list, "
") + for _, l := range kit.SplitLine(strings.Join(arg[1:], ice.NL)) { + list = append(list, "
", Format("label", kit.Select("> ", "$ ", arg[0] == SHELL)), Format("span", l), "
") } - list = append(list, "
") - return strings.Join(list, "") + return strings.Join(append(list, ""), "") }) }}, "md": {Name: "md file", Help: "md", Hand: func(m *ice.Message, arg ...string) { @@ -102,35 +89,23 @@ func init() { return } - switch block { - case "": - code = append(code, line) - default: - code = append(code, line) - } + code = append(code, line) }) text() }}, - }, Hand: func(m *ice.Message, arg ...string) { + }, WordAction(`

{{.Option "text"}}

`, ssh.PROMPT, kit.Dict(SHELL, "$ "))), Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 { m.Echo(`
`) return } - switch kit.Ext(arg[0]) { - case "md": + if kit.Ext(arg[0]) == "md" { m.Cmdy(SPARK, "md", arg) return } - arg = _name(m, arg) _spark_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...) }}, - }, Configs: ice.Configs{ - SPARK: {Name: SPARK, Help: "段落", Value: kit.Data( - nfs.TEMPLATE, `

{{.Option "text"}}

`, - ssh.PROMPT, kit.Dict(SHELL, "$ "), - )}, - }}) + }) } func Format(tag string, arg ...ice.Any) string { return kit.Format("<%s>%s", tag, strings.Join(kit.Simple(arg), ""), tag) diff --git a/core/wiki/table.go b/core/wiki/table.go index af350f0c..de15d258 100644 --- a/core/wiki/table.go +++ b/core/wiki/table.go @@ -4,7 +4,6 @@ import ( "strings" ice "shylinux.com/x/icebergs" - "shylinux.com/x/icebergs/base/nfs" kit "shylinux.com/x/toolkits" ) @@ -16,7 +15,6 @@ func _table_run(m *ice.Message, arg ...string) { if index == 0 { m.Optionv("head", head) } - line := []string{} for _, h := range head { line = append(line, value[h]) @@ -24,18 +22,17 @@ func _table_run(m *ice.Message, arg ...string) { list = append(list, line) }) m.Optionv("list", list) - - _wiki_template(m, TABLE, "", "") + _wiki_template(m, "", "") } func _table_show(m *ice.Message, text string, arg ...string) { head, list := []string{}, [][]string{} - for i, v := range kit.Split(strings.TrimSpace(text), ice.NL) { + for i, v := range kit.SplitLine(text) { if v = strings.ReplaceAll(v, "%", "%%"); i == 0 { - head = kit.Split(v) + head = kit.SplitWord(v) } else { - line := kit.Split(v) + line := kit.SplitWord(v) for i, v := range line { - if ls := kit.Split(v); len(ls) > 1 { + if ls := kit.SplitWord(v); len(ls) > 1 { style := []string{} for i := 1; i < len(ls)-1; i += 2 { switch ls[i] { @@ -54,29 +51,18 @@ func _table_show(m *ice.Message, text string, arg ...string) { } m.Optionv("head", head) m.Optionv("list", list) - - _wiki_template(m, TABLE, "", text, arg...) + _wiki_template(m, "", text, arg...) } const TABLE = "table" func init() { - Index.Merge(&ice.Context{Commands: ice.Commands{ - TABLE: {Name: "table `[item item\n]...`", Help: "表格", Actions: ice.Actions{ - ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { - _table_run(m, arg...) - }}, - }, Hand: func(m *ice.Message, arg ...string) { - _table_show(m, arg[0], arg[1:]...) - }}, - }, Configs: ice.Configs{ - TABLE: {Name: TABLE, Help: "表格", Value: kit.Data( - nfs.TEMPLATE, ` + Index.MergeCommands(ice.Commands{ + TABLE: {Name: "table text", Help: "表格", Actions: ice.MergeActions(ice.Actions{ + ice.RUN: {Name: "run", Hand: func(m *ice.Message, arg ...string) { _table_run(m, arg...) }}, + }, WordAction(`
{{range $i, $v := .Optionv "head"}}{{end}} -{{range $index, $value := .Optionv "list"}} -{{range $i, $v := $value}}{{end}} -{{end}} -
{{$v}}
{{$v}}
`, - )}, - }}) +{{range $index, $value := .Optionv "list"}}{{range $i, $v := $value}}{{$v}}{{end}}{{end}} +`)), Hand: func(m *ice.Message, arg ...string) { _table_show(m, arg[0], arg[1:]...) }}, + }) } diff --git a/core/wiki/title.go b/core/wiki/title.go index 2688f74c..400ef4ef 100644 --- a/core/wiki/title.go +++ b/core/wiki/title.go @@ -19,48 +19,39 @@ func _title_parse(m *ice.Message, dir string, text string) string { }) } -func _title_show(m *ice.Message, kind, text string, arg ...string) { +func _title_show(m *ice.Message, kind, text string, arg ...string) *ice.Message { switch title, _ := m.Optionv(TITLE).(map[string]int); kind { - case NAVMENU: // 导航目录 - _option(m, kind, "", text, arg...) - data := _title_parse(m, path.Dir(m.Option(ice.MSG_SCRIPT)), text) - m.RenderTemplate(kit.Format("
", data), &Message{m}) - return - - case PREMENU: // 前置目录 - _option(m, kind, "", "", arg...) - m.RenderTemplate(m.Config(kind), &Message{m}) - return - - case ENDMENU: // 后置目录 - _option(m, kind, "", "", arg...) - m.RenderTemplate(m.Config(kind), &Message{m}) - return - - case SECTION: // 分节标题 + case NAVMENU: + m.Option(mdb.DATA, _title_parse(m, path.Dir(m.Option(ice.MSG_SCRIPT)), text)) + return _option(m, kind, "", text, arg...).RenderTemplate(m.Config(kind), &Message{m}) + case PREMENU: + return _option(m, kind, "", "", arg...).RenderTemplate(m.Config(kind), &Message{m}) + case ENDMENU: + return _option(m, kind, "", "", arg...).RenderTemplate(m.Config(kind), &Message{m}) + case SECTION: title[SECTION]++ m.Option(LEVEL, "h3") m.Option(PREFIX, kit.Format("%d.%d ", title[CHAPTER], title[SECTION])) - - case CHAPTER: // 章节标题 + case CHAPTER: title[CHAPTER]++ title[SECTION] = 0 m.Option(LEVEL, "h2") m.Option(PREFIX, kit.Format("%d ", title[CHAPTER])) - - default: // 文章标题 + default: m.Option(LEVEL, "h1") m.Option(PREFIX, "") } - - // 渲染引擎 - _wiki_template(m, TITLE, "", text, arg...) - - // 添加目录 + _wiki_template(m, "", text, arg...) menu, _ := m.Optionv(MENU).(ice.Map) menu[mdb.LIST] = append(menu[mdb.LIST].([]ice.Any), kit.Dict(m.OptionSimple("level,prefix,text"))) + return m } +const ( + PREFIX = "prefix" + LEVEL = "level" + MENU = "menu" +) const ( NAVMENU = "navmenu" PREMENU = "premenu" @@ -68,20 +59,17 @@ const ( SECTION = "section" ENDMENU = "endmenu" ) - -const ( - PREFIX = "prefix" - LEVEL = "level" - MENU = "menu" -) const TITLE = "title" func init() { - Index.Merge(&ice.Context{Commands: ice.Commands{ - TITLE: {Name: "title [navmenu|premenu|chapter|section|endmenu] text", Help: "标题", Hand: func(m *ice.Message, arg ...string) { - if len(arg) == 0 { - arg = append(arg, kit.Slice(kit.Split(ice.Info.NodeName, "-"), -1)[0]) - } + Index.MergeCommands(ice.Commands{ + TITLE: {Name: "title [navmenu|premenu|chapter|section|endmenu] text", Actions: WordAction( + `<{{.Option "level"}} {{.OptionTemplate}}>{{.Option "prefix"}} {{.Option "text"}}`, + NAVMENU, `
`, + PREMENU, ``, + ENDMENU, ``), Help: "标题", Hand: func(m *ice.Message, arg ...string) { switch arg[0] { case NAVMENU: _title_show(m, arg[0], arg[1], arg[2:]...) @@ -93,13 +81,5 @@ func init() { _title_show(m, "", arg[0], arg[1:]...) } }}, - }, Configs: ice.Configs{ - TITLE: {Name: TITLE, Help: "标题", Value: kit.Data( - nfs.TEMPLATE, `<{{.Option "level"}} {{.OptionTemplate}}>{{.Option "prefix"}} {{.Option "text"}}`, - PREMENU, ``, - ENDMENU, ``, - )}, - }}) + }) } diff --git a/core/wiki/video.go b/core/wiki/video.go index 9299d2d4..7f0e346e 100644 --- a/core/wiki/video.go +++ b/core/wiki/video.go @@ -1,39 +1,21 @@ package wiki import ( - "path" - ice "shylinux.com/x/icebergs" - "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" - kit "shylinux.com/x/toolkits" ) -func _video_show(m *ice.Message, text string, arg ...string) { - _wiki_template(m, VIDEO, "", _wiki_link(m, VIDEO, text), arg...) -} - const ( mp4 = "mp4" m4v = "m4v" MOV = "mov" ) - const VIDEO = "video" func init() { - Index.Merge(&ice.Context{Commands: ice.Commands{ - VIDEO: {Name: "video url", Help: "视频", Actions: ice.Actions{ - mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { - _video_show(m, path.Join(arg[2], arg[1])) - }}, - }, Hand: func(m *ice.Message, arg ...string) { - _video_show(m, arg[0], arg[1:]...) - }}, - }, Configs: ice.Configs{ - VIDEO: {Name: "video", Help: "视频", Value: kit.Data( - nfs.PATH, ice.USR_LOCAL_IMAGE, - nfs.TEMPLATE, ``, - )}, - }}) + Index.MergeCommands(ice.Commands{ + VIDEO: {Name: "video url", Help: "视频", Actions: WordAction( + ``, nfs.PATH, ice.USR_LOCAL_IMAGE, + ), Hand: func(m *ice.Message, arg ...string) { _image_show(m, arg[0], arg[1:]...) }}, + }) } diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index b7379c83..4027c140 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -6,6 +6,7 @@ import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/ctx" + "shylinux.com/x/icebergs/base/lex" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/web" @@ -18,7 +19,7 @@ func _name(m *ice.Message, arg []string) []string { } return arg } -func _option(m *ice.Message, kind, name, text string, arg ...string) { +func _option(m *ice.Message, kind, name, text string, arg ...string) *ice.Message { m.Option(mdb.TYPE, kind) m.Option(mdb.NAME, name) m.Option(mdb.TEXT, text) @@ -28,46 +29,40 @@ func _option(m *ice.Message, kind, name, text string, arg ...string) { for i := 0; i < len(arg); i += 2 { extra[arg[i]] = kit.Format(kit.Parse(nil, "", kit.Split(arg[i+1])...)) } + return m } -func _wiki_path(m *ice.Message, cmd string, arg ...string) string { - return path.Join(m.Conf(cmd, kit.Keym(nfs.PATH)), path.Join(arg...)) +func _wiki_path(m *ice.Message, arg ...string) string { + return path.Join(m.Config(nfs.PATH), path.Join(arg...)) } -func _wiki_link(m *ice.Message, cmd string, text string) string { - if !strings.HasPrefix(text, ice.HTTP) && !strings.HasPrefix(text, ice.PS) { - text = path.Join(web.SHARE_LOCAL, _wiki_path(m, cmd, text)) +func _wiki_link(m *ice.Message, text string) string { + if !strings.HasPrefix(text, ice.PS) && !strings.HasPrefix(text, ice.HTTP) { + text = path.Join(web.SHARE_LOCAL, _wiki_path(m, text)) } return text } -func _wiki_list(m *ice.Message, cmd string, arg ...string) bool { - m.Option(nfs.DIR_ROOT, _wiki_path(m, cmd)) - if len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) { - if m.Option(nfs.DIR_DEEP) != ice.TRUE { // 目录列表 - m.Option(nfs.DIR_TYPE, nfs.DIR) - m.Cmdy(nfs.DIR, kit.Select(nfs.PWD, arg, 0)) +func _wiki_list(m *ice.Message, arg ...string) bool { + if m.Option(nfs.DIR_ROOT, _wiki_path(m)); len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) { + if m.Option(nfs.DIR_DEEP) != ice.TRUE { + m.Cmdy(nfs.DIR, kit.Slice(arg, 0, 1), kit.Dict(nfs.DIR_TYPE, nfs.DIR)) } - - // 文件列表 - m.Option(nfs.DIR_TYPE, nfs.CAT) - m.Cmdy(nfs.DIR, kit.Select(nfs.PWD, arg, 0)) + m.Cmdy(nfs.DIR, kit.Slice(arg, 0, 1), kit.Dict(nfs.DIR_TYPE, nfs.CAT, nfs.DIR_REG, m.Config(lex.REGEXP))) return true } + ctx.DisplayLocal(m, path.Join(kit.PathName(2), kit.Keys(kit.FileName(2), ice.JS))) return false } -func _wiki_show(m *ice.Message, cmd, name string, arg ...string) { - m.Option(nfs.DIR_ROOT, _wiki_path(m, cmd)) - m.Cmdy(nfs.CAT, name) +func _wiki_show(m *ice.Message, name string, arg ...string) { + m.Cmdy(nfs.CAT, name, kit.Dict(nfs.DIR_ROOT, _wiki_path(m))) } -func _wiki_save(m *ice.Message, cmd, name, text string, arg ...string) { - m.Option(nfs.DIR_ROOT, _wiki_path(m, cmd)) - m.Cmd(nfs.SAVE, name, text) +func _wiki_save(m *ice.Message, name, text string, arg ...string) { + m.Cmd(nfs.SAVE, name, text, kit.Dict(nfs.DIR_ROOT, _wiki_path(m))) } -func _wiki_upload(m *ice.Message, cmd string, dir string) { - m.Cmdy(web.CACHE, web.UPLOAD_WATCH, _wiki_path(m, cmd, dir)) +func _wiki_upload(m *ice.Message, dir string) { + m.Cmdy(web.CACHE, web.UPLOAD_WATCH, _wiki_path(m, dir)) } -func _wiki_template(m *ice.Message, cmd string, name, text string, arg ...string) { - _option(m, cmd, name, strings.TrimSpace(text), arg...) - m.RenderTemplate(m.Conf(cmd, kit.Keym(nfs.TEMPLATE)), &Message{m}) +func _wiki_template(m *ice.Message, name, text string, arg ...string) *ice.Message { + return _option(m, m.CommandKey(), name, strings.TrimSpace(text), arg...).RenderTemplate(m.Config(nfs.TEMPLATE), &Message{m}) } const WIKI = "wiki" @@ -76,36 +71,54 @@ var Index = &ice.Context{Name: WIKI, Help: "文档中心"} func init() { web.Index.Register(Index, &web.Frame{}, - TITLE, BRIEF, REFER, SPARK, CHART, - ORDER, TABLE, IMAGE, VIDEO, - FIELD, SHELL, LOCAL, PARSE, + TITLE, BRIEF, REFER, SPARK, FIELD, PARSE, + ORDER, TABLE, CHART, IMAGE, VIDEO, AUDIO, FEEL, DRAW, WORD, DATA, ) } -type Message struct { - *ice.Message +func WikiAction(dir string, ext ...string) ice.Actions { + return ice.Actions{ + ice.CTX_INIT: &ice.Action{Hand: func(m *ice.Message, arg ...string) { + if cs := m.Target().Configs; cs[m.CommandKey()] == nil { + cs[m.CommandKey()] = &ice.Config{Value: kit.Data()} + ice.Info.Load(m, m.CommandKey()) + } + m.Config(nfs.PATH, dir) + m.Config(lex.REGEXP, kit.FileReg(ext...)) + }}, + nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { + m.Cmd(nfs.TRASH, path.Join(m.Config(nfs.PATH), m.Option(nfs.PATH))) + }}, + nfs.SAVE: {Name: "save path text", Hand: func(m *ice.Message, arg ...string) { + m.Cmd(nfs.SAVE, arg[0], arg[1], kit.Dict(nfs.DIR_ROOT, m.Config(nfs.PATH))) + }}, + web.UPLOAD: {Hand: func(m *ice.Message, arg ...string) { + _wiki_upload(m, m.Option(nfs.PATH)) + }}, + } } +type Message struct{ *ice.Message } + func (m *Message) OptionTemplate() string { res := []string{`class="story"`} - for _, key := range kit.Split(ctx.STYLE) { + add := func(pre, key string) { if m.Option(key) != "" { - res = append(res, kit.Format(`s="%s"`, key, m.Option(key))) + res = append(res, kit.Format(`%s%s="%s"`, pre, key, m.Option(key))) } } for _, key := range kit.Split("type,name,text") { - if key == mdb.TEXT && m.Option(mdb.TYPE) == "spark" { + if key == mdb.TEXT && m.Option(mdb.TYPE) == SPARK { continue } - if m.Option(key) != "" { - res = append(res, kit.Format(`data-%s="%s"`, key, m.Option(key))) - } + add("data-", key) } - kit.Fetch(m.Optionv("extra"), func(key string, value string) { - if value != "" { - res = append(res, kit.Format(`data-%s="%s"`, key, value)) - } + kit.Fetch(m.Optionv(mdb.EXTRA), func(key string, value string) { + add("data-", key) }) + for _, key := range kit.Split(ctx.STYLE) { + add("", key) + } return kit.Join(res, ice.SP) } diff --git a/core/wiki/wiki.shy b/core/wiki/wiki.shy index 051cb0c9..67697971 100644 --- a/core/wiki/wiki.shy +++ b/core/wiki/wiki.shy @@ -1,25 +1,22 @@ +wiki.shy +wiki.go +word.go title.go brief.go refer.go spark.go -chart.go +field.go +parse.go order.go table.go +chart.go image.go video.go - -field.go -shell.go -local.go -parse.go +audio.go feel.go draw.go -word.go data.go -json.go -wiki.go -wiki.shy diff --git a/core/wiki/word.go b/core/wiki/word.go index b46a365b..ef3ed111 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -1,112 +1,69 @@ package wiki import ( - "path" - "strings" - ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/ctx" - "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" ) func _word_show(m *ice.Message, name string, arg ...string) { m.SetResult() + defer m.StatusTime() m.Option(TITLE, map[string]int{}) m.Option(MENU, kit.Dict(mdb.LIST, kit.List())) m.Option(ice.MSG_ALIAS, m.Configv(mdb.ALIAS)) - m.Cmdy("ssh.source", name, kit.Dict(nfs.DIR_ROOT, _wiki_path(m, WORD))) + m.Cmdy("ssh.source", name, kit.Dict(nfs.DIR_ROOT, _wiki_path(m))) } const WORD = "word" func init() { - Index.Merge(&ice.Context{Configs: ice.Configs{ - WORD: {Name: WORD, Help: "笔记文档", Value: kit.Data( - nfs.PATH, "", lex.REGEXP, ".*\\.shy", mdb.ALIAS, kit.Dict( - NAVMENU, kit.List(TITLE, NAVMENU), - PREMENU, kit.List(TITLE, PREMENU), - CHAPTER, kit.List(TITLE, CHAPTER), - SECTION, kit.List(TITLE, SECTION), - ENDMENU, kit.List(TITLE, ENDMENU), - LABEL, kit.List(CHART, LABEL), - CHAIN, kit.List(CHART, CHAIN), - SEQUENCE, kit.List(CHART, SEQUENCE), - ), - mdb.SHORT, "type,name,text", - mdb.FIELD, "time,hash,type,name,text", - )}, - }, Commands: ice.Commands{ + Index.MergeCommands(ice.Commands{ WORD: {Name: "word path=src/main.shy@key list play", Help: "笔记文档", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, m.PrefixKey()) m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, ice.SRC_MAIN_SHY) + WordAlias(m, NAVMENU, TITLE, NAVMENU) + WordAlias(m, PREMENU, TITLE, PREMENU) + WordAlias(m, CHAPTER, TITLE, CHAPTER) + WordAlias(m, SECTION, TITLE, SECTION) + WordAlias(m, ENDMENU, TITLE, ENDMENU) + WordAlias(m, LABEL, CHART, LABEL) + WordAlias(m, CHAIN, CHART, CHAIN) + WordAlias(m, SEQUENCE, CHART, SEQUENCE) }}, - mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { - if (arg[0] != mdb.FOREACH && arg[0] != m.CommandKey()) || arg[1] == "" { - return - } - if arg[1] == "" { - m.PushSearch(mdb.TYPE, nfs.SHY, mdb.NAME, ice.SRC_MAIN_SHY, mdb.TEXT, web.MergePodCmd(m, "", "")) - } - - m.Cmd(mdb.SELECT, m.PrefixKey(), "", mdb.HASH, func(value ice.Maps) { - if arg[1] == "" { - if value[mdb.TYPE] == SPARK { - value[mdb.TEXT] = ice.Render(m, ice.RENDER_SCRIPT, value[mdb.TEXT]) - } - m.PushSearch(value) - } - }) - m.Cmd("", mdb.INPUTS).Tables(func(value ice.Maps) { - if strings.Contains(value[nfs.PATH], arg[1]) { - m.PushSearch(mdb.TYPE, "shy", mdb.NAME, value[nfs.PATH], value) - } - }) - }}, - mdb.CREATE: {Name: "create", Help: "创建", Hand: func(m *ice.Message, arg ...string) { - m.Cmd(mdb.INSERT, m.PrefixKey(), "", mdb.HASH, arg) - }}, - "recent": {Name: "recent", Help: "最近", Hand: func(m *ice.Message, arg ...string) { - m.OptionFields(m.Config(mdb.FIELD)) - m.Cmd(mdb.SELECT, m.PrefixKey(), "", mdb.HASH).Table(func(index int, value ice.Maps, head []string) { - if value[mdb.TYPE] == "spark" { - value[mdb.TEXT] = ice.Render(m, ice.RENDER_SCRIPT, value[mdb.TEXT]) - } - m.Push("", value, head) - }) - m.PushAction(mdb.REMOVE) - }}, - mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(nfs.DIR, arg[1:], kit.Dict(nfs.DIR_REG, ".*\\.shy")) - m.ProcessAgain() - return - for _, p := range []string{"src/", "src/help/", "usr/icebergs/", "usr/linux-story/", "usr/nginx-story/", "usr/golang-story/", "usr/redis-story/", "usr/mysql-story/"} { - m.Cmdy(nfs.DIR, p, kit.Dict(nfs.DIR_DEEP, ice.TRUE, nfs.DIR_REG, ".*\\.shy"), nfs.DIR_CLI_FIELDS) + m.Option(nfs.DIR_DEEP, ice.TRUE) + for _, p := range []string{"src/", "usr/icebergs/", "usr/learning/", "usr/linux-story/", "usr/nginx-story/", "usr/golang-story/", "usr/redis-story/", "usr/mysql-story/"} { + _wiki_list(m, p) } - }}, - ice.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(arg[0], ice.RUN, arg[2:]) - }}, - "play": {Name: "play", Help: "演示"}, - }, ctx.CmdAction(), mdb.HashAction()), Hand: func(m *ice.Message, arg ...string) { - if len(arg) == 0 { + }}, "play": {Name: "play", Help: "演示"}, + ice.STORY: {Name: "story", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(arg[0], ice.RUN, arg[2:]) }}, + }, WikiAction("", nfs.SHY), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) { + if m.Option(nfs.DIR_DEEP, ice.TRUE); len(arg) == 0 { arg = append(arg, "src/") } - m.Option(nfs.DIR_REG, m.Config(lex.REGEXP)) - if m.Option(nfs.DIR_DEEP, ice.TRUE); !_wiki_list(m, m.CommandKey(), arg...) { - if !nfs.ExistsFile(m, arg[0]) && nfs.ExistsFile(m, path.Join(ice.SRC, arg[0])) { - arg[0] = path.Join(ice.SRC, arg[0]) - } - ctx.DisplayLocal(m, "") + if !_wiki_list(m, arg...) { _word_show(m, arg[0]) - m.StatusTime() } }}, - }}) + }) +} +func WordAlias(m *ice.Message, cmd string, cmds ...string) { + m.Conf(WORD, kit.Keym(mdb.ALIAS, cmd), cmds) +} +func WordAction(template string, arg ...ice.Any) ice.Actions { + return ice.Actions{ice.CTX_INIT: &ice.Action{Hand: func(m *ice.Message, args ...string) { + if cs := m.Target().Configs; cs[m.CommandKey()] == nil { + cs[m.CommandKey()] = &ice.Config{Value: kit.Data()} + ice.Info.Load(m, m.CommandKey()) + } + m.Config(nfs.TEMPLATE, template) + for i := 0; i < len(arg)-1; i += 2 { + m.Config(kit.Format(arg[i]), arg[i+1]) + } + }}} } diff --git a/misc/webview/webview.go b/misc/webview/webview.go index 60ec0a89..72d86d17 100644 --- a/misc/webview/webview.go +++ b/misc/webview/webview.go @@ -75,6 +75,17 @@ func (w WebView) OpenCmd(cmd string) { func (w WebView) SetSize(width, height int) { w.Cmd(nfs.SAVE, "etc/webview.size", kit.Format("%v,%v", width, height)) } +func (w WebView) System(arg ...string) string { + return w.Cmdx(cli.SYSTEM, arg) +} +func (w WebView) Power() string { + ls := strings.Split(w.Cmdx(cli.SYSTEM, "pmset", "-g", "ps"), ice.NL) + for _, line := range ls[1:] { + ls := kit.Split(line, "\t ;", "\t ;") + return ls[2] + } + return "" +} func (w WebView) Terminate() { w.WebView.Terminate() } func (w WebView) Close() { if !w.Menu() {