1
0
forked from x/icebergs

add 20200202

This commit is contained in:
shaoying 2020-02-02 04:21:47 +08:00
parent f00e1e17f8
commit b82e74f038
17 changed files with 387 additions and 205 deletions

View File

@ -58,6 +58,7 @@ var Index = &Context{Name: "ice", Help: "冰山模块",
Caches: map[string]*Cache{ Caches: map[string]*Cache{
CTX_STATUS: {Value: "begin"}, CTX_STATUS: {Value: "begin"},
CTX_STREAM: {Value: "shy"}, CTX_STREAM: {Value: "shy"},
CTX_FOLLOW: {Value: ""},
}, },
Configs: map[string]*Config{ Configs: map[string]*Config{
"table": {Name: "数据缓存", Value: map[string]interface{}{ "table": {Name: "数据缓存", Value: map[string]interface{}{

View File

@ -16,8 +16,18 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
ice.CTX_CONFIG: {Name: "config", Help: "配置", Value: kit.Data("path", "var/conf")}, ice.CTX_CONFIG: {Name: "config", Help: "配置", Value: kit.Data("path", "var/conf")},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.CTX_CONTEXT: {Name: "context", Help: "模块", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.CTX_CONTEXT: {Name: "context [all]", Help: "模块", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
ice.Pulse.Travel(func(p *ice.Context, s *ice.Context) { all := false
if len(arg) > 0 && arg[0] == "all" {
all, arg = true, arg[1:]
}
if p := m.Spawn(m.Source()); len(arg) == 0 {
if all == true {
p = ice.Pulse
}
// 模块列表
p.Travel(func(p *ice.Context, s *ice.Context) {
if p != nil { if p != nil {
m.Push("ups", p.Name) m.Push("ups", p.Name)
} else { } else {
@ -28,13 +38,24 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
m.Push(ice.CTX_STREAM, s.Cap(ice.CTX_STREAM)) m.Push(ice.CTX_STREAM, s.Cap(ice.CTX_STREAM))
m.Push("help", s.Help) m.Push("help", s.Help)
}) })
}
}}, }},
ice.CTX_COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.CTX_COMMAND: {Name: "command [all] [context [command run arg...]]", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 { all := false
ice.Pulse.Travel(func(p *ice.Context, s *ice.Context) { if len(arg) > 0 && arg[0] == "all" {
all, arg = true, arg[1:]
}
if p := m.Spawn(m.Source()); len(arg) == 0 {
if all == true {
p = ice.Pulse
}
// 命令列表
p.Travel(func(p *ice.Context, s *ice.Context) {
list := []string{} list := []string{}
for k := range s.Commands { for k := range s.Commands {
if k[0] == '/' || k[0] == '_' { if k[0] == '/' || k[0] == '_' {
// 内部命令
continue continue
} }
list = append(list, k) list = append(list, k)
@ -43,11 +64,7 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
for _, k := range list { for _, k := range list {
v := s.Commands[k] v := s.Commands[k]
if p != nil && p != ice.Index { m.Push("key", s.Cap(ice.CTX_FOLLOW))
m.Push("key", p.Name+"."+s.Name)
} else {
m.Push("key", s.Name)
}
m.Push("index", k) m.Push("index", k)
m.Push("name", v.Name) m.Push("name", v.Name)
m.Push("help", v.Help) m.Push("help", v.Help)
@ -64,22 +81,35 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
arg = arg[1:] arg = arg[1:]
m.Search(chain, func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) { m.Search(chain, func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
if len(arg) == 0 { if len(arg) == 0 {
// 命令列表
m.Push("name", cmd.Name) m.Push("name", cmd.Name)
m.Push("help", cmd.Help) m.Push("help", cmd.Help)
m.Push("meta", kit.Format(cmd.Meta)) m.Push("meta", kit.Format(cmd.Meta))
m.Push("list", kit.Format(cmd.List)) m.Push("list", kit.Format(cmd.List))
} else { } else {
if you := m.Option(kit.Format(kit.Value(cmd.Meta, "remote"))); you != "" { if you := m.Option(kit.Format(kit.Value(cmd.Meta, "remote"))); you != "" {
// 远程命令
m.Copy(m.Spawns(s).Cmd("web.space", you, "ctx.command", chain, "run", arg[1:])) m.Copy(m.Spawns(s).Cmd("web.space", you, "ctx.command", chain, "run", arg[1:]))
} else { } else {
// 本地命令
m.Copy(s.Run(m.Spawns(s), cmd, key, arg[1:]...)) m.Copy(s.Run(m.Spawns(s), cmd, key, arg[1:]...))
} }
} }
}) })
}}, }},
ice.CTX_CONFIG: {Name: "config", Help: "配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.CTX_CONFIG: {Name: "config [all] save|load", Help: "配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
all := false
if len(arg) > 0 && arg[0] == "all" {
all, arg = true, arg[1:]
}
msg := m.Spawn(m.Source())
if len(arg) == 0 { if len(arg) == 0 {
ice.Pulse.Travel(func(p *ice.Context, s *ice.Context, key string, conf *ice.Config) { if all == true {
msg = ice.Pulse
}
// 配置列表
msg.Travel(func(p *ice.Context, s *ice.Context, key string, conf *ice.Config) {
m.Push("key", key) m.Push("key", key)
m.Push("name", conf.Name) m.Push("name", conf.Name)
m.Push("value", kit.Format(conf.Value)) m.Push("value", kit.Format(conf.Value))
@ -89,11 +119,12 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
switch arg[0] { switch arg[0] {
case "save": case "save":
arg[1] = path.Join(m.Conf(ice.CTX_CONFIG, ice.Meta("path")), arg[1]) // 保存配置
arg[1] = path.Join(msg.Conf(ice.CTX_CONFIG, ice.Meta("path")), arg[1])
if f, p, e := kit.Create(arg[1]); m.Assert(e) { if f, p, e := kit.Create(arg[1]); m.Assert(e) {
data := map[string]interface{}{} data := map[string]interface{}{}
for _, k := range arg[2:] { for _, k := range arg[2:] {
data[k] = m.Confv(k) data[k] = msg.Confv(k)
} }
if s, e := json.MarshalIndent(data, "", " "); m.Assert(e) { if s, e := json.MarshalIndent(data, "", " "); m.Assert(e) {
if n, e := f.Write(s); m.Assert(e) { if n, e := f.Write(s); m.Assert(e) {
@ -103,13 +134,14 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
m.Echo(p) m.Echo(p)
} }
case "load": case "load":
arg[1] = path.Join(m.Conf(ice.CTX_CONFIG, ice.Meta("path")), arg[1]) // 加载配置
arg[1] = path.Join(msg.Conf(ice.CTX_CONFIG, ice.Meta("path")), arg[1])
if f, e := os.Open(arg[1]); e == nil { if f, e := os.Open(arg[1]); e == nil {
data := map[string]interface{}{} data := map[string]interface{}{}
json.NewDecoder(f).Decode(&data) json.NewDecoder(f).Decode(&data)
for k, v := range data { for k, v := range data {
m.Search(k, func(p *ice.Context, s *ice.Context, key string) { msg.Search(k, func(p *ice.Context, s *ice.Context, key string) {
m.Log("info", "load %s.%s %v", s.Name, key, kit.Format(v)) m.Log("info", "load %s.%s %v", s.Name, key, kit.Format(v))
s.Configs[key].Value = v s.Configs[key].Value = v
}) })
@ -117,12 +149,15 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
} }
default: default:
if len(arg) > 2 { if len(arg) > 2 {
m.Conf(arg[0], arg[1], arg[2]) // 修改配置
msg.Conf(arg[0], arg[1], arg[2])
} }
if len(arg) > 1 { if len(arg) > 1 {
m.Echo(m.Conf(arg[0], arg[1])) // 读取配置
m.Echo(msg.Conf(arg[0], arg[1]))
} else { } else {
m.Echo(kit.Formats(m.Confv(arg[0]))) // 读取配置
m.Echo(kit.Formats(msg.Confv(arg[0])))
} }
} }
}}, }},

View File

@ -141,10 +141,8 @@ 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{},
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
}}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
"dir": {Name: "dir", Help: "目录", List: kit.List( "dir": {Name: "dir", Help: "目录", List: kit.List(
kit.MDB_INPUT, "text", "name", "path", "action", "auto", kit.MDB_INPUT, "text", "name", "path", "action", "auto",
@ -155,6 +153,17 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
dir(m, kit.Select("./", m.Option("dir_root")), kit.Select("", arg, 0), 0, m.Options("dir_deep"), "both", rg, dir(m, kit.Select("./", m.Option("dir_root")), kit.Select("", arg, 0), 0, m.Options("dir_deep"), "both", rg,
strings.Split(kit.Select("time size line path", arg, 1), " "), ice.ICE_TIME) strings.Split(kit.Select("time size line path", arg, 1), " "), ice.ICE_TIME)
}}, }},
"cat": {Name: "cat path", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, e := os.OpenFile(arg[0], os.O_RDONLY, 0777); m.Assert(e) {
defer f.Close()
buf := make([]byte, 1024)
if n, e := f.Read(buf); m.Assert(e) {
m.Log(ice.LOG_IMPORT, "%d: %s", n, arg[0])
m.Echo(string(buf[:n]))
}
}
}},
"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) { if f, p, e := kit.Create(arg[0]); m.Assert(e) {
defer f.Close() defer f.Close()
@ -176,16 +185,6 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
} }
} }
}}, }},
"cat": {Name: "cat path", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, e := os.OpenFile(arg[0], os.O_RDONLY, 0777); m.Assert(e) {
defer f.Close()
buf := make([]byte, 1024)
if n, e := f.Read(buf); m.Assert(e) {
m.Log(ice.LOG_IMPORT, "%d: %s", n, arg[0])
m.Echo(string(buf[:n]))
}
}
}},
"copy": {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "copy": {Name: "save path text", 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) {
defer f.Close() defer f.Close()

View File

@ -64,21 +64,20 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
if len(ls) > 0 && strings.HasPrefix(ls[0], "~") { if len(ls) > 0 && strings.HasPrefix(ls[0], "~") {
// 切换模块 // 切换模块
target := ls[0][1:] target := ls[0][1:]
if ls = ls[1:]; len(target) == 0 { if ls = ls[1:]; len(target) == 0 && len(ls) > 0 {
target, ls = ls[0], ls[1:] target, ls = ls[0], ls[1:]
} }
ice.Pulse.Search(target+".", func(p *ice.Context, s *ice.Context, key string) { m.Spawn(f.target).Search(target+".", func(p *ice.Context, s *ice.Context, key string) {
m.Info("choice: %s", s.Name) m.Info("choice: %s", s.Name)
f.target = s f.target = s
}) })
} }
if len(ls) == 0 { if len(ls) == 0 {
continue continue
} }
msg := m.Spawns(f.target)
// 执行命令 // 执行命令
msg := m.Spawns(f.target)
if msg.Cmdy(ls); !msg.Hand { if msg.Cmdy(ls); !msg.Hand {
msg = msg.Set("result").Cmdy(ice.CLI_SYSTEM, ls) msg = msg.Set("result").Cmdy(ice.CLI_SYSTEM, ls)
} }
@ -116,6 +115,13 @@ var Index = &ice.Context{Name: "ssh", Help: "终端模块",
"scan": {Name: "scan", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "scan": {Name: "scan", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Starts(arg[0], arg[1], arg[2:]...) m.Starts(arg[0], arg[1], arg[2:]...)
}}, }},
"show": {Name: "show", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
msg := m.Spawn()
msg.Option("title", "疫情分布")
msg.Info("what %v", msg.Format("meta"))
m.Copy(msg)
msg.Info("what %v", m.Format("meta"))
}},
}, },
} }

View File

@ -1457,6 +1457,9 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
"/share/": {Name: "/share/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "/share/": {Name: "/share/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] { switch arg[0] {
case "local":
http.ServeFile(m.W, m.R, "usr/"+path.Join(arg[1:]...))
case "login": case "login":
Cookie(m, m.Cmdx(ice.AAA_USER, "login", m.Option("username"), m.Option("password"))) Cookie(m, m.Cmdx(ice.AAA_USER, "login", m.Option("username"), m.Option("password")))

View File

@ -10,6 +10,7 @@ const ( // ICE
const ( // CTX const ( // CTX
CTX_STATUS = "status" CTX_STATUS = "status"
CTX_STREAM = "stream" CTX_STREAM = "stream"
CTX_FOLLOW = "follow"
CTX_CONFIG = "config" CTX_CONFIG = "config"
CTX_COMMAND = "command" CTX_COMMAND = "command"
CTX_CONTEXT = "context" CTX_CONTEXT = "context"

View File

@ -37,18 +37,18 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "share") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "share")
m.Cmd(ice.WEB_FAVOR, "river.root", "storm", "misc") m.Cmd(ice.WEB_FAVOR, "river.root", "storm", "misc")
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "buffer", "cli.tmux") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "buffer", "web.code.tmux")
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "session", "cli.tmux") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "session", "web.code.tmux")
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "image", "cli.docker") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "image", "web.code.docker")
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "container", "cli.docker") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "container", "web.code.docker")
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "command", "cli.docker") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "command", "web.code.docker")
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "repos", "cli.git") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "repos", "web.code.git")
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "total", "cli.git") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "total", "web.code.git")
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "branch", "cli.git") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "branch", "web.code.git")
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "status", "cli.git") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "status", "web.code.git")
m.Cmd(ice.WEB_FAVOR, "river.root", "storm", "note") m.Cmd(ice.WEB_FAVOR, "river.root", "storm", "note")
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "total", "cli.git") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "total", "web.code.git")
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "date", "web.team") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "date", "web.team")
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "miss", "web.team") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "miss", "web.team")
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "progress", "web.team") m.Cmd(ice.WEB_FAVOR, "river.root", "field", "progress", "web.team")

View File

@ -33,16 +33,12 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
"compile": {Name: "compile", Help: "编译", Value: kit.Data("path", "usr/publish")}, "compile": {Name: "compile", Help: "编译", Value: kit.Data("path", "usr/publish")},
"publish": {Name: "publish", Help: "发布", Value: kit.Data("path", "usr/publish")}, "publish": {Name: "publish", Help: "发布", Value: kit.Data("path", "usr/publish")},
"upgrade": {Name: "upgrade", Help: "升级", Value: kit.Dict( "upgrade": {Name: "upgrade", Help: "升级", Value: kit.Dict(kit.MDB_HASH, kit.Dict(
kit.MDB_HASH, kit.Dict( "system", kit.Dict(kit.MDB_LIST, kit.List(
"system", kit.Dict(
kit.MDB_LIST, kit.List(
kit.MDB_INPUT, "bin", "file", "ice.sh", "path", "bin/ice.sh", kit.MDB_INPUT, "bin", "file", "ice.sh", "path", "bin/ice.sh",
kit.MDB_INPUT, "bin", "file", "ice.bin", "path", "bin/ice.bin", kit.MDB_INPUT, "bin", "file", "ice.bin", "path", "bin/ice.bin",
), )),
), ))},
),
)},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@ -249,12 +245,6 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
m.Push("_output", "result") m.Push("_output", "result")
} }
}}, }},
"/input/": {Name: "/input/", Help: "编辑器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd("cli.input.match", arg[0]).Table(func(index int, value map[string]string, head []string) {
m.Echo("%s %s\n", value["code"], value["text"])
m.Push("_output", "result")
})
}},
"/vim": {Name: "/vim", Help: "编辑器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "/vim": {Name: "/vim", Help: "编辑器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, _, e := m.R.FormFile("sub"); e == nil { if f, _, e := m.R.FormFile("sub"); e == nil {
defer f.Close() defer f.Close()
@ -288,19 +278,21 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
arg := kit.Split(strings.TrimPrefix(strings.TrimSpace(m.Option("arg")), "ice ")) arg := kit.Split(strings.TrimPrefix(strings.TrimSpace(m.Option("arg")), "ice "))
switch arg[0] { switch arg[0] {
case "add": case "add":
m.Cmd("cli.input.input", "push", arg[1:]) // 添加词汇
m.Cmd("input.push", arg[1:])
m.Option("arg", arg[2]) m.Option("arg", arg[2])
default: default:
// 执行命令
m.Set("append") m.Set("append")
if m.Cmdy(arg).Table(); strings.TrimSpace(m.Result()) == "" { if m.Cmdy(arg).Table(); strings.TrimSpace(m.Result()) == "" {
m.Cmdy(ice.CLI_SYSTEM, arg) m.Cmdy(ice.CLI_SYSTEM, arg)
} }
m.Info("trans: --%s--", m.Result())
m.Push("_output", "result") m.Push("_output", "result")
return return
} }
} }
m.Cmd("cli.input.match", m.Option("arg")).Table(func(index int, value map[string]string, head []string) { // 词汇列表
m.Cmd("input.find", m.Option("arg")).Table(func(index int, value map[string]string, head []string) {
m.Echo("%s\n", value["text"]) m.Echo("%s\n", value["text"])
m.Push("_output", "result") m.Push("_output", "result")
}) })

View File

@ -37,8 +37,19 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
"order": {Name: "order", Help: "列表", Value: kit.Data("template", order)}, "order": {Name: "order", Help: "列表", Value: kit.Data("template", order)},
"table": {Name: "table", Help: "表格", Value: kit.Data("template", table)}, "table": {Name: "table", Help: "表格", Value: kit.Data("template", table)},
"chart": {Name: "chart", Help: "绘图", Value: kit.Data("prefix", prefix, "suffix", `</svg>`)}, "chart": {Name: "chart", Help: "绘图", Value: kit.Data("prefix", prefix, "suffix", `</svg>`)},
"mind": {Name: "mind", Help: "思维导图", Value: kit.Data(kit.MDB_SHORT, "name", "prefix", `<svg vertion="1.1" xmlns="http://www.w3.org/2000/svg" width="%v" height="%v">`, "suffix", `</svg>`)},
"word": {Name: "word", Help: "语言文字", Value: kit.Data(kit.MDB_SHORT, "name")},
"data": {Name: "data", Help: "数据表格", Value: kit.Data(kit.MDB_SHORT, "name")},
"feel": {Name: "feel", Help: "影音媒体", Value: kit.Data(kit.MDB_SHORT, "name")},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(ice.CTX_CONFIG, "load", kit.Keys(m.Cap(ice.CTX_FOLLOW), "json"))
}},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(ice.CTX_CONFIG, "save", kit.Keys(m.Cap(ice.CTX_FOLLOW), "json"), kit.Keys(m.Cap(ice.CTX_FOLLOW), "mind"))
}},
"chart": {Name: "chart block|chain|table name text [fg bg fs ls p m]", Help: "绘图", Meta: map[string]interface{}{ "chart": {Name: "chart block|chain|table name text [fg bg fs ls p m]", Help: "绘图", Meta: map[string]interface{}{
"display": "inner", "display": "inner",
}, List: kit.List( }, List: kit.List(
@ -243,6 +254,99 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
} }
m.Cmdy(kit.Select("_tree", "_text", len(arg) > 0 && strings.HasSuffix(arg[0], ".md")), arg) m.Cmdy(kit.Select("_tree", "_text", len(arg) > 0 && strings.HasSuffix(arg[0], ".md")), arg)
}}, }},
"mind": {Name: "mind", Help: "思维导图", Meta: kit.Dict("display", "wiki/mind"), List: kit.List(
kit.MDB_INPUT, "text", "name", "name",
kit.MDB_INPUT, "button", "name", "执行",
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
if len(arg) > 0 && arg[0] == "action" {
switch arg[1] {
case "保存":
m.Cmd("nfs.save", path.Join("usr", arg[2]), arg[3:])
}
return
}
m.Option("dir_root", "usr")
m.Cmdy("nfs.dir", kit.Select("./", arg, 0))
if m.Append("path") == "" && m.Result() == "" {
m.Echo(m.Conf("mind", "meta.prefix"), "100%", "100%")
m.Echo(m.Conf("mind", "meta.suffix"))
}
}},
"word": {Name: "word", Help: "语言文字", Meta: kit.Dict("display", "wiki/word"), List: kit.List(
kit.MDB_INPUT, "text", "name", "name",
kit.MDB_INPUT, "button", "name", "执行",
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
if len(arg) > 0 && arg[0] == "action" {
switch arg[1] {
case "保存":
m.Cmd("nfs.save", path.Join("usr", arg[2]), arg[3])
}
return
}
m.Option("dir_root", "usr")
m.Cmdy("nfs.dir", kit.Select("./", arg, 0))
}},
"data": {Name: "data", Help: "数据表格", Meta: kit.Dict("display", "wiki/data"), List: kit.List(
kit.MDB_INPUT, "text", "name", "name",
kit.MDB_INPUT, "button", "name", "执行",
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
if len(arg) > 0 && arg[0] == "action" {
switch arg[1] {
case "保存":
m.Cmd("nfs.save", path.Join("usr", arg[2]), arg[3])
}
return
}
m.Option("dir_root", "usr")
m.Cmdy("nfs.dir", kit.Select("./", arg, 0))
if len(arg) > 0 && strings.HasSuffix(arg[0], ".csv") {
m.CSV(m.Result())
}
}},
"feel": {Name: "feel", Help: "影音媒体", Meta: kit.Dict("display", "wiki/feel"), List: kit.List(
kit.MDB_INPUT, "text", "name", "name",
kit.MDB_INPUT, "button", "name", "执行",
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
if len(arg) > 0 && arg[0] == "action" {
switch arg[1] {
case "保存":
m.Cmd("nfs.save", path.Join("usr", arg[2]), arg[3])
}
return
}
m.Option("dir_root", "usr")
m.Cmdy("nfs.dir", kit.Select("./", arg, 0))
m.Sort("time", "time_r")
}},
"walk": {Name: "walk", Help: "走遍世界", Meta: kit.Dict("display", "wiki/walk"), List: kit.List(
kit.MDB_INPUT, "text", "name", "file",
kit.MDB_INPUT, "button", "name", "执行",
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
if len(arg) > 0 && arg[0] == "action" {
switch arg[1] {
case "保存":
m.Cmd("nfs.save", path.Join("usr", arg[2]), arg[3])
}
return
}
m.Option("dir_root", "usr")
m.Cmdy("nfs.dir", kit.Select("./", arg, 0))
if len(arg) > 0 && strings.HasSuffix(arg[0], ".csv") {
m.Option("title", "我走过的世界")
m.CSV(m.Result())
}
}},
}, },
} }

View File

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"encoding/csv" "encoding/csv"
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/core/wiki"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"math/rand" "math/rand"
"os" "os"
@ -23,7 +23,7 @@ var Index = &ice.Context{Name: "alpha", Help: "英汉词典",
m.Cmd(ice.CTX_CONFIG, "load", "alpha.json") m.Cmd(ice.CTX_CONFIG, "load", "alpha.json")
}}, }},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(ice.CTX_CONFIG, "save", "alpha.json", "cli.alpha.alpha") m.Cmd(ice.CTX_CONFIG, "save", "alpha.json", "alpha")
}}, }},
"alpha": {Name: "alpha [load|list]", Help: "英汉词典", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "alpha": {Name: "alpha [load|list]", Help: "英汉词典", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@ -35,7 +35,7 @@ var Index = &ice.Context{Name: "alpha", Help: "英汉词典",
switch arg[0] { switch arg[0] {
case "load": case "load":
// 加载词库 // 加载词库
m.Cmd(ice.MDB_IMPORT, "cli.alpha.alpha", "", "list", m.Cmd(ice.MDB_IMPORT, "web.wiki.alpha.alpha", "", "list",
m.Cmd(ice.WEB_CACHE, "catch", "csv", arg[1]).Append("data")) m.Cmd(ice.WEB_CACHE, "catch", "csv", arg[1]).Append("data"))
case "list": case "list":
// 词汇列表 // 词汇列表
@ -75,7 +75,7 @@ var Index = &ice.Context{Name: "alpha", Help: "英汉词典",
if field == nil { if field == nil {
field = map[string]interface{}{} field = map[string]interface{}{}
head := []string{} head := []string{}
if f, e := os.Open(path.Join(m.Conf("alpha", "meta.store"), "cli.alpha.alpha..csv")); m.Assert(e) { if f, e := os.Open(path.Join(m.Conf("alpha", "meta.store"), "web.wiki.alpha.alpha.csv")); m.Assert(e) {
defer f.Close() defer f.Close()
bio := csv.NewReader(f) bio := csv.NewReader(f)
head, e = bio.Read() head, e = bio.Read()
@ -109,4 +109,4 @@ var Index = &ice.Context{Name: "alpha", Help: "英汉词典",
}, },
} }
func init() { cli.Index.Register(Index, nil) } func init() { wiki.Index.Register(Index, nil) }

View File

@ -2,7 +2,7 @@ package docker
import ( import (
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/core/code"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"strings" "strings"
) )
@ -95,4 +95,4 @@ var Index = &ice.Context{Name: "docker", Help: "容器管理",
}, },
} }
func init() { cli.Index.Register(Index, nil) } func init() { code.Index.Register(Index, nil) }

View File

@ -2,7 +2,7 @@ package git
import ( import (
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/core/code"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"os" "os"
@ -14,39 +14,44 @@ import (
var Index = &ice.Context{Name: "git", Help: "代码管理", var Index = &ice.Context{Name: "git", Help: "代码管理",
Caches: map[string]*ice.Cache{}, Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
"repos": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name")}, "repos": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "owner", "https://github.com/shylinux")},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
// 前端代码 // 前端代码
for _, repos := range []string{"volcanos"} {
m.Rich("repos", nil, kit.Data( m.Rich("repos", nil, kit.Data(
"name", "volcanos", "path", "usr/volcanos", "branch", "master", "name", repos, "path", "usr/"+repos, "branch", "master",
"remote", "https://github.com/shylinux/volcanos", "remote", m.Conf("repos", "meta.owner")+"/"+repos,
)) ))
}
// 后端代码
for _, repos := range []string{"contexts", "icebergs", "toolkits"} {
m.Rich("repos", nil, kit.Data( m.Rich("repos", nil, kit.Data(
"name", "icebergs", "path", "../icebergs", "branch", "master", "name", repos, "path", "../"+repos, "branch", "master",
"remote", "https://github.com/shylinux/icebergs", "remote", m.Conf("repos", "meta.owner")+"/"+repos,
))
m.Rich("repos", nil, kit.Data(
"name", "toolkits", "path", "../toolkits", "branch", "master",
"remote", "https://github.com/shylinux/toolkits",
))
m.Rich("repos", nil, kit.Data(
"name", "contexts", "path", "../contexts", "branch", "master",
"remote", "https://github.com/shylinux/context",
)) ))
}
// 应用代码
m.Cmd("nfs.dir", m.Conf(ice.WEB_DREAM, "meta.path"), "name path").Table(func(index int, value map[string]string, head []string) { m.Cmd("nfs.dir", m.Conf(ice.WEB_DREAM, "meta.path"), "name path").Table(func(index int, value map[string]string, head []string) {
if s, e := os.Stat(path.Join(value["path"], ".git")); e == nil && s.IsDir() { if s, e := os.Stat(m.Option("cmd_dir", path.Join(value["path"], ".git"))); e == nil && s.IsDir() {
m.Rich("repos", nil, kit.Data( m.Rich("repos", nil, kit.Data(
"name", value["name"], "path", value["path"], "branch", "master", "name", value["name"], "path", value["path"], "branch", "master",
"remote", m.Cmdx(ice.CLI_SYSTEM, "git", "remote", "get-url", "origin"), "remote", m.Cmdx(ice.CLI_SYSTEM, "git", "remote", "get-url", "origin"),
)) ))
} }
}) })
m.Watch(ice.SYSTEM_INIT, "cli.git.check", "volcanos") m.Watch(ice.SYSTEM_INIT, "web.code.git.check", "volcanos")
}}, }},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
"repos": {Name: "repos", Help: "仓库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
"repos": {Name: "repos [name [path]]", Help: "仓库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 {
m.Rich("repos", nil, kit.Data(
"name", arg[0], "path", "usr/"+kit.Select(arg[0], arg, 1), "branch", "master",
"remote", m.Conf("repos", "meta.owner")+"/"+arg[0],
))
}
m.Richs("repos", nil, "*", func(key string, value map[string]interface{}) { m.Richs("repos", nil, "*", func(key string, value map[string]interface{}) {
m.Push(key, value["meta"], []string{"time", "name", "branch", "path", "remote"}) m.Push(key, value["meta"], []string{"time", "name", "branch", "path", "remote"})
}) })
@ -192,4 +197,4 @@ var Index = &ice.Context{Name: "git", Help: "代码管理",
}, },
} }
func init() { cli.Index.Register(Index, nil) } func init() { code.Index.Register(Index, nil) }

View File

@ -1,13 +1,14 @@
package input package input
import ( import (
"github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/core/code"
"github.com/shylinux/toolkits"
"bufio" "bufio"
"bytes" "bytes"
"encoding/csv" "encoding/csv"
"fmt" "fmt"
"github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/toolkits"
"os" "os"
"path" "path"
"strings" "strings"
@ -17,34 +18,40 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
Caches: map[string]*ice.Cache{}, Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
"input": {Name: "input", Help: "输入法", Value: kit.Data( "input": {Name: "input", Help: "输入法", Value: kit.Data(
"store", "var/input/", "limit", "2000", "least", "1000", "fsize", "100000", "store", "var/input/", "fsize", "100000", "limit", "2000", "least", "1000",
"field", kit.Dict("file", 0, "line", 1, "code", 2, "id", 3, "text", 4, "time", 5, "weight", 6), "repos", "wubi-dict", "local", "some",
)}, )},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(ice.CTX_CONFIG, "load", "input.json") m.Cmd(ice.CTX_CONFIG, "load", kit.Keys(m.Cap(ice.CTX_FOLLOW), "json"))
m.Cmd("web.code.git.repos", m.Conf("input", "meta.repos"))
}}, }},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(ice.CTX_CONFIG, "save", "input.json", "cli.input.input") m.Cmd(ice.CTX_CONFIG, "save", kit.Keys(m.Cap(ice.CTX_FOLLOW), "json"), kit.Keys(m.Cap(ice.CTX_FOLLOW), "input"))
}}, }},
"input": {Name: "input load|list|push|save", Help: "输入法", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "load": {Name: "load file [name]", Help: "加载词库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 { if len(arg) == 0 {
arg = append(arg, "list") // 默认词库
if m.Cmd("web.code.git.check", m.Conf("input", "meta.repos")); m.Confs("input", "wubi86") {
m.Echo("wubi86: %v", m.Conf("input", "wubi86.meta.count"))
return
} }
arg = append(arg, path.Join("usr", m.Conf("input", "meta.repos"), "wubi86"))
}
lib := kit.Select(path.Base(arg[0]), arg, 1)
switch arg[0] { // 缓存配置
case "load":
// 加载词库
lib := kit.Select(path.Base(arg[1]), arg, 2)
m.Option("cache.fsize", m.Conf("input", "meta.fsize"))
m.Option("cache.limit", m.Conf("input", "meta.limit"))
m.Option("cache.least", m.Conf("input", "meta.least")) m.Option("cache.least", m.Conf("input", "meta.least"))
m.Option("cache.limit", m.Conf("input", "meta.limit"))
m.Option("cache.fsize", m.Conf("input", "meta.fsize"))
m.Assert(os.RemoveAll(m.Option("cache.store", path.Join(m.Conf("input", "meta.store"), lib)))) m.Assert(os.RemoveAll(m.Option("cache.store", path.Join(m.Conf("input", "meta.store"), lib))))
m.Conf("input", lib, "") m.Conf("input", lib, "")
if f, e := os.Open(arg[1]); m.Assert(e) {
if f, e := os.Open(arg[0]); m.Assert(e) {
bio := bufio.NewScanner(f) bio := bufio.NewScanner(f)
// 加载词库
for bio.Scan() { for bio.Scan() {
if strings.HasPrefix(bio.Text(), "#") { if strings.HasPrefix(bio.Text(), "#") {
continue continue
@ -53,52 +60,46 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
if line[2] == "0" { if line[2] == "0" {
continue continue
} }
m.Grow("input", lib, kit.Dict( m.Grow("input", lib, kit.Dict("text", line[0], "code", line[1], "weight", line[2]))
"text", line[0], "code", line[1], "weight", line[2],
))
} }
m.Option("cache.limit", 0) // 保存词库
m.Option("cache.least", 0) m.Option("cache.least", 0)
n := m.Grow("input", lib, kit.Dict( m.Option("cache.limit", 0)
"text", "成功", "code", "z", "weight", "0", m.Echo("%s: %d", lib, m.Grow("input", lib, kit.Dict("text", "成功", "code", "z", "weight", "0")))
))
m.Echo("%s: %d", lib, n)
} }
case "push": }},
// 添加词汇 "push": {Name: "push text code [weight [lib]]", Help: "添加词汇", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
lib := kit.Select("person", arg, 3) lib := kit.Select("person", arg, 2)
m.Option("cache.limit", 0)
m.Option("cache.least", 0) m.Option("cache.least", 0)
m.Option("cache.limit", 0)
m.Option("cache.store", path.Join(m.Conf("input", "meta.store"), lib)) m.Option("cache.store", path.Join(m.Conf("input", "meta.store"), lib))
n := m.Grow("input", lib, kit.Dict( m.Echo("%s: %d", lib, m.Grow("input", lib, kit.Dict("text", arg[0], "code", arg[1], "weight", kit.Select("99990000", arg, 3))))
"text", arg[1], "code", arg[2], "weight", kit.Select("99990000", arg, 4), }},
)) "list": {Name: "list [lib [offend [limit]]]", Help: "查看词汇", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Echo("%s: %d", lib, n) lib := kit.Select("person", arg, 0)
case "list": m.Option("cache.offend", kit.Select("0", arg, 1))
// 词汇列表 m.Option("cache.limit", kit.Select("10", arg, 2))
lib := kit.Select("person", arg, 1)
m.Option("cache.offend", kit.Select("0", arg, 2))
m.Option("cache.limit", kit.Select("10", arg, 3))
m.Grows("input", lib, "", "", func(index int, value map[string]interface{}) { m.Grows("input", lib, "", "", func(index int, value map[string]interface{}) {
m.Push("", value, []string{"id", "code", "text", "weight"}) m.Push("", value, []string{"id", "code", "text", "weight"})
}) })
case "save": }},
// 导出词库 "save": {Name: "save lib [filename]", Help: "导出词库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option("cache.offend", 0) lib := kit.Select("person", arg, 0)
m.Option("cache.limit", 1000000) m.Option("cache.limit", 1000000)
if f, p, e := kit.Create(kit.Select(arg[1], arg, 2)); m.Assert(e) { m.Option("cache.offend", 0)
if f, p, e := kit.Create(path.Join("usr", m.Conf("input", "meta.repos"), lib)); m.Assert(e) {
defer f.Close() defer f.Close()
n := 0 n := 0
m.Grows("input", arg[1], "", "", func(index int, value map[string]interface{}) { m.Grows("input", lib, "", "", func(index int, value map[string]interface{}) {
n++ n++
fmt.Fprintf(f, "%s %s %s\n", value["text"], value["code"], value["weight"]) fmt.Fprintf(f, "%s %s %s\n", value["text"], value["code"], value["weight"])
}) })
m.Log(ice.LOG_EXPORT, "%s: %d", p, n) m.Log(ice.LOG_EXPORT, "%s: %d", p, n)
m.Echo("%s: %d", p, n) m.Echo("%s: %d", p, n)
} }
}
}}, }},
"match": {Name: "match [word [method]]", Help: "五笔字码", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
"find": {Name: "find key [word|line [limit]]", Help: "五笔字码", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 { if len(arg) == 0 {
// 收藏列表 // 收藏列表
m.Cmdy(ice.WEB_FAVOR, "input.word") m.Cmdy(ice.WEB_FAVOR, "input.word")
@ -117,7 +118,6 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
} }
// 搜索词汇 // 搜索词汇
field := m.Confm("input", "meta.field")
bio := csv.NewReader(bytes.NewBufferString(strings.Replace(m.Cmdx(ice.CLI_SYSTEM, "grep", "-rn", arg[0], m.Conf("input", "meta.store")), ":", ",", -1))) bio := csv.NewReader(bytes.NewBufferString(strings.Replace(m.Cmdx(ice.CLI_SYSTEM, "grep", "-rn", arg[0], m.Conf("input", "meta.store")), ":", ",", -1)))
for i := 0; i < kit.Int(kit.Select("100", arg, 2)); i++ { for i := 0; i < kit.Int(kit.Select("100", arg, 2)); i++ {
if line, e := bio.Read(); e != nil { if line, e := bio.Read(); e != nil {
@ -126,16 +126,15 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
} else { } else {
if method == "word" && i == 0 { if method == "word" && i == 0 {
// 添加收藏 // 添加收藏
m.Cmd(ice.WEB_FAVOR, "input.word", "input", m.Cmd(ice.WEB_FAVOR, "input.word", "input", line[2], line[4], "id", line[3], "weight", line[6])
line[kit.Int(field["code"])], line[kit.Int(field["text"])],
"id", line[kit.Int(field["id"])], "weight", line[kit.Int(field["weight"])],
)
} }
// 输出词汇 // 输出词汇
m.Push("file", path.Base(line[kit.Int(field["file"])])) m.Push("file", path.Base(line[0]))
for _, k := range []string{"id", "code", "text", "weight"} { m.Push("id", line[3])
m.Push(k, line[kit.Int(field[k])]) m.Push("code", line[2])
} m.Push("text", line[4])
m.Push("weight", line[6])
} }
} }
m.Sort("weight", "int_r") m.Sort("weight", "int_r")
@ -143,4 +142,4 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
}, },
} }
func init() { cli.Index.Register(Index, nil) } func init() { code.Index.Register(Index, nil) }

View File

@ -2,7 +2,7 @@ package pi
import ( import (
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/core/chat"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"os" "os"
"path" "path"
@ -35,4 +35,4 @@ var Index = &ice.Context{Name: "pi", Help: "pi",
}, },
} }
func init() { cli.Index.Register(Index, nil) } func init() { chat.Index.Register(Index, nil) }

View File

@ -2,7 +2,7 @@ package tmux
import ( import (
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/core/code"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"os" "os"
"path" "path"
@ -53,9 +53,9 @@ var Index = &ice.Context{Name: "tmux", Help: "终端管理",
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Watch(ice.SYSTEM_INIT, "cli.tmux.init") m.Watch(ice.SYSTEM_INIT, "web.code.tmux.init")
m.Watch(ice.DREAM_START, "cli.tmux.auto") m.Watch(ice.DREAM_START, "web.code.tmux.auto")
m.Watch(ice.FAVOR_START, "cli.tmux.auto") m.Watch(ice.FAVOR_START, "web.code.tmux.auto")
}}, }},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}}, }},
@ -240,7 +240,7 @@ var Index = &ice.Context{Name: "tmux", Help: "终端管理",
"auto": {Name: "auto", Help: "终端", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "auto": {Name: "auto", Help: "终端", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
prefix := []string{"cli.system", "tmux"} prefix := []string{"cli.system", "tmux"}
if arg[0] == "" { if arg[0] == "" {
m.Cmd("cli.tmux.session").Table(func(index int, value map[string]string, head []string) { m.Cmd("web.code.tmux.session").Table(func(index int, value map[string]string, head []string) {
if value["tag"] == "1" { if value["tag"] == "1" {
arg[0] = value["session"] arg[0] = value["session"]
} }
@ -273,4 +273,4 @@ var Index = &ice.Context{Name: "tmux", Help: "终端管理",
}, },
} }
func init() { cli.Index.Register(Index, &Frame{}) } func init() { code.Index.Register(Index, &Frame{}) }

View File

@ -2,7 +2,7 @@ package wx
import ( import (
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/core/chat"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"regexp" "regexp"
) )
@ -53,4 +53,4 @@ var Index = &ice.Context{Name: "wx", Help: "wx",
}, },
} }
func init() { cli.Index.Register(Index, nil) } func init() { chat.Index.Register(Index, nil) }

51
type.go
View File

@ -3,6 +3,7 @@ package ice
import ( import (
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"bytes"
"encoding/csv" "encoding/csv"
"encoding/json" "encoding/json"
"errors" "errors"
@ -113,6 +114,7 @@ func (c *Context) Spawn(m *Message, name string, help string, arg ...string) *Co
func (c *Context) Begin(m *Message, arg ...string) *Context { func (c *Context) Begin(m *Message, arg ...string) *Context {
c.Caches[CTX_STATUS] = &Cache{Name: CTX_STATUS, Value: ""} c.Caches[CTX_STATUS] = &Cache{Name: CTX_STATUS, Value: ""}
c.Caches[CTX_STREAM] = &Cache{Name: CTX_STREAM, Value: ""} c.Caches[CTX_STREAM] = &Cache{Name: CTX_STREAM, Value: ""}
c.Caches[CTX_FOLLOW] = &Cache{Name: CTX_FOLLOW, Value: ""}
m.Log(LOG_BEGIN, "%s", c.Name) m.Log(LOG_BEGIN, "%s", c.Name)
if c.begin = m; c.server != nil { if c.begin = m; c.server != nil {
@ -120,6 +122,11 @@ func (c *Context) Begin(m *Message, arg ...string) *Context {
c.server.Begin(m, arg...) c.server.Begin(m, arg...)
}) })
} }
if c.context == Index {
c.Cap(CTX_FOLLOW, c.Name)
} else if c.context != nil {
c.Cap(CTX_FOLLOW, kit.Keys(c.context.Cap(CTX_FOLLOW), c.Name))
}
return c return c
} }
func (c *Context) Start(m *Message, arg ...string) bool { func (c *Context) Start(m *Message, arg ...string) bool {
@ -192,6 +199,9 @@ func (m *Message) Time(args ...interface{}) string {
func (m *Message) Target() *Context { func (m *Message) Target() *Context {
return m.target return m.target
} }
func (m *Message) Source() *Context {
return m.source
}
func (m *Message) Format(key interface{}) string { func (m *Message) Format(key interface{}) string {
switch key := key.(type) { switch key := key.(type) {
case string: case string:
@ -316,6 +326,21 @@ func (m *Message) Spawns(arg ...interface{}) *Message {
return msg return msg
} }
func (m *Message) CSV(text string) *Message {
bio := bytes.NewBufferString(text)
r := csv.NewReader(bio)
heads, _ := r.Read()
for {
lines, e := r.Read()
if e != nil {
break
}
for i, k := range heads {
m.Push(k, kit.Select("", lines, i))
}
}
return m
}
func (m *Message) Add(key string, arg ...string) *Message { func (m *Message) Add(key string, arg ...string) *Message {
switch key { switch key {
case MSG_DETAIL, MSG_RESULT: case MSG_DETAIL, MSG_RESULT:
@ -352,17 +377,19 @@ func (m *Message) Copy(msg *Message) *Message {
if msg == nil { if msg == nil {
return m return m
} }
for _, k := range msg.meta[MSG_OPTION] {
if kit.IndexOf(m.meta[MSG_OPTION], k) == -1 {
m.meta[MSG_OPTION] = append(m.meta[MSG_OPTION], k)
}
m.meta[k] = append(m.meta[k], msg.meta[k]...)
}
for _, k := range msg.meta[MSG_APPEND] { for _, k := range msg.meta[MSG_APPEND] {
if kit.IndexOf(m.meta[MSG_APPEND], k) == -1 { if kit.IndexOf(m.meta[MSG_APPEND], k) == -1 {
m.meta[MSG_APPEND] = append(m.meta[MSG_APPEND], k) m.meta[MSG_APPEND] = append(m.meta[MSG_APPEND], k)
} }
for _, v := range msg.meta[k] { m.meta[k] = append(m.meta[k], msg.meta[k]...)
m.meta[k] = append(m.meta[k], v)
}
}
for _, v := range msg.meta[MSG_RESULT] {
m.meta[MSG_RESULT] = append(m.meta[MSG_RESULT], v)
} }
m.meta[MSG_RESULT] = append(m.meta[MSG_RESULT], msg.meta[MSG_RESULT]...)
return m return m
} }
func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Message { func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Message {
@ -868,9 +895,13 @@ func (m *Message) Search(key interface{}, cb interface{}) *Message {
p := m.target.root p := m.target.root
if strings.Contains(key, ":") { if strings.Contains(key, ":") {
} else if key == "." {
if m.target.context != nil {
p = m.target.context
}
} else if strings.Contains(key, ".") { } else if strings.Contains(key, ".") {
list := strings.Split(key, ".") list := strings.Split(key, ".")
for _, p = range []*Context{m.target.root, m.target, m.source} {
for _, v := range list[:len(list)-1] { for _, v := range list[:len(list)-1] {
if s, ok := p.contexts[v]; ok { if s, ok := p.contexts[v]; ok {
p = s p = s
@ -879,6 +910,10 @@ func (m *Message) Search(key interface{}, cb interface{}) *Message {
break break
} }
} }
if p != nil {
break
}
}
if p == nil { if p == nil {
m.Log(LOG_WARN, "not found %s", key) m.Log(LOG_WARN, "not found %s", key)
break break
@ -1316,7 +1351,9 @@ func (m *Message) Capv(arg ...interface{}) interface{} {
for _, s := range []*Context{m.target} { for _, s := range []*Context{m.target} {
for c := s; c != nil; c = c.context { for c := s; c != nil; c = c.context {
if caps, ok := c.Caches[key]; ok { if caps, ok := c.Caches[key]; ok {
if len(arg) > 0 {
caps.Value = kit.Format(arg[0]) caps.Value = kit.Format(arg[0])
}
return caps.Value return caps.Value
} }
} }