From e20bcc8c858299ccff7c7386a9f822482da217d7 Mon Sep 17 00:00:00 2001 From: "shylinux@163.com" Date: Fri, 9 Sep 2022 07:41:32 +0800 Subject: [PATCH] opt some --- base/ctx/ctx.go | 2 +- base/ctx/message.go | 8 ++++++++ base/ssh/script.go | 1 + meta.go | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/base/ctx/ctx.go b/base/ctx/ctx.go index ce801f7d..8bee9bdf 100644 --- a/base/ctx/ctx.go +++ b/base/ctx/ctx.go @@ -6,4 +6,4 @@ const CTX = "ctx" var Index = &ice.Context{Name: CTX, Help: "标准模块"} -func init() { ice.Index.Register(Index, nil, CONTEXT, COMMAND, CONFIG, MESSAGE) } +func init() { ice.Index.Register(Index, nil, CONTEXT, COMMAND, CONFIG, MESSAGE, OPTION) } diff --git a/base/ctx/message.go b/base/ctx/message.go index 7c70aa48..768de305 100644 --- a/base/ctx/message.go +++ b/base/ctx/message.go @@ -10,6 +10,7 @@ import ( ) const MESSAGE = "message" +const OPTION = "option" func init() { Index.MergeCommands(ice.Commands{ @@ -22,5 +23,12 @@ func init() { m.Push(mdb.TEXT, strings.Split(p, ice.ICEBERGS+"/")[1]) } }}, + OPTION: {Name: "option", Help: "选项", Hand: func(m *ice.Message, arg ...string) { + if len(arg) > 1 { + if msg, ok := m.Optionv("message").(*ice.Message); ok { + msg.Option(arg[0], arg[1]) + } + } + }}, }) } diff --git a/base/ssh/script.go b/base/ssh/script.go index 61c38422..ec6cd646 100644 --- a/base/ssh/script.go +++ b/base/ssh/script.go @@ -109,6 +109,7 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame { f.ps2 = kit.Simple(m.Confv(PROMPT, kit.Keym(PS2))) ps := f.ps1 + m.Optionv("message", m) if m.I, m.O = f.stdin, f.stdout; h == STDIO { gdb.Event(m, SOURCE_STDIO) m.Sleep("3s") diff --git a/meta.go b/meta.go index 5eb8aa43..40cb8986 100644 --- a/meta.go +++ b/meta.go @@ -485,6 +485,9 @@ func (m *Message) Optionv(key string, arg ...Any) Any { } return nil } +func (m *Message) Message() *Message { + return m.message +} func (m *Message) Option(key string, arg ...Any) string { return kit.Select("", kit.Simple(m.Optionv(key, arg...)), 0) }