1
0
forked from x/icebergs

opt vimer.js

This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-03-15 20:37:25 +08:00
parent 6283d157ce
commit 2edcda85e8
5 changed files with 33 additions and 28 deletions

View File

@ -11,16 +11,16 @@ import (
const GREP = "grep"
func init() {
const CMD_DIR = "cmd_dir"
Index.MergeCommands(ice.Commands{
GREP: {Name: "grep word path auto", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
m.Option(mdb.VALUE, arg[0])
m.Option("cmd_dir", kit.Select(m.Option(PATH), arg, 1))
for _, line := range strings.Split(m.Cmdx("cli.system", GREP, "--exclude=.[a-z]*", "--exclude-dir=.[a-z]*", "--exclude-dir=node_modules", "-rni", arg[0], ice.PT), ice.NL) {
GREP: {Name: "grep word file path auto", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
m.Options(mdb.VALUE, arg[0], CMD_DIR, kit.Select("", arg, 2))
for _, line := range strings.Split(m.Cmdx("cli.system", GREP, "--exclude=.[a-z]*", "--exclude-dir=.[a-z]*", "--exclude-dir=node_modules", "-rni", arg[0], kit.Select(ice.PT, arg, 1)), ice.NL) {
if ls := strings.SplitN(line, ice.DF, 3); len(ls) > 2 {
m.Push(FILE, strings.TrimPrefix(ls[0], PWD)).Push(LINE, ls[1]).Push(mdb.TEXT, ls[2])
}
}
m.StatusTimeCount(PATH, m.Option("cmd_dir"))
m.StatusTimeCount(PATH, m.Option(CMD_DIR))
}},
})
}

View File

@ -109,7 +109,7 @@ func init() {
} else {
text = "cli.system go run " + path.Join(arg[2], arg[1])
}
ProcessXterm(m, cmds, text)
ProcessXterm(m, cmds, text, arg[1])
}},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
if cmd := ctx.GetFileCmd(path.Join(arg[2], arg[1])); cmd != "" {

View File

@ -28,7 +28,7 @@ func _inner_exec(m *ice.Message, ext, file, dir string) {
kit.If(aaa.Right(m, dir, file), func() { m.Cmdy(mdb.ENGINE, ext, file, dir) })
}
func _inner_tags(m *ice.Message, dir string, value string) {
for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, cli.GREP, "^"+value+"\\>", nfs.TAGS, kit.Dict(cli.CMD_DIR, dir)), ice.NL) {
for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, cli.GREP, "^"+value+"\\>", nfs.TAGS, dir), ice.NL) {
if strings.HasPrefix(l, "!_") {
continue
}
@ -86,13 +86,26 @@ func init() {
INNER: {Name: "inner path=src/@key file=main.go@key line=1 auto", Help: "源代码", Actions: ice.MergeActions(ice.Actions{
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
switch p := kit.Select(nfs.PWD, arg, 1); arg[0] {
case ice.CMD:
m.Cmd(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, ice.OptionFields(ctx.INDEX), func(value ice.Maps) {
if strings.HasPrefix(value[ctx.INDEX], kit.Select("", arg, 1)) {
ls := kit.Split(strings.TrimPrefix(value[ctx.INDEX], kit.Select("", arg, 1)), ice.PT)
m.Push(arg[0], ls[0]+kit.Select("", ice.PT, len(ls) > 1))
}
})
case ctx.INDEX:
m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, ice.OptionFields(ctx.INDEX))
case ctx.ARGS:
if m.Option(ctx.INDEX) != "" {
m.Cmdy(m.Option(ctx.INDEX))
}
case nfs.PATH:
m.Cmdy(nfs.DIR, p, nfs.DIR_CLI_FIELDS)
kit.If(strings.HasPrefix(p, bind[0]), func() { m.Cmdy(nfs.DIR, strings.Replace(p, bind[0], bind[1], 1), nfs.DIR_CLI_FIELDS) })
kit.If(strings.HasPrefix(p, bind[1]), func() { m.Cmdy(nfs.DIR, strings.Replace(p, bind[1], bind[0], 1), nfs.DIR_CLI_FIELDS) })
case nfs.FILE:
m.Option(nfs.DIR_ROOT, m.Option(nfs.PATH))
m.Cmdy(nfs.DIR, kit.Select(path.Dir(p), p, strings.HasSuffix(p, ice.PS))+ice.PS, nfs.DIR_CLI_FIELDS)
m.Option(nfs.DIR_DEEP, ice.TRUE)
m.Cmdy(nfs.DIR, path.Join(m.Option(nfs.PATH), kit.Select(path.Dir(p), p, strings.HasSuffix(p, ice.PS))+ice.PS), nfs.PATH)
default:
m.Cmdy(FAVOR, mdb.INPUTS, arg)
}
@ -100,7 +113,7 @@ func init() {
mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(mdb.PLUGIN, arg) }},
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _inner_show(m, arg[0], arg[1], arg[2]) }},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _inner_exec(m, arg[0], arg[1], arg[2]) }},
nfs.GREP: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.GREP, arg[0], kit.Select(m.Option(nfs.PATH), arg, 1)) }},
nfs.GREP: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.GREP, arg) }},
nfs.TAGS: {Hand: func(m *ice.Message, arg ...string) { _inner_tags(m, m.Option(nfs.PATH), arg[0]) }}, FAVOR: {},
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(NAVIGATE, kit.Ext(m.Option(mdb.FILE)), m.Option(nfs.FILE), m.Option(nfs.PATH))

View File

@ -42,9 +42,7 @@ func _vimer_make(m *ice.Message, dir string, msg *ice.Message) {
}
}
}
if m.Length() == 0 {
m.Echo(msg.Append(cli.CMD_OUT)).Echo(msg.Append(cli.CMD_ERR))
}
kit.If(m.Length() == 0, func() { m.Echo(msg.Append(cli.CMD_OUT)).Echo(msg.Append(cli.CMD_ERR)) })
}
const VIMER = "vimer"
@ -75,14 +73,6 @@ func init() {
m.Cmdy(m.Option(ctx.ACTION), mdb.INPUTS, arg)
default:
switch arg[0] {
case ctx.INDEX:
m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, ice.OptionFields(ctx.INDEX))
case ctx.ARGS:
if m.Option(ctx.INDEX) != "" {
m.Cmdy(m.Option(ctx.INDEX))
}
case nfs.PATH:
m.Cmdy(INNER, mdb.INPUTS, arg).Cut(nfs.DIR_CLI_FIELDS)
case nfs.FILE:
list := ice.Map{}
push := func(k, p string) {
@ -114,6 +104,8 @@ func init() {
}
m.Cmd(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, ice.OptionFields(ctx.INDEX)).Tables(func(value ice.Maps) { push(ctx.INDEX, value[ctx.INDEX]) })
m.Cmd(mdb.SEARCH, cli.SYSTEM, cli.OPENS, ice.OptionFields("type,name,text")).Sort("type,name,text").Tables(func(value ice.Maps) { push(cli.OPENS, value[nfs.NAME]) })
default:
m.Cmdy(INNER, mdb.INPUTS, arg)
}
}
}},
@ -140,7 +132,7 @@ func init() {
nfs.SCRIPT: {Name: "script file*=hi/hi.js", Help: "脚本", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(nfs.DEFS, path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)), m.Cmdx("", TEMPLATE))
}},
nfs.REPOS: {Help: "仓库"}, FAVOR: {Help: "收藏"}, web.DREAM: {Help: "空间"}, web.SPACE: {Help: "空间"},
nfs.REPOS: {Help: "仓库"}, web.SPACE: {Help: "空间"}, web.DREAM: {Help: "空间"}, FAVOR: {Help: "收藏"},
cli.OPENS: {Hand: func(m *ice.Message, arg ...string) { cli.Opens(m, arg...) }},
"listTags": {Help: "生成索引", Hand: func(m *ice.Message, arg ...string) { m.Cmd("web.code.vim.tags", nfs.LOAD) }},
@ -150,9 +142,6 @@ func init() {
COMPLETE: {Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(COMPLETE, kit.Ext(m.Option(mdb.FILE)), m.Option(nfs.FILE), m.Option(nfs.PATH))
}},
AUTOGEN: {Name: "create name*=h2 help=示例 type*=Zone,Hash,Data,Code main*=main.go zone key", Help: "模块", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(AUTOGEN, nfs.MODULE, arg)
}},
COMPILE: {Help: "编译", Hand: func(m *ice.Message, arg ...string) {
const app, _app = "usr/publish/contexts.app", "Contents/MacOS/contexts"
isWebview := func() bool { return strings.HasSuffix(os.Args[0], _app) }
@ -179,7 +168,7 @@ func init() {
}, mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path"), web.DreamAction(), aaa.RoleAction(ctx.COMMAND)), Hand: func(m *ice.Message, arg ...string) {
if m.Cmdy(INNER, arg); arg[0] != ctx.ACTION {
kit.If(len(arg) > 1, func() { mdb.HashCreate(m.Spawn(), nfs.PATH, path.Join(kit.Slice(arg, 0, 2)...)) })
m.Action(AUTOGEN, nfs.SCRIPT, nfs.SAVE, COMPILE)
m.Action(nfs.MODULE, nfs.SCRIPT, nfs.SAVE, COMPILE)
ctx.DisplayLocal(m, "")
}
}},

View File

@ -59,8 +59,11 @@ func _xterm_get(m *ice.Message, h string) _xterm {
for {
if n, e := tty.Read(buf); !m.Warn(e) && e == nil {
if _xterm_echo(m, h, string(buf[:n])); len(text) > 0 {
if text[0] != "" {
tty.Write([]byte(text[0] + ice.NL))
if cmd := text[0]; text[0] != "" {
m.Go(func() {
m.Sleep("10ms")
tty.Write([]byte(cmd + ice.NL))
})
}
text = text[1:]
}