")
+ m.Echo("")
+ m.Echo("").Echo(l).Echo("")
+ m.Echo("
")
+ }
+ m.Echo("diff --git a/core/wiki/brief.go b/core/wiki/brief.go new file mode 100644 index 00000000..5c719e78 --- /dev/null +++ b/core/wiki/brief.go @@ -0,0 +1,23 @@ +package wiki + +import ( + ice "github.com/shylinux/icebergs" + kit "github.com/shylinux/toolkits" +) + +const BRIEF = "brief" + +func init() { + Index.Merge(&ice.Context{ + Commands: map[string]*ice.Command{ + BRIEF: {Name: "brief [name] text", Help: "摘要", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + _word_template(m, cmd, arg...) + }}, + }, + Configs: map[string]*ice.Config{ + BRIEF: {Name: BRIEF, Help: "摘要", Value: kit.Data( + kit.MDB_TEMPLATE, `
{{.Option "text"}}
`, + )}, + }, + }) +} diff --git a/core/wiki/field.go b/core/wiki/field.go new file mode 100644 index 00000000..0ce7a8ea --- /dev/null +++ b/core/wiki/field.go @@ -0,0 +1,98 @@ +package wiki + +import ( + "path" + "strings" + + ice "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/base/cli" + kit "github.com/shylinux/toolkits" +) + +func _field_show(m *ice.Message, name, text string, arg ...string) { + // 基本参数 + m.Option(kit.MDB_TYPE, FIELD) + m.Option(kit.MDB_NAME, name) + m.Option(kit.MDB_TEXT, text) + + // 命令参数 + data := kit.Dict(kit.MDB_NAME, name) + cmds := kit.Split(text) + m.Search(cmds[0], func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) { + data["feature"], data["inputs"] = cmd.Meta, cmd.List + }) + + // 扩展参数 + for i := 0; i < len(arg)-1; i += 2 { + if strings.HasPrefix(arg[i], "args.") { + m.Option(arg[i], strings.TrimSpace(arg[i+1])) + kit.Value(data, arg[i], m.Option(arg[i])) + } else if strings.HasPrefix(arg[i], "args") { + m.Option(arg[i], kit.Split(strings.TrimSuffix(strings.TrimPrefix(arg[i+1], "["), "]"))) + kit.Value(data, arg[i], m.Optionv(arg[i])) + } else { + m.Parse("option", arg[i], arg[i+1]) + kit.Value(data, arg[i], m.Optionv(arg[i])) + } + + switch arg[i] { + case "content": + data[arg[i]] = arg[i+1] + + case "args": + args := kit.Simple(m.Optionv(arg[i])) + + count := 0 + kit.Fetch(data["inputs"], func(index int, value map[string]interface{}) { + if value["_input"] != "button" && value["type"] != "button" { + count++ + } + }) + + if len(args) > count { + list := data["inputs"].([]interface{}) + for i := count; i < len(args); i++ { + list = append(list, kit.Dict( + "_input", "text", "name", "args", "value", args[i], + )) + } + data["inputs"] = list + } + } + } + + // 渲染引擎 + m.Option(kit.MDB_META, data) + m.RenderTemplate(m.Conf(FIELD, kit.Keym(kit.MDB_TEMPLATE))) +} + +const FIELD = "field" + +func init() { + Index.Merge(&ice.Context{ + Commands: map[string]*ice.Command{ + FIELD: {Name: "field [name] cmd", Help: "插件", Action: map[string]*ice.Action{ + cli.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { + if !m.Warn(!m.Right(arg[1:]), ice.ErrNotRight, arg[1:]) { + m.Cmdy(arg[1:]) + } + }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + arg = _name(m, arg) + _field_show(m, strings.ReplaceAll(kit.Select(path.Base(arg[1]), arg[0]), " ", "_"), arg[1], arg[2:]...) + }}, + }, + Configs: map[string]*ice.Config{ + FIELD: {Name: FIELD, Help: "插件", Value: kit.Data( + kit.MDB_TEMPLATE, ``, + )}, + }, + }) +} diff --git a/core/wiki/local.go b/core/wiki/local.go new file mode 100644 index 00000000..34ca9fce --- /dev/null +++ b/core/wiki/local.go @@ -0,0 +1,32 @@ +package wiki + +import ( + ice "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/base/nfs" + kit "github.com/shylinux/toolkits" +) + +func _local_show(m *ice.Message, name, text string, arg ...string) { + m.Option("input", m.Cmdx(nfs.CAT, text)) + _option(m, LOCAL, name, text, arg...) + m.RenderTemplate(m.Conf(LOCAL, kit.Keym(kit.MDB_TEMPLATE))) +} + +const LOCAL = "local" + +func init() { + Index.Merge(&ice.Context{ + Commands: map[string]*ice.Command{ + LOCAL: {Name: "local [name] file", Help: "文件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + arg = _name(m, arg) + _local_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) + }}, + }, + Configs: map[string]*ice.Config{ + LOCAL: {Name: LOCAL, Help: "文件", Value: kit.Data( + kit.MDB_TEMPLATE, `{{range $index, $value := .Optionv "input"}}{{$value}}{{end}}
`,
+ )},
+ },
+ })
+}
diff --git a/core/wiki/order.go b/core/wiki/order.go
new file mode 100644
index 00000000..b8b75848
--- /dev/null
+++ b/core/wiki/order.go
@@ -0,0 +1,35 @@
+package wiki
+
+import (
+ "strings"
+
+ ice "github.com/shylinux/icebergs"
+ kit "github.com/shylinux/toolkits"
+)
+
+func _order_show(m *ice.Message, name, text string, arg ...string) {
+ m.Optionv("list", kit.Split(strings.TrimSpace(text), "\n"))
+ _option(m, ORDER, name, text, arg...)
+ m.RenderTemplate(m.Conf(ORDER, kit.Keym(kit.MDB_TEMPLATE)))
+}
+
+const ORDER = "order"
+
+func init() {
+ Index.Merge(&ice.Context{
+ Commands: map[string]*ice.Command{
+ ORDER: {Name: "order [name] `[item \n]...`", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ arg = _name(m, arg)
+ _order_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
+ }},
+ },
+ Configs: map[string]*ice.Config{
+ ORDER: {Name: ORDER, Help: "列表", Value: kit.Data(
+ kit.MDB_TEMPLATE, `$ {{.Option "input"}} # {{.Option "name"}}
+{{.Option "output"}}
`,
+ )},
+ },
+ })
+}
diff --git a/core/wiki/spark.go b/core/wiki/spark.go
new file mode 100644
index 00000000..312ea2d4
--- /dev/null
+++ b/core/wiki/spark.go
@@ -0,0 +1,49 @@
+package wiki
+
+import (
+ "strings"
+
+ ice "github.com/shylinux/icebergs"
+ kit "github.com/shylinux/toolkits"
+)
+
+func _spark_show(m *ice.Message, name, text string, arg ...string) {
+ if name == "" {
+ _wiki_template(m, SPARK, name, text, arg...)
+ return
+ }
+
+ prompt := kit.Select(name+"> ", m.Conf(SPARK, kit.Keym("prompt", name)))
+ m.Echo(`{{.Option "text"}}
`, + "prompt", kit.Dict("shell", "$ "), + )}, + }, + }) +} diff --git a/core/wiki/table.go b/core/wiki/table.go new file mode 100644 index 00000000..93d07dce --- /dev/null +++ b/core/wiki/table.go @@ -0,0 +1,65 @@ +package wiki + +import ( + "strings" + + ice "github.com/shylinux/icebergs" + kit "github.com/shylinux/toolkits" +) + +func _table_show(m *ice.Message, name, text string, arg ...string) { + head, list := []string{}, [][]string{} + for i, v := range kit.Split(strings.TrimSpace(text), "\n") { + if v = strings.ReplaceAll(v, "%", "%%"); i == 0 { + head = kit.Split(v) + } else { + line := kit.Split(v) + for i, v := range line { + if ls := kit.Split(v); len(ls) > 1 { + style := []string{} + for i := 1; i < len(ls)-1; i += 2 { + switch ls[i] { + case "bg": + ls[i] = "background-color" + case "fg": + ls[i] = "color" + } + style = append(style, ls[i]+":"+ls[i+1]) + } + line[i] = kit.Format(`%s`, strings.Join(style, ";"), ls[0]) + } + } + list = append(list, line) + } + } + m.Optionv("head", head) + m.Optionv("list", list) + + _option(m, TABLE, name, text, arg...) + m.RenderTemplate(m.Conf(TABLE, kit.Keym(kit.MDB_TEMPLATE))) +} + +const TABLE = "table" + +func init() { + Index.Merge(&ice.Context{ + Commands: map[string]*ice.Command{ + TABLE: {Name: "table [name] `[item item\n]...`", Help: "表格", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + arg = _name(m, arg) + _table_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) + }}, + }, + Configs: map[string]*ice.Config{ + TABLE: {Name: TABLE, Help: "表格", Value: kit.Data( + kit.MDB_TEMPLATE, `{{$v}} | {{end}}
---|
{{$v}} | {{end}}