diff --git a/base/nfs/nfs.go b/base/nfs/nfs.go
index 6a505107..c825f079 100644
--- a/base/nfs/nfs.go
+++ b/base/nfs/nfs.go
@@ -24,7 +24,6 @@ func _file_ext(name string) string {
}
func _file_list(m *ice.Message, root string, name string, level int, deep bool, dir_type string, dir_reg *regexp.Regexp, fields []string) {
- m.Debug("fuck %v %v", root, name)
if fs, e := ioutil.ReadDir(path.Join(root, name)); e != nil {
if f, e := os.Open(path.Join(root, name)); e == nil {
defer f.Close()
@@ -230,13 +229,6 @@ func _file_search(m *ice.Message, kind, name, text string, arg ...string) {
m.Push(kit.MDB_TEXT, "")
})
}
-func _file_render(m *ice.Message, kind, name, text string, arg ...string) {
- if m.Conf(FILE, kit.Keys("meta.source", _file_ext(name))) == "true" {
- _file_show(m, name)
- } else {
- m.Echo(name)
- }
-}
const (
CAT = "cat"
@@ -280,7 +272,8 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
},
Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- m.Cmd(mdb.SEARCH, mdb.CREATE, FILE, FILE, NFS)
+ m.Cmd(mdb.SEARCH, mdb.CREATE, FILE)
+ m.Cmd(mdb.SEARCH, mdb.CREATE, DIR)
m.Cmd(mdb.RENDER, mdb.CREATE, FILE, FILE, NFS)
m.Cmd(mdb.RENDER, mdb.CREATE, DIR)
@@ -300,7 +293,7 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
_file_search(m, arg[0], arg[1], arg[2], arg[3:]...)
}},
mdb.RENDER: {Name: "render type name text", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
- _file_render(m, arg[0], arg[1], arg[2], arg[3:]...)
+ _file_show(m, path.Join(arg[2], arg[1]))
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
@@ -309,7 +302,8 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
_file_search(m, arg[0], arg[1], arg[2], arg[3:]...)
}},
mdb.RENDER: {Name: "render type name text", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
- _file_list(m, "./", arg[1], 0, false, "both", nil, []string{"time", "size", "type", "path"})
+ _file_list(m, arg[2], arg[1], 0, m.Option(DIR_DEEP) == "true", kit.Select("both", m.Option(DIR_TYPE)),
+ nil, []string{"time", "size", "type", "path"})
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
rg, _ := regexp.Compile(m.Option(DIR_REG))
diff --git a/core/code/c.go b/core/code/c.go
index 6ef2b0b7..2f82d990 100644
--- a/core/code/c.go
+++ b/core/code/c.go
@@ -1,32 +1,39 @@
package code
import (
+ ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/mdb"
+ "github.com/shylinux/icebergs/base/nfs"
+ kit "github.com/shylinux/toolkits"
+
"bufio"
"os"
"path"
"strings"
-
- ice "github.com/shylinux/icebergs"
- "github.com/shylinux/icebergs/base/cli"
- "github.com/shylinux/icebergs/base/mdb"
- kit "github.com/shylinux/toolkits"
)
func _c_find(m *ice.Message, key string) {
- for _, p := range strings.Split(m.Cmdx(cli.SYSTEM, "find", ".", "-name", key), "\n") {
+ for _, p := range strings.Split(m.Cmdx(cli.SYSTEM, FIND, ".", "-name", key), "\n") {
if p == "" {
continue
}
- m.Push("file", strings.TrimPrefix(p, "./"))
- m.Push("line", 1)
- m.Push("text", "")
+ m.Push(kit.MDB_FILE, strings.TrimPrefix(p, "./"))
+ m.Push(kit.MDB_LINE, 1)
+ m.Push(kit.MDB_TEXT, "")
}
}
+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")
+}
func _c_tags(m *ice.Message, key string) {
- if _, e := os.Stat(path.Join(m.Option("_path"), ".tags")); e != nil {
- m.Cmd(cli.SYSTEM, "ctags", "-R", "-f", ".tags", "./")
+ if _, e := os.Stat(path.Join(m.Option("_path"), m.Conf(C, "meta.tags"))); e != nil {
+ // 创建索引
+ m.Cmd(cli.SYSTEM, CTAGS, "-R", "-f", m.Conf(C, "meta.tags"), "./")
}
- for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, "grep", "^"+key, ".tags"), "\n") {
+
+ for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, GREP, "^"+key+"\\>", m.Conf(C, "meta.tags")), "\n") {
ls := strings.SplitN(l, "\t", 2)
if len(ls) < 2 {
continue
@@ -44,29 +51,20 @@ func _c_tags(m *ice.Message, key string) {
bio := bufio.NewScanner(f)
for i := 1; bio.Scan(); i++ {
if i == line || bio.Text() == text {
- m.Push("file", strings.TrimPrefix(file, "./"))
- m.Push("line", i)
- m.Push("text", bio.Text())
+ m.Push(kit.MDB_FILE, strings.TrimPrefix(file, "./"))
+ m.Push(kit.MDB_LINE, i)
+ m.Push(kit.MDB_TEXT, bio.Text())
}
}
}
- m.Sort("line", "int")
+ m.Sort(kit.MDB_LINE, "int")
}
-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")
-}
-func _c_help(m *ice.Message, section, key string) {
- p := m.Cmd(cli.SYSTEM, "man", section, key).Append(cli.CMD_OUT)
+func _c_help(m *ice.Message, section, key string) string {
+ p := m.Cmd(cli.SYSTEM, MAN, section, key).Append(cli.CMD_OUT)
if p == "" {
- return
+ return ""
}
- ls := strings.Split(p, "\n")
- if len(ls) > 20 {
- p = strings.Join(ls[:20], "\n")
- }
p = strings.Replace(p, "_\x08", "", -1)
res := make([]byte, 0, len(p))
for i := 0; i < len(p); i++ {
@@ -77,10 +75,7 @@ func _c_help(m *ice.Message, section, key string) {
res = append(res, p[i])
}
}
-
- m.Push("file", key+".man"+section)
- m.Push("line", 1)
- m.Push("text", string(res))
+ return string(res)
}
const C = "c"
@@ -90,27 +85,135 @@ const MAN2 = "man2"
const MAN3 = "man3"
const MAN8 = "man8"
+const (
+ FIND = "find"
+ GREP = "grep"
+ CTAGS = "ctags"
+ MAN = "man"
+)
+
func init() {
Index.Register(&ice.Context{Name: C, Help: "c",
Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- m.Cmd(mdb.SEARCH, mdb.CREATE, H, C, c.Cap(ice.CTX_FOLLOW))
m.Cmd(mdb.SEARCH, mdb.CREATE, C, C, c.Cap(ice.CTX_FOLLOW))
- m.Cmd(mdb.SEARCH, mdb.CREATE, MAN3, C, c.Cap(ice.CTX_FOLLOW))
- m.Cmd(mdb.SEARCH, mdb.CREATE, MAN2, C, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.PLUGIN, mdb.CREATE, C, C, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.RENDER, mdb.CREATE, C, C, c.Cap(ice.CTX_FOLLOW))
+
+ m.Cmd(mdb.SEARCH, mdb.CREATE, H, C, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.PLUGIN, mdb.CREATE, H, C, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.RENDER, mdb.CREATE, H, C, c.Cap(ice.CTX_FOLLOW))
+
+ for _, k := range []string{MAN1, MAN2, MAN3, MAN8} {
+ m.Cmd(mdb.SEARCH, mdb.CREATE, k, MAN, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.PLUGIN, mdb.CREATE, k, MAN, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.RENDER, mdb.CREATE, k, MAN, c.Cap(ice.CTX_FOLLOW))
+ }
}},
C: {Name: C, Help: "c", Action: map[string]*ice.Action{
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
m.Option(cli.CMD_DIR, m.Option("_path"))
_c_find(m, kit.Select("main", arg, 1))
- _c_help(m, "2", kit.Select("main", arg, 1))
- _c_help(m, "3", kit.Select("main", arg, 1))
+ m.Cmdy(mdb.SEARCH, "man2", arg[1:])
_c_tags(m, kit.Select("main", arg, 1))
_c_grep(m, kit.Select("main", arg, 1))
}},
- }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) {
+ m.Echo(m.Conf(C, "meta.plug"))
+ }},
+ mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
+ m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1]))
+ }},
+ }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
+ MAN: {Name: MAN, Help: "man", Action: map[string]*ice.Action{
+ mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
+ for _, k := range []string{"1", "2", "3", "8"} {
+ if text := _c_help(m, k, kit.Select("main", arg, 1)); text != "" {
+ m.Push(kit.MDB_FILE, arg[1]+".man"+k)
+ m.Push(kit.MDB_LINE, "1")
+ m.Push(kit.MDB_TEXT, text)
+ }
+ }
+ }},
+ mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) {
+ m.Echo(m.Conf(C, "meta.man.plug"))
+ }},
+ mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
+ m.Echo(_c_help(m, strings.TrimPrefix(arg[0], "man"), strings.TrimSuffix(arg[1], "."+arg[0])))
+ }},
+ }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
+ },
+ Configs: map[string]*ice.Config{
+ C: {Name: C, Help: "c", Value: kit.Data(
+ "tags", ".tags",
+ "man.plug", kit.Dict(
+ "prefix", kit.Dict(
+ "NAME", "comment",
+ "LIBRARY", "comment",
+ "SYNOPSIS", "comment",
+ "DESCRIPTION", "comment",
+ "STANDARDS", "comment",
+ "SEE ALSO", "comment",
+ "HISTORY", "comment",
+ "BUGS", "comment",
+ ),
+ ),
+ "plug", kit.Dict(
+ "split", kit.Dict(
+ "space", " ",
+ "operator", "{[(.,;!|<>)]}",
+ ),
+ "prefix", kit.Dict(
+ "//", "comment",
+ "/*", "comment",
+ "*", "comment",
+ ),
+ "keyword", kit.Dict(
+ "#include", "keyword",
+ "#define", "keyword",
+ "#ifndef", "keyword",
+ "#ifdef", "keyword",
+ "#else", "keyword",
+ "#endif", "keyword",
- }},
+ "if", "keyword",
+ "else", "keyword",
+ "for", "keyword",
+ "while", "keyword",
+ "do", "keyword",
+ "break", "keyword",
+ "continue", "keyword",
+ "switch", "keyword",
+ "case", "keyword",
+ "default", "keyword",
+ "return", "keyword",
+
+ "typedef", "keyword",
+ "extern", "keyword",
+ "static", "keyword",
+ "const", "keyword",
+ "sizeof", "keyword",
+
+ "union", "datatype",
+ "struct", "datatype",
+ "unsigned", "datatype",
+ "double", "datatype",
+ "void", "datatype",
+ "long", "datatype",
+ "char", "datatype",
+ "int", "datatype",
+
+ "assert", "function",
+ "zmalloc", "function",
+
+ "NULL", "string",
+ "-1", "string",
+ "0", "string",
+ "1", "string",
+ "2", "string",
+ ),
+ ),
+ )},
},
}, nil)
}
diff --git a/core/code/go.go b/core/code/go.go
index 860cd899..b27637d7 100644
--- a/core/code/go.go
+++ b/core/code/go.go
@@ -1,15 +1,16 @@
package code
import (
+ ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/mdb"
+ "github.com/shylinux/icebergs/base/nfs"
+ kit "github.com/shylinux/toolkits"
+
"bufio"
"os"
"path"
"strings"
-
- ice "github.com/shylinux/icebergs"
- "github.com/shylinux/icebergs/base/cli"
- "github.com/shylinux/icebergs/base/mdb"
- kit "github.com/shylinux/toolkits"
)
func _go_find(m *ice.Message, key string) {
@@ -26,7 +27,7 @@ func _go_tags(m *ice.Message, key string) {
if _, e := os.Stat(path.Join(m.Option("_path"), ".tags")); e != nil {
m.Cmd(cli.SYSTEM, "gotags", "-R", "-f", ".tags", "./")
}
- for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, "grep", "^"+key, ".tags"), "\n") {
+ for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, "grep", "^"+key+"\\>", ".tags"), "\n") {
ls := strings.SplitN(l, "\t", 2)
if len(ls) < 2 {
continue
@@ -70,14 +71,54 @@ func _go_help(m *ice.Message, key string) {
m.Push("line", 1)
m.Push("text", string(res))
}
+
+const GO = "go"
+const GODOC = "godoc"
+const MOD = "mod"
+const SUM = "sum"
+
func init() {
- Index.Register(&ice.Context{Name: "go", Help: "go",
+ Index.Register(&ice.Context{Name: GO, Help: "go",
Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- m.Cmd(mdb.SEARCH, mdb.CREATE, "go", "go", c.Cap(ice.CTX_FOLLOW))
- m.Cmd(mdb.SEARCH, mdb.CREATE, "godoc", "go", c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.SEARCH, mdb.CREATE, GO, GO, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.PLUGIN, mdb.CREATE, GO, GO, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.RENDER, mdb.CREATE, GO, GO, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.ENGINE, mdb.CREATE, GO, GO, c.Cap(ice.CTX_FOLLOW))
+
+ m.Cmd(mdb.SEARCH, mdb.CREATE, GODOC, GO, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.PLUGIN, mdb.CREATE, GODOC, GO, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.RENDER, mdb.CREATE, GODOC, GODOC, c.Cap(ice.CTX_FOLLOW))
+
+ m.Cmd(mdb.PLUGIN, mdb.CREATE, MOD, MOD, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.PLUGIN, mdb.CREATE, MOD, MOD, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.RENDER, mdb.CREATE, SUM, SUM, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.RENDER, mdb.CREATE, SUM, SUM, c.Cap(ice.CTX_FOLLOW))
+
}},
- "go": {Name: "go", Help: "go", Action: map[string]*ice.Action{
+ MOD: {Name: MOD, Help: "mod", Action: map[string]*ice.Action{
+ mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) {
+ m.Echo(m.Conf(GO, "meta.mod.plug"))
+ }},
+ mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
+ m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1]))
+ }},
+ }},
+ SUM: {Name: SUM, Help: "sum", Action: map[string]*ice.Action{
+ mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) {
+ m.Echo(m.Conf(GO, "meta.mod.plug"))
+ }},
+ mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
+ m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1]))
+ }},
+ }},
+ GODOC: {Name: GODOC, Help: "godoc", Action: map[string]*ice.Action{
+ mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
+ m.Option(cli.CMD_DIR, arg[2])
+ m.Echo(m.Cmdx(cli.SYSTEM, GO, "doc", strings.TrimSuffix(arg[1], "."+arg[0])))
+ }},
+ }},
+ GO: {Name: GO, Help: "go", Action: map[string]*ice.Action{
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
m.Option(cli.CMD_DIR, m.Option("_path"))
_go_find(m, kit.Select("main", arg, 1))
@@ -85,9 +126,96 @@ func init() {
_go_help(m, kit.Select("main", arg, 1))
_go_grep(m, kit.Select("main", arg, 1))
}},
- }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) {
+ m.Echo(m.Conf(GO, "meta.plug"))
+ }},
+ mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
+ m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1]))
+ }},
+ mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
+ m.Option(cli.CMD_DIR, arg[2])
+ if strings.HasSuffix(arg[1], "test.go") {
+ m.Cmdy(cli.SYSTEM, GO, "test", "-v", "./"+arg[1])
+ } else {
+ m.Cmdy(cli.SYSTEM, GO, "run", "./"+arg[1])
+ }
+ }},
+ }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
+ },
+ Configs: map[string]*ice.Config{
+ GO: {Name: GO, Help: "go", Value: kit.Data(
+ "mod.plug", kit.Dict(
+ "prefix", kit.Dict(
+ "#", "comment",
+ ),
+ "keyword", kit.Dict(
+ "module", "keyword",
+ "require", "keyword",
+ "replace", "keyword",
+ "=>", "keyword",
+ ),
+ ),
+ "plug", kit.Dict(
+ "split", kit.Dict(
+ "space", " \t",
+ "operator", "{[(&.,;!|<>)]}",
+ ),
+ "prefix", kit.Dict(
+ "//", "comment",
+ "/*", "comment",
+ "*", "comment",
+ ),
+ "keyword", kit.Dict(
+ "package", "keyword",
+ "import", "keyword",
+ "const", "keyword",
+ "func", "keyword",
+ "var", "keyword",
+ "type", "keyword",
+ "struct", "keyword",
+ "interface", "keyword",
- }},
+ "if", "keyword",
+ "else", "keyword",
+ "for", "keyword",
+ "range", "keyword",
+ "break", "keyword",
+ "continue", "keyword",
+ "switch", "keyword",
+ "case", "keyword",
+ "default", "keyword",
+ "fallthrough", "keyword",
+
+ "go", "keyword",
+ "select", "keyword",
+ "return", "keyword",
+ "defer", "keyword",
+
+ "map", "datatype",
+ "chan", "datatype",
+ "string", "datatype",
+ "error", "datatype",
+ "bool", "datatype",
+ "byte", "datatype",
+ "int", "datatype",
+ "int64", "datatype",
+ "float64", "datatype",
+
+ "len", "function",
+ "cap", "function",
+ "copy", "function",
+ "append", "function",
+ "msg", "function",
+ "m", "function",
+
+ "nil", "string",
+ "-1", "string",
+ "0", "string",
+ "1", "string",
+ "2", "string",
+ ),
+ ),
+ )},
},
}, nil)
}
diff --git a/core/code/inner.go b/core/code/inner.go
index 320e42f0..9c4471b1 100644
--- a/core/code/inner.go
+++ b/core/code/inner.go
@@ -20,149 +20,78 @@ const (
const (
LIST = "list"
- SAVE = "save"
PLUG = "plug"
SHOW = "show"
+ SAVE = "save"
)
-func _inner_protect(m *ice.Message, name string) bool {
- ls := strings.Split(name, "/")
- return !m.Right(ls) && m.Conf(INNER, kit.Keys("meta.protect", ls[0])) == "true"
-}
-func _inner_source(m *ice.Message, name string) bool {
- return m.Conf(INNER, kit.Keys("meta.source", _inner_ext(name))) == "true"
-}
func _inner_ext(name string) string {
return strings.ToLower(kit.Select(path.Base(name), strings.TrimPrefix(path.Ext(name), ".")))
}
-func _inner_sub(m *ice.Message, action string, name string, arg ...string) bool {
- if _inner_protect(m, name) {
- m.Push("file", "../")
- return true
- }
- p := _inner_ext(name)
- if m.Cmdy(kit.Keys(p, action), name, arg); len(m.Resultv()) > 0 && m.Result(0) != "warn: " {
- return true
- }
- return false
-}
-
-func _inner_list(m *ice.Message, dir, file string) {
- if _inner_sub(m, LIST, path.Join(dir, file)) {
- return
- }
-
- if m.Set(ice.MSG_RESULT); file == "" || strings.HasSuffix(file, "/") || _inner_source(m, file) {
- m.Option(nfs.DIR_ROOT, dir)
- m.Option(nfs.DIR_DEEP, "true")
- m.Option(nfs.DIR_TYPE, nfs.TYPE_FILE)
- m.Cmdy(nfs.DIR, file, "path size time")
- return
- }
- m.Echo(path.Join(dir, file))
-}
-func _inner_save(m *ice.Message, name, text string) {
- if _inner_sub(m, SAVE, name) {
- return
- }
-
- if f, p, e := kit.Create(name); m.Assert(e) {
- defer f.Close()
- m.Cmd(web.FAVOR, "inner.save", "shell", name, text)
- if n, e := f.WriteString(text); m.Assert(e) {
- m.Log_EXPORT("file", name, "size", n)
+func _inner_show(m *ice.Message, ext, file, dir string, arg ...string) {
+ if m.Cmdy(mdb.RENDER, 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)
}
- m.Echo(p)
}
}
-func _inner_plug(m *ice.Message, name string) {
- if _inner_sub(m, PLUG, name) {
- return
- }
-
- p := _inner_ext(name)
- if ls := m.Confv(INNER, kit.Keys("meta.plug", p)); ls != nil {
- m.Echo(kit.Format(ls))
- return
- }
-
- m.Echo("{}")
-}
-func _inner_show(m *ice.Message, dir, file string) {
- name := path.Join(dir, file)
- if _inner_sub(m, SHOW, name) {
- return
- }
-
- p := _inner_ext(name)
- if ls := kit.Simple(m.Confv(INNER, kit.Keys("meta.show", p))); len(ls) > 0 {
- m.Cmdy(cli.SYSTEM, ls, name)
- m.Set(ice.MSG_APPEND)
- m.Cmd(web.FAVOR, "inner.run", "shell", name, m.Result())
- return
- }
-
- switch m.Set(ice.MSG_RESULT); p {
- case "go":
- m.Option(cli.CMD_DIR, dir)
- if strings.HasSuffix(name, "test.go") {
- m.Cmdy(cli.SYSTEM, "go", "test", "-v", "./"+file)
- } else {
- m.Cmdy(cli.SYSTEM, "go", "run", "./"+file)
- }
-
- case "csv":
- m.CSV(m.Cmdx("nfs.cat", name))
- case "md":
- m.Cmdy("web.wiki.md.note", name)
- case "shy":
- m.Echo(strings.ReplaceAll(strings.Join(m.Cmd("web.wiki.word", name).Resultv(), ""), "\n", " "))
- }
-}
-func _inner_main(m *ice.Message, dir, file string) {
- p := _inner_ext(file)
- key := strings.TrimSuffix(path.Base(file), "."+p)
- switch p {
- case "godoc":
- m.Option(cli.CMD_DIR, dir)
- m.Echo(m.Cmdx(cli.SYSTEM, "go", "doc", key))
-
- case "man8", "man3", "man2", "man1":
- p := m.Cmdx(cli.SYSTEM, "man", strings.TrimPrefix(p, "man"), key)
- p = strings.Replace(p, "_\x08", "", -1)
- res := make([]byte, 0, len(p))
- for i := 0; i < len(p); i++ {
- switch p[i] {
- case '\x08':
- i++
- default:
- res = append(res, p[i])
+func _inner_list(m *ice.Message, ext, file, dir string, arg ...string) {
+ if m.Cmdy(mdb.RENDER, ext, file, dir, arg); m.Result() == "" {
+ if m.Conf(INNER, kit.Keys("meta.source", ext)) == "true" {
+ if m.Cmdy(mdb.RENDER, nfs.FILE, file, dir, arg); m.Result() == "" {
+ m.Echo(path.Join(dir, file))
}
}
-
- m.Echo(string(res))
- default:
- _inner_list(m, dir, file)
}
}
func init() {
Index.Merge(&ice.Context{
+ Commands: map[string]*ice.Command{
+ INNER: {Name: "inner path=usr/demo file=hi.qrc line=1 查看:button=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) {
+ m.Cmdy(web.CACHE, web.UPLOAD)
+ m.Cmdy(web.CACHE, web.WATCH, m.Option(web.DATA), path.Join(m.Option("path"), m.Option("name")))
+ }},
+
+ mdb.SEARCH: {Name: "search type name text arg...", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
+ m.Cmdy(mdb.SEARCH, arg)
+ }},
+ mdb.PLUGIN: {Name: "plugin type name text arg...", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
+ if m.Cmdy(mdb.PLUGIN, arg); m.Result() == "" {
+ if m.Echo(m.Conf(INNER, kit.Keys("meta.plug", arg[0]))); m.Result() == "" {
+ m.Echo("{}")
+ }
+ }
+ }},
+ mdb.RENDER: {Name: "render type name text arg...", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
+ _inner_list(m, arg[0], arg[1], arg[2], arg[3:]...)
+ }},
+ mdb.ENGINE: {Name: "engine type name text arg...", Help: "引擎", Hand: func(m *ice.Message, arg ...string) {
+ _inner_show(m, arg[0], arg[1], arg[2], arg[3:]...)
+ }},
+ }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ if len(arg) < 2 {
+ _inner_list(m, nfs.DIR, "", kit.Select("", arg, 0))
+ return
+ }
+ _inner_list(m, _inner_ext(arg[1]), arg[1], arg[0])
+ }},
+ },
Configs: map[string]*ice.Config{
INNER: {Name: "inner", Help: "编辑器", Value: kit.Data(
- "protect", kit.Dict("etc", "true", "var", "true", "usr", "true"),
"source", kit.Dict(
"makefile", "true",
- "c", "true", "h", "true",
- "sh", "true", "shy", "true", "py", "true",
- "mod", "true", "sum", "true",
- "go", "true", "js", "true",
+ "shy", "true", "py", "true",
"md", "true", "csv", "true",
"txt", "true", "url", "true",
"conf", "true", "json", "true",
"ts", "true", "tsx", "true", "vue", "true", "sass", "true",
+ "html", "true", "css", "true",
),
"plug", kit.Dict(
"py", kit.Dict(
@@ -221,75 +150,5 @@ func init() {
),
)},
},
- Commands: map[string]*ice.Command{
- INNER: {Name: "inner path=usr/demo file=hi.qrc line=1 查看:button=auto", Help: "编辑器", Meta: kit.Dict(
- "display", "/plugin/local/code/inner.js", "style", "editor",
- ), Action: map[string]*ice.Action{
- "cmd": {Name: "cmd arg", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
- if m.Cmdy(kit.Split(arg[0])); !m.Hand {
- m.Cmdy(cli.SYSTEM, kit.Split(arg[0]))
- }
- }},
-
- "favor": {Name: "favor", Help: "收藏", Hand: func(m *ice.Message, arg ...string) {
- m.Cmd(web.FAVOR, arg, "extra", "extra.poster").Table(func(index int, value map[string]string, header []string) {
- m.Push("image", kit.Format(`
`,
- value["name"], value["text"], value["extra.poster"]))
- m.Push("video", kit.Format(``, value["text"]))
- })
- }},
- "find": {Name: "find word", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
- web.FavorList(m, arg[0], arg[1], arg[2:]...)
- }},
-
- "history": {Name: "history path name", Help: "历史", Hand: func(m *ice.Message, arg ...string) {
- msg := m.Cmd(web.STORY, web.HISTORY, path.Join("./", arg[0], arg[1]))
- m.Copy(msg, ice.MSG_APPEND, "time", "count", "key")
-
- if len(arg) > 2 && arg[2] != "" {
- m.Echo(m.Cmd(web.STORY, web.INDEX, arg[2]).Result())
- }
- }},
- "commit": {Name: "commit path name", Help: "提交", Hand: func(m *ice.Message, arg ...string) {
- msg := m.Cmd(web.STORY, web.CATCH, "", path.Join("./", arg[0], arg[1]))
- m.Copy(msg, ice.MSG_APPEND, "time", "count", "key")
- }},
- "recover": {Name: "recover", Help: "复盘", Hand: func(m *ice.Message, arg ...string) {
- msg := m.Cmd(web.STORY, web.HISTORY, path.Join("./", arg[0], arg[1])+".display")
- m.Copy(msg, ice.MSG_APPEND, "time", "count", "key", "drama")
-
- if len(arg) > 2 && arg[2] != "" {
- m.Echo(m.Cmd(web.STORY, web.INDEX, arg[2]).Result())
- }
- }},
- "record": {Name: "record", Help: "记录", Hand: func(m *ice.Message, arg ...string) {
- msg := m.Cmd(web.STORY, web.CATCH, "display", path.Join("./", m.Option("path"), m.Option("name"))+".display", m.Option("display"))
- m.Copy(msg, ice.MSG_APPEND, "time", "count", "key")
- }},
-
- "log": {Name: "log path name", Help: "日志", Hand: func(m *ice.Message, arg ...string) {
- web.FavorList(m, "inner.run", "", "time", "id", "type", "name", "text")
- }},
- "run": {Name: "run path name", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
- _inner_show(m, arg[0], arg[1])
- }},
- PLUG: {Name: "plug path name", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
- _inner_plug(m, path.Join("./", arg[0], arg[1]))
- }},
- SAVE: {Name: "save path name content", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
- _inner_save(m, path.Join("./", arg[0], arg[1]), kit.Select(m.Option("content"), arg, 2))
- }},
-
- web.UPLOAD: {Name: "upload path name", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
- m.Cmdy(web.CACHE, web.UPLOAD)
- m.Cmdy(web.CACHE, web.WATCH, m.Option(web.DATA), path.Join(m.Option("path"), m.Option("name")))
- }},
- mdb.SEARCH: {Name: "search type name text arg...", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
- m.Cmdy(mdb.SEARCH, arg)
- }},
- }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
- _inner_main(m, arg[0], kit.Select("", arg, 1))
- }},
- },
}, nil)
}
diff --git a/core/code/js.go b/core/code/js.go
index f7c83e98..db65923d 100644
--- a/core/code/js.go
+++ b/core/code/js.go
@@ -1,16 +1,17 @@
package code
import (
+ ice "github.com/shylinux/icebergs"
+ "github.com/shylinux/icebergs/base/cli"
+ "github.com/shylinux/icebergs/base/mdb"
+ "github.com/shylinux/icebergs/base/nfs"
+ "github.com/shylinux/icebergs/base/web"
+ kit "github.com/shylinux/toolkits"
+
"net/http"
"os"
"path"
"strings"
-
- ice "github.com/shylinux/icebergs"
- "github.com/shylinux/icebergs/base/cli"
- "github.com/shylinux/icebergs/base/mdb"
- "github.com/shylinux/icebergs/base/web"
- kit "github.com/shylinux/toolkits"
)
func _js_find(m *ice.Message, key string) {
@@ -28,18 +29,19 @@ func _js_grep(m *ice.Message, key string) {
}
const JS = "js"
+const TS = "ts"
+const TSX = "tsx"
+const CSS = "css"
+const HTML = "html"
const NODE = "node"
func init() {
Index.Register(&ice.Context{Name: JS, Help: "js",
- Configs: map[string]*ice.Config{
- NODE: {Name: NODE, Help: "服务器", Value: kit.Data(
- "source", "https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-x64.tar.xz",
- )},
- },
Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(mdb.SEARCH, mdb.CREATE, JS, JS, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.PLUGIN, mdb.CREATE, JS, JS, c.Cap(ice.CTX_FOLLOW))
+ m.Cmd(mdb.RENDER, mdb.CREATE, JS, JS, c.Cap(ice.CTX_FOLLOW))
}},
NODE: {Name: NODE, Help: "node", Action: map[string]*ice.Action{
"install": {Name: "install", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
@@ -56,18 +58,101 @@ func init() {
m.Cmd(cli.SYSTEM, "tar", "xvf", path.Base(source))
m.Echo(p)
}},
- }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
- }},
JS: {Name: JS, Help: "js", Action: map[string]*ice.Action{
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
m.Option(cli.CMD_DIR, m.Option("_path"))
_js_find(m, kit.Select("main", arg, 1))
_js_grep(m, kit.Select("main", arg, 1))
}},
- }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) {
+ m.Echo(m.Conf(JS, "meta.plug"))
+ }},
+ mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
+ m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1]))
+ }},
+ }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
+ },
+ Configs: map[string]*ice.Config{
+ NODE: {Name: NODE, Help: "服务器", Value: kit.Data(
+ "source", "https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-x64.tar.xz",
+ )},
+ JS: {Name: JS, Help: "js", Value: kit.Data(
+ "plug", kit.Dict(
+ "split", kit.Dict(
+ "space", " \t",
+ "operator", "{[(&.,;!|<>)]}",
+ ),
+ "prefix", kit.Dict(
+ "//", "comment",
+ "/*", "comment",
+ "*", "comment",
+ ),
+ "keyword", kit.Dict(
+ "var", "keyword",
+ "new", "keyword",
+ "delete", "keyword",
+ "typeof", "keyword",
+ "function", "keyword",
- }},
+ "if", "keyword",
+ "else", "keyword",
+ "for", "keyword",
+ "while", "keyword",
+ "break", "keyword",
+ "continue", "keyword",
+ "switch", "keyword",
+ "case", "keyword",
+ "default", "keyword",
+ "return", "keyword",
+
+ "window", "function",
+ "console", "function",
+ "document", "function",
+ "arguments", "function",
+ "event", "function",
+ "Date", "function",
+ "JSON", "function",
+
+ "0", "string",
+ "1", "string",
+ "10", "string",
+ "-1", "string",
+ "true", "string",
+ "false", "string",
+ "undefined", "string",
+ "null", "string",
+
+ "__proto__", "function",
+ "setTimeout", "function",
+ "createElement", "function",
+ "appendChild", "function",
+ "removeChild", "function",
+ "parentNode", "function",
+ "childNodes", "function",
+
+ "Volcanos", "function",
+ "request", "function",
+ "require", "function",
+
+ "cb", "function",
+ "cbs", "function",
+ "shy", "function",
+ "can", "function",
+ "sub", "function",
+ "msg", "function",
+ "res", "function",
+ "pane", "function",
+ "plugin", "function",
+
+ "-1", "string",
+ "0", "string",
+ "1", "string",
+ "2", "string",
+ ),
+ ),
+ )},
},
}, nil)
}
diff --git a/core/code/sh.go b/core/code/sh.go
index de8368e2..ca1f0aaa 100644
--- a/core/code/sh.go
+++ b/core/code/sh.go
@@ -4,7 +4,10 @@ import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/icebergs/base/mdb"
+ "github.com/shylinux/icebergs/base/nfs"
kit "github.com/shylinux/toolkits"
+
+ "path"
)
const SH = "sh"
@@ -14,20 +17,77 @@ func init() {
Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(mdb.SEARCH, mdb.CREATE, SH, SH, c.Cap(ice.CTX_FOLLOW))
- m.Cmd(mdb.SEARCH, mdb.CREATE, "man1", SH, c.Cap(ice.CTX_FOLLOW))
- m.Cmd(mdb.SEARCH, mdb.CREATE, "man8", 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))
}},
SH: {Name: SH, Help: "sh", Action: map[string]*ice.Action{
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
m.Option(cli.CMD_DIR, m.Option("_path"))
_c_find(m, kit.Select("main", arg, 1))
- _c_help(m, "1", kit.Select("main", arg, 1))
- _c_help(m, "8", kit.Select("main", arg, 1))
+ m.Cmdy(mdb.SEARCH, "man1", arg[1:])
_c_grep(m, kit.Select("main", arg, 1))
}},
- }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) {
+ m.Echo(m.Conf(SH, "meta.plug"))
+ }},
+ mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
+ m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1]))
+ }},
+ }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
+ },
+ Configs: map[string]*ice.Config{
+ SH: {Name: SH, Help: "sh", Value: kit.Data(
+ "plug", kit.Dict(
+ "split", kit.Dict(
+ "space", " ",
+ "operator", "{[(.,;!|<>)]}",
+ ),
+ "prefix", kit.Dict(
+ "#", "comment",
+ ),
+ "suffix", kit.Dict(
+ "{", "comment",
+ ),
+ "keyword", kit.Dict(
+ "export", "keyword",
+ "source", "keyword",
+ "require", "keyword",
- }},
+ "if", "keyword",
+ "then", "keyword",
+ "else", "keyword",
+ "fi", "keyword",
+ "for", "keyword",
+ "while", "keyword",
+ "do", "keyword",
+ "done", "keyword",
+ "esac", "keyword",
+ "case", "keyword",
+ "in", "keyword",
+ "return", "keyword",
+
+ "shift", "keyword",
+ "local", "keyword",
+ "echo", "keyword",
+ "eval", "keyword",
+ "kill", "keyword",
+ "let", "keyword",
+ "cd", "keyword",
+
+ "xargs", "function",
+ "date", "function",
+ "find", "function",
+ "grep", "function",
+ "sed", "function",
+ "awk", "function",
+ "pwd", "function",
+ "ps", "function",
+ "ls", "function",
+ "rm", "function",
+ "go", "function",
+ ),
+ ),
+ )},
},
}, nil)
}
diff --git a/misc/git/git.go b/misc/git/git.go
index 594f95e7..aa96e49b 100644
--- a/misc/git/git.go
+++ b/misc/git/git.go
@@ -4,6 +4,7 @@ import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/icebergs/base/mdb"
+ "github.com/shylinux/icebergs/base/nfs"
"github.com/shylinux/icebergs/base/web"
"github.com/shylinux/icebergs/core/code"
"github.com/shylinux/icebergs/core/wiki"
@@ -274,8 +275,8 @@ var Index = &ice.Context{Name: "git", Help: "代码库",
}
}},
- "trend": {Name: "trend name=auto begin_time=@date auto", Help: "趋势图", Meta: kit.Dict(
- "display", "story/trend",
+ "trend": {Name: "trend repos=auto begin_time=@date auto", Help: "趋势图", Meta: kit.Dict(
+ "display", "/plugin/local/story/trend.js",
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 {
m.Option("_display", "table")
@@ -283,7 +284,16 @@ var Index = &ice.Context{Name: "git", Help: "代码库",
m.Cmdy("total", arg)
}},
- "/webhook": {Name: "/webhook", Help: "/webhook", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ "spide": {Name: "spide repos=auto begin_time=@date auto", Help: "趋势图", Meta: kit.Dict(
+ "display", "/plugin/local/story/trend.js",
+ ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ if len(arg) == 0 {
+ m.Option("_display", "table")
+ m.Cmdy("total", arg)
+ return
+ }
+ m.Option(nfs.DIR_DEEP, "true")
+ m.Cmdy(nfs.DIR, mdb.RENDER, nfs.DIR, "", path.Join("usr", arg[0]))
}},
},
}