From c02663d87dd5c2f588c5975bf66f2c2f906abb98 Mon Sep 17 00:00:00 2001 From: shaoying Date: Sat, 5 Nov 2022 09:13:05 +0800 Subject: [PATCH] opt some --- base/web/render.go | 1 + core/wiki/audio.go | 2 +- core/wiki/brief.go | 2 +- core/wiki/chart.go | 20 ++++++++++---------- core/wiki/chart/block.go | 4 ++-- render.go | 9 +++++---- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/base/web/render.go b/base/web/render.go index 372d9635..ede3f458 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -74,6 +74,7 @@ func Render(msg *ice.Message, cmd string, args ...ice.Any) { } { msg.Set(k) } + msg.Debug("what %v %v", cmd, args) if cmd != "" && cmd != ice.RENDER_RAW { // [str [arg...]] msg.Echo(kit.Format(cmd, args...)) diff --git a/core/wiki/audio.go b/core/wiki/audio.go index ee3f73a5..96ab287c 100644 --- a/core/wiki/audio.go +++ b/core/wiki/audio.go @@ -9,7 +9,7 @@ const AUDIO = "audio" func init() { Index.MergeCommands(ice.Commands{ - AUDIO: {Name: "audio url", Help: "音频", Actions: WordAction( + AUDIO: {Name: "audio url run", 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/brief.go b/core/wiki/brief.go index 52acaaa3..8ff386f7 100644 --- a/core/wiki/brief.go +++ b/core/wiki/brief.go @@ -8,7 +8,7 @@ const BRIEF = "brief" func init() { Index.MergeCommands(ice.Commands{ - BRIEF: {Name: "brief text", Help: "摘要", Actions: WordAction( + BRIEF: {Name: "brief text run", 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 ac60ff6c..32d4765d 100644 --- a/core/wiki/chart.go +++ b/core/wiki/chart.go @@ -12,12 +12,8 @@ type Item struct { args []ice.Any } -func NewItem(list []string, args ...ice.Any) *Item { - return &Item{list, args} -} -func (item *Item) Echo(str string, arg ...ice.Any) *Item { - item.list = append(item.list, kit.Format(str, arg...)) - return item +func NewItem(str string, args ...ice.Any) *Item { + return &Item{[]string{str}, args} } func (item *Item) Push(str string, arg ice.Any) *Item { switch arg := arg.(type) { @@ -33,6 +29,10 @@ func (item *Item) Push(str string, arg ice.Any) *Item { item.list, item.args = append(item.list, str), append(item.args, arg) return item } +func (item *Item) Echo(str string, arg ...ice.Any) *Item { + item.list = append(item.list, kit.Format(str, arg...)) + return item +} func (item *Item) Dump(m *ice.Message) *ice.Message { return m.Echo(kit.Join(item.list, ice.SP), item.args...).Echo(ice.NL) } @@ -57,14 +57,14 @@ func (g *Group) Option(group string, key string, arg ...ice.Any) string { func (g *Group) Get(group string) *ice.Message { return g.list[group] } func (g *Group) Join(arg ...string) string { - args := []string{} + res := []string{} for i := 0; i < len(arg)-1; i += 2 { if arg[i] == "" { continue } - args = append(args, kit.Format(`%s="%s"`, arg[i], arg[i+1])) + res = append(res, kit.Format(`%s="%s"`, arg[i], arg[i+1])) } - return kit.Join(args, ice.SP) + return kit.Join(res, ice.SP) } func (g *Group) Echo(group string, str string, arg ...ice.Any) *ice.Message { return g.Get(group).Echo(str, arg...) @@ -102,7 +102,7 @@ func (g *Group) EchoArrowLine(group string, x1, y1, x2, y2 int, arg ...string) * return g.Echo(group, "", x1, y1, x2, y2, kit.Select("arrowhead", arg, 0)) } func (g *Group) Dump(m *ice.Message, group string, arg ...string) *Group { - item := NewItem([]string{"").Dump(m) } - item := wiki.NewItem([]string{`%v`, b.Text).Dump(m) diff --git a/render.go b/render.go index 3641a19a..0c172fd8 100644 --- a/render.go +++ b/render.go @@ -47,9 +47,6 @@ func Render(m *Message, cmd string, args ...Any) string { } func (m *Message) Render(cmd string, args ...Any) *Message { - m.Optionv(MSG_OUTPUT, cmd) - m.Optionv(MSG_ARGS, args) - switch cmd { case RENDER_TEMPLATE: // text [data] if len(args) == 1 { @@ -58,7 +55,11 @@ func (m *Message) Render(cmd string, args ...Any) *Message { if res, err := kit.Render(args[0].(string), args[1]); m.Assert(err) { m.Echo(string(res)) } + return m } + m.Optionv(MSG_OUTPUT, cmd) + m.Optionv(MSG_ARGS, args) + return m } func (m *Message) RenderTemplate(args ...Any) *Message { @@ -83,7 +84,7 @@ func (m *Message) RenderRedirect(args ...Any) *Message { return m.Render(RENDER_REDIRECT, args...) } func (m *Message) RenderDownload(args ...Any) *Message { - + m.Debug("what %v", kit.Format(args)) return m.Render(RENDER_DOWNLOAD, args...) }