1
0
forked from x/icebergs
This commit is contained in:
shylinux 2020-06-13 19:02:23 +08:00
parent 9fce461628
commit 5979129951
4 changed files with 72 additions and 20 deletions

View File

@ -165,6 +165,21 @@ func travel(m *ice.Message, root string, name string, cb func(name string)) {
} }
} }
func _nfs_save(m *ice.Message, file string, text ...string) {
if f, p, e := kit.Create(file); m.Assert(e) {
defer f.Close()
for _, v := range text {
if n, e := f.WriteString(v); m.Assert(e) {
m.Log_EXPORT("file", p, "size", n)
}
}
m.Echo(p)
}
}
func Save(m *ice.Message, file string, text ...string) {
_nfs_save(m, file, text...)
}
var Index = &ice.Context{Name: "nfs", Help: "存储模块", var Index = &ice.Context{Name: "nfs", Help: "存储模块",
Caches: map[string]*ice.Cache{}, Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
@ -271,15 +286,7 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
}}, }},
"save": {Name: "save path text...", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "save": {Name: "save path text...", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, p, e := kit.Create(arg[0]); m.Assert(e) { _nfs_save(m, arg[0], arg[1:]...)
defer f.Close()
for _, v := range arg[1:] {
if n, e := f.WriteString(v); m.Assert(e) {
m.Log("export", "%v: %v", n, p)
m.Echo(p)
}
}
}
}}, }},
"copy": {Name: "copy path file...", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "copy": {Name: "copy path file...", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, _, e := kit.Create(arg[0]); m.Assert(e) { if f, _, e := kit.Create(arg[0]); m.Assert(e) {

View File

@ -12,8 +12,15 @@ import (
const ( const (
INNER = "inner" INNER = "inner"
QRCODE = "qrcode"
VEDIO = "vedio" VEDIO = "vedio"
QRCODE = "qrcode"
)
const (
LIST = "list"
SAVE = "save"
PLUG = "plug"
SHOW = "show"
) )
func _inner_protect(m *ice.Message, name string) bool { func _inner_protect(m *ice.Message, name string) bool {
@ -40,7 +47,7 @@ func _inner_sub(m *ice.Message, action string, name string, arg ...string) bool
} }
func _inner_list(m *ice.Message, name string) { func _inner_list(m *ice.Message, name string) {
if _inner_sub(m, "list", name) { if _inner_sub(m, LIST, name) {
return return
} }
@ -51,7 +58,7 @@ func _inner_list(m *ice.Message, name string) {
m.Echo(name) m.Echo(name)
} }
func _inner_save(m *ice.Message, name, text string) { func _inner_save(m *ice.Message, name, text string) {
if _inner_sub(m, "save", name) { if _inner_sub(m, SAVE, name) {
return return
} }
@ -64,7 +71,7 @@ func _inner_save(m *ice.Message, name, text string) {
} }
} }
func _inner_plug(m *ice.Message, name string) { func _inner_plug(m *ice.Message, name string) {
if _inner_sub(m, "plug", name) { if _inner_sub(m, PLUG, name) {
return return
} }
@ -77,7 +84,7 @@ func _inner_plug(m *ice.Message, name string) {
m.Echo("{}") m.Echo("{}")
} }
func _inner_show(m *ice.Message, name string) { func _inner_show(m *ice.Message, name string) {
if _inner_sub(m, "show", name) { if _inner_sub(m, SHOW, name) {
return return
} }
@ -129,7 +136,7 @@ func init() {
)}, )},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
INNER: {Name: "inner path=tmp name=hi.qrc key auto", Help: "编辑器", Meta: map[string]interface{}{ INNER: {Name: "inner path=tmp file=hi.qrc key auto", Help: "编辑器", Meta: map[string]interface{}{
"display": "/plugin/local/code/inner.js", "style": "editor", "display": "/plugin/local/code/inner.js", "style": "editor",
}, Action: map[string]*ice.Action{ }, Action: map[string]*ice.Action{
"cmd": {Name: "cmd arg", Help: "命令", Hand: func(m *ice.Message, arg ...string) { "cmd": {Name: "cmd arg", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
@ -186,10 +193,10 @@ func init() {
"run": {Name: "run path name", Help: "运行", Hand: func(m *ice.Message, arg ...string) { "run": {Name: "run path name", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
_inner_show(m, path.Join("./", arg[0], arg[1])) _inner_show(m, path.Join("./", arg[0], arg[1]))
}}, }},
"plug": {Name: "plug path name", Help: "插件", Hand: func(m *ice.Message, arg ...string) { PLUG: {Name: "plug path name", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
_inner_plug(m, path.Join("./", arg[0], arg[1])) _inner_plug(m, path.Join("./", arg[0], arg[1]))
}}, }},
"save": {Name: "save path name content", Help: "保存", Hand: func(m *ice.Message, arg ...string) { SAVE: {Name: "save path name content", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
_inner_save(m, path.Join("./", arg[0], arg[1]), kit.Select(m.Option("content"), arg, 2)) _inner_save(m, path.Join("./", arg[0], arg[1]), kit.Select(m.Option("content"), arg, 2))
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { _inner_main(m, arg...) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { _inner_main(m, arg...) }},

View File

@ -27,8 +27,8 @@ func init() {
if file, e := avutil.Open(arg[0]); m.Assert(e) { if file, e := avutil.Open(arg[0]); m.Assert(e) {
if streams, e := file.Streams(); m.Assert(e) { if streams, e := file.Streams(); m.Assert(e) {
for _, stream := range streams { for _, stream := range streams {
m.Info("what %v", kit.Formats(stream))
if stream.Type().IsAudio() { if stream.Type().IsAudio() {
} else if stream.Type().IsVideo() { } else if stream.Type().IsVideo() {
vstream := stream.(av.VideoCodecData) vstream := stream.(av.VideoCodecData)
m.Push("type", vstream.Type().String()) m.Push("type", vstream.Type().String())

View File

@ -2,6 +2,7 @@ package wiki
import ( import (
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/nfs"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"path" "path"
@ -11,8 +12,20 @@ const (
DRAW = "draw" DRAW = "draw"
) )
func _draw_show(m *ice.Message, zone, kind, name, text string, arg ...string) {
m.Cmdy(kit.Keys(zone, kind), name, text, arg)
}
func _draw_plugin(m *ice.Message, arg ...string) {
m.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
if m.Target() == s {
return
}
m.Push(s.Name, cmd.Name)
})
}
func init() { func init() {
Index.Merge(&ice.Context{ sub := &ice.Context{Name: "draw", Help: "思维导图",
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
DRAW: {Name: "draw", Help: "思维导图", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.svg", DRAW: {Name: "draw", Help: "思维导图", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.svg",
"prefix", `<svg vertion="1.1" xmlns="http://www.w3.org/2000/svg" width="%v" height="%v">`, "suffix", `</svg>`, "prefix", `<svg vertion="1.1" xmlns="http://www.w3.org/2000/svg" width="%v" height="%v">`, "suffix", `</svg>`,
@ -23,11 +36,36 @@ func init() {
"display", "/plugin/local/wiki/draw.js", "display", "/plugin/local/wiki/draw.js",
), Action: map[string]*ice.Action{ ), Action: map[string]*ice.Action{
"save": {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) { "save": {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
m.Cmd("nfs.save", path.Join(m.Conf(DRAW, "meta.path"), kit.Select("hi.svg", arg[0])), arg[1:]) nfs.Save(m, path.Join(m.Conf(DRAW, "meta.path"), kit.Select("hi.svg", arg, 0)), kit.Select(m.Option("content"), arg, 1))
}},
"run": {Name: "show path text", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
_draw_show(m, arg[0], arg[1], arg[2], arg[3], arg[4:]...)
}},
"plugin": {Name: "plugin", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
_draw_plugin(m, arg...)
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
reply(m, cmd, arg...) reply(m, cmd, arg...)
}}, }},
}, },
}
sub.Register(&ice.Context{Name: "创业", Help: "创业",
Commands: map[string]*ice.Command{
"项目开发": {Name: "项目开发", Help: "项目开发", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
m.Echo("hello world")
}},
"项目测试": {Name: "项目测试", Help: "项目测试", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
}},
"改变世界": {Name: "改变世界", Help: "改变世界", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
m.Echo("hello world")
}},
"认识世界": {Name: "认识世界", Help: "认识世界", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
m.Echo("hello world")
}},
},
}, nil) }, nil)
Index.Register(sub, nil)
} }