1
0
forked from x/icebergs
This commit is contained in:
shylinux@163.com 2022-09-11 19:18:12 +08:00
parent e20bcc8c85
commit 44527ed4ef
19 changed files with 281 additions and 91 deletions

View File

@ -124,6 +124,9 @@ func init() {
STOP: {Name: "stop", Help: "停止", Hand: func(m *ice.Message, arg ...string) {
m.OptionFields(m.Config(mdb.FIELD))
mdb.HashSelect(m, m.Option(mdb.HASH)).Tables(func(value ice.Maps) {
if m.Option(mdb.HASH) == "" && value[PID] != m.Option(PID) {
return
}
mdb.HashModify(m, m.OptionSimple(mdb.HASH), STATUS, STOP)
m.Cmd(gdb.SIGNAL, gdb.KILL, value[PID])
})

View File

@ -134,6 +134,8 @@ const (
CMD_ERR = "cmd_err"
CMD_OUT = "cmd_out"
MAN = "man"
)
const SYSTEM = "system"
@ -152,6 +154,13 @@ func init() {
}
m.Cmdy(nfs.CAT, ice.ETC_PATH)
}},
MAN: {Name: "man", Help: "文档", Hand: func(m *ice.Message, arg ...string) {
m.Option(CMD_ENV, "COLUMNS", kit.Int(kit.Select("1920", m.Option("width")))/12)
m.Cmdy(SYSTEM, "sh", "-c", kit.Format("man %s %s|col -b", kit.Select("", arg[1], arg[1] != "1"), arg[0]))
if IsSuccess(m) && m.Append(CMD_ERR) == "" {
m.SetAppend()
}
}},
}, Hand: func(m *ice.Message, arg ...string) {
if len(arg) == 0 {
return

View File

@ -97,6 +97,36 @@ func init() {
_command_search(m, arg[0], kit.Select("", arg, 1), kit.Select("", arg, 2))
}
}},
"tags": {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) {
m.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
if key[0] == '/' || key[0] == '_' {
return // 内部命令
}
var ls []string
if cmd.RawHand != nil {
switch h := cmd.RawHand.(type) {
case string:
ls = kit.Split(h, ":")
default:
ls = kit.Split(kit.FileLine(cmd.RawHand, 100), ":")
}
} else if cmd.Hand != nil {
return
ls = kit.Split(kit.FileLine(cmd.Hand, 100), ":")
} else {
return
}
m.Push("name", key)
m.Push("file", strings.TrimPrefix(ls[0], kit.Path("")+ice.PS))
m.Push("line", ls[1])
})
m.Sort("name")
m.Tables(func(value ice.Maps) {
m.Echo("%s\t%s\t%s;\" m\n", value["name"], value["file"], value["line"])
})
m.Cmd("nfs.save", "tags", m.Result())
}},
}, Hand: func(m *ice.Message, arg ...string) {
if len(arg) == 0 {
arg = append(arg, "")
@ -143,6 +173,15 @@ func CmdAction(args ...ice.Any) ice.Actions {
}},
}
}
func ProcessField(m *ice.Message, cmd string, args []string, arg ...string) {
if len(arg) > 0 && arg[0] == ice.RUN {
m.Cmdy(cmd, arg[1:])
} else {
if m.Cmdy(COMMAND, cmd).ProcessField(m.ActionKey(), ice.RUN); len(args) > 0 {
m.Push(ARGS, kit.Format(args))
}
}
}
func PodCmd(m *ice.Message, arg ...ice.Any) bool {
if pod := m.Option(ice.POD); pod != "" {
if m.Option(ice.POD, ""); m.Option(ice.MSG_UPLOAD) != "" {

View File

@ -281,20 +281,17 @@ func HashTarget(m *ice.Message, h string, add Any) (p Any) {
if pp, ok := p.(Map); ok && len(pp) == 0 {
p = nil
}
m.Debug("what %v", p)
if p == nil && add != nil {
switch add := add.(type) {
case func(ice.Map) ice.Any:
p = add(value)
case func() ice.Any:
p = add()
m.Debug("what %v", p)
default:
m.ErrorNotImplement(p)
return
}
value[TARGET] = p
m.Debug("what %v", p)
}
})
return

View File

@ -93,6 +93,7 @@ const (
STDIO = "stdio"
SOURCE = "source"
MODULE = "module"
SCRIPT = "script"
BINARY = "binary"
TARGET = "target"

View File

@ -48,6 +48,9 @@ const PORT = "port"
func init() {
Index.MergeCommands(ice.Commands{
PORT: {Name: "port port path auto", Help: "端口", Actions: ice.MergeActions(ice.Actions{
CURRENT: {Name: "current", Help: "分配", Hand: func(m *ice.Message, arg ...string) {
m.Echo(m.Config(CURRENT))
}},
aaa.RIGHT: {Name: "right", Help: "分配", Hand: func(m *ice.Message, arg ...string) {
m.Echo(_port_right(m, arg...))
}},

View File

@ -59,8 +59,8 @@ func _inner_make(m *ice.Message, msg *ice.Message) {
}
m.StatusTime()
}
func _inner_tags(m *ice.Message, path string, value string) {
for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, "grep", "^"+value+"\\>", "tags", kit.Dict(cli.CMD_DIR, m.Option(nfs.PATH))), ice.NL) {
func _inner_tags(m *ice.Message, dir string, value string) {
for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, nfs.GREP, "^"+value+"\\>", nfs.TAGS, kit.Dict(cli.CMD_DIR, dir)), ice.NL) {
ls := strings.SplitN(l, ice.TB, 2)
if len(ls) < 2 {
continue
@ -72,38 +72,24 @@ func _inner_tags(m *ice.Message, path string, value string) {
text := strings.TrimSuffix(strings.TrimPrefix(ls[0], "/^"), "$/")
line := kit.Int(text)
f, e := nfs.OpenFile(m, kit.Path(path, file))
f, e := nfs.OpenFile(m, kit.Path(dir, file))
m.Assert(e)
defer f.Close()
bio := bufio.NewScanner(f)
for i := 1; bio.Scan(); i++ {
if i == line || bio.Text() == text {
m.PushRecord(kit.Dict(nfs.PATH, path, nfs.FILE, strings.TrimPrefix(file, nfs.PWD), nfs.LINE, kit.Format(i)))
if dir == "" {
m.PushRecord(kit.Dict(nfs.PATH, path.Dir(file), nfs.FILE, path.Base(file), nfs.LINE, kit.Format(i), mdb.TEXT, bio.Text()))
} else {
m.PushRecord(kit.Dict(nfs.PATH, dir, nfs.FILE, strings.TrimPrefix(file, nfs.PWD), nfs.LINE, kit.Format(i), mdb.TEXT, bio.Text()))
}
return
}
}
}
}
func LoadPlug(m *ice.Message, language ...string) {
for _, language := range language {
m.Conf(nfs.CAT, kit.Keym(nfs.SOURCE, kit.Ext(language)), ice.TRUE)
m.Confm(language, kit.Keym(PLUG, PREPARE), func(key string, value interface{}) {
for _, v := range kit.Simple(value) {
m.Conf(language, kit.Keym(PLUG, KEYWORD, v), key)
}
})
}
}
func PlugAction() ice.Actions {
return ice.Actions{
mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { m.Echo(m.Config(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.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }},
}
}
const (
COMMENT = "comment"
KEYWORD = "keyword"
@ -113,10 +99,10 @@ const (
)
const (
SPLIT = "split"
PREFIX = "prefix"
SUFFIX = "suffix"
SPACE = "space"
OPERATE = "operate"
PREFIX = "prefix"
SUFFIX = "suffix"
)
const (
PLUG = "plug"
@ -146,6 +132,9 @@ func init() {
}},
mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_inner_tags(m, m.Option(nfs.PATH), arg[1])
if m.Length() == 0 {
_inner_tags(m, "", arg[1])
}
return
m.Option(nfs.DIR_ROOT, arg[2])
m.Option(cli.CMD_DIR, kit.Path(arg[2]))
@ -192,24 +181,17 @@ func init() {
}
}},
nfs.TAGS: {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) {
_inner_tags(m, m.Option(nfs.PATH), arg[0])
}},
nfs.GREP: {Name: "grep", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(nfs.GREP, m.Option(nfs.PATH), arg[0])
m.StatusTimeCount(mdb.INDEX, 0)
}},
nfs.TAGS: {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) {
_inner_tags(m, m.Option(nfs.PATH), arg[0])
}},
cli.MAKE: {Name: "make", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
_inner_make(m, m.Cmd(cli.SYSTEM, cli.MAKE, arg))
}},
FAVOR: {Name: "favor", Help: "收藏"},
"man": {Name: "man", Help: "手册", Hand: func(m *ice.Message, arg ...string) {
m.Option(cli.CMD_ENV, "COLUMNS", kit.Int(kit.Select("1920", m.Option("width")))/12)
m.Cmdy(cli.SYSTEM, "sh", "-c", kit.Format("man %s %s|col -b", kit.Select("", arg, 1, arg[1] != "1"), arg[0]))
}},
"doc": {Name: "man", Help: "手册", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(cli.SYSTEM, "go", "doc", arg[0])
}},
}, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
if arg[0] = strings.Split(arg[0], ice.FS)[0]; !strings.HasSuffix(arg[0], ice.PS) {
arg[1] = kit.Slice(strings.Split(arg[0], ice.PS), -1)[0]
@ -239,6 +221,7 @@ func init() {
if _inner_list(m, kit.Ext(arg[1]), arg[1], arg[0]); m.IsErrNotFound() {
m.SetResult("")
}
ctx.DisplayLocal(m, "")
m.Set(ice.MSG_STATUS)
}},
}, Configs: ice.Configs{
@ -248,7 +231,7 @@ func init() {
"S", kit.Dict(PREFIX, kit.Dict("//", COMMENT)),
"s", kit.Dict(PREFIX, kit.Dict("//", COMMENT), KEYWORD, kit.Dict("TEXT", KEYWORD, "RET", KEYWORD)),
"py", kit.Dict(PREFIX, kit.Dict("#", COMMENT), KEYWORD, kit.Dict("print", KEYWORD)),
nfs.HTML, kit.Dict(SPLIT, kit.Dict("space", " ", "operator", "<>"), KEYWORD, kit.Dict("head", KEYWORD, "body", KEYWORD)),
nfs.HTML, kit.Dict(SPLIT, kit.Dict(SPACE, " ", OPERATE, "<>"), KEYWORD, kit.Dict("head", KEYWORD, "body", KEYWORD)),
nfs.CSS, kit.Dict(SUFFIX, kit.Dict("{", COMMENT)),
"yaml", kit.Dict(PREFIX, kit.Dict("#", COMMENT)),
"yml", kit.Dict(PREFIX, kit.Dict("#", COMMENT)),
@ -260,3 +243,21 @@ func init() {
)},
}})
}
func PlugAction() ice.Actions {
return ice.Actions{
mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { m.Echo(m.Config(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.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }},
}
}
func LoadPlug(m *ice.Message, language ...string) {
for _, language := range language {
m.Conf(nfs.CAT, kit.Keym(nfs.SOURCE, kit.Ext(language)), ice.TRUE)
m.Confm(language, kit.Keym(PLUG, PREPARE), func(key string, value interface{}) {
for _, v := range kit.Simple(value) {
m.Conf(language, kit.Keym(PLUG, KEYWORD, v), key)
}
})
}
}

View File

@ -55,9 +55,9 @@ func _install_download(m *ice.Message) {
}
})
m.Cmd(nfs.TAR, mdb.EXPORT, name, kit.Dict(cli.CMD_DIR, path.Dir(file)))
web.PushNoticeRefresh(m)
web.ToastSuccess(m)
})
m.Cmdy(nfs.DIR, file)
m.SetResult()
}
func _install_build(m *ice.Message, arg ...string) string {

View File

@ -231,6 +231,13 @@ func init() {
m.Option("plug", m.Config("show.plug"))
m.Option("exts", m.Config("show.exts"))
m.Option("tabs", m.Config("show.tabs"))
if arg[0] != ctx.ACTION {
ctx.DisplayLocal(m, "")
m.Action(nfs.SAVE, COMPILE, AUTOGEN, nfs.SCRIPT, chat.WEBSITE, web.DREAM)
}
}},
})
}
func ProcessVimer(m *ice.Message, path, file, line string, arg ...string) {
ctx.ProcessField(m, "web.code.vimer", kit.Simple(path, file, line), arg...)
}

View File

@ -120,12 +120,8 @@ func init() {
}
func ProcessXterm(m *ice.Message, bin string, arg ...string) {
if cmd := "web.code.xterm"; len(arg) > 0 && arg[0] == ice.RUN {
if len(arg) > 2 && arg[1] == ctx.ACTION && arg[2] == mdb.CREATE {
arg = append(arg, mdb.TYPE, bin)
}
m.Cmdy(cmd, arg[1:])
} else {
m.Cmdy(ctx.COMMAND, cmd).ProcessField(m.ActionKey(), ice.RUN)
if len(arg) > 2 && arg[0] == ice.RUN && arg[1] == ctx.ACTION && arg[2] == mdb.CREATE {
arg = append(arg, mdb.TYPE, bin)
}
ctx.ProcessField(m, "web.code.xterm", nil, arg...)
}

View File

@ -9,7 +9,6 @@ import (
"shylinux.com/x/icebergs/base/lex"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/ssh"
"shylinux.com/x/icebergs/core/chat"
kit "shylinux.com/x/toolkits"
)
@ -19,7 +18,7 @@ func _word_show(m *ice.Message, name string, arg ...string) {
m.Option(TITLE, map[string]int{})
m.Option(MENU, kit.Dict(mdb.LIST, kit.List()))
m.Option(ice.MSG_ALIAS, m.Configv(mdb.ALIAS))
m.Cmdy(ssh.SOURCE, name, kit.Dict(nfs.DIR_ROOT, _wiki_path(m, WORD)))
m.Cmdy("ssh.source", name, kit.Dict(nfs.DIR_ROOT, _wiki_path(m, WORD)))
}
const WORD = "word"

View File

@ -22,7 +22,7 @@ func (m *Message) TryCatch(msg *Message, silent bool, hand ...func(msg *Message)
m.Log(LOG_WARN, "catch: %s %s", e, fileline)
m.Log("stack", msg.FormatStack(2, 100))
m.Log(LOG_WARN, "catch: %s %s", e, fileline)
m.Result(ErrWarn, e)
m.Result(ErrWarn, e, " ", fileline)
if len(hand) > 1 {
m.TryCatch(msg, silent, hand[1:]...)
} else if !silent {

View File

@ -203,7 +203,8 @@ func (m *Message) FormatStack(s, n int) string {
name := kit.Slice(kit.Split(frame.Function, PS, PS), -1)[0]
switch ls := kit.Split(name, PT, PT); kit.Select("", ls, 0) {
case "reflect", "runtime", "http", "task", "icebergs":
// case "reflect", "runtime", "http", "task", "icebergs":
case "reflect", "runtime", "http":
default:
list = append(list, kit.Format("%s:%d\t%s", file, frame.Line, name))
}

View File

@ -250,7 +250,8 @@ func (c *Context) _command(m *Message, cmd *Command, key string, arg ...string)
m._target = kit.FileLine(cmd.Hand, 3)
if cmd.RawHand != nil {
m._target = kit.FileLine(cmd.RawHand, 3)
// m._target = kit.FileLine(cmd.RawHand, 3)
m._target = kit.Format(cmd.RawHand)
}
if key == "select" {
m.Log(LOG_CMDS, "%s.%s %d %v %v", c.Name, key, len(arg), arg, m.Optionv(MSG_FIELDS),
@ -294,9 +295,10 @@ func (c *Context) _action(m *Message, cmd *Command, key string, sub string, h *A
}
}
m._target = kit.FileLine(cmd.Hand, 3)
m._target = kit.FileLine(h.Hand, 3)
if cmd.RawHand != nil {
m._target = kit.FileLine(cmd.RawHand, 3)
// m._target = kit.FileLine(cmd.RawHand, 3)
m._target = kit.Format(cmd.RawHand)
}
m.Log(LOG_CMDS, "%s.%s %s %d %v", c.Name, key, sub, len(arg), arg,
logs.FileLineMeta(kit.Select(m._target, m._source, m.target.Name == MDB)))

View File

@ -10,38 +10,56 @@ import (
kit "shylinux.com/x/toolkits"
)
func _count_count(m *ice.Message, arg []string, cb func(string)) {
if len(arg) == 0 || arg[0] == "usr/" {
m.Echo("to many file, please choice sub dir")
return
}
m.Option(nfs.DIR_DEEP, ice.TRUE)
m.Option(nfs.DIR_TYPE, nfs.TYPE_CAT)
m.Cmdy(nfs.DIR, arg, func(file string) {
if strings.Contains(file, "node_modules/") {
return
}
if strings.Contains(file, "bin/") {
return
}
if strings.Contains(file, "var/") {
return
}
if strings.Contains(file, "tags") {
return
}
switch kit.Ext(file) {
case "sum", "log":
return
}
cb(file)
})
}
const COUNT = "count"
func init() {
Index.MergeCommands(ice.Commands{
COUNT: {Name: "count path auto count", Help: "代码行", Actions: ice.Actions{
COUNT: {Name: "count", Help: "计数", Hand: func(m *ice.Message, arg ...string) {
if len(arg) == 0 || arg[0] == "usr/" {
m.Echo("to many file, please choice sub dir")
return
COUNT: {Name: "count path auto count order", Help: "代码行", Actions: ice.Actions{
"order": {Name: "order", Help: "排行", Hand: func(m *ice.Message, arg ...string) {
files := map[string]int{}
_count_count(m, arg, func(file string) {
m.Cmdy(nfs.CAT, file, func(text string, line int) {
files[strings.TrimPrefix(file, arg[0])]++
})
})
for k, n := range files {
m.Push("files", k)
m.Push("lines", n)
}
m.StatusTimeCount().SortIntR("lines")
}},
COUNT: {Name: "count", Help: "计数", Hand: func(m *ice.Message, arg ...string) {
files := map[string]int{}
lines := map[string]int{}
m.Option(nfs.DIR_DEEP, ice.TRUE)
m.Option(nfs.DIR_TYPE, nfs.TYPE_CAT)
m.Cmdy(nfs.DIR, arg, func(file string) {
if strings.Contains(file, "node_modules/") {
return
}
if strings.Contains(file, "bin/") {
return
}
if strings.Contains(file, "var/") {
return
}
if strings.Contains(file, "tags") {
return
}
switch kit.Ext(file) {
case "sum", "log":
return
}
_count_count(m, arg, func(file string) {
files[mdb.TOTAL]++
files[kit.Ext(file)]++
m.Cmdy(nfs.CAT, file, func(text string, line int) {
@ -63,8 +81,7 @@ func init() {
m.Push("files", files[k])
m.Push("lines", lines[k])
}
m.SortIntR("lines")
m.StatusTime()
m.StatusTime().SortIntR("lines")
}},
}, Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.DIR, arg) }},
})

View File

@ -16,6 +16,8 @@ const (
SID = "sid"
ARG = "arg"
SUB = "sub"
PRE = "pre"
PWD = "pwd"
BUF = "buf"
ROW = "row"
COL = "col"

View File

@ -15,6 +15,64 @@ import (
const TAGS = "tags"
func init() {
_tags_split := func(pre, col string) []string {
ls := kit.Split(pre[:kit.Int(col)-1])
ls[len(ls)-1] += kit.Split(pre[kit.Int(col)-1:])[0]
return ls
}
_tags_field := func(m *ice.Message, arg ...string) {
if arg[0] == "" {
return
}
pre, sp := "", ""
if word := kit.Slice(kit.Split(arg[1]+arg[0]), -1)[0]; arg[0] == ice.SP {
sp = ice.SP
} else if strings.HasSuffix(word, ice.PT) {
pre = strings.TrimSuffix(word, ice.PT)
} else if p := kit.Split(word, ice.PT); true {
sp, pre = p[len(p)-1], word
}
m.OptionFields(ctx.INDEX)
list0 := map[string]bool{}
list := map[string]bool{}
push := func(index string) {
if strings.HasPrefix(index, pre) {
p := kit.Split(sp+strings.TrimPrefix(index, pre), ice.PT)[0]
list0[p+kit.Select("", ice.PT, !strings.HasSuffix(index, p))] = true
}
list[strings.TrimPrefix(index, kit.Join(kit.Slice(kit.Split(pre, ice.PT), 0, -1), ice.PT)+ice.PT)] = true
}
m.Cmd(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND).Tables(func(value ice.Maps) {
if ls := kit.Split(pre, ice.PT); len(ls) == 1 && strings.Contains(value[ctx.INDEX], pre) && !strings.HasSuffix(arg[0], ice.PT) {
push(value[ctx.INDEX])
} else if len(ls) > 1 && strings.HasPrefix(value[ctx.INDEX], kit.Join(ls[:len(ls)-1], ice.PT)) && strings.Contains(value[ctx.INDEX], ls[len(ls)-1]) && !strings.HasSuffix(arg[0], ice.PT) {
push(value[ctx.INDEX])
} else if strings.HasPrefix(value[ctx.INDEX], pre) {
res := sp + strings.TrimPrefix(value[ctx.INDEX], pre)
ls := kit.Split(res, ice.PT)
if len(ls) == 0 {
return
}
if len(ls) > 1 {
ls[0] += ice.PT
}
if strings.HasPrefix(res, ice.PT) {
list[ice.PT+ls[0]] = true
} else {
list[ls[0]] = true
}
}
})
for _, k := range kit.SortedKey(list0) {
m.Echo("%s\n", k)
}
for _, k := range kit.SortedKey(list) {
m.Echo("%s\n", k)
}
}
const (
MODULE = "module"
PATTERN = "pattern"
@ -28,7 +86,27 @@ func init() {
libs_pattern = "4\nusr/volcanos/lib/%s.js\n/\\<%s: \\(shy\\|func\\)/\n"
)
Index.MergeCommands(ice.Commands{
"/tags": {Name: "/tags", Help: "跳转", Hand: func(m *ice.Message, arg ...string) {
"/tags": {Name: "/tags", Help: "跳转", Actions: ice.Actions{
"server": {Name: "server", Help: "服务", Hand: func(m *ice.Message, arg ...string) {
switch args := _tags_split(m.Option(PRE), m.Option(COL)); args[0] {
case "field":
m.Echo(`!curl "localhost:9020/code/bash/qrcode?text=%s"`, kit.Format("http://2022.shylinux.com:9020/chat/cmd/%s?topic=black", args[1]))
case "qrcode":
m.Echo(`!curl "localhost:9020/code/bash/qrcode?text=%s"`, args[1])
}
}},
"source": {Name: "source", Help: "源码", Hand: func(m *ice.Message, arg ...string) {
switch args := _tags_split(m.Option(PRE), m.Option(COL)); args[0] {
case "field":
m.Search(kit.Select(args[1], args, 2), func(key string, cmd *ice.Command) {
ls := kit.Split(cmd.GetFileLine(), ":")
m.Echo("vi +%s %s", ls[1], ls[0])
})
case "qrcode":
m.Echo(`!curl "localhost:9020/code/bash/qrcode?text=%s"`, args[1])
}
}},
}, Hand: func(m *ice.Message, arg ...string) {
switch m.Option(MODULE) {
case ONIMPORT, ONACTION, ONEXPORT:
m.Echo(func_pattern, m.Option(BUF), m.Option(PATTERN))
@ -60,10 +138,31 @@ func init() {
ctx.ProcessCommand(m, code.INNER, m.OptionSplit("path,file,line"), arg...)
}},
INPUT: {Name: "input name text", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
if m.Option(mdb.TEXT) == "" {
if kit.Ext(m.Option(BUF)) == nfs.SHY && arg[1] == "" {
for _, k := range []string{
"field",
"shell",
"refer",
"section",
"chapter",
"title",
} {
if strings.HasPrefix(k, arg[0]) {
m.Echo("%s \n", k)
}
}
_tags_field(m, arg...)
return
}
name := kit.Select("", kit.Slice(kit.Split(m.Option(mdb.TEXT), "\t \n."), -1), 0)
if arg[1] == "" {
_tags_field(m, arg...)
return
}
if kit.Ext(m.Option(BUF)) == nfs.SHY && strings.HasPrefix(arg[1], "field") {
_tags_field(m, arg...)
return
}
name := kit.Select("", kit.Slice(kit.Split(arg[1], "\t \n."), -1), 0)
switch name {
case "can":
mdb.ZoneSelectCB(m, "", func(value ice.Maps) {
@ -72,7 +171,7 @@ func init() {
return
}
mdb.ZoneSelectCB(m, name, func(value ice.Maps) {
if !strings.Contains(value[mdb.NAME], m.Option(mdb.NAME)) && m.Option(mdb.NAME) != "." {
if !strings.Contains(value[mdb.NAME], arg[0]) && arg[0] != ice.PT {
return
}
if m.Length() == 0 {

View File

@ -135,13 +135,13 @@ func (m *Message) ProcessField(arg ...Any) {
m.Process(PROCESS_FIELD)
m.Option(FIELD_PREFIX, arg...)
}
func (m *Message) ProcessInner() { m.Process(PROCESS_INNER) }
func (m *Message) ProcessAgain() { m.Process(PROCESS_AGAIN) }
func (m *Message) ProcessHold(text ...string) { m.Process(PROCESS_HOLD) }
func (m *Message) ProcessBack() { m.Process(PROCESS_BACK) }
func (m *Message) ProcessRich(arg ...Any) { m.Process(PROCESS_RICH, arg...) }
func (m *Message) ProcessGrow(arg ...Any) { m.Process(PROCESS_GROW, arg...) }
func (m *Message) ProcessOpen(url string) { m.Process(PROCESS_OPEN, url) }
func (m *Message) ProcessInner() { m.Process(PROCESS_INNER) }
func (m *Message) ProcessAgain() { m.Process(PROCESS_AGAIN) }
func (m *Message) ProcessHold(text ...Any) { m.Process(PROCESS_HOLD, text...) }
func (m *Message) ProcessBack() { m.Process(PROCESS_BACK) }
func (m *Message) ProcessRich(arg ...Any) { m.Process(PROCESS_RICH, arg...) }
func (m *Message) ProcessGrow(arg ...Any) { m.Process(PROCESS_GROW, arg...) }
func (m *Message) ProcessOpen(url string) { m.Process(PROCESS_OPEN, url) }
func (m *Message) Display(file string, arg ...Any) *Message { // repos local file
m.Option(MSG_DISPLAY, kit.MergeURL(displayRequire(2, file)[DISPLAY], arg...))

14
type.go
View File

@ -78,6 +78,20 @@ type Server interface {
func (c *Context) ID() int32 {
return atomic.AddInt32(&c.id, 1)
}
func (c *Command) GetFileLine() string {
if c.RawHand != nil {
switch h := c.RawHand.(type) {
case string:
return h
default:
return kit.FileLine(c.RawHand, 100)
}
} else if c.Hand != nil {
return kit.FileLine(c.Hand, 100)
} else {
return ""
}
}
func (c *Context) Cap(key string, arg ...Any) string {
if len(arg) > 0 {
c.Caches[key].Value = kit.Format(arg[0])