forked from x/icebergs
opt wiki
This commit is contained in:
parent
e2549d0f82
commit
12a7ac761a
@ -220,12 +220,6 @@ func init() {
|
|||||||
DISKINFO: {Name: "diskinfo", Help: "磁盘信息", Hand: func(m *ice.Message, arg ...string) {
|
DISKINFO: {Name: "diskinfo", Help: "磁盘信息", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_runtime_diskinfo(m)
|
_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) {
|
MAXPROCS: {Name: "maxprocs", Help: "最大并发", Hand: func(m *ice.Message, arg ...string) {
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
runtime.GOMAXPROCS(kit.Int(m.Conf(RUNTIME, kit.Keys(HOST, MAXPROCS), kit.Select("1", arg, 0))))
|
runtime.GOMAXPROCS(kit.Int(m.Conf(RUNTIME, kit.Keys(HOST, MAXPROCS), kit.Select("1", arg, 0))))
|
||||||
|
@ -47,7 +47,7 @@ func DisplayLocal(m *ice.Message, file string, arg ...ice.Any) *ice.Message { //
|
|||||||
if file == "" {
|
if file == "" {
|
||||||
file = path.Join(kit.PathName(2), kit.Keys(kit.FileName(2), ice.JS))
|
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)
|
file = path.Join(ice.PLUGIN_LOCAL, file)
|
||||||
}
|
}
|
||||||
return DisplayBase(m, file, arg...)
|
return DisplayBase(m, file, arg...)
|
||||||
|
@ -351,6 +351,7 @@ const (
|
|||||||
CLIENT_URL = "client.url"
|
CLIENT_URL = "client.url"
|
||||||
LOGHEADERS = "logheaders"
|
LOGHEADERS = "logheaders"
|
||||||
|
|
||||||
|
HTTP = "http"
|
||||||
FORM = "form"
|
FORM = "form"
|
||||||
ADDRESS = "address"
|
ADDRESS = "address"
|
||||||
REQUEST = "request"
|
REQUEST = "request"
|
||||||
|
@ -103,7 +103,7 @@ func init() {
|
|||||||
switch m.Option(ctx.ACTION) {
|
switch m.Option(ctx.ACTION) {
|
||||||
case nfs.SCRIPT:
|
case nfs.SCRIPT:
|
||||||
m.Push(nfs.PATH, strings.ReplaceAll(arg[1], ice.PT+kit.Ext(arg[1]), ice.PT+JS))
|
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)
|
nfs.DirDeepAll(m, ice.SRC, nfs.PWD, nil).Cut(nfs.PATH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,16 +2,15 @@ package wiki
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
const AUDIO = "audio"
|
const AUDIO = "audio"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.MergeCommands(ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
AUDIO: {Name: "audio path auto", Help: "音频", Actions: ice.MergeActions(
|
AUDIO: {Name: "audio url", Help: "音频", Actions: WordAction(
|
||||||
), Hand: func(m *ice.Message, arg ...string) {
|
`<audio {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}" controls></audio>`, nfs.PATH, ice.USR_LOCAL_IMAGE,
|
||||||
if len(arg) > 0 {
|
), Hand: func(m *ice.Message, arg ...string) { _image_show(m, arg[0], arg[1:]...) }},
|
||||||
m.Echo("<audio class='story' src='%s'></audio>", arg[0])
|
|
||||||
}
|
|
||||||
}},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
@ -2,18 +2,14 @@ package wiki
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
|
||||||
kit "shylinux.com/x/toolkits"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const BRIEF = "brief"
|
const BRIEF = "brief"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Commands: ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
BRIEF: {Name: "brief text", Help: "摘要", Hand: func(m *ice.Message, arg ...string) {
|
BRIEF: {Name: "brief text", Help: "摘要", Actions: WordAction(
|
||||||
_wiki_template(m, m.CommandKey(), "", arg[0], arg[1:]...)
|
`<p {{.OptionTemplate}}>{{.Option "text"}}</p>`,
|
||||||
}},
|
), Hand: func(m *ice.Message, arg ...string) { _wiki_template(m, "", arg[0], arg[1:]...) }},
|
||||||
}, Configs: ice.Configs{
|
})
|
||||||
BRIEF: {Name: BRIEF, Help: "摘要", Value: kit.Data(nfs.TEMPLATE, `<p {{.OptionTemplate}}>{{.Option "text"}}</p>`)},
|
|
||||||
}})
|
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ func _chart_show(m *ice.Message, kind, text string, arg ...string) {
|
|||||||
m.Option(HEIGHT, chart.GetHeight())
|
m.Option(HEIGHT, chart.GetHeight())
|
||||||
|
|
||||||
// 渲染引擎
|
// 渲染引擎
|
||||||
_wiki_template(m, CHART, "", text, arg...)
|
_wiki_template(m, "", text, arg...)
|
||||||
defer m.Echo("</svg>")
|
defer m.Echo("</svg>")
|
||||||
chart.Draw(m, 0, 0)
|
chart.Draw(m, 0, 0)
|
||||||
m.RenderResult()
|
m.RenderResult()
|
||||||
|
@ -6,8 +6,6 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
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/mdb"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
kit "shylinux.com/x/toolkits"
|
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) {
|
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)
|
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) {
|
}, WikiAction(ice.USR_LOCAL_EXPORT, nfs.CSV)), Hand: func(m *ice.Message, arg ...string) {
|
||||||
if !_wiki_list(m, m.CommandKey(), kit.Select(nfs.PWD, arg, 0)) {
|
if !_wiki_list(m, arg...) {
|
||||||
CSV(m, m.Cmd(nfs.CAT, arg[0]).Result()).StatusTimeCount()
|
CSV(m, m.Cmd(nfs.CAT, arg[0]).Result()).StatusTimeCount()
|
||||||
ctx.DisplayLocal(m, "")
|
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
func FileAction(arg ...ice.Any) ice.Actions {
|
func FileAction(arg ...ice.Any) ice.Actions {
|
||||||
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(arg...),
|
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) {
|
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)))
|
m.Cmd(nfs.SAVE, arg[0], arg[1], kit.Dict(nfs.DIR_ROOT, m.Config(nfs.PATH)))
|
||||||
}},
|
}},
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/ctx"
|
"shylinux.com/x/icebergs/base/ctx"
|
||||||
"shylinux.com/x/icebergs/base/lex"
|
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
@ -14,10 +13,8 @@ import (
|
|||||||
const DRAW = "draw"
|
const DRAW = "draw"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Configs: ice.Configs{
|
Index.MergeCommands(ice.Commands{
|
||||||
DRAW: {Name: DRAW, Help: "思维导图", Value: kit.Data(lex.REGEXP, ".*\\.svg")},
|
DRAW: {Name: "draw path=src/main.svg pid refresh:button=auto save edit actions", Help: "思维导图", Actions: ice.MergeActions(ice.Actions{
|
||||||
}, 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{
|
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmd(mdb.RENDER, mdb.CREATE, mdb.TYPE, nfs.SVG, mdb.NAME, m.PrefixKey())
|
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]))
|
m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1]))
|
||||||
}},
|
}},
|
||||||
nfs.SAVE: {Name: "save", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
|
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) {
|
}, WikiAction("", nfs.SVG), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||||
if !_wiki_list(m, DRAW, kit.Select(nfs.PWD, arg, 0)) {
|
if !_wiki_list(m, kit.Select(nfs.PWD, arg, 0)) {
|
||||||
_wiki_show(m, DRAW, arg[0])
|
_wiki_show(m, arg[0])
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
}})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,18 @@
|
|||||||
package wiki
|
package wiki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
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"
|
const FEEL = "feel"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Configs: ice.Configs{
|
Index.MergeCommands(ice.Commands{
|
||||||
FEEL: {Name: FEEL, Help: "影音媒体", Value: kit.Data(nfs.PATH, ice.USR_LOCAL_IMAGE, lex.REGEXP, ".*.(png|PNG|jpg|JPG|jpeg|mp4|m4v|MOV|webm)")},
|
FEEL: {Name: "feel path auto record1 record upload prev next actions", Help: "影音媒体", Actions: ice.MergeActions(ice.Actions{
|
||||||
}, Commands: ice.Commands{
|
"record1": {Name: "record1", Help: "截图", Hand: func(m *ice.Message, arg ...string) {}},
|
||||||
FEEL: {Name: "feel path auto record1 record upload prev next actions", Help: "影音媒体", Meta: kit.Dict(ice.DisplayLocal("")), Actions: ice.Actions{
|
"record": {Name: "record", Help: "录屏", Hand: func(m *ice.Message, arg ...string) {}},
|
||||||
"record1": {Name: "record1", 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...)
|
||||||
}},
|
}},
|
||||||
"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))
|
|
||||||
}},
|
|
||||||
}})
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
func Parse(m *ice.Message, meta string, key string, arg ...string) (data ice.Any) {
|
func Parse(m *ice.Message, meta string, key string, arg ...string) (data ice.Any) {
|
||||||
list := []string{}
|
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)
|
ls := kit.Split(line)
|
||||||
for i := 0; i < len(ls); i++ {
|
for i := 0; i < len(ls); i++ {
|
||||||
if strings.HasPrefix(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...)
|
list = append(list, ls...)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch data = kit.Parse(nil, "", list...); meta {
|
switch data = kit.Parse(nil, "", list...); meta {
|
||||||
case ice.MSG_OPTION:
|
case ice.MSG_OPTION:
|
||||||
m.Option(key, data)
|
m.Option(key, data)
|
||||||
@ -34,17 +33,13 @@ func Parse(m *ice.Message, meta string, key string, arg ...string) (data ice.Any
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
func _field_show(m *ice.Message, name, text string, arg ...string) {
|
func _field_show(m *ice.Message, name, text string, arg ...string) {
|
||||||
// 命令参数
|
|
||||||
meta, cmds := kit.Dict(), kit.Split(text)
|
meta, cmds := kit.Dict(), kit.Split(text)
|
||||||
m.Search(cmds[0], func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
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 == "" {
|
if meta[FEATURE], meta[INPUTS] = kit.Dict(cmd.Meta), cmd.List; name == "" {
|
||||||
name = cmd.Help
|
name = cmd.Help
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if len(meta) == 0 {
|
if len(meta) == 0 || !aaa.Right(m.Spawn(), cmds[0]) {
|
||||||
return
|
|
||||||
}
|
|
||||||
if !aaa.Right(m.Spawn(), cmds[0]) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +47,6 @@ func _field_show(m *ice.Message, name, text string, arg ...string) {
|
|||||||
meta[mdb.NAME], meta[mdb.INDEX] = name, text
|
meta[mdb.NAME], meta[mdb.INDEX] = name, text
|
||||||
msg := m.Spawn()
|
msg := m.Spawn()
|
||||||
|
|
||||||
// 扩展参数
|
|
||||||
for i := 0; i < len(arg)-1; i += 2 {
|
for i := 0; i < len(arg)-1; i += 2 {
|
||||||
if strings.HasPrefix(arg[i], "opts.") {
|
if strings.HasPrefix(arg[i], "opts.") {
|
||||||
kit.Value(meta, arg[i], m.Option(arg[i], strings.TrimSpace(arg[i+1])))
|
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] {
|
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:
|
case ARGS:
|
||||||
args := kit.Simple(m.Optionv(arg[i]))
|
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
kit.Fetch(meta[INPUTS], func(index int, value ice.Map) {
|
kit.Fetch(meta[INPUTS], func(index int, value ice.Map) {
|
||||||
if value[mdb.TYPE] != "button" {
|
if value[mdb.TYPE] != "button" {
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if args := kit.Simple(m.Optionv(arg[i])); len(args) > count {
|
||||||
if len(args) > count {
|
|
||||||
list := meta[INPUTS].([]ice.Any)
|
list := meta[INPUTS].([]ice.Any)
|
||||||
for i := count; i < len(args); i++ {
|
for i := count; i < len(args); i++ {
|
||||||
list = append(list, kit.Dict(mdb.TYPE, "text", mdb.NAME, ARGS, mdb.VALUE, args[i]))
|
list = append(list, kit.Dict(mdb.TYPE, "text", mdb.NAME, ARGS, mdb.VALUE, args[i]))
|
||||||
}
|
}
|
||||||
meta[INPUTS] = list
|
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:
|
default:
|
||||||
kit.Value(meta, kit.Keys(FEATURE, arg[i]), msg.Optionv(arg[i], arg[i+1]))
|
kit.Value(meta, kit.Keys(FEATURE, arg[i]), msg.Optionv(arg[i], arg[i+1]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Option(mdb.META, meta)
|
m.Option(mdb.META, meta)
|
||||||
|
_wiki_template(m, name, text)
|
||||||
// 渲染引擎
|
|
||||||
_wiki_template(m, FIELD, name, text)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -128,27 +111,21 @@ const (
|
|||||||
const FIELD = "field"
|
const FIELD = "field"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Commands: ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
FIELD: {Name: "field [name] cmd", Help: "插件", Actions: ice.MergeActions(ice.Actions{
|
FIELD: {Name: "field [name] cmd", Help: "插件", Actions: ice.MergeActions(WordAction(`<fieldset {{.OptionTemplate}}" data-meta='{{.Optionv "meta"|Format}}'>
|
||||||
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, `<fieldset {{.OptionTemplate}}" data-meta='{{.Optionv "meta"|Format}}'>
|
|
||||||
<legend>{{.Option "name"}}</legend>
|
<legend>{{.Option "name"}}</legend>
|
||||||
<form class="option"></form>
|
<form class="option"></form>
|
||||||
<div class="action"></div>
|
<div class="action"></div>
|
||||||
<div class="output"></div>
|
<div class="output"></div>
|
||||||
<div class="status"></div>
|
<div class="status"></div>
|
||||||
</fieldset>`,
|
</fieldset>`), 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:]...)
|
||||||
|
}},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
package wiki
|
package wiki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
kit "shylinux.com/x/toolkits"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func _image_show(m *ice.Message, text string) {
|
func _image_show(m *ice.Message, text string, arg ...string) {
|
||||||
_wiki_template(m, IMAGE, "", _wiki_link(m, IMAGE, text))
|
_wiki_template(m, "", _wiki_link(m, text), arg...)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -22,25 +18,9 @@ const (
|
|||||||
const IMAGE = "image"
|
const IMAGE = "image"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Commands: ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
IMAGE: {Name: "image url height auto", Help: "图片", Actions: ice.Actions{
|
IMAGE: {Name: "image url", Help: "图片", Actions: WordAction(
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
`<img {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}">`, nfs.PATH, ice.USR_LOCAL_IMAGE,
|
||||||
m.Cmd(mdb.RENDER, mdb.CREATE, PNG, m.PrefixKey())
|
), Hand: func(m *ice.Message, arg ...string) { _image_show(m, arg[0], arg[1:]...) }},
|
||||||
}},
|
})
|
||||||
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, `<img {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}" height="{{.Option "height"}}">`,
|
|
||||||
nfs.PATH, ice.USR_LOCAL_IMAGE,
|
|
||||||
)},
|
|
||||||
}})
|
|
||||||
}
|
}
|
||||||
|
@ -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, `<code {{.OptionTemplate}}>{{range $index, $value := .Optionv "input"}}{{$value}}{{end}}</code>`,
|
|
||||||
)},
|
|
||||||
}})
|
|
||||||
}
|
|
@ -5,25 +5,20 @@ import (
|
|||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _order_show(m *ice.Message, text string, arg ...string) {
|
func _order_show(m *ice.Message, text string, arg ...string) {
|
||||||
m.Optionv(mdb.LIST, kit.Split(strings.TrimSpace(text), ice.NL))
|
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"
|
const ORDER = "order"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Commands: ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
ORDER: {Name: "order `[item\n]...`", Help: "列表", Hand: func(m *ice.Message, arg ...string) {
|
ORDER: {Name: "order text", Help: "列表", Actions: WordAction(
|
||||||
_order_show(m, arg[0], arg[1:]...)
|
`<ul {{.OptionTemplate}}>{{range $index, $value := .Optionv "list"}}<li>{{$value}}</li>{{end}}</ul>`,
|
||||||
}},
|
), 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, `<ul {{.OptionTemplate}}>{{range $index, $value := .Optionv "list"}}<li>{{$value}}</li>{{end}}</ul>`,
|
|
||||||
)},
|
|
||||||
}})
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
const PARSE = "parse"
|
const PARSE = "parse"
|
||||||
|
|
||||||
func init() {
|
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) {
|
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 {
|
if len(arg) < 2 {
|
||||||
return
|
return
|
||||||
@ -28,8 +28,8 @@ func init() {
|
|||||||
if arg[1] = strings.TrimSpace(arg[1]); arg[0] == ice.AUTO {
|
if arg[1] = strings.TrimSpace(arg[1]); arg[0] == ice.AUTO {
|
||||||
if strings.HasPrefix(arg[1], "{") || strings.HasPrefix(arg[1], "[") {
|
if strings.HasPrefix(arg[1], "{") || strings.HasPrefix(arg[1], "[") {
|
||||||
arg[0] = nfs.JSON
|
arg[0] = nfs.JSON
|
||||||
} else if strings.HasPrefix(arg[1], ice.HTTP) {
|
} else if strings.HasPrefix(arg[1], web.HTTP) {
|
||||||
arg[0] = ice.HTTP
|
arg[0] = web.HTTP
|
||||||
} else if strings.Contains(arg[1], "=") {
|
} else if strings.Contains(arg[1], "=") {
|
||||||
arg[0] = web.FORM
|
arg[0] = web.FORM
|
||||||
} else if _, e := strconv.ParseInt(arg[1], 10, 64); e == nil {
|
} else if _, e := strconv.ParseInt(arg[1], 10, 64); e == nil {
|
||||||
@ -41,15 +41,12 @@ func init() {
|
|||||||
|
|
||||||
switch m.OptionFields(mdb.DETAIL); arg[0] {
|
switch m.OptionFields(mdb.DETAIL); arg[0] {
|
||||||
case "base64":
|
case "base64":
|
||||||
buf, err := base64.StdEncoding.DecodeString(arg[1])
|
if buf, err := base64.StdEncoding.DecodeString(arg[1]); err == nil {
|
||||||
if err == nil {
|
|
||||||
m.Echo(hex.EncodeToString(buf))
|
m.Echo(hex.EncodeToString(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
case nfs.JSON:
|
case nfs.JSON:
|
||||||
m.Echo(kit.Formats(kit.UnMarshal(arg[1])))
|
m.Echo(kit.Formats(kit.UnMarshal(arg[1])))
|
||||||
|
case web.HTTP:
|
||||||
case ice.HTTP:
|
|
||||||
u, _ := url.Parse(arg[1])
|
u, _ := url.Parse(arg[1])
|
||||||
m.Push(tcp.PROTO, u.Scheme)
|
m.Push(tcp.PROTO, u.Scheme)
|
||||||
m.Push(tcp.HOST, u.Host)
|
m.Push(tcp.HOST, u.Host)
|
||||||
@ -60,25 +57,20 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.EchoQRCode(arg[1])
|
m.EchoQRCode(arg[1])
|
||||||
|
|
||||||
case web.FORM:
|
case web.FORM:
|
||||||
for _, v := range kit.Split(arg[1], "&", "&", "&") {
|
for _, v := range strings.Split(arg[1], "&") {
|
||||||
ls := kit.Split(v, "=", "=", "=")
|
ls := strings.Split(v, ice.EQ)
|
||||||
key, _ := url.QueryUnescape(ls[0])
|
m.Push(kit.QueryUnescape(ls[0]), kit.QueryUnescape(kit.Select("", ls, 1)))
|
||||||
value, _ := url.QueryUnescape(kit.Select("", ls, 1))
|
|
||||||
m.Push(key, value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case mdb.TIME:
|
case mdb.TIME:
|
||||||
if i, e := strconv.ParseInt(arg[1], 10, 64); e == nil {
|
if i, e := strconv.ParseInt(arg[1], 10, 64); e == nil {
|
||||||
m.Echo(time.Unix(i, 0).Format(ice.MOD_TIME))
|
m.Echo(time.Unix(i, 0).Format(ice.MOD_TIME))
|
||||||
}
|
}
|
||||||
|
|
||||||
case mdb.LIST:
|
case mdb.LIST:
|
||||||
for i, v := range kit.Split(arg[1]) {
|
for i, v := range kit.Split(arg[1]) {
|
||||||
m.Push(kit.Format(i), v)
|
m.Push(kit.Format(i), v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
}})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,41 +1,33 @@
|
|||||||
package wiki
|
package wiki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _refer_show(m *ice.Message, text string, arg ...string) {
|
func _refer_show(m *ice.Message, text string, arg ...string) {
|
||||||
list := [][]string{}
|
list := [][]string{}
|
||||||
for _, v := range kit.Split(strings.TrimSpace(text), ice.NL, ice.NL) {
|
for _, v := range kit.SplitLine(text) {
|
||||||
if ls := kit.Split(v, " ", " "); len(ls) == 1 {
|
if ls := kit.SplitWord(v); len(ls) == 1 {
|
||||||
p, _ := url.QueryUnescape(ls[0])
|
p := kit.QueryUnescape(ls[0])
|
||||||
list = append(list, []string{kit.Select(ls[0], path.Base(p)), ls[0], p})
|
list = append(list, []string{kit.Select(ls[0], path.Base(p)), ls[0], p})
|
||||||
} else {
|
} else {
|
||||||
p, _ := url.QueryUnescape(ls[1])
|
list = append(list, append(ls, kit.QueryUnescape(ls[1])))
|
||||||
list = append(list, append(ls, p))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Optionv(mdb.LIST, list)
|
m.Optionv(mdb.LIST, list)
|
||||||
_wiki_template(m, REFER, "", text, arg...)
|
_wiki_template(m, "", text, arg...)
|
||||||
}
|
}
|
||||||
|
|
||||||
const REFER = "refer"
|
const REFER = "refer"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Commands: ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
REFER: {Name: "refer `[[name] url\n]...`", Help: "参考", Hand: func(m *ice.Message, arg ...string) {
|
REFER: {Name: "refer text", Help: "参考", Actions: WordAction(
|
||||||
_refer_show(m, arg[0], arg[1:]...)
|
`<ul {{.OptionTemplate}}>{{range $index, $value := .Optionv "list"}}<li>{{index $value 0}}: <a href="{{index $value 1}}" data-name="{{index $value 0}}" target="_blank">{{index $value 2}}</a></li>{{end}}</ul>`,
|
||||||
}},
|
), 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, `<ul {{.OptionTemplate}}>{{range $index, $value := .Optionv "list"}}<li>{{index $value 0}}: <a href="{{index $value 1}}" data-name="{{index $value 0}}" target="_blank">{{index $value 2}}</a></li>{{end}}</ul>`,
|
|
||||||
)},
|
|
||||||
}})
|
|
||||||
}
|
}
|
||||||
|
@ -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, `<code {{.OptionTemplate}}>$ {{.Option "input"}} # {{.Option "name"}}
|
|
||||||
{{.Option "output"}}</code>`,
|
|
||||||
)},
|
|
||||||
}})
|
|
||||||
}
|
|
@ -9,41 +9,37 @@ import (
|
|||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _spark_show(m *ice.Message, name, text string, arg ...string) {
|
func _spark_show(m *ice.Message, name, text string, arg ...string) *ice.Message {
|
||||||
for i := 0; i < len(arg); i += 2 {
|
if _option(m, m.CommandKey(), name, text, arg...); name == "" {
|
||||||
m.Option(arg[i], arg[i+1])
|
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(`<div class="story" data-type="spark" data-name="%s" style="%s">`, name, m.Option("style"))
|
m.Echo(`<div class="story" data-type="spark" data-name="%s" style="%s">`, name, m.Option("style"))
|
||||||
defer m.Echo("</div>")
|
defer m.Echo("</div>")
|
||||||
|
|
||||||
switch name {
|
switch name {
|
||||||
case "inner", "field":
|
case "inner", "field":
|
||||||
m.Echo(text)
|
return m.Echo(text)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)))
|
m.Echo(Format("div", Format("label", prompt), Format("span", l)))
|
||||||
}
|
}
|
||||||
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PROMPT = "prompt"
|
PROMPT = "prompt"
|
||||||
BREAK = "break"
|
BREAK = "break"
|
||||||
|
SHELL = "shell"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SPARK = "spark"
|
const SPARK = "spark"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Commands: ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
SPARK: {Name: "spark [name] text auto field:text value:text", Help: "段落", Actions: ice.Actions{
|
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.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
ice.AddRender(ice.RENDER_SCRIPT, func(m *ice.Message, cmd string, args ...ice.Any) string {
|
ice.AddRender(ice.RENDER_SCRIPT, func(m *ice.Message, cmd string, args ...ice.Any) string {
|
||||||
arg := kit.Simple(args...)
|
arg := kit.Simple(args...)
|
||||||
@ -57,19 +53,10 @@ func init() {
|
|||||||
arg = []string{SHELL, arg[0]}
|
arg = []string{SHELL, arg[0]}
|
||||||
}
|
}
|
||||||
list := []string{kit.Format(`<div class="story" data-type="spark" data-name="%s">`, arg[0])}
|
list := []string{kit.Format(`<div class="story" data-type="spark" data-name="%s">`, arg[0])}
|
||||||
for _, l := range strings.Split(strings.Join(arg[1:], ice.NL), ice.NL) {
|
for _, l := range kit.SplitLine(strings.Join(arg[1:], ice.NL)) {
|
||||||
list = append(list, "<div>")
|
list = append(list, "<div>", Format("label", kit.Select("> ", "$ ", arg[0] == SHELL)), Format("span", l), "</div>")
|
||||||
switch arg[0] {
|
|
||||||
case SHELL:
|
|
||||||
list = append(list, Format("label", "$ "))
|
|
||||||
default:
|
|
||||||
list = append(list, Format("label", "> "))
|
|
||||||
}
|
}
|
||||||
list = append(list, Format("span", l))
|
return strings.Join(append(list, "</div>"), "")
|
||||||
list = append(list, "</div>")
|
|
||||||
}
|
|
||||||
list = append(list, "</div>")
|
|
||||||
return strings.Join(list, "")
|
|
||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
"md": {Name: "md file", Help: "md", Hand: func(m *ice.Message, arg ...string) {
|
"md": {Name: "md file", Help: "md", Hand: func(m *ice.Message, arg ...string) {
|
||||||
@ -102,35 +89,23 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch block {
|
|
||||||
case "":
|
|
||||||
code = append(code, line)
|
code = append(code, line)
|
||||||
default:
|
|
||||||
code = append(code, line)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
text()
|
text()
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, arg ...string) {
|
}, WordAction(`<p {{.OptionTemplate}}>{{.Option "text"}}</p>`, ssh.PROMPT, kit.Dict(SHELL, "$ "))), Hand: func(m *ice.Message, arg ...string) {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
m.Echo(`<br class="story" data-type="spark">`)
|
m.Echo(`<br class="story" data-type="spark">`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch kit.Ext(arg[0]) {
|
if kit.Ext(arg[0]) == "md" {
|
||||||
case "md":
|
|
||||||
m.Cmdy(SPARK, "md", arg)
|
m.Cmdy(SPARK, "md", arg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
arg = _name(m, arg)
|
arg = _name(m, arg)
|
||||||
_spark_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...)
|
_spark_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...)
|
||||||
}},
|
}},
|
||||||
}, Configs: ice.Configs{
|
})
|
||||||
SPARK: {Name: SPARK, Help: "段落", Value: kit.Data(
|
|
||||||
nfs.TEMPLATE, `<p {{.OptionTemplate}}>{{.Option "text"}}</p>`,
|
|
||||||
ssh.PROMPT, kit.Dict(SHELL, "$ "),
|
|
||||||
)},
|
|
||||||
}})
|
|
||||||
}
|
}
|
||||||
func Format(tag string, arg ...ice.Any) string {
|
func Format(tag string, arg ...ice.Any) string {
|
||||||
return kit.Format("<%s>%s</%s>", tag, strings.Join(kit.Simple(arg), ""), tag)
|
return kit.Format("<%s>%s</%s>", tag, strings.Join(kit.Simple(arg), ""), tag)
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,7 +15,6 @@ func _table_run(m *ice.Message, arg ...string) {
|
|||||||
if index == 0 {
|
if index == 0 {
|
||||||
m.Optionv("head", head)
|
m.Optionv("head", head)
|
||||||
}
|
}
|
||||||
|
|
||||||
line := []string{}
|
line := []string{}
|
||||||
for _, h := range head {
|
for _, h := range head {
|
||||||
line = append(line, value[h])
|
line = append(line, value[h])
|
||||||
@ -24,18 +22,17 @@ func _table_run(m *ice.Message, arg ...string) {
|
|||||||
list = append(list, line)
|
list = append(list, line)
|
||||||
})
|
})
|
||||||
m.Optionv("list", list)
|
m.Optionv("list", list)
|
||||||
|
_wiki_template(m, "", "")
|
||||||
_wiki_template(m, TABLE, "", "")
|
|
||||||
}
|
}
|
||||||
func _table_show(m *ice.Message, text string, arg ...string) {
|
func _table_show(m *ice.Message, text string, arg ...string) {
|
||||||
head, list := []string{}, [][]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 {
|
if v = strings.ReplaceAll(v, "%", "%%"); i == 0 {
|
||||||
head = kit.Split(v)
|
head = kit.SplitWord(v)
|
||||||
} else {
|
} else {
|
||||||
line := kit.Split(v)
|
line := kit.SplitWord(v)
|
||||||
for i, v := range line {
|
for i, v := range line {
|
||||||
if ls := kit.Split(v); len(ls) > 1 {
|
if ls := kit.SplitWord(v); len(ls) > 1 {
|
||||||
style := []string{}
|
style := []string{}
|
||||||
for i := 1; i < len(ls)-1; i += 2 {
|
for i := 1; i < len(ls)-1; i += 2 {
|
||||||
switch ls[i] {
|
switch ls[i] {
|
||||||
@ -54,29 +51,18 @@ func _table_show(m *ice.Message, text string, arg ...string) {
|
|||||||
}
|
}
|
||||||
m.Optionv("head", head)
|
m.Optionv("head", head)
|
||||||
m.Optionv("list", list)
|
m.Optionv("list", list)
|
||||||
|
_wiki_template(m, "", text, arg...)
|
||||||
_wiki_template(m, TABLE, "", text, arg...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const TABLE = "table"
|
const TABLE = "table"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Commands: ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
TABLE: {Name: "table `[item item\n]...`", Help: "表格", Actions: ice.Actions{
|
TABLE: {Name: "table text", Help: "表格", Actions: ice.MergeActions(ice.Actions{
|
||||||
ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
|
ice.RUN: {Name: "run", Hand: func(m *ice.Message, arg ...string) { _table_run(m, arg...) }},
|
||||||
_table_run(m, arg...)
|
}, WordAction(`<table {{.OptionTemplate}}>
|
||||||
}},
|
|
||||||
}, 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, `<table {{.OptionTemplate}}>
|
|
||||||
<tr>{{range $i, $v := .Optionv "head"}}<th>{{$v}}</th>{{end}}</tr>
|
<tr>{{range $i, $v := .Optionv "head"}}<th>{{$v}}</th>{{end}}</tr>
|
||||||
{{range $index, $value := .Optionv "list"}}
|
{{range $index, $value := .Optionv "list"}}<tr>{{range $i, $v := $value}}<td>{{$v}}</td>{{end}}</tr>{{end}}
|
||||||
<tr>{{range $i, $v := $value}}<td>{{$v}}</td>{{end}}</tr>
|
</table>`)), Hand: func(m *ice.Message, arg ...string) { _table_show(m, arg[0], arg[1:]...) }},
|
||||||
{{end}}
|
})
|
||||||
</table>`,
|
|
||||||
)},
|
|
||||||
}})
|
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
switch title, _ := m.Optionv(TITLE).(map[string]int); kind {
|
||||||
case NAVMENU: // 导航目录
|
case NAVMENU:
|
||||||
_option(m, kind, "", text, arg...)
|
m.Option(mdb.DATA, _title_parse(m, path.Dir(m.Option(ice.MSG_SCRIPT)), text))
|
||||||
data := _title_parse(m, path.Dir(m.Option(ice.MSG_SCRIPT)), text)
|
return _option(m, kind, "", text, arg...).RenderTemplate(m.Config(kind), &Message{m})
|
||||||
m.RenderTemplate(kit.Format("<div {{.OptionTemplate}} data-data='%s'></div>", data), &Message{m})
|
case PREMENU:
|
||||||
return
|
return _option(m, kind, "", "", arg...).RenderTemplate(m.Config(kind), &Message{m})
|
||||||
|
case ENDMENU:
|
||||||
case PREMENU: // 前置目录
|
return _option(m, kind, "", "", arg...).RenderTemplate(m.Config(kind), &Message{m})
|
||||||
_option(m, kind, "", "", arg...)
|
case SECTION:
|
||||||
m.RenderTemplate(m.Config(kind), &Message{m})
|
|
||||||
return
|
|
||||||
|
|
||||||
case ENDMENU: // 后置目录
|
|
||||||
_option(m, kind, "", "", arg...)
|
|
||||||
m.RenderTemplate(m.Config(kind), &Message{m})
|
|
||||||
return
|
|
||||||
|
|
||||||
case SECTION: // 分节标题
|
|
||||||
title[SECTION]++
|
title[SECTION]++
|
||||||
m.Option(LEVEL, "h3")
|
m.Option(LEVEL, "h3")
|
||||||
m.Option(PREFIX, kit.Format("%d.%d ", title[CHAPTER], title[SECTION]))
|
m.Option(PREFIX, kit.Format("%d.%d ", title[CHAPTER], title[SECTION]))
|
||||||
|
case CHAPTER:
|
||||||
case CHAPTER: // 章节标题
|
|
||||||
title[CHAPTER]++
|
title[CHAPTER]++
|
||||||
title[SECTION] = 0
|
title[SECTION] = 0
|
||||||
m.Option(LEVEL, "h2")
|
m.Option(LEVEL, "h2")
|
||||||
m.Option(PREFIX, kit.Format("%d ", title[CHAPTER]))
|
m.Option(PREFIX, kit.Format("%d ", title[CHAPTER]))
|
||||||
|
default:
|
||||||
default: // 文章标题
|
|
||||||
m.Option(LEVEL, "h1")
|
m.Option(LEVEL, "h1")
|
||||||
m.Option(PREFIX, "")
|
m.Option(PREFIX, "")
|
||||||
}
|
}
|
||||||
|
_wiki_template(m, "", text, arg...)
|
||||||
// 渲染引擎
|
|
||||||
_wiki_template(m, TITLE, "", text, arg...)
|
|
||||||
|
|
||||||
// 添加目录
|
|
||||||
menu, _ := m.Optionv(MENU).(ice.Map)
|
menu, _ := m.Optionv(MENU).(ice.Map)
|
||||||
menu[mdb.LIST] = append(menu[mdb.LIST].([]ice.Any), kit.Dict(m.OptionSimple("level,prefix,text")))
|
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 (
|
const (
|
||||||
NAVMENU = "navmenu"
|
NAVMENU = "navmenu"
|
||||||
PREMENU = "premenu"
|
PREMENU = "premenu"
|
||||||
@ -68,20 +59,17 @@ const (
|
|||||||
SECTION = "section"
|
SECTION = "section"
|
||||||
ENDMENU = "endmenu"
|
ENDMENU = "endmenu"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
PREFIX = "prefix"
|
|
||||||
LEVEL = "level"
|
|
||||||
MENU = "menu"
|
|
||||||
)
|
|
||||||
const TITLE = "title"
|
const TITLE = "title"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Commands: ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
TITLE: {Name: "title [navmenu|premenu|chapter|section|endmenu] text", Help: "标题", Hand: func(m *ice.Message, arg ...string) {
|
TITLE: {Name: "title [navmenu|premenu|chapter|section|endmenu] text", Actions: WordAction(
|
||||||
if len(arg) == 0 {
|
`<{{.Option "level"}} {{.OptionTemplate}}>{{.Option "prefix"}} {{.Option "text"}}</{{.Option "level"}}>`,
|
||||||
arg = append(arg, kit.Slice(kit.Split(ice.Info.NodeName, "-"), -1)[0])
|
NAVMENU, `<div {{.OptionTemplate}} data-data='{{.Option "data"}}'></div>`,
|
||||||
}
|
PREMENU, `<ul {{.OptionTemplate}}></ul>`,
|
||||||
|
ENDMENU, `<ul {{.OptionTemplate}}>{{$menu := .Optionv "menu"}}
|
||||||
|
{{range $index, $value := Value $menu "list"}}<li>{{Value $value "prefix"}} {{Value $value "text"}}</li>{{end}}
|
||||||
|
</ul>`), Help: "标题", Hand: func(m *ice.Message, arg ...string) {
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
case NAVMENU:
|
case NAVMENU:
|
||||||
_title_show(m, arg[0], arg[1], arg[2:]...)
|
_title_show(m, arg[0], arg[1], arg[2:]...)
|
||||||
@ -93,13 +81,5 @@ func init() {
|
|||||||
_title_show(m, "", arg[0], arg[1:]...)
|
_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"}}</{{.Option "level"}}>`,
|
|
||||||
PREMENU, `<ul {{.OptionTemplate}}></ul>`,
|
|
||||||
ENDMENU, `<ul {{.OptionTemplate}}>{{$menu := .Optionv "menu"}}
|
|
||||||
{{range $index, $value := Value $menu "list"}}<li>{{Value $value "prefix"}} {{Value $value "text"}}</li>{{end}}
|
|
||||||
</ul>`,
|
|
||||||
)},
|
|
||||||
}})
|
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,21 @@
|
|||||||
package wiki
|
package wiki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"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 (
|
const (
|
||||||
mp4 = "mp4"
|
mp4 = "mp4"
|
||||||
m4v = "m4v"
|
m4v = "m4v"
|
||||||
MOV = "mov"
|
MOV = "mov"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VIDEO = "video"
|
const VIDEO = "video"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Commands: ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
VIDEO: {Name: "video url", Help: "视频", Actions: ice.Actions{
|
VIDEO: {Name: "video url", Help: "视频", Actions: WordAction(
|
||||||
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
`<video {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}" controls></video>`, nfs.PATH, ice.USR_LOCAL_IMAGE,
|
||||||
_video_show(m, path.Join(arg[2], arg[1]))
|
), Hand: func(m *ice.Message, arg ...string) { _image_show(m, arg[0], 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, `<video {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}" controls></video>`,
|
|
||||||
)},
|
|
||||||
}})
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/ctx"
|
"shylinux.com/x/icebergs/base/ctx"
|
||||||
|
"shylinux.com/x/icebergs/base/lex"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
"shylinux.com/x/icebergs/base/web"
|
"shylinux.com/x/icebergs/base/web"
|
||||||
@ -18,7 +19,7 @@ func _name(m *ice.Message, arg []string) []string {
|
|||||||
}
|
}
|
||||||
return arg
|
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.TYPE, kind)
|
||||||
m.Option(mdb.NAME, name)
|
m.Option(mdb.NAME, name)
|
||||||
m.Option(mdb.TEXT, text)
|
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 {
|
for i := 0; i < len(arg); i += 2 {
|
||||||
extra[arg[i]] = kit.Format(kit.Parse(nil, "", kit.Split(arg[i+1])...))
|
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 {
|
func _wiki_path(m *ice.Message, arg ...string) string {
|
||||||
return path.Join(m.Conf(cmd, kit.Keym(nfs.PATH)), path.Join(arg...))
|
return path.Join(m.Config(nfs.PATH), path.Join(arg...))
|
||||||
}
|
}
|
||||||
func _wiki_link(m *ice.Message, cmd string, text string) string {
|
func _wiki_link(m *ice.Message, text string) string {
|
||||||
if !strings.HasPrefix(text, ice.HTTP) && !strings.HasPrefix(text, ice.PS) {
|
if !strings.HasPrefix(text, ice.PS) && !strings.HasPrefix(text, ice.HTTP) {
|
||||||
text = path.Join(web.SHARE_LOCAL, _wiki_path(m, cmd, text))
|
text = path.Join(web.SHARE_LOCAL, _wiki_path(m, text))
|
||||||
}
|
}
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
func _wiki_list(m *ice.Message, cmd string, arg ...string) bool {
|
func _wiki_list(m *ice.Message, arg ...string) bool {
|
||||||
m.Option(nfs.DIR_ROOT, _wiki_path(m, cmd))
|
if m.Option(nfs.DIR_ROOT, _wiki_path(m)); len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) {
|
||||||
if len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) {
|
if m.Option(nfs.DIR_DEEP) != ice.TRUE {
|
||||||
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.DIR)
|
|
||||||
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)))
|
||||||
// 文件列表
|
|
||||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
|
||||||
m.Cmdy(nfs.DIR, kit.Select(nfs.PWD, arg, 0))
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
ctx.DisplayLocal(m, path.Join(kit.PathName(2), kit.Keys(kit.FileName(2), ice.JS)))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func _wiki_show(m *ice.Message, cmd, name string, arg ...string) {
|
func _wiki_show(m *ice.Message, name string, arg ...string) {
|
||||||
m.Option(nfs.DIR_ROOT, _wiki_path(m, cmd))
|
m.Cmdy(nfs.CAT, name, kit.Dict(nfs.DIR_ROOT, _wiki_path(m)))
|
||||||
m.Cmdy(nfs.CAT, name)
|
|
||||||
}
|
}
|
||||||
func _wiki_save(m *ice.Message, cmd, name, text string, arg ...string) {
|
func _wiki_save(m *ice.Message, name, text string, arg ...string) {
|
||||||
m.Option(nfs.DIR_ROOT, _wiki_path(m, cmd))
|
m.Cmd(nfs.SAVE, name, text, kit.Dict(nfs.DIR_ROOT, _wiki_path(m)))
|
||||||
m.Cmd(nfs.SAVE, name, text)
|
|
||||||
}
|
}
|
||||||
func _wiki_upload(m *ice.Message, cmd string, dir string) {
|
func _wiki_upload(m *ice.Message, dir string) {
|
||||||
m.Cmdy(web.CACHE, web.UPLOAD_WATCH, _wiki_path(m, cmd, dir))
|
m.Cmdy(web.CACHE, web.UPLOAD_WATCH, _wiki_path(m, dir))
|
||||||
}
|
}
|
||||||
func _wiki_template(m *ice.Message, cmd string, name, text string, arg ...string) {
|
func _wiki_template(m *ice.Message, name, text string, arg ...string) *ice.Message {
|
||||||
_option(m, cmd, name, strings.TrimSpace(text), arg...)
|
return _option(m, m.CommandKey(), name, strings.TrimSpace(text), arg...).RenderTemplate(m.Config(nfs.TEMPLATE), &Message{m})
|
||||||
m.RenderTemplate(m.Conf(cmd, kit.Keym(nfs.TEMPLATE)), &Message{m})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const WIKI = "wiki"
|
const WIKI = "wiki"
|
||||||
@ -76,36 +71,54 @@ var Index = &ice.Context{Name: WIKI, Help: "文档中心"}
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
web.Index.Register(Index, &web.Frame{},
|
web.Index.Register(Index, &web.Frame{},
|
||||||
TITLE, BRIEF, REFER, SPARK, CHART,
|
TITLE, BRIEF, REFER, SPARK, FIELD, PARSE,
|
||||||
ORDER, TABLE, IMAGE, VIDEO,
|
ORDER, TABLE, CHART, IMAGE, VIDEO, AUDIO,
|
||||||
FIELD, SHELL, LOCAL, PARSE,
|
|
||||||
FEEL, DRAW, WORD, DATA,
|
FEEL, DRAW, WORD, DATA,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Message struct {
|
func WikiAction(dir string, ext ...string) ice.Actions {
|
||||||
*ice.Message
|
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 {
|
func (m *Message) OptionTemplate() string {
|
||||||
res := []string{`class="story"`}
|
res := []string{`class="story"`}
|
||||||
for _, key := range kit.Split(ctx.STYLE) {
|
add := func(pre, key string) {
|
||||||
if m.Option(key) != "" {
|
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") {
|
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
|
continue
|
||||||
}
|
}
|
||||||
if m.Option(key) != "" {
|
add("data-", key)
|
||||||
res = append(res, kit.Format(`data-%s="%s"`, key, m.Option(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)
|
return kit.Join(res, ice.SP)
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,22 @@
|
|||||||
|
wiki.shy
|
||||||
|
wiki.go
|
||||||
|
word.go
|
||||||
|
|
||||||
title.go
|
title.go
|
||||||
brief.go
|
brief.go
|
||||||
refer.go
|
refer.go
|
||||||
spark.go
|
spark.go
|
||||||
chart.go
|
field.go
|
||||||
|
parse.go
|
||||||
|
|
||||||
order.go
|
order.go
|
||||||
table.go
|
table.go
|
||||||
|
chart.go
|
||||||
image.go
|
image.go
|
||||||
video.go
|
video.go
|
||||||
|
audio.go
|
||||||
field.go
|
|
||||||
shell.go
|
|
||||||
local.go
|
|
||||||
parse.go
|
|
||||||
|
|
||||||
feel.go
|
feel.go
|
||||||
draw.go
|
draw.go
|
||||||
word.go
|
|
||||||
data.go
|
data.go
|
||||||
json.go
|
|
||||||
|
|
||||||
wiki.go
|
|
||||||
wiki.shy
|
|
||||||
|
@ -1,112 +1,69 @@
|
|||||||
package wiki
|
package wiki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/aaa"
|
"shylinux.com/x/icebergs/base/aaa"
|
||||||
"shylinux.com/x/icebergs/base/ctx"
|
"shylinux.com/x/icebergs/base/ctx"
|
||||||
"shylinux.com/x/icebergs/base/lex"
|
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
"shylinux.com/x/icebergs/base/web"
|
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _word_show(m *ice.Message, name string, arg ...string) {
|
func _word_show(m *ice.Message, name string, arg ...string) {
|
||||||
m.SetResult()
|
m.SetResult()
|
||||||
|
defer m.StatusTime()
|
||||||
m.Option(TITLE, map[string]int{})
|
m.Option(TITLE, map[string]int{})
|
||||||
m.Option(MENU, kit.Dict(mdb.LIST, kit.List()))
|
m.Option(MENU, kit.Dict(mdb.LIST, kit.List()))
|
||||||
m.Option(ice.MSG_ALIAS, m.Configv(mdb.ALIAS))
|
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"
|
const WORD = "word"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Configs: ice.Configs{
|
Index.MergeCommands(ice.Commands{
|
||||||
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{
|
|
||||||
WORD: {Name: "word path=src/main.shy@key list play", Help: "笔记文档", Actions: ice.MergeActions(ice.Actions{
|
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) {
|
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, m.PrefixKey())
|
||||||
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, ice.SRC_MAIN_SHY)
|
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) {
|
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.Option(nfs.DIR_DEEP, ice.TRUE)
|
||||||
m.ProcessAgain()
|
for _, p := range []string{"src/", "usr/icebergs/", "usr/learning/", "usr/linux-story/", "usr/nginx-story/", "usr/golang-story/", "usr/redis-story/", "usr/mysql-story/"} {
|
||||||
return
|
_wiki_list(m, p)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}},
|
}}, "play": {Name: "play", Help: "演示"},
|
||||||
ice.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
ice.STORY: {Name: "story", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(arg[0], ice.RUN, arg[2:]) }},
|
||||||
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 {
|
||||||
"play": {Name: "play", Help: "演示"},
|
|
||||||
}, ctx.CmdAction(), mdb.HashAction()), Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
if len(arg) == 0 {
|
|
||||||
arg = append(arg, "src/")
|
arg = append(arg, "src/")
|
||||||
}
|
}
|
||||||
m.Option(nfs.DIR_REG, m.Config(lex.REGEXP))
|
if !_wiki_list(m, arg...) {
|
||||||
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, "")
|
|
||||||
_word_show(m, arg[0])
|
_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])
|
||||||
|
}
|
||||||
|
}}}
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,17 @@ func (w WebView) OpenCmd(cmd string) {
|
|||||||
func (w WebView) SetSize(width, height int) {
|
func (w WebView) SetSize(width, height int) {
|
||||||
w.Cmd(nfs.SAVE, "etc/webview.size", kit.Format("%v,%v", width, height))
|
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) Terminate() { w.WebView.Terminate() }
|
||||||
func (w WebView) Close() {
|
func (w WebView) Close() {
|
||||||
if !w.Menu() {
|
if !w.Menu() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user