1
0
forked from x/icebergs
This commit is contained in:
harveyshao 2021-09-29 19:57:01 +08:00
parent 46cee7a64e
commit 169888c834
3 changed files with 104 additions and 93 deletions

View File

@ -65,106 +65,104 @@ const (
const INNER = "inner" const INNER = "inner"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{ INNER: {Name: "inner path=src/ file=main.go line=1 auto", Help: "源代码", Meta: kit.Dict(
INNER: {Name: "inner path=src/ file=main.go line=1 auto", Help: "源代码", Meta: kit.Dict( ice.Display("/plugin/local/code/inner.js", "editor"),
ice.Display("/plugin/local/code/inner.js", "editor"), ), Action: map[string]*ice.Action{
), Action: map[string]*ice.Action{ mdb.PLUGIN: {Name: "plugin", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
mdb.PLUGIN: {Name: "plugin", Help: "插件", Hand: func(m *ice.Message, arg ...string) { if m.Cmdy(mdb.PLUGIN, arg); m.Result() == "" {
if m.Cmdy(mdb.PLUGIN, arg); m.Result() == "" { m.Echo(kit.Select("{}", m.Conf(INNER, kit.Keym(PLUG, arg[0]))))
m.Echo(kit.Select("{}", m.Conf(INNER, kit.Keym(PLUG, arg[0]))))
}
}},
mdb.ENGINE: {Name: "engine", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
_inner_show(m, arg[0], arg[1], arg[2])
}},
mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
if strings.Contains(arg[1], ";") {
ls := strings.Split(arg[1], ";")
arg[0] = ls[0]
arg[1] = ls[1]
}
m.Option(cli.CMD_DIR, arg[2])
m.Option(nfs.DIR_ROOT, arg[2])
m.Cmdy(mdb.SEARCH, arg[:2], "cmd,file,line,text")
}},
mdb.INPUTS: {Name: "favor inputs", Help: "补全"},
ctx.COMMAND: {Name: "command", Help: "命令"},
FAVOR: {Name: "favor", Help: "收藏"},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) < 2 {
nfs.Dir(m, kit.MDB_PATH)
return
} }
_inner_list(m, kit.Ext(arg[1]), arg[1], arg[0])
}}, }},
}, mdb.ENGINE: {Name: "engine", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
Configs: map[string]*ice.Config{ _inner_show(m, arg[0], arg[1], arg[2])
INNER: {Name: "inner", Help: "源代码", Value: kit.Data( }},
cli.SOURCE, kit.Dict( mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
"s", ice.TRUE, "S", ice.TRUE, if strings.Contains(arg[1], ";") {
"shy", ice.TRUE, "py", ice.TRUE, ls := strings.Split(arg[1], ";")
"csv", ice.TRUE, "json", ice.TRUE, arg[0] = ls[0]
"css", ice.TRUE, "html", ice.TRUE, arg[1] = ls[1]
"txt", ice.TRUE, "url", ice.TRUE, }
"log", ice.TRUE, "err", ice.TRUE, m.Option(cli.CMD_DIR, arg[2])
m.Option(nfs.DIR_ROOT, arg[2])
m.Cmdy(mdb.SEARCH, arg[:2], "cmd,file,line,text")
}},
mdb.INPUTS: {Name: "favor inputs", Help: "补全"},
ctx.COMMAND: {Name: "command", Help: "命令"},
FAVOR: {Name: "favor", Help: "收藏"},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) < 2 {
nfs.Dir(m, kit.MDB_PATH)
return
}
_inner_list(m, kit.Ext(arg[1]), arg[1], arg[0])
}},
}, Configs: map[string]*ice.Config{
INNER: {Name: "inner", Help: "源代码", Value: kit.Data(
cli.SOURCE, kit.Dict(
"s", ice.TRUE, "S", ice.TRUE,
"shy", ice.TRUE, "py", ice.TRUE,
"csv", ice.TRUE, "json", ice.TRUE,
"css", ice.TRUE, "html", ice.TRUE,
"txt", ice.TRUE, "url", ice.TRUE,
"log", ice.TRUE, "err", ice.TRUE,
"md", ice.TRUE, "license", ice.TRUE, "makefile", ice.TRUE, "sql", ice.TRUE, "md", ice.TRUE, "license", ice.TRUE, "makefile", ice.TRUE, "sql", ice.TRUE,
"ini", ice.TRUE, "conf", ice.TRUE, "toml", ice.TRUE, "yaml", ice.TRUE, "yml", ice.TRUE, "ini", ice.TRUE, "conf", ice.TRUE, "toml", ice.TRUE, "yaml", ice.TRUE, "yml", ice.TRUE,
),
PLUG, kit.Dict(
"s", kit.Dict(
PREFIX, kit.Dict("//", COMMENT),
KEYWORD, kit.Dict(
"TEXT", KEYWORD,
"RET", KEYWORD,
),
), ),
PLUG, kit.Dict( "S", kit.Dict(
"s", kit.Dict( PREFIX, kit.Dict("//", COMMENT),
PREFIX, kit.Dict("//", COMMENT), KEYWORD, kit.Dict(),
KEYWORD, kit.Dict( ),
"TEXT", KEYWORD, "py", kit.Dict(
"RET", KEYWORD, PREFIX, kit.Dict("#", COMMENT),
), KEYWORD, kit.Dict("print", KEYWORD),
),
"html", kit.Dict(
SPLIT, kit.Dict(
"space", " ",
"operator", "<>",
), ),
"S", kit.Dict( KEYWORD, kit.Dict(
PREFIX, kit.Dict("//", COMMENT), "head", KEYWORD,
KEYWORD, kit.Dict(), "body", KEYWORD,
),
"py", kit.Dict(
PREFIX, kit.Dict("#", COMMENT),
KEYWORD, kit.Dict("print", KEYWORD),
),
"html", kit.Dict(
SPLIT, kit.Dict(
"space", " ",
"operator", "<>",
),
KEYWORD, kit.Dict(
"head", KEYWORD,
"body", KEYWORD,
),
),
"css", kit.Dict(
SUFFIX, kit.Dict("{", COMMENT),
),
"yaml", kit.Dict(
PREFIX, kit.Dict("#", COMMENT),
),
"yml", kit.Dict(
PREFIX, kit.Dict("#", COMMENT),
), ),
),
"css", kit.Dict(
SUFFIX, kit.Dict("{", COMMENT),
),
"yaml", kit.Dict(
PREFIX, kit.Dict("#", COMMENT),
),
"yml", kit.Dict(
PREFIX, kit.Dict("#", COMMENT),
),
"md", kit.Dict(), "md", kit.Dict(),
"makefile", kit.Dict( "makefile", kit.Dict(
PREFIX, kit.Dict("#", COMMENT), PREFIX, kit.Dict("#", COMMENT),
SUFFIX, kit.Dict(":", COMMENT), SUFFIX, kit.Dict(":", COMMENT),
KEYWORD, kit.Dict( KEYWORD, kit.Dict(
"ifeq", KEYWORD, "ifeq", KEYWORD,
"ifneq", KEYWORD, "ifneq", KEYWORD,
"else", KEYWORD, "else", KEYWORD,
"endif", KEYWORD, "endif", KEYWORD,
),
), ),
), ),
SHOW, kit.Dict( ),
"py", []string{"python"}, SHOW, kit.Dict(
"js", []string{"node"}, "py", []string{"python"},
), "js", []string{"node"},
)}, ),
}, )},
},
}) })
} }

View File

@ -16,13 +16,19 @@ func _spark_show(m *ice.Message, name, text string, arg ...string) {
prompt := kit.Select(name+"> ", m.Conf(SPARK, kit.Keym(ssh.PROMPT, name))) prompt := kit.Select(name+"> ", m.Conf(SPARK, kit.Keym(ssh.PROMPT, name)))
m.Echo(`<div class="story" data-type="spark" data-name="%s">`, name) m.Echo(`<div class="story" data-type="spark" data-name="%s">`, name)
defer m.Echo("</div>")
if name == "inner" {
m.Echo(text)
return
}
for _, l := range strings.Split(text, "\n") { for _, l := range strings.Split(text, "\n") {
m.Echo("<div>") m.Echo("<div>")
m.Echo("<label>").Echo(prompt).Echo("</label>") m.Echo("<label>").Echo(prompt).Echo("</label>")
m.Echo("<span>").Echo(l).Echo("</span>") m.Echo("<span>").Echo(l).Echo("</span>")
m.Echo("</div>") m.Echo("</div>")
} }
m.Echo("</div>")
} }
const ( const (

View File

@ -2,6 +2,7 @@ package ice
import ( import (
"path" "path"
"reflect"
"strings" "strings"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
@ -75,6 +76,12 @@ func (m *Message) PushVideos(key, src string, arg ...string) { // key src [size]
m.Push(key, Render(m, RENDER_VIDEOS, src, arg)) m.Push(key, Render(m, RENDER_VIDEOS, src, arg))
} }
func (m *Message) PushAction(list ...interface{}) { func (m *Message) PushAction(list ...interface{}) {
for i, item := range list {
if t := reflect.TypeOf(item); t.Kind() == reflect.Func {
list[i] = kit.FuncName(item)
}
}
m.Table(func(index int, value map[string]string, head []string) { m.Table(func(index int, value map[string]string, head []string) {
m.PushButton(kit.Simple(list...)...) m.PushButton(kit.Simple(list...)...)
}) })