diff --git a/base/mdb/mdb.go b/base/mdb/mdb.go index bb0f2e6a..87539dc0 100644 --- a/base/mdb/mdb.go +++ b/base/mdb/mdb.go @@ -23,6 +23,17 @@ func _hash_insert(m *ice.Message, prefix, key string, arg ...string) string { return m.Rich(prefix, key, kit.Dict(arg)) } +func _hash_inputs(m *ice.Message, prefix, key string, field, value string) { + list := map[string]int{} + m.Richs(prefix, key, kit.MDB_FOREACH, func(key string, val map[string]interface{}) { + list[kit.Format(val[field])]++ + }) + for k, i := range list { + m.Push("key", k) + m.Push("count", i) + } + m.Sort("count", "int_r") +} func _hash_modify(m *ice.Message, prefix, key string, field, value string, arg ...string) { m.Richs(prefix, key, value, func(key string, value map[string]interface{}) { for i := 0; i < len(arg)-1; i += 2 { @@ -84,9 +95,7 @@ func _hash_import(m *ice.Message, prefix, key, file string) { } func _hash_select(m *ice.Message, prefix, key, field, value string) { fields := strings.Split(kit.Select("time,name", m.Option("fields")), ",") - m.Debug("what %v %v", prefix, key, value) m.Richs(prefix, key, value, func(key string, val map[string]interface{}) { - m.Debug("what %v %v", prefix, key) if value == kit.MDB_FOREACH { m.Push(key, val, fields) return @@ -279,6 +288,8 @@ const ( IMPORT = "import" EXPORT = "export" + INPUTS = "inputs" + INSERT = "insert" MODIFY = "modify" DELETE = "delete" @@ -338,6 +349,13 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块", _list_import(m, arg[0], arg[1], file) } }}, + INPUTS: {Name: "inputs conf key type field value", Help: "输入补全", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + switch arg[2] { + case HASH: + _hash_inputs(m, arg[0], arg[1], arg[3], kit.Select("", arg, 4)) + case LIST: + } + }}, }, } @@ -346,5 +364,6 @@ func init() { IMPORT, EXPORT, SELECT, PLUGIN, ENGINE, SEARCH, RENDER, INSERT, MODIFY, DELETE, + INPUTS, ) } diff --git a/core/chat/study.go b/core/chat/study.go new file mode 100644 index 00000000..61e04f9c --- /dev/null +++ b/core/chat/study.go @@ -0,0 +1,68 @@ +package chat + +import ( + ice "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/base/mdb" + kit "github.com/shylinux/toolkits" +) + +var _target_insert = kit.List( + "_input", "text", "name", "type", "value", "@key", + "_input", "text", "name", "name", "value", "@key", + "_input", "text", "name", "text", "value", "@key", +) + +const ( + STUDY = "study" + TARGET = "target" + // ACTION = "action" + ASSESS = "assess" +) + +func init() { + Index.Register(&ice.Context{Name: STUDY, Help: "study", + Configs: map[string]*ice.Config{ + TARGET: {Name: "target", Help: "大纲", Value: kit.Data()}, + ACTION: {Name: "action", Help: "互动", Value: kit.Data()}, + ASSESS: {Name: "assess", Help: "评测", Value: kit.Data()}, + }, + 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() }}, + + TARGET: {Name: "target hash=auto auto 添加:button 导出:button 导入:button", Help: "大纲", Meta: kit.Dict( + "添加", _target_insert, + ), Action: map[string]*ice.Action{ + mdb.INSERT: {Name: "insert [key value]...", Help: "添加", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(mdb.INSERT, m.Prefix(TARGET), m.Option(ice.MSG_DOMAIN), mdb.HASH, arg) + }}, + mdb.MODIFY: {Name: "modify key value", Help: "编辑", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(mdb.MODIFY, m.Prefix(TARGET), m.Option(ice.MSG_DOMAIN), mdb.HASH, "", m.Option("hash"), arg[0], arg[1]) + }}, + mdb.DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(mdb.DELETE, m.Prefix(TARGET), m.Option(ice.MSG_DOMAIN), mdb.HASH, "", m.Option("hash")) + }}, + mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(mdb.EXPORT, m.Prefix(TARGET), m.Option(ice.MSG_DOMAIN), mdb.HASH) + }}, + mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(mdb.IMPORT, m.Prefix(TARGET), m.Option(ice.MSG_DOMAIN), mdb.HASH) + }}, + + mdb.INPUTS: {Name: "inputs key value", Help: "补全", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(mdb.INPUTS, m.Prefix(TARGET), m.Option(ice.MSG_DOMAIN), mdb.HASH, arg) + }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Option("fields", "time,hash,type,name,text") + m.Cmdy(mdb.SELECT, m.Prefix(TARGET), m.Option(ice.MSG_DOMAIN), mdb.HASH, "", kit.Select(kit.MDB_FOREACH, arg, 0)) + if len(arg) == 0 { + m.PushAction("备课", "学习", "测试", "删除") + } + }}, + ACTION: {Name: "action", Help: "互动", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }}, + ASSESS: {Name: "assess", Help: "评测", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }}, + }, + }, nil) +} diff --git a/core/code/c.go b/core/code/c.go index c6f2199a..545288b2 100644 --- a/core/code/c.go +++ b/core/code/c.go @@ -25,7 +25,7 @@ func _c_find(m *ice.Message, key string) { } func _c_grep(m *ice.Message, key string) { m.Split(m.Cmd(cli.SYSTEM, GREP, "--exclude-dir=.git", "--exclude-dir=pluged", "--exclude=.[a-z]*", - "-rn", key, ".").Append(cli.CMD_OUT), "file:line:text", ":", "\n") + "-rn", "\\<"+key+"\\>", ".").Append(cli.CMD_OUT), "file:line:text", ":", "\n") } func _c_tags(m *ice.Message, key string) { if _, e := os.Stat(path.Join(m.Option("_path"), m.Conf(C, "meta.tags"))); e != nil { diff --git a/core/code/code.go b/core/code/code.go index e49218ff..765dd248 100644 --- a/core/code/code.go +++ b/core/code/code.go @@ -17,6 +17,11 @@ import ( "strings" ) +const ( + VEDIO = "vedio" + QRCODE = "qrcode" +) + const ( // CODE INSTALL = "_install" PREPARE = "_prepare" diff --git a/core/code/go.go b/core/code/go.go index a68e38e1..7c479f2c 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -146,6 +146,7 @@ func init() { } else { m.Cmdy(cli.SYSTEM, GO, "run", "./"+arg[1]) } + m.Set(ice.MSG_APPEND) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, }, diff --git a/core/code/inner.go b/core/code/inner.go index 7b482588..5cbbb73d 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -12,30 +12,10 @@ import ( "strings" ) -const ( - INNER = "inner" - VEDIO = "vedio" - QRCODE = "qrcode" -) - -const ( - LIST = "list" - PLUG = "plug" - SHOW = "show" - SAVE = "save" -) - func _inner_ext(name string) string { return strings.ToLower(kit.Select(path.Base(name), strings.TrimPrefix(path.Ext(name), "."))) } -func _inner_show(m *ice.Message, ext, file, dir string, arg ...string) { - if m.Cmdy(mdb.ENGINE, ext, file, dir, arg); m.Result() == "" { - if ls := kit.Simple(m.Confv(INNER, kit.Keys("meta.show", ext))); len(ls) > 0 { - m.Cmdy(cli.SYSTEM, ls, path.Join(dir, file)).Set(ice.MSG_APPEND) - } - } -} func _inner_list(m *ice.Message, ext, file, dir string, arg ...string) { if !m.Right(strings.Split(dir, "/"), file) { return @@ -48,11 +28,30 @@ func _inner_list(m *ice.Message, ext, file, dir string, arg ...string) { } } } +func _inner_show(m *ice.Message, ext, file, dir string, arg ...string) { + if m.Cmdy(mdb.ENGINE, ext, file, dir, arg); m.Result() == "" { + if ls := kit.Simple(m.Confv(INNER, kit.Keys("meta.show", ext))); len(ls) > 0 { + m.Cmdy(cli.SYSTEM, ls, path.Join(dir, file)).Set(ice.MSG_APPEND) + } + } +} + +const ( + LIST = "list" + PLUG = "plug" + SHOW = "show" + SAVE = "save" +) + +const ( + INNER = "inner" + VIMER = "vimer" +) func init() { Index.Merge(&ice.Context{ Commands: map[string]*ice.Command{ - INNER: {Name: "inner path=usr/demo file=hi.sh line=1 auto", Help: "编辑器", Meta: kit.Dict( + INNER: {Name: "inner path=usr/demo file=hi.sh line=1 auto", Help: "阅读器", Meta: kit.Dict( "display", "/plugin/local/code/inner.js", "style", "editor", ), Action: map[string]*ice.Action{ web.UPLOAD: {Name: "upload path name", Help: "上传", Hand: func(m *ice.Message, arg ...string) { @@ -83,9 +82,14 @@ func init() { } _inner_list(m, _inner_ext(arg[1]), arg[1], arg[0]) }}, + VIMER: {Name: "vimer path=usr/demo file=hi.sh line=1 auto", Help: "编辑器", Meta: kit.Dict( + "display", "/plugin/local/code/vimer.js", "style", "editor", + ), Action: map[string]*ice.Action{}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Cmdy(INNER, arg) + }}, }, Configs: map[string]*ice.Config{ - INNER: {Name: "inner", Help: "编辑器", Value: kit.Data( + INNER: {Name: "inner", Help: "阅读器", Value: kit.Data( "source", kit.Dict( "license", "true", "makefile", "true", diff --git a/core/code/sh.go b/core/code/sh.go index b79c6159..825147eb 100644 --- a/core/code/sh.go +++ b/core/code/sh.go @@ -19,6 +19,7 @@ func init() { m.Cmd(mdb.SEARCH, mdb.CREATE, SH, SH, c.Cap(ice.CTX_FOLLOW)) m.Cmd(mdb.PLUGIN, mdb.CREATE, SH, SH, c.Cap(ice.CTX_FOLLOW)) m.Cmd(mdb.RENDER, mdb.CREATE, SH, SH, c.Cap(ice.CTX_FOLLOW)) + m.Cmd(mdb.ENGINE, mdb.CREATE, SH, SH, c.Cap(ice.CTX_FOLLOW)) }}, SH: {Name: SH, Help: "sh", Action: map[string]*ice.Action{ mdb.SEARCH: {Name: "search type name text", Hand: func(m *ice.Message, arg ...string) { @@ -37,7 +38,9 @@ func init() { m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }}, mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(cli.SYSTEM, path.Join(arg[2], arg[1])) + m.Option(cli.CMD_DIR, arg[2]) + m.Cmdy(cli.SYSTEM, arg[1]) + m.Set(ice.MSG_APPEND) }}, "man": {Hand: func(m *ice.Message, arg ...string) { diff --git a/meta.go b/meta.go index 49be484a..c35b154f 100644 --- a/meta.go +++ b/meta.go @@ -83,7 +83,7 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa // 查找数据 var v interface{} switch k { - case kit.MDB_KEY, kit.MDB_ZONE: + case kit.MDB_KEY, kit.MDB_ZONE, kit.MDB_HASH: if key != "" { v = key break diff --git a/misc.go b/misc.go index c4362a4d..36a1ac83 100644 --- a/misc.go +++ b/misc.go @@ -13,6 +13,11 @@ func (m *Message) Prefix(arg ...string) string { } func (m *Message) Save(arg ...string) *Message { list := []string{} + if len(arg) == 0 { + for k := range m.target.Configs { + arg = append(arg, k) + } + } for _, k := range arg { list = append(list, kit.Keys(m.Cap(CTX_FOLLOW), k)) }