1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00
This commit is contained in:
shaoying 2020-09-24 19:06:48 +08:00
parent ef946ab109
commit 0fdfe06c23
6 changed files with 52 additions and 30 deletions

View File

@ -94,17 +94,12 @@ const (
BEGIN = "begin"
END = "end"
START = "start"
STOP = "stop"
OPEN = "open"
CLOSE = "close"
START = "start"
STOP = "stop"
RELOAD = "reload"
RESTART = "restart"
CHANGE = "change"
BUILD = "build"
PRUNE = "prune"
CLEAR = "clear"
)
const (

View File

@ -35,6 +35,10 @@ func init() {
m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), SEARCH, arg[0], arg[1], kit.Select("", arg, 2))
})
}
m.Richs(SEARCH, nil, "alpha", func(key string, value map[string]interface{}) {
m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), SEARCH, arg[0], strings.ToLower(arg[1]), kit.Select("", arg, 2))
})
}},
}}, nil)
}

View File

@ -13,7 +13,6 @@ var ErrNotLogin = "not login: "
var ErrNotAuth = "not auth: "
var ErrNotJoin = "not join: "
var ErrNotFound = "not found: "
var ErrNotEnough = "not enough: "
var ErrStart = "err start: "
func (m *Message) log(level string, str string, arg ...interface{}) *Message {

View File

@ -484,9 +484,12 @@ func (m *Message) Append(key string, arg ...interface{}) string {
}
func (m *Message) Appendv(key string, arg ...interface{}) []string {
if key == MSG_APPEND {
m.meta[MSG_APPEND] = kit.Simple(arg)
if len(arg) > 0 {
m.meta[MSG_APPEND] = kit.Simple(arg)
}
return m.meta[key]
}
if key == "_index" {
max := 0
for _, k := range m.meta[MSG_APPEND] {

View File

@ -13,7 +13,7 @@ import (
"strings"
)
func _alpha_find(m *ice.Message, method, word string) {
func _alpha_find(m *ice.Message, method, word string) *ice.Message {
// 搜索方法
switch word = strings.TrimSpace(word); method {
case "line":
@ -31,6 +31,7 @@ func _alpha_find(m *ice.Message, method, word string) {
m.Push(k, value[k])
}
})
return m
}
func _alpha_load(m *ice.Message, file, name string) {
// 清空数据
@ -66,16 +67,28 @@ var Index = &ice.Context{Name: ALPHA, Help: "英汉词典",
)},
},
Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save() }},
ALPHA: {Name: "alpha method=word,line word auto", Help: "英汉", Action: map[string]*ice.Action{
mdb.IMPORT: {Name: "import file=usr/word-dict/ecdict name", Help: "加载词库", Hand: func(m *ice.Message, arg ...string) {
_alpha_load(m, m.Option(kit.MDB_FILE), kit.Select(path.Base(m.Option(kit.MDB_FILE)), m.Option(kit.MDB_NAME)))
}},
mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_alpha_find(m.Spawn(), "word", arg[1]).Table(func(index int, value map[string]string, head []string) {
m.Push("file", "")
m.Push("line", arg[1])
m.Push("text", value["definition"]+"\n"+value["translation"])
})
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_alpha_find(m, arg[0], arg[1])
}},
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load()
m.Cmd(mdb.SEARCH, mdb.CREATE, ALPHA, ALPHA, c.Cap(ice.CTX_FOLLOW))
}},
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save()
}},
},
}

42
type.go
View File

@ -544,11 +544,11 @@ func (m *Message) Search(key interface{}, cb interface{}) *Message {
p := m.target.root
if ctx, ok := names[key].(*Context); ok {
p = ctx
} else if strings.Contains(key, ":") {
} else if key == "." {
p, key = m.target, ""
} else if key == ".." {
if m.target.context != nil {
p = m.target.context
p, key = m.target.context, ""
}
} else if strings.Contains(key, ".") {
list := strings.Split(key, ".")
@ -579,6 +579,14 @@ func (m *Message) Search(key interface{}, cb interface{}) *Message {
// 遍历命令
switch cb := cb.(type) {
case func(key string, cmd *Command):
if key == "" {
for k, v := range p.Commands {
cb(k, v)
}
break
}
case func(p *Context, s *Context, key string, cmd *Command):
if key == "" {
for k, v := range p.Commands {
@ -639,22 +647,22 @@ func (m *Message) Cmd(arg ...interface{}) *Message {
}
func (m *Message) Confv(arg ...interface{}) (val interface{}) {
m.Search(arg[0], func(p *Context, s *Context, key string, conf *Config) {
if len(arg) > 1 {
if len(arg) > 2 {
if arg[1] == nil {
// 写配置
conf.Value = arg[2]
} else {
// 写修改项
kit.Value(conf.Value, arg[1:]...)
}
}
// 读配置项
val = kit.Value(conf.Value, arg[1])
} else {
// 读配置
if len(arg) == 1 {
val = conf.Value
return // 读配置
}
if len(arg) > 2 {
if arg[1] == nil || arg[1] == "" {
// 写配置
conf.Value = arg[2]
} else {
// 写修改项
kit.Value(conf.Value, arg[1:]...)
}
}
// 读配置项
val = kit.Value(conf.Value, arg[1])
})
return
}