From 5979129951592ee5b81f2aa49adb7d1ecc75e048 Mon Sep 17 00:00:00 2001 From: shylinux Date: Sat, 13 Jun 2020 19:02:23 +0800 Subject: [PATCH] opt draw --- base/nfs/nfs.go | 25 ++++++++++++++++--------- core/code/inner.go | 23 +++++++++++++++-------- core/code/video.go | 2 +- core/wiki/draw.go | 42 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 72 insertions(+), 20 deletions(-) diff --git a/base/nfs/nfs.go b/base/nfs/nfs.go index c4cc77c6..e921478e 100644 --- a/base/nfs/nfs.go +++ b/base/nfs/nfs.go @@ -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: "存储模块", Caches: map[string]*ice.Cache{}, 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) { - if f, p, e := kit.Create(arg[0]); m.Assert(e) { - 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) - } - } - } + _nfs_save(m, arg[0], arg[1:]...) }}, "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) { diff --git a/core/code/inner.go b/core/code/inner.go index 5499f0e2..f11f8ab8 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -12,8 +12,15 @@ import ( const ( INNER = "inner" - QRCODE = "qrcode" VEDIO = "vedio" + QRCODE = "qrcode" +) + +const ( + LIST = "list" + SAVE = "save" + PLUG = "plug" + SHOW = "show" ) 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) { - if _inner_sub(m, "list", name) { + if _inner_sub(m, LIST, name) { return } @@ -51,7 +58,7 @@ func _inner_list(m *ice.Message, name string) { m.Echo(name) } func _inner_save(m *ice.Message, name, text string) { - if _inner_sub(m, "save", name) { + if _inner_sub(m, SAVE, name) { return } @@ -64,7 +71,7 @@ func _inner_save(m *ice.Message, name, text string) { } } func _inner_plug(m *ice.Message, name string) { - if _inner_sub(m, "plug", name) { + if _inner_sub(m, PLUG, name) { return } @@ -77,7 +84,7 @@ func _inner_plug(m *ice.Message, name string) { m.Echo("{}") } func _inner_show(m *ice.Message, name string) { - if _inner_sub(m, "show", name) { + if _inner_sub(m, SHOW, name) { return } @@ -129,7 +136,7 @@ func init() { )}, }, 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", }, Action: map[string]*ice.Action{ "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) { _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])) }}, - "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)) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { _inner_main(m, arg...) }}, diff --git a/core/code/video.go b/core/code/video.go index 3624bc50..345cc0a8 100644 --- a/core/code/video.go +++ b/core/code/video.go @@ -27,8 +27,8 @@ func init() { if file, e := avutil.Open(arg[0]); m.Assert(e) { if streams, e := file.Streams(); m.Assert(e) { for _, stream := range streams { - m.Info("what %v", kit.Formats(stream)) if stream.Type().IsAudio() { + } else if stream.Type().IsVideo() { vstream := stream.(av.VideoCodecData) m.Push("type", vstream.Type().String()) diff --git a/core/wiki/draw.go b/core/wiki/draw.go index 5d721099..81345212 100644 --- a/core/wiki/draw.go +++ b/core/wiki/draw.go @@ -2,6 +2,7 @@ package wiki import ( "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/base/nfs" "github.com/shylinux/toolkits" "path" @@ -11,8 +12,20 @@ const ( 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() { - Index.Merge(&ice.Context{ + sub := &ice.Context{Name: "draw", Help: "思维导图", Configs: map[string]*ice.Config{ DRAW: {Name: "draw", Help: "思维导图", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.svg", "prefix", ``, "suffix", ``, @@ -23,11 +36,36 @@ func init() { "display", "/plugin/local/wiki/draw.js", ), Action: map[string]*ice.Action{ "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) { 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) + + Index.Register(sub, nil) }