forked from x/icebergs
opt gdb
This commit is contained in:
parent
a2a14be186
commit
96671f03c8
@ -29,8 +29,8 @@ var _color_map = map[string]color.Color{
|
||||
}
|
||||
|
||||
var _color_list = map[string]string{
|
||||
"aliceblue": "#f0f8ff",
|
||||
"navy": "#000080",
|
||||
"aliceblue": "#f0f8ff",
|
||||
"firebrick": "#b22222",
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ func _daemon_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
cmd.Stderr = w
|
||||
}
|
||||
h := mdb.HashCreate(m.Spawn(), STATUS, START,
|
||||
ice.CMD, kit.Join(cmd.Args, lex.SP), DIR, cmd.Dir, ENV, kit.Select("", cmd.Env),
|
||||
ice.CMD, kit.JoinWord(cmd.Args...), DIR, cmd.Dir, ENV, kit.Select("", cmd.Env),
|
||||
m.OptionSimple(CMD_INPUT, CMD_OUTPUT, CMD_ERRPUT, mdb.CACHE_CLEAR_ONEXIT),
|
||||
)
|
||||
if e := cmd.Start(); m.Warn(e, ice.ErrNotStart, cmd.Args, err.String()) {
|
||||
@ -38,8 +38,7 @@ func _daemon_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
return
|
||||
}
|
||||
mdb.HashSelectUpdate(m, h, func(value ice.Map) { value[PID] = cmd.Process.Pid })
|
||||
m.Echo("%d", cmd.Process.Pid)
|
||||
m.Go(func() {
|
||||
m.Echo("%d", cmd.Process.Pid).Go(func() {
|
||||
if e := cmd.Wait(); !m.Warn(e, ice.ErrNotStart, cmd.Args, err.String()) && cmd.ProcessState != nil && cmd.ProcessState.Success() {
|
||||
mdb.HashModify(m, mdb.HASH, h, STATUS, STOP)
|
||||
m.Cost(CODE, "0", ctx.ARGS, cmd.Args)
|
||||
@ -187,6 +186,4 @@ tell application "%s"
|
||||
end tell
|
||||
`, app, strings.Join(arg, lex.NL)))
|
||||
}
|
||||
func OSAScript(m *ice.Message, arg ...string) {
|
||||
m.Cmd(SYSTEM, "osascript", "-e", arg)
|
||||
}
|
||||
func OSAScript(m *ice.Message, arg ...string) { m.Cmd(SYSTEM, "osascript", "-e", arg) }
|
||||
|
@ -35,26 +35,26 @@ func init() {
|
||||
CMD: {Name: "cmd cli osid", Hand: func(m *ice.Message, arg ...string) {
|
||||
osid := kit.Select(mdb.Conf(m, RUNTIME, kit.Keys(HOST, OSID)), m.Option(OSID))
|
||||
mdb.ZoneSelectCB(m, m.Option(CLI), func(value ice.Map) {
|
||||
kit.If(strings.Contains(osid, kit.Format(value[OSID])), func() { m.Cmdy(kit.Split(kit.Format(value[CMD]))) })
|
||||
kit.If(strings.Contains(osid, kit.Format(value[OSID])), func() {
|
||||
m.Cmdy(kit.Split(kit.Format(value[CMD])))
|
||||
})
|
||||
})
|
||||
}},
|
||||
ADD: {Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.ZoneSelect(m, m.Option(CLI)).Table(func(value ice.Maps) {
|
||||
ice.Info.PushStream(m)
|
||||
m.Toast(ice.PROCESS, "", "-1")
|
||||
mdb.ZoneSelect(m, m.Option(CLI)).Table(func(value ice.Maps) {
|
||||
m.ToastProcess()
|
||||
if msg := m.Cmd(kit.Split(value[CMD])); IsSuccess(msg) {
|
||||
m.Toast(ice.SUCCESS)
|
||||
m.ToastSuccess()
|
||||
} else {
|
||||
m.Toast(ice.FAILURE)
|
||||
m.ToastFailure()
|
||||
}
|
||||
})
|
||||
}},
|
||||
REPOS: {Name: "repos proxy=mirrors.tencent.com", Help: "镜像", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch {
|
||||
case strings.Contains(_release, ALPINE):
|
||||
m.Toast(ice.PROCESS, "", "-1")
|
||||
defer m.Toast(ice.SUCCESS)
|
||||
ice.Info.PushStream(m)
|
||||
defer m.PushStream().ToastProcess()()
|
||||
kit.If(m.Option("proxy"), func(p string) {
|
||||
m.Cmd(nfs.SAVE, ETC_APK_REPOS, strings.ReplaceAll(m.Cmdx(nfs.CAT, ETC_APK_REPOS), "dl-cdn.alpinelinux.org", p))
|
||||
})
|
||||
@ -95,7 +95,7 @@ func release(m *ice.Message) string {
|
||||
}
|
||||
return text
|
||||
})
|
||||
_release = strings.Join(list, lex.SP)
|
||||
_release = kit.JoinWord(list...)
|
||||
return _release
|
||||
}
|
||||
func insert(m *ice.Message, sys, cmd string, arg ...string) bool {
|
||||
|
@ -1,32 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
PROCINFO: {Name: "procinfo PID auto filter:text terminal monitor docker", Help: "进程列表", Actions: ice.MergeActions(ice.Actions{
|
||||
PROCKILL: {Help: "结束进程", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(gdb.SIGNAL, gdb.STOP, m.Option("PID")).ProcessRefresh() }},
|
||||
"terminal": {Help: "终端", Hand: func(m *ice.Message, arg ...string) { Opens(m, "Terminal.app") }},
|
||||
"monitor": {Help: "监控", Hand: func(m *ice.Message, arg ...string) { Opens(m, "Activity Monitor.app") }},
|
||||
"docker": {Help: "容器", Hand: func(m *ice.Message, arg ...string) { Opens(m, "Docker Desktop.app") }},
|
||||
}), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || arg[0] == "" {
|
||||
m.Split(m.Cmdx(SYSTEM, "ps", "u")).Sort("COMMAND").PushAction(PROCKILL).StatusTimeCount(m.Cmd(RUNTIME, HOSTINFO).AppendSimple("nCPU,MemTotal,MemFree"))
|
||||
return
|
||||
}
|
||||
m.OptionFields(mdb.DETAIL)
|
||||
for _, line := range kit.SplitLine(m.Cmdx(nfs.CAT, kit.Format("/proc/%s/status", arg[0]))) {
|
||||
ls := strings.SplitN(line, nfs.DF, 2)
|
||||
m.Push(ls[0], ls[1])
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
type procstat struct {
|
||||
utime int64
|
||||
stime int64
|
||||
vmsize int64
|
||||
vmrss int64
|
||||
user int64
|
||||
sys int64
|
||||
idle int64
|
||||
total int64
|
||||
free int64
|
||||
rx int64
|
||||
tx int64
|
||||
established int64
|
||||
time_wait int64
|
||||
}
|
||||
|
||||
func newprocstat(m *ice.Message) (stat procstat) {
|
||||
if runtime.GOOS != LINUX {
|
||||
return
|
||||
}
|
||||
m.Option(ice.MSG_USERROLE, aaa.ROOT)
|
||||
if ls := kit.Split(m.Cmdx(nfs.CAT, "/proc/self/stat"), " ()"); len(ls) > 0 {
|
||||
stat = procstat{utime: kit.Int64(ls[13]), stime: kit.Int64(ls[14]), vmsize: kit.Int64(ls[22]), vmrss: kit.Int64(ls[23]) * 4096}
|
||||
}
|
||||
if ls := kit.Split(kit.Select("", strings.Split(m.Cmdx(nfs.CAT, "/proc/stat"), lex.NL), 1)); len(ls) > 0 {
|
||||
stat.user, stat.sys, stat.idle = kit.Int64(ls[1]), kit.Int64(ls[3]), kit.Int64(ls[4])
|
||||
}
|
||||
for _, line := range strings.Split(strings.TrimSpace(m.Cmdx(nfs.CAT, "/proc/meminfo")), lex.NL) {
|
||||
switch ls := kit.Split(line, ": "); ls[0] {
|
||||
case "MemTotal":
|
||||
stat.total = kit.Int64(ls[1]) * 1024
|
||||
case "MemFree":
|
||||
stat.free = kit.Int64(ls[1]) * 1024
|
||||
}
|
||||
}
|
||||
for _, line := range strings.Split(strings.TrimSpace(m.Cmdx(nfs.CAT, "/proc/net/dev")), lex.NL)[2:] {
|
||||
if ls := kit.Split(line, ": "); ls[0] != "lo" {
|
||||
stat.rx += kit.Int64(ls[1])
|
||||
stat.tx += kit.Int64(ls[9])
|
||||
}
|
||||
}
|
||||
for _, line := range strings.Split(strings.TrimSpace(m.Cmdx(nfs.CAT, "/proc/net/tcp")), lex.NL)[1:] {
|
||||
switch ls := kit.Split(line, ": "); ls[5] {
|
||||
case "01":
|
||||
stat.established++
|
||||
case "06":
|
||||
stat.time_wait++
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
var last procstat
|
||||
Index.MergeCommands(ice.Commands{
|
||||
PROCSTAT: {Name: "procstat id list page start", Help: "进程统计", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { last = newprocstat(m) }},
|
||||
START: {Name: "start interval*=10s least*=360 limit*=720", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(gdb.TIMER, mdb.CREATE, mdb.NAME, m.CommandKey(), gdb.DELAY, "1s", m.OptionSimple(gdb.INTERVAL), mdb.COUNT, "-1", ice.CMD, "cli.procstat insert")
|
||||
mdb.Config(m, mdb.LEAST, m.Option(mdb.LEAST))
|
||||
mdb.Config(m, mdb.LIMIT, m.Option(mdb.LIMIT))
|
||||
}},
|
||||
mdb.INSERT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
stat := newprocstat(m)
|
||||
total := stat.user - last.user + stat.sys - last.sys + stat.idle - last.idle
|
||||
m.Cmd(mdb.INSERT, m.PrefixKey(), "", mdb.LIST,
|
||||
"utime", (stat.utime-last.utime+stat.stime-last.stime)*1000/total, "vmrss", stat.vmrss*1000/stat.total,
|
||||
"user", (stat.user-last.user+stat.sys-last.sys)*1000/total, "idle", (stat.idle-last.idle)*1000/total, "free", stat.free*1000/stat.total,
|
||||
"rx", (stat.rx-last.rx)*1000/20000000, "tx", (stat.tx-last.tx)*1000/20000000, "established", stat.established, "time_wait", stat.time_wait,
|
||||
)
|
||||
last = stat
|
||||
}},
|
||||
}, mdb.PageListAction(mdb.FIELD, "time,id,utime,vmrss,user,idle,free,rx,tx,established,time_wait")), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionDefault(mdb.CACHE_LIMIT, mdb.Config(m, mdb.LEAST))
|
||||
if mdb.PageListSelect(m, arg...); (len(arg) == 0 || arg[0] == "") && m.Length() > 0 {
|
||||
m.SortInt(mdb.ID).Display("/plugin/story/trend.js", "view", "折线图", "min", "0", "max", "1000", COLOR, "yellow,cyan,red,green,blue,purple,purple")
|
||||
m.StatusTime(mdb.TIME, m.Append(mdb.TIME), "span", kit.FmtDuration(time.Duration(kit.Time(m.Time())-kit.Time(m.Append(mdb.TIME)))), m.AppendSimple(mdb.Config(m, mdb.FIELD)), "cursor", "0")
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
@ -50,9 +50,7 @@ const QRCODE = "qrcode"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
QRCODE: {Name: "qrcode text fg@key bg@key size auto", Help: "二维码", Role: aaa.VOID, Meta: kit.Dict(
|
||||
ice.CTX_TRANS, kit.Dict(html.INPUT, kit.Dict(
|
||||
mdb.TEXT, "文本", BG, "背景色", FG, "字体色",
|
||||
)),
|
||||
ice.CTX_TRANS, kit.Dict(html.INPUT, kit.Dict(mdb.TEXT, "文本", BG, "背景色", FG, "字体色")),
|
||||
), Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.AddRender(ice.RENDER_QRCODE, func(m *ice.Message, args ...ice.Any) string {
|
||||
|
@ -1,43 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"debug/elf"
|
||||
"debug/macho"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
"readelf": {Name: "readelf path=bin/ice.bin auto", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], nfs.PS) {
|
||||
m.Cmdy(nfs.DIR, arg)
|
||||
return
|
||||
}
|
||||
if f, e := nfs.OpenFile(m, arg[0]); !m.Warn(e) {
|
||||
defer f.Close()
|
||||
buf := make([]byte, 1024)
|
||||
n, e := f.Read(buf)
|
||||
if m.Warn(e) {
|
||||
return
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case LINUX:
|
||||
f, _ := elf.Open(arg[0])
|
||||
m.Echo("%v", kit.Formats(f))
|
||||
case DARWIN:
|
||||
f, _ := macho.Open(arg[0])
|
||||
m.Echo("%v", kit.Formats(f))
|
||||
}
|
||||
for i := 0; i < n; i++ {
|
||||
kit.If(i%16 == 0, func() { m.Push("addr", kit.Format("%04x", i)) })
|
||||
m.Push(kit.Format("%02x", i%16), kit.Format("%02x", buf[i]))
|
||||
}
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
@ -11,7 +10,6 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
@ -21,6 +19,7 @@ import (
|
||||
|
||||
func _runtime_init(m *ice.Message) {
|
||||
count := kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT)))
|
||||
defer m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), count+1)
|
||||
kit.For(kit.UnMarshal(kit.Format(ice.Info.Make)), func(k string, v ice.Any) { m.Conf(RUNTIME, kit.Keys(MAKE, strings.ToLower(k)), v) })
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, GOARCH), runtime.GOARCH)
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, GOOS), runtime.GOOS)
|
||||
@ -29,37 +28,29 @@ func _runtime_init(m *ice.Message) {
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, PWD), kit.Path(""))
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, HOME), kit.HomePath(""))
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, MAXPROCS), runtime.GOMAXPROCS(0))
|
||||
nfs.Exists(m, "/proc/meminfo", func(p string) {
|
||||
kit.For(kit.SplitLine(m.Cmdx(nfs.CAT, p)), func(p string) {
|
||||
switch ls := kit.Split(p, ": "); kit.Select("", ls, 0) {
|
||||
case "MemTotal", "MemFree", "MemAvailable", "Buffers", "Cached":
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, ls[0]), kit.FmtSize(kit.Int(ls[1])*1024))
|
||||
}
|
||||
})
|
||||
})
|
||||
ice.Info.System = m.Conf(RUNTIME, kit.Keys(HOST, OSID))
|
||||
ice.Info.PidPath = ice.VAR_LOG_ICE_PID
|
||||
kit.For(ENV_LIST, func(k string) {
|
||||
m.Conf(RUNTIME, kit.Keys(CONF, k), kit.Env(k))
|
||||
kit.If(k == CTX_PID, func() { ice.Info.PidPath = kit.Env(k) })
|
||||
})
|
||||
ice.Info.PidPath = ice.VAR_LOG_ICE_PID
|
||||
ice.Info.Lang = m.Conf(RUNTIME, kit.Keys(CONF, LANG))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME), kit.UserName())
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME), kit.Env("HOSTNAME"))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME), path.Base(kit.Path("")))
|
||||
if name, e := os.Hostname(); e == nil && name != "" {
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME), name)
|
||||
}
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME), kit.UserName())
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME), path.Base(kit.Path("")))
|
||||
ice.Info.Hostname = m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME))
|
||||
ice.Info.Username = m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME))
|
||||
ice.Info.Hostname = m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME))
|
||||
ice.Info.Pathname = m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME))
|
||||
kit.HashSeed = append(kit.HashSeed, ice.Info.Hostname)
|
||||
kit.HashSeed = append(kit.HashSeed, ice.Info.Username)
|
||||
kit.HashSeed = append(kit.HashSeed, ice.Info.Hostname)
|
||||
kit.HashSeed = append(kit.HashSeed, ice.Info.Pathname)
|
||||
ice.Info.System = m.Conf(RUNTIME, kit.Keys(HOST, OSID))
|
||||
aaa.UserRoot(ice.Pulse, "", ice.Info.Make.Username, aaa.TECH, ice.DEV)
|
||||
aaa.UserRoot(ice.Pulse, "", ice.Info.Username, aaa.ROOT, ice.OPS)
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.TIME), m.Time())
|
||||
ice.Info.Time = m.Time()
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.TIME), ice.Info.Time)
|
||||
if runtime.GOARCH != MIPSLE {
|
||||
msg := m.Cmd(nfs.DIR, _system_find(m, os.Args[0]), "time,path,size,hash")
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.HASH), msg.Append(mdb.HASH))
|
||||
@ -68,9 +59,14 @@ func _runtime_init(m *ice.Message) {
|
||||
ice.Info.Hash = msg.Append(mdb.HASH)
|
||||
ice.Info.Size = msg.Append(nfs.SIZE)
|
||||
}
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), count+1)
|
||||
m.Conf(RUNTIME, mdb.META, "")
|
||||
m.Conf(RUNTIME, mdb.HASH, "")
|
||||
nfs.Exists(m, "/proc/meminfo", func(p string) {
|
||||
kit.For(kit.SplitLine(m.Cmdx(nfs.CAT, p)), func(p string) {
|
||||
switch ls := kit.Split(p, ": "); kit.Select("", ls, 0) {
|
||||
case "MemTotal", "MemFree", "MemAvailable", "Buffers", "Cached":
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, ls[0]), kit.FmtSize(kit.Int(ls[1])*1024))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
func _runtime_hostinfo(m *ice.Message) {
|
||||
m.Push("time", ice.Info.Make.Time)
|
||||
@ -82,14 +78,12 @@ func _runtime_hostinfo(m *ice.Message) {
|
||||
m.Push("Sys", kit.FmtSize(stats.Sys))
|
||||
m.Push("Alloc", kit.FmtSize(stats.Alloc))
|
||||
m.Push("TotalAlloc", kit.FmtSize(stats.TotalAlloc))
|
||||
m.Push("Objects", stats.HeapObjects)
|
||||
m.Push("StackSys", kit.FmtSize(stats.StackSys))
|
||||
m.Push("StackInuse", kit.FmtSize(stats.StackInuse))
|
||||
m.Push("HeapSys", kit.FmtSize(stats.HeapSys))
|
||||
m.Push("HeapInuse", kit.FmtSize(stats.HeapInuse))
|
||||
m.Push("HeapIdle", kit.FmtSize(stats.HeapIdle))
|
||||
m.Push("HeapReleased", kit.FmtSize(stats.HeapReleased))
|
||||
|
||||
m.Push("NumGC", stats.NumGC)
|
||||
m.Push("LastGC", time.Unix(int64(stats.LastGC)/int64(time.Second), int64(stats.LastGC)%int64(time.Second)))
|
||||
m.Push("uptime", kit.Split(m.Cmdx(SYSTEM, "uptime"), mdb.FS)[0])
|
||||
@ -148,12 +142,10 @@ const (
|
||||
const (
|
||||
CTX_SHY = "ctx_shy"
|
||||
CTX_DEV = "ctx_dev"
|
||||
CTX_HUB = "ctx_hub"
|
||||
CTX_COM = "ctx_com"
|
||||
CTX_OPS = "ctx_ops"
|
||||
CTX_DEMO = "ctx_demo"
|
||||
CTX_ROOT = "ctx_root"
|
||||
CTX_MAIL = "ctx_mail"
|
||||
CTX_ROOT = "ctx_root"
|
||||
|
||||
CTX_PID = "ctx_pid"
|
||||
CTX_LOG = "ctx_log"
|
||||
@ -161,21 +153,18 @@ const (
|
||||
CTX_ENV = "ctx_env"
|
||||
)
|
||||
|
||||
var ENV_LIST = []string{TZ, LANG, TERM, SHELL, CTX_SHY, CTX_DEV, CTX_HUB, CTX_COM, CTX_OPS, CTX_ROOT, CTX_DEMO, CTX_MAIL, CTX_PID}
|
||||
var ENV_LIST = []string{TZ, LANG, TERM, SHELL, CTX_SHY, CTX_DEV, CTX_OPS, CTX_DEMO, CTX_MAIL, CTX_ROOT, CTX_PID}
|
||||
|
||||
const (
|
||||
USERNAME = "username"
|
||||
HOSTNAME = "hostname"
|
||||
PATHNAME = "pathname"
|
||||
USERNAME = "username"
|
||||
)
|
||||
const (
|
||||
IFCONFIG = "ifconfig"
|
||||
DISKINFO = "diskinfo"
|
||||
HOSTINFO = "hostinfo"
|
||||
USERINFO = "userinfo"
|
||||
PROCSTAT = "procstat"
|
||||
PROCINFO = "procinfo"
|
||||
PROCKILL = "prockill"
|
||||
BOOTINFO = "bootinfo"
|
||||
MAXPROCS = "maxprocs"
|
||||
)
|
||||
@ -183,11 +172,8 @@ const RUNTIME = "runtime"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
RUNTIME: {Name: "runtime info=bootinfo,ifconfig,diskinfo,hostinfo,userinfo,procstat,procinfo,bootinfo,role,api,cli,cmd,mod,env,path,chain,routine auto upgrade reboot stash logs conf", Icon: "Infomation.png", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
aaa.White(m, ice.LICENSE)
|
||||
_runtime_init(m)
|
||||
}},
|
||||
RUNTIME: {Name: "runtime info=bootinfo,ifconfig,diskinfo,hostinfo,userinfo,bootinfo,role,api,cli,cmd,mod,env,path,chain auto upgrade reboot stash logs conf lock", Icon: "Infomation.png", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { _runtime_init(m); aaa.White(m, ice.LICENSE) }},
|
||||
IFCONFIG: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(tcp.HOST) }},
|
||||
DISKINFO: {Hand: func(m *ice.Message, arg ...string) { _runtime_diskinfo(m) }},
|
||||
HOSTINFO: {Hand: func(m *ice.Message, arg ...string) { _runtime_hostinfo(m) }},
|
||||
@ -197,14 +183,11 @@ func init() {
|
||||
}
|
||||
m.Echo(ice.Info.Hostname)
|
||||
}},
|
||||
USERINFO: {Hand: func(m *ice.Message, arg ...string) { m.Split(m.Cmdx(SYSTEM, "who"), "user term time") }},
|
||||
PROCSTAT: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(PROCSTAT) }},
|
||||
PROCINFO: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(PROCINFO) }},
|
||||
PROCKILL: {Help: "结束进程", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(gdb.SIGNAL, gdb.STOP, m.Option("PID")).ProcessRefresh() }},
|
||||
MAXPROCS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(len(arg) > 0, func() { runtime.GOMAXPROCS(kit.Int(mdb.Conf(m, RUNTIME, kit.Keys(HOST, MAXPROCS), arg[0]))) })
|
||||
m.Echo("%d", runtime.GOMAXPROCS(0))
|
||||
}},
|
||||
USERINFO: {Hand: func(m *ice.Message, arg ...string) { m.Split(m.Cmdx(SYSTEM, "who"), "user term time") }},
|
||||
aaa.ROLE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(aaa.ROLE, func(value ice.Maps) { m.Push(mdb.KEY, kit.Keys(value[aaa.ROLE], value[mdb.ZONE], value[mdb.KEY])) })
|
||||
ctx.DisplayStorySpide(m.Options(nfs.DIR_ROOT, "ice."), mdb.FIELD, mdb.KEY, lex.SPLIT, nfs.PT)
|
||||
@ -235,47 +218,13 @@ func init() {
|
||||
kit.For(ice.Info.Gomod, func(k string, v string) { m.Push(nfs.MODULE, k).Push(nfs.VERSION, v) })
|
||||
}},
|
||||
ENV: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.For(os.Environ(), func(v string) {
|
||||
ls := strings.SplitN(v, mdb.EQ, 2)
|
||||
m.Push(mdb.NAME, ls[0]).Push(mdb.VALUE, ls[1])
|
||||
})
|
||||
kit.For(os.Environ(), func(v string) { ls := strings.SplitN(v, mdb.EQ, 2); m.Push(mdb.NAME, ls[0]).Push(mdb.VALUE, ls[1]) })
|
||||
m.Sort(mdb.NAME)
|
||||
}},
|
||||
nfs.PATH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.For(_path_split(os.Getenv(PATH)), func(p string) { m.Push(nfs.PATH, p) })
|
||||
}},
|
||||
"chain": {Hand: func(m *ice.Message, arg ...string) { m.Echo(m.FormatChain()) }},
|
||||
"routine": {Hand: func(m *ice.Message, arg ...string) {
|
||||
status := map[string]int{}
|
||||
buf := make([]byte, 4096*4096)
|
||||
runtime.Stack(buf, true)
|
||||
outer:
|
||||
for _, v := range bytes.Split(buf, []byte(lex.NL+lex.NL)) {
|
||||
ls := bytes.Split(v, []byte(lex.NL))
|
||||
if ls := strings.SplitN(string(ls[0]), " ", 3); len(ls) > 0 {
|
||||
m.Push(mdb.ID, ls[1]).Push(mdb.STATUS, ls[2])
|
||||
status[kit.Split(string(ls[2]), " []:")[0]]++
|
||||
}
|
||||
for i := 1; i < len(ls); i += 2 {
|
||||
if bytes.HasPrefix(ls[i], []byte("shylinux.com/x/")) {
|
||||
m.Push(nfs.PATH, kit.TrimPath(string(ls[i+1]))).Push("func", string(ls[i]))
|
||||
continue outer
|
||||
}
|
||||
}
|
||||
m.Push(nfs.PATH, kit.TrimPath(string(ls[2]))).Push("func", string(ls[1]))
|
||||
}
|
||||
var stats runtime.MemStats
|
||||
runtime.ReadMemStats(&stats)
|
||||
m.StatusTimeCount(status, "GOMAXPROCS", runtime.GOMAXPROCS(0), "NumGC", stats.NumGC,
|
||||
"Sys", kit.FmtSize(stats.Sys),
|
||||
"Alloc", kit.FmtSize(stats.Alloc),
|
||||
"StackSys", kit.FmtSize(stats.StackSys),
|
||||
"StackInuse", kit.FmtSize(stats.StackInuse),
|
||||
"HeapSys", kit.FmtSize(stats.HeapSys),
|
||||
"HeapInuse", kit.FmtSize(stats.HeapInuse),
|
||||
)
|
||||
m.Echo("%v", string(buf))
|
||||
}},
|
||||
"upgrade": {Help: "升级", Hand: func(m *ice.Message, arg ...string) {
|
||||
if nfs.Exists(m, ice.SRC_MAIN_GO) && nfs.Exists(m, ".git") && SystemFind(m, "go") != "" {
|
||||
m.Cmdy("web.code.vimer", "compile")
|
||||
@ -310,9 +259,8 @@ func init() {
|
||||
m.Cmdy(ctx.CONFIG, RUNTIME, arg).StatusTime(mdb.TIME, ice.Info.Make.Time,
|
||||
mdb.HASH, kit.Cut(ice.Info.Hash, 6), nfs.SIZE, ice.Info.Size,
|
||||
mdb.NAME, ice.Info.NodeName, nfs.VERSION, ice.Info.Make.Versions(),
|
||||
).Option(ice.MSG_ACTION, "")
|
||||
).Action()
|
||||
ctx.DisplayStoryJSON(m)
|
||||
m.Action("lock")
|
||||
}},
|
||||
})
|
||||
}
|
||||
@ -344,8 +292,8 @@ func ParseMake(str string) []string {
|
||||
}
|
||||
func SimpleMake() []string {
|
||||
return []string{
|
||||
"bootTime", ice.Info.Time, "compileTime", ice.Info.Make.Time, "commitTime", ice.Info.Make.When,
|
||||
nfs.MODULE, ice.Info.Make.Module, nfs.VERSION, ice.Info.Make.Versions(),
|
||||
"commitTime", ice.Info.Make.When, "compileTime", ice.Info.Make.Time, "bootTime", ice.Info.Time,
|
||||
"kernel", runtime.GOOS, "arch", runtime.GOARCH,
|
||||
}
|
||||
}
|
||||
|
@ -91,6 +91,7 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
if m.Echo(out.String()).Echo(err.String()); m.IsErr() {
|
||||
m.Option(ice.MSG_ARGS, kit.Simple(http.StatusBadRequest, cmd.Args, err.String()))
|
||||
m.Echo(strings.TrimRight(err.String(), lex.NL))
|
||||
m.Info("err: %v", err.String())
|
||||
}
|
||||
}()
|
||||
}
|
||||
@ -105,19 +106,16 @@ func _system_code(cmd *exec.Cmd) string {
|
||||
func _system_find(m *ice.Message, bin string, dir ...string) string {
|
||||
if strings.Contains(bin, nfs.DF) {
|
||||
return bin
|
||||
}
|
||||
if strings.HasPrefix(bin, nfs.PS) {
|
||||
} else if strings.HasPrefix(bin, nfs.PS) {
|
||||
return bin
|
||||
}
|
||||
if strings.HasPrefix(bin, nfs.PWD) {
|
||||
} else if strings.HasPrefix(bin, nfs.PWD) {
|
||||
return bin
|
||||
}
|
||||
kit.If(len(dir) == 0, func() { dir = append(dir, _path_split(kit.Env(PATH))...) })
|
||||
for _, p := range dir {
|
||||
if nfs.Exists(m, path.Join(p, bin)) {
|
||||
return kit.Path(p, bin)
|
||||
}
|
||||
if IsWindows() && nfs.Exists(m, path.Join(p, bin)+".exe") {
|
||||
} else if IsWindows() && nfs.Exists(m, path.Join(p, bin)+".exe") {
|
||||
return kit.Path(p, bin) + ".exe"
|
||||
}
|
||||
}
|
||||
@ -177,10 +175,8 @@ func init() {
|
||||
m.Echo(SystemCmds(m, "man %s %s|col -b", kit.Select("", arg[1], arg[1] != "1"), arg[0]))
|
||||
}},
|
||||
OPENS: {Hand: func(m *ice.Message, arg ...string) { Opens(m, arg...) }},
|
||||
}, mdb.HashAction(mdb.SHORT, CMD, mdb.FIELD, "time,cmd,arg")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
mdb.HashSelect(m)
|
||||
} else if _system_exec(m, _system_cmd(m, arg...)); IsSuccess(m) && m.Append(CMD_ERR) == "" {
|
||||
}), Hand: func(m *ice.Message, arg ...string) {
|
||||
if _system_exec(m, _system_cmd(m, arg...)); IsSuccess(m) && m.Append(CMD_ERR) == "" {
|
||||
m.SetAppend()
|
||||
}
|
||||
}},
|
||||
@ -199,9 +195,7 @@ func IsSuccess(m *ice.Message) bool { return m.Append(CODE) == "" || m.Append(CO
|
||||
|
||||
var _cache_path []string
|
||||
|
||||
func Shell(m *ice.Message) string {
|
||||
return kit.Select("/bin/sh", os.Getenv("SHELL"))
|
||||
}
|
||||
func Shell(m *ice.Message) string { return kit.Select("/bin/sh", os.Getenv("SHELL")) }
|
||||
func EtcPath(m *ice.Message) (res []string) {
|
||||
if len(_cache_path) > 0 {
|
||||
return _cache_path
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -24,11 +23,10 @@ func _command_list(m *ice.Message, name string) *ice.Message {
|
||||
m.Push(mdb.LIST, kit.Format(cmd.List))
|
||||
m.Push(mdb.META, kit.Format(cmd.Meta))
|
||||
m.Push("_command", ShortCmd(kit.Keys(s.Prefix(), key)))
|
||||
if !nfs.Exists(m, kit.Split(cmd.FileLine(), ":")[0], func(p string) {
|
||||
m.Push("_fileline", kit.MergeURL(FileURI(p), ice.POD, m.Option(ice.MSG_USERPOD)))
|
||||
if !nfs.Exists(m, kit.Split(cmd.FileLine(), nfs.DF)[0], func(p string) {
|
||||
m.Push("_fileline", m.FileURI(p))
|
||||
}) {
|
||||
m.Push("_fileline", "")
|
||||
|
||||
}
|
||||
m.Push("_role", kit.Select("", ice.OK, aaa.Right(m.Spawn(), name)))
|
||||
m.Push("_help", GetCmdHelp(m, name))
|
||||
@ -40,16 +38,10 @@ func _command_search(m *ice.Message, kind, name, text string) {
|
||||
if IsOrderCmd(key) || !strings.Contains(s.Prefix(key), name) {
|
||||
return
|
||||
}
|
||||
m.PushSearch(ice.CTX, kit.PathName(1),
|
||||
ice.CMD, kit.FileName(1),
|
||||
m.PushSearch(ice.CTX, kit.PathName(1), ice.CMD, kit.FileName(1),
|
||||
kit.SimpleKV("", s.Prefix(), kit.Select(key, cmd.Name), cmd.Help),
|
||||
CONTEXT, s.Prefix(),
|
||||
COMMAND, key,
|
||||
INDEX, kit.Keys(s.Prefix(), key),
|
||||
mdb.HELP, cmd.Help,
|
||||
nfs.FILE, FileURI(cmd.FileLine()))
|
||||
})
|
||||
m.Sort(m.OptionFields())
|
||||
INDEX, kit.Keys(s.Prefix(), key))
|
||||
}).Sort(m.OptionFields())
|
||||
}
|
||||
|
||||
const (
|
||||
@ -103,56 +95,24 @@ func init() {
|
||||
})
|
||||
}
|
||||
}},
|
||||
mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
TravelCmd(m, func(key, file, line string) { m.Push(mdb.NAME, key).Push(nfs.FILE, file).Push(nfs.LINE, line) }).Sort(mdb.NAME).Table(func(value ice.Maps) {
|
||||
m.Echo(`%s %s %s;" f`+lex.NL, value[mdb.NAME], value[nfs.FILE], value[nfs.LINE])
|
||||
}).Cmd(nfs.SAVE, nfs.TAGS, m.Result())
|
||||
}},
|
||||
}), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy("", mdb.SEARCH, COMMAND, ice.OptionFields(INDEX)).Action(mdb.EXPORT)
|
||||
DisplayStory(m.Options(nfs.DIR_ROOT, "ice."), "spide.js?split=.")
|
||||
} else {
|
||||
kit.For(arg, func(k string) { _command_list(m, k) })
|
||||
}
|
||||
}},
|
||||
}), Hand: func(m *ice.Message, arg ...string) { kit.For(arg, func(k string) { _command_list(m, k) }) }},
|
||||
})
|
||||
}
|
||||
|
||||
var PodCmd = func(m *ice.Message, arg ...ice.Any) bool { return false }
|
||||
|
||||
func Run(m *ice.Message, arg ...string) {
|
||||
kit.If(kit.IsIn(arg[0], "web.chat.grant") || !PodCmd(m, arg) && aaa.Right(m, arg), func() { m.Cmdy(arg) })
|
||||
kit.If(!PodCmd(m, arg) && aaa.Right(m, arg), func() { m.Cmdy(arg) })
|
||||
}
|
||||
func Command(m *ice.Message, arg ...string) {
|
||||
kit.If(kit.IsIn(arg[0], "web.chat.grant") || !PodCmd(m, COMMAND, arg), func() { m.Cmdy(COMMAND, arg) })
|
||||
kit.If(!PodCmd(m, COMMAND, arg), func() { m.Cmdy(COMMAND, arg) })
|
||||
}
|
||||
|
||||
func FileURI(dir string) string {
|
||||
if dir == "" {
|
||||
return ""
|
||||
} else if strings.Contains(dir, "/pkg/mod/") {
|
||||
dir = strings.Split(dir, "/pkg/mod/")[1]
|
||||
} else if ice.Info.Make.Path != "" && strings.HasPrefix(dir, ice.Info.Make.Path) {
|
||||
dir = strings.TrimPrefix(dir, ice.Info.Make.Path)
|
||||
} else if strings.HasPrefix(dir, kit.Path("")+nfs.PS) {
|
||||
dir = strings.TrimPrefix(dir, kit.Path("")+nfs.PS)
|
||||
} else if strings.HasPrefix(dir, ice.ISH_PLUGED) {
|
||||
dir = strings.TrimPrefix(dir, ice.ISH_PLUGED)
|
||||
} else if kit.HasPrefix(dir, nfs.PS, ice.HTTP) {
|
||||
return dir
|
||||
}
|
||||
if strings.HasPrefix(dir, ice.USR_VOLCANOS) {
|
||||
return strings.TrimPrefix(dir, ice.USR)
|
||||
} else {
|
||||
return path.Join(nfs.PS, ice.REQUIRE, dir)
|
||||
}
|
||||
}
|
||||
func FileCmd(dir string) string {
|
||||
if strings.Index(dir, ":") == 1 {
|
||||
return FileURI(kit.ExtChange(strings.Join(kit.Slice(strings.Split(dir, ":"), 0, 2), ":"), nfs.GO))
|
||||
return ice.Pulse.FileURI(kit.ExtChange(strings.Join(kit.Slice(strings.Split(dir, ":"), 0, 2), ":"), nfs.GO))
|
||||
}
|
||||
return FileURI(kit.ExtChange(strings.Split(dir, nfs.DF)[0], nfs.GO))
|
||||
return ice.Pulse.FileURI(kit.ExtChange(strings.Split(dir, nfs.DF)[0], nfs.GO))
|
||||
}
|
||||
func AddFileCmd(dir, key string) {
|
||||
ice.Info.File[FileCmd(dir)] = key
|
||||
@ -180,7 +140,7 @@ func GetFileCmd(dir string) string {
|
||||
return ""
|
||||
}
|
||||
func GetCmdHelp(m *ice.Message, cmds string) (file string) {
|
||||
file = strings.TrimPrefix(FileURI(kit.ExtChange(GetCmdFile(m, cmds), nfs.SHY)), nfs.REQUIRE)
|
||||
file = strings.TrimPrefix(m.FileURI(kit.ExtChange(GetCmdFile(m, cmds), nfs.SHY)), nfs.REQUIRE)
|
||||
if !nfs.Exists(m, path.Join(nfs.USR_LEARNING_PORTAL, "commands", strings.TrimPrefix(file, nfs.USR_ICEBERGS)), func(p string) { file = p }) {
|
||||
kit.If(!nfs.Exists(m, file), func() { file = "" })
|
||||
}
|
||||
@ -188,7 +148,7 @@ func GetCmdHelp(m *ice.Message, cmds string) (file string) {
|
||||
}
|
||||
func GetCmdFile(m *ice.Message, cmds string) (file string) {
|
||||
m.Search(kit.Select(m.PrefixKey(), cmds), func(key string, cmd *ice.Command) {
|
||||
if file = strings.TrimPrefix(FileURI(kit.Split(cmd.FileLine(), nfs.DF)[0]), nfs.REQUIRE); !nfs.Exists(m, file) {
|
||||
if file = strings.TrimPrefix(m.FileURI(kit.Split(cmd.FileLine(), nfs.DF)[0]), nfs.REQUIRE); !nfs.Exists(m, file) {
|
||||
file = path.Join(nfs.REQUIRE, file)
|
||||
}
|
||||
})
|
||||
@ -211,7 +171,9 @@ func TravelCmd(m *ice.Message, cb func(key, file, line string)) *ice.Message {
|
||||
})
|
||||
return m
|
||||
}
|
||||
func IsOrderCmd(key string) bool { return key[0] == '/' || key[0] == '_' }
|
||||
func IsOrderCmd(key string) bool {
|
||||
return key[0] == '/' || key[0] == '_'
|
||||
}
|
||||
func ShortCmd(key string) string {
|
||||
_key := kit.Select("", kit.Split(key, nfs.PT), -1)
|
||||
if _p, ok := ice.Info.Index[_key].(*ice.Context); ok && _p.Prefix(_key) == key {
|
||||
|
@ -13,24 +13,6 @@ import (
|
||||
"shylinux.com/x/toolkits/miss"
|
||||
)
|
||||
|
||||
func _config_format_list(m *ice.Message, v ice.Any) string {
|
||||
list := []string{"{", lex.NL}
|
||||
kit.For(v, func(k string, v ice.Any) {
|
||||
if k == mdb.HASH {
|
||||
list = append(list, lex.TB, kit.Format("%q", k), nfs.DF, "{", lex.NL)
|
||||
kit.For(v, func(k string, v ice.Any) {
|
||||
list = append(list, lex.TB, lex.TB, kit.Format("%q", k), nfs.DF, kit.Format(v), mdb.FS, lex.NL)
|
||||
})
|
||||
list = list[:len(list)-2]
|
||||
list = append(list, lex.TB, lex.NL, lex.TB, "}", mdb.FS, lex.NL)
|
||||
} else {
|
||||
list = append(list, lex.TB, kit.Format("%q", k), nfs.DF, kit.Format(v), mdb.FS, lex.NL)
|
||||
}
|
||||
})
|
||||
list = list[:len(list)-2]
|
||||
list = append(list, lex.NL, "}")
|
||||
return strings.Join(list, "")
|
||||
}
|
||||
func _config_only(v ice.Any, arg ...string) bool {
|
||||
switch v := v.(type) {
|
||||
case nil:
|
||||
@ -55,9 +37,9 @@ func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
for _, k := range arg {
|
||||
if v := mdb.Confv(msg, k); _config_only(v, mdb.META) && _config_only(kit.Value(v, mdb.META),
|
||||
mdb.IMPORTANT, mdb.EXPIRE, mdb.SHORT, mdb.FIELD, mdb.FIELDS, mdb.ACTION, mdb.SORT, mdb.TOOLS,
|
||||
"regexp", "path", "link",
|
||||
nfs.SOURCE, nfs.SCRIPT,
|
||||
lex.REGEXP, nfs.PATH, "link",
|
||||
"linux", "darwin", "windows",
|
||||
"source", "script",
|
||||
) {
|
||||
continue
|
||||
} else {
|
||||
@ -91,40 +73,32 @@ func _config_load(m *ice.Message, name string, arg ...string) {
|
||||
func _config_make(m *ice.Message, key string, arg ...string) {
|
||||
msg := m.Spawn(m.Source())
|
||||
if len(arg) > 1 {
|
||||
kit.If(!kit.IsIn(strings.Split(arg[0], nfs.PT)[0], mdb.META, mdb.HASH, mdb.LIST), func() { arg[0] = kit.Keys(mdb.META, arg[0]) })
|
||||
kit.If(strings.HasPrefix(arg[1], mdb.AT), func() { arg[1] = msg.Cmdx(nfs.CAT, arg[1][1:]) })
|
||||
if !kit.IsIn(strings.Split(arg[0], nfs.PT)[0], mdb.META, mdb.HASH, mdb.LIST) {
|
||||
arg[0] = kit.Keys(mdb.META, arg[0])
|
||||
}
|
||||
mdb.Confv(msg, key, arg[0], kit.Parse(nil, "", arg[1:]...))
|
||||
}
|
||||
if len(arg) > 0 {
|
||||
m.Echo(FormatPretty(mdb.Confv(msg, key, arg[0]), 0, 1))
|
||||
m.Echo(kit.Formats(mdb.Confv(msg, key, arg[0])))
|
||||
} else {
|
||||
m.Echo(FormatPretty(mdb.Confv(msg, key), 0, 1))
|
||||
m.StatusTime(mdb.COUNT, kit.Length(mdb.Confv(msg, key, mdb.HASH)))
|
||||
m.Echo(kit.Formats(mdb.Confv(msg, key))).StatusTime(mdb.COUNT, kit.Length(mdb.Confv(msg, key, mdb.HASH)))
|
||||
}
|
||||
}
|
||||
func _config_list(m *ice.Message) {
|
||||
for k, v := range m.Source().Configs {
|
||||
if IsOrderCmd(k) {
|
||||
continue
|
||||
}
|
||||
if !IsOrderCmd(k) {
|
||||
m.Push(mdb.KEY, k).Push(mdb.NAME, v.Name).Push(mdb.VALUE, kit.Format(v.Value))
|
||||
}
|
||||
}
|
||||
m.Sort(mdb.KEY)
|
||||
}
|
||||
|
||||
const (
|
||||
SAVE = "save"
|
||||
LOAD = "load"
|
||||
)
|
||||
const CONFIG = "config"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CONFIG: {Name: "config key auto", Help: "配置", Actions: ice.Actions{
|
||||
SAVE: {Hand: func(m *ice.Message, arg ...string) { _config_save(m, arg[0], arg[1:]...) }},
|
||||
LOAD: {Hand: func(m *ice.Message, arg ...string) { _config_load(m, arg[0], arg[1:]...) }},
|
||||
nfs.SAVE: {Hand: func(m *ice.Message, arg ...string) { _config_save(m, arg[0], arg[1:]...) }},
|
||||
nfs.LOAD: {Hand: func(m *ice.Message, arg ...string) { _config_load(m, arg[0], arg[1:]...) }},
|
||||
mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(arg[0], mdb.EXPORT) }},
|
||||
mdb.IMPORT: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(arg[0], mdb.IMPORT) }},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -132,11 +106,6 @@ func init() {
|
||||
nfs.Trash(m, m.Cmdx(arg[0], mdb.EXPORT))
|
||||
mdb.Config(m, arg[0], nil, nil)
|
||||
}},
|
||||
mdb.LIST: {Hand: func(m *ice.Message, arg ...string) {
|
||||
list := []ice.Any{}
|
||||
kit.For(arg[2:], func(v string) { list = append(list, v) })
|
||||
mdb.Confv(m, arg[0], arg[1], list)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
_config_list(m)
|
||||
@ -152,14 +121,16 @@ func init() { ice.Info.Save = Save; ice.Info.Load = Load }
|
||||
func Save(m *ice.Message, arg ...string) *ice.Message {
|
||||
kit.If(len(arg) == 0, func() { arg = kit.SortedKey(m.Target().Configs) })
|
||||
kit.For(arg, func(i int, k string) { arg[i] = strings.Replace(m.Prefix(k), nfs.PS, "", 1) })
|
||||
return m.Cmd(CONFIG, SAVE, m.Prefix(nfs.JSON), arg)
|
||||
return m.Cmd(CONFIG, nfs.SAVE, m.Prefix(nfs.JSON), arg)
|
||||
}
|
||||
func Load(m *ice.Message, arg ...string) *ice.Message {
|
||||
kit.If(len(arg) == 0, func() { arg = kit.SortedKey(m.Target().Configs) })
|
||||
kit.For(arg, func(i int, k string) { arg[i] = strings.Replace(m.Prefix(k), nfs.PS, "", 1) })
|
||||
return m.Cmd(CONFIG, LOAD, m.Prefix(nfs.JSON), arg)
|
||||
return m.Cmd(CONFIG, nfs.LOAD, m.Prefix(nfs.JSON), arg)
|
||||
}
|
||||
func ConfAction(arg ...ice.Any) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(arg...)}
|
||||
}
|
||||
func ConfAction(arg ...ice.Any) ice.Actions { return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(arg...)} }
|
||||
func ConfigSimple(m *ice.Message, key ...string) (res []string) {
|
||||
kit.For(kit.Split(kit.Join(key)), func(k string) { res = append(res, k, mdb.Config(m, k)) })
|
||||
return
|
||||
@ -176,59 +147,3 @@ func OptionFromConfig(m *ice.Message, arg ...string) string {
|
||||
kit.For(arg, func(k string) { m.Option(k, mdb.Config(m, k)) })
|
||||
return m.Option(arg[0])
|
||||
}
|
||||
func FormatPretty(v ice.Any, i, n int) string {
|
||||
return kit.Formats(v)
|
||||
switch v := v.(type) {
|
||||
case map[string]ice.Any:
|
||||
if n == 0 {
|
||||
list := []string{"{"}
|
||||
kit.For(v, func(k string, v ice.Any) {
|
||||
list = append(list, kit.Format("%q", k), nfs.DF, FormatPretty(v, 0, 0), mdb.FS)
|
||||
})
|
||||
list = list[:len(list)-1]
|
||||
list = append(list, "}")
|
||||
return strings.Join(list, "")
|
||||
}
|
||||
list := []string{"{", lex.NL}
|
||||
kit.For(v, func(k string, v ice.Any) {
|
||||
list = append(list, strings.Repeat(lex.TB, i+1), kit.Format("%q", k), nfs.DF)
|
||||
if i < n && !kit.IsIn(k, mdb.META) && !strings.HasPrefix(k, "_") {
|
||||
list = append(list, FormatPretty(v, i+1, n))
|
||||
} else {
|
||||
list = append(list, FormatPretty(v, 0, 0))
|
||||
}
|
||||
list = append(list, mdb.FS, lex.NL)
|
||||
})
|
||||
list = append(list[:len(list)-2], lex.NL)
|
||||
list = append(list, strings.Repeat(lex.TB, i), "}")
|
||||
return strings.Join(list, "")
|
||||
case []ice.Any:
|
||||
if n == 0 {
|
||||
list := []string{"["}
|
||||
kit.For(v, func(k string, v ice.Any) {
|
||||
list = append(list, FormatPretty(v, 0, 0), mdb.FS)
|
||||
})
|
||||
list = list[:len(list)-1]
|
||||
list = append(list, "]")
|
||||
return strings.Join(list, "")
|
||||
}
|
||||
list := []string{"[", lex.NL}
|
||||
kit.For(v, func(v ice.Any) {
|
||||
list = append(list, strings.Repeat(lex.TB, i+1))
|
||||
if i < n {
|
||||
list = append(list, FormatPretty(v, i+1, n))
|
||||
} else {
|
||||
list = append(list, FormatPretty(v, 0, 0))
|
||||
}
|
||||
list = append(list, mdb.FS, lex.NL)
|
||||
})
|
||||
list = append(list[:len(list)-2], lex.NL)
|
||||
list = append(list, strings.Repeat(lex.TB, i), "]")
|
||||
return strings.Join(list, "")
|
||||
case string:
|
||||
return kit.Format(v)
|
||||
return kit.Format("%q", v)
|
||||
default:
|
||||
return kit.Format(v)
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package ctx
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const CTX = "ctx"
|
||||
@ -10,5 +9,3 @@ const CTX = "ctx"
|
||||
var Index = &ice.Context{Name: CTX, Help: "标准模块"}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, CONTEXT, COMMAND, CONFIG) }
|
||||
|
||||
func Prefix(arg ...string) string { return kit.Keys(CTX, arg) }
|
||||
|
@ -10,22 +10,11 @@ import (
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/logs"
|
||||
)
|
||||
|
||||
type displayMessage interface {
|
||||
Option(key string, arg ...ice.Any) string
|
||||
Action(arg ...ice.Any) *ice.Message
|
||||
}
|
||||
|
||||
func isLocalFile(p string) bool {
|
||||
return !strings.HasPrefix(p, nfs.PS) && !strings.HasPrefix(p, ice.HTTP)
|
||||
}
|
||||
func Display(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
kit.If(file == "", func() { file = kit.Keys(kit.FileName(5), nfs.JS) })
|
||||
kit.If(isLocalFile(file), func() { file = path.Join(nfs.PS, path.Join(path.Dir(FileURI(logs.FileLines(2))), file)) })
|
||||
return DisplayBase(m, file, arg...)
|
||||
}
|
||||
func DisplayTable(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayBase(m, ice.PLUGIN_TABLE_JS, arg...)
|
||||
}
|
||||
@ -47,16 +36,12 @@ func DisplayStoryForm(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
trans := kit.Value(m.Commands(m.CommandKey()).Meta, ice.CTX_TRANS)
|
||||
if t := reflect.TypeOf(v); t.Kind() == reflect.Func {
|
||||
name := kit.FuncName(arg[i])
|
||||
args = append(args, kit.Dict(mdb.TYPE, html.BUTTON, mdb.NAME, name,
|
||||
mdb.VALUE, kit.Select(name, kit.Value(trans, name), !m.IsEnglish()),
|
||||
))
|
||||
args = append(args, kit.Dict(mdb.TYPE, html.BUTTON, mdb.NAME, name, mdb.VALUE, kit.Select(name, kit.Value(trans, name), !m.IsEnglish())))
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, v := range args {
|
||||
m.Push("", v, kit.Split("type,name,value,values,need,action"))
|
||||
}
|
||||
return DisplayStory(m, "form.js")
|
||||
kit.For(args, func(v string) { m.Push("", v, kit.Split("type,name,value,values,need,action")) })
|
||||
return DisplayStory(m, "form")
|
||||
}
|
||||
func DisplayStoryJSON(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayStory(m, "json", arg...)
|
||||
@ -71,21 +56,20 @@ func DisplayStudio(m *ice.Message, cmd ...string) *ice.Message {
|
||||
for i, k := range cmd {
|
||||
kit.If(!strings.Contains(cmd[i], nfs.PT), func() { cmd[i] = m.Prefix(k) })
|
||||
}
|
||||
return DisplayStory(m.Cmdy(COMMAND, cmd), "studio.js")
|
||||
return DisplayStory(m.Cmdy(COMMAND, cmd), "studio")
|
||||
}
|
||||
func DisplayLocal(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
kit.If(file == "", func() { file = path.Join(kit.PathName(5), kit.Keys(kit.FileName(5), nfs.JS)) })
|
||||
kit.If(file == "", func() { file = strings.ReplaceAll(strings.TrimPrefix(m.PrefixKey(), "web."), nfs.PT, nfs.PS) })
|
||||
kit.If(isLocalFile(file), func() { file = path.Join(ice.PLUGIN_LOCAL, file) })
|
||||
return DisplayBase(m, file, arg...)
|
||||
}
|
||||
func DisplayLocalInner(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayLocal(m, "code/inner.js", arg...)
|
||||
return DisplayLocal(m, "code/inner", arg...)
|
||||
}
|
||||
func DisplayBase(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
m.Option(ice.MSG_DISPLAY, m.MergeLink(kit.Select(kit.ExtChange(file, nfs.JS), file, strings.Contains(file, mdb.QS)), arg...))
|
||||
Toolkit(m, "")
|
||||
return m
|
||||
return Toolkit(m, "")
|
||||
}
|
||||
func Toolkit(m *ice.Message, arg ...string) {
|
||||
m.Option(ice.MSG_TOOLKIT, kit.Select(mdb.Config(m, mdb.TOOLS), kit.Fields(arg)))
|
||||
func Toolkit(m *ice.Message, arg ...string) *ice.Message {
|
||||
return m.Options(ice.MSG_TOOLKIT, kit.Select(mdb.Config(m, mdb.TOOLS), kit.Fields(arg)))
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
@ -14,7 +15,9 @@ import (
|
||||
|
||||
type Frame struct{ s chan os.Signal }
|
||||
|
||||
func (f *Frame) Begin(m *ice.Message, arg ...string) { f.s = make(chan os.Signal, 10) }
|
||||
func (f *Frame) Begin(m *ice.Message, arg ...string) {
|
||||
f.s = make(chan os.Signal, 10)
|
||||
}
|
||||
func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
kit.If(ice.Info.PidPath, func(p string) {
|
||||
if f, p, e := logs.CreateFile(p); e == nil {
|
||||
@ -23,11 +26,12 @@ func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
fmt.Fprint(f, os.Getpid())
|
||||
}
|
||||
})
|
||||
// t := kit.Duration(mdb.Conf(m, TIMER, kit.Keym(TICK)))
|
||||
t := time.NewTicker(kit.Duration(mdb.Conf(m, TIMER, kit.Keym(TICK))))
|
||||
for {
|
||||
select {
|
||||
// case <-time.Tick(t):
|
||||
// m.Cmd(TIMER, HAPPEN, kit.Dict(ice.LOG_DISABLE, ice.TRUE))
|
||||
case <-t.C:
|
||||
m.Options(ice.LOG_DISABLE, ice.TRUE)
|
||||
m.Cmd(TIMER, HAPPEN)
|
||||
case s, ok := <-f.s:
|
||||
if !ok {
|
||||
return
|
||||
|
@ -21,13 +21,7 @@ func _signal_action(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m.Spawn(), arg...).Table(func(value ice.Maps) { m.Cmdy(kit.Split(value[ice.CMD])) })
|
||||
}
|
||||
func _signal_process(m *ice.Message, p string, s os.Signal) {
|
||||
if p == "" {
|
||||
b, _ := file.ReadFile(ice.Info.PidPath)
|
||||
p = string(b)
|
||||
if runtime.GOOS == ice.WINDOWS {
|
||||
return
|
||||
}
|
||||
}
|
||||
kit.If(p == "", func() { b, _ := file.ReadFile(ice.Info.PidPath); p = string(b) })
|
||||
if p, e := os.FindProcess(kit.Int(kit.Select(kit.Format(os.Getpid()), p))); e == nil {
|
||||
p.Signal(s)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -14,11 +15,10 @@ func _timer_action(m *ice.Message, now time.Time, arg ...string) {
|
||||
if count == 0 || value[mdb.TIME] > now.Format(ice.MOD_TIME) {
|
||||
return
|
||||
}
|
||||
m.Option(ice.LOG_DISABLE, ice.FALSE)
|
||||
// m.Cmd(ROUTINE, mdb.CREATE, mdb.NAME, value[mdb.NAME], kit.Keycb(ROUTINE), value[ice.CMD])
|
||||
m.Options(ice.LOG_DISABLE, ice.FALSE)
|
||||
m.Cmd(kit.Split(value[ice.CMD])).Cost()
|
||||
kit.If(count < 0, func() { count++ })
|
||||
mdb.HashModify(m, mdb.HASH, value[mdb.HASH], mdb.COUNT, count-1, mdb.TIME, m.Time(value[INTERVAL]))
|
||||
mdb.HashModify(m, mdb.NAME, value[mdb.NAME], mdb.COUNT, count-1, mdb.TIME, m.Time(value[INTERVAL]))
|
||||
})
|
||||
}
|
||||
|
||||
@ -31,7 +31,9 @@ const TIMER = "timer"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TIMER: {Help: "定时器", Actions: ice.MergeActions(ice.Actions{
|
||||
TIMER: {Help: "定时器", Meta: kit.Dict(
|
||||
ice.CTX_TRANS, kit.Dict(html.INPUT, kit.Dict(DELAY, "延时", INTERVAL, "间隔", TICK, "周期")),
|
||||
), Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch mdb.HashInputs(m, arg); arg[0] {
|
||||
case mdb.COUNT:
|
||||
@ -43,7 +45,8 @@ func init() {
|
||||
mdb.CREATE: {Name: "create name*=hi delay=10ms interval=10s count=3 cmd*=runtime"},
|
||||
mdb.PRUNES: {Hand: func(m *ice.Message, arg ...string) { mdb.HashPrunesValue(m, mdb.COUNT, "0") }},
|
||||
HAPPEN: {Hand: func(m *ice.Message, arg ...string) { _timer_action(m, time.Now(), arg...) }},
|
||||
RESTART: {Name: "restart count=3", Hand: func(m *ice.Message, arg ...string) { mdb.HashModify(m, m.OptionSimple(mdb.HashShort(m)), arg) }},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,delay,interval,count,cmd", TICK, "1s"))},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,delay,interval,count,cmd", TICK, "10s")), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).StatusTimeCount(mdb.ConfigSimple(m, TICK))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -413,11 +413,11 @@ func init() {
|
||||
if kit.HasPrefix(value, HTTP, nfs.PS) {
|
||||
return value
|
||||
} else if nfs.ExistsFile(m, path.Join(ice.USR_LOCAL_WORK, m.Appendv(mdb.NAME)[index], value)) {
|
||||
return kit.MergeURL(ctx.FileURI(value), ice.POD, m.Appendv(mdb.NAME)[index])
|
||||
return m.Spawn(kit.Dict(ice.MSG_USERPOD, m.Appendv(mdb.NAME)[index])).FileURI(value)
|
||||
} else if nfs.ExistsFile(m, value) {
|
||||
return kit.MergeURL(ctx.FileURI(value))
|
||||
return m.FileURI(value)
|
||||
} else {
|
||||
return kit.MergeURL(ctx.FileURI(nfs.USR_ICONS_ICEBERGS))
|
||||
return m.FileURI(nfs.USR_ICONS_ICEBERGS)
|
||||
}
|
||||
}
|
||||
return value
|
||||
|
@ -49,7 +49,7 @@ func _space_dial(m *ice.Message, dev, name string, arg ...string) {
|
||||
}
|
||||
}).Cost(mdb.COUNT, i, mdb.NEXT, next, tcp.DIAL, dev, LINK, u.String()).Sleep(next)
|
||||
}
|
||||
}, kit.Join(kit.Simple(SPACE, name), lex.SP))
|
||||
}, kit.JoinWord(SPACE, dev))
|
||||
}
|
||||
func _space_agent(m *ice.Message, args ...string) []string {
|
||||
kit.If(m.Option(cli.GOOS), func(p string) { args = append(args, cli.SYSTEM, p) })
|
||||
@ -127,7 +127,7 @@ func _space_fork(m *ice.Message) {
|
||||
})
|
||||
}
|
||||
_space_handle(m, safe, name, c)
|
||||
}, kit.Join(kit.Simple(SPACE, name), lex.SP))
|
||||
}, kit.JoinWord(SPACE, name))
|
||||
}
|
||||
}
|
||||
func _space_handle(m *ice.Message, safe bool, name string, c *websocket.Conn) {
|
||||
|
@ -285,7 +285,7 @@ func init() {
|
||||
if p := path.Join(ice.SRC_TEMPLATE, m.PrefixKey(), path.Join(arg...)); nfs.Exists(m, p) {
|
||||
return p + kit.Select("", nfs.PS, len(arg) == 0)
|
||||
} else {
|
||||
return kit.MergeURL(ctx.FileURI(path.Join(path.Dir(ctx.GetCmdFile(m, m.PrefixKey())), path.Join(arg...))), ice.POD, m.Option(ice.MSG_USERPOD))
|
||||
return m.FileURI(path.Join(path.Dir(ctx.GetCmdFile(m, m.PrefixKey())), path.Join(arg...)))
|
||||
// return path.Join(path.Dir(ctx.GetCmdFile(m, m.PrefixKey())), path.Join(arg...)) + kit.Select("", nfs.PS, len(arg) == 0)
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
f.HandleFunc(key, func(w http.ResponseWriter, r *http.Request) {
|
||||
m.Spawn(key, cmd, c, w, r).TryCatch(true, func(msg *ice.Message) { _serve_handle(key, cmd, msg, w, r) })
|
||||
})
|
||||
ice.Info.Route[path.Join(list[c], key)+kit.Select("", nfs.PS, strings.HasSuffix(key, nfs.PS))] = ctx.FileURI(cmd.FileLine())
|
||||
ice.Info.Route[path.Join(list[c], key)+kit.Select("", nfs.PS, strings.HasSuffix(key, nfs.PS))] = m.FileURI(cmd.FileLine())
|
||||
}(key, cmd)
|
||||
}
|
||||
})
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
@ -458,7 +457,7 @@ func (m Message) Call(cmd string, arg ...Any) Any {
|
||||
} else if !strings.HasPrefix(file, nfs.PS) && !strings.HasPrefix(file, ice.HTTP) {
|
||||
file = path.Join(path.Dir(kit.Split(_parse_stack(m.Message).name, nfs.DF)[0]), file)
|
||||
}
|
||||
m.Display(ctx.FileURI(file), arg[1:]...)
|
||||
m.Display(m.FileURI(file), arg[1:]...)
|
||||
case "DebugStack":
|
||||
list := []string{}
|
||||
s := _parse_stack(m.Message)
|
||||
|
@ -53,7 +53,7 @@ func PodCmdAction(arg ...string) ice.Actions {
|
||||
file := kit.FileLine(2, 100)
|
||||
return ice.Actions{
|
||||
mdb.SELECT: {Name: "list hash auto create", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer m.Display(ctx.FileURI(file))
|
||||
defer m.Display(m.FileURI(file))
|
||||
msg := disableApp(mdb.HashSelect(m.Spawn(), arg...).Sort(mdb.NAME))
|
||||
web.PushPodCmd(msg, m.PrefixKey(), arg...)
|
||||
has := map[string]bool{}
|
||||
@ -75,7 +75,7 @@ func CmdHashAction(arg ...string) ice.Actions {
|
||||
}
|
||||
}},
|
||||
mdb.SELECT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
disableApp(mdb.HashSelect(m, arg...).Sort(mdb.NAME).Display(ctx.FileURI(file)))
|
||||
disableApp(mdb.HashSelect(m, arg...).Sort(mdb.NAME).Display(m.FileURI(file)))
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, kit.Select("", arg, 0), mdb.FIELD, kit.Select("time,hash,icon,name,text,space,index,args", arg, 1), kit.Slice(arg, 2)))
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ func _portal_commands(m *ice.Message, arg ...string) {
|
||||
if p := path.Join(nfs.USR_LEARNING_PORTAL, path.Join(arg...), mod, last, strings.Replace(cmd, nfs.PT, nfs.PS, -1)+".shy"); nfs.Exists(m, p) {
|
||||
text = append(text, kit.Format(" %s %s.shy", cmd, cmd))
|
||||
} else if p, ok := help[last+nfs.PT+cmd]; ok {
|
||||
text = append(text, kit.Format(" %s %s", cmd, strings.TrimPrefix(ctx.FileURI(p), "/require/")))
|
||||
text = append(text, kit.Format(" %s %s", cmd, strings.TrimPrefix(m.FileURI(p), "/require/")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func _wiki_list(m *ice.Message, arg ...string) bool {
|
||||
m.Copy(m.Cmd(nfs.DIR, kit.Slice(arg, 0, 1), kit.Dict(nfs.DIR_TYPE, nfs.CAT, nfs.DIR_REG, mdb.Config(m, lex.REGEXP))).SortStr(nfs.PATH))
|
||||
return true
|
||||
} else {
|
||||
ctx.Display(m, ctx.FileURI(nfs.Relative(m, ctx.GetCmdFile(m, m.PrefixKey()))))
|
||||
m.Display(m.FileURI(nfs.Relative(m, ctx.GetCmdFile(m, m.PrefixKey()))))
|
||||
// ctx.DisplayLocal(m, path.Join(kit.PathName(2), kit.Keys(kit.FileName(2), nfs.JS)))
|
||||
return false
|
||||
}
|
||||
|
4
info.go
4
info.go
@ -304,7 +304,7 @@ func Module(prefix string, arg ...Any) {
|
||||
return m
|
||||
}
|
||||
}
|
||||
func FileURI(dir string) string {
|
||||
func (m *Message) FileURI(dir string) string {
|
||||
if dir == "" {
|
||||
return ""
|
||||
} else if strings.Contains(dir, "/pkg/mod/") {
|
||||
@ -321,6 +321,6 @@ func FileURI(dir string) string {
|
||||
if strings.HasPrefix(dir, USR_VOLCANOS) {
|
||||
return strings.TrimPrefix(dir, USR)
|
||||
} else {
|
||||
return path.Join(PS, REQUIRE, dir)
|
||||
return kit.MergeURL(path.Join(PS, REQUIRE, dir), POD, m.Option(MSG_USERPOD))
|
||||
}
|
||||
}
|
||||
|
8
misc.go
8
misc.go
@ -159,6 +159,14 @@ func (m *Message) CmdMap(arg ...string) map[string]map[string]string {
|
||||
func (m *Message) Toast(content string, arg ...string) { // title duration
|
||||
Info.PushNotice(m, "toast", content, arg)
|
||||
}
|
||||
func (m *Message) PushStream() *Message { return Info.PushStream(m) }
|
||||
func (m *Message) ToastSuccess(arg ...string) { m.Toast(SUCCESS, arg...) }
|
||||
func (m *Message) ToastFailure(arg ...string) { m.Toast(FAILURE, arg...) }
|
||||
func (m *Message) ToastProcess(arg ...string) func(...string) {
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, "", "-1") })
|
||||
m.Toast(PROCESS, arg...)
|
||||
return func(arg ...string) { m.ToastSuccess(arg...) }
|
||||
}
|
||||
func (m *Message) Trans(en string, zh string) string {
|
||||
switch strings.ToLower(kit.Select("", kit.Split(m.Option(MSG_LANGUAGE), "_-"), 0)) {
|
||||
case "zh":
|
||||
|
@ -58,7 +58,7 @@ func _ide_autogen_pages(m *ice.Message) {
|
||||
head_wxml, foot_wxml, wxml := nfs.TemplateText(m, "pages_head.wxml"), nfs.TemplateText(m, "pages_foot.wxml"), nfs.TemplateText(m, "pages.wxml")
|
||||
m.Travel(func(_ *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
||||
if h, ok := cmd.Actions[PAGES]; ok {
|
||||
file := path.Join(path.Dir(strings.TrimPrefix(m.Resource(ctx.FileURI(cmd.FileLine())), nfs.REQUIRE)), kit.Select(key+".js", h.Name))
|
||||
file := path.Join(path.Dir(strings.TrimPrefix(m.Resource(m.FileURI(cmd.FileLine())), nfs.REQUIRE)), kit.Select(key+".js", h.Name))
|
||||
if !nfs.Exists(m, file) {
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user