diff --git a/base/cli/daemon.go b/base/cli/daemon.go index 6db096c7..9f1b2593 100644 --- a/base/cli/daemon.go +++ b/base/cli/daemon.go @@ -5,6 +5,7 @@ import ( "io" "os/exec" "runtime" + "strings" ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/ctx" @@ -146,6 +147,21 @@ func init() { }}, }) } + +func OpenCmds(m *ice.Message, arg ...string) { + if !tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) { + return + } + if len(arg) == 0 || arg[0] == "" { + return + } + m.Cmd(SYSTEM, "osascript", "-e", kit.Format(` +tell application "Terminal" + do script "%s" + activate +end tell +`, strings.Join(arg, "; "))) +} func Opens(m *ice.Message, arg ...string) { if !tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) { return diff --git a/base/cli/runtime.go b/base/cli/runtime.go index c9b677af..522dba38 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -157,7 +157,7 @@ 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 restart", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{ + RUNTIME: {Name: "runtime info=bootinfo,ifconfig,diskinfo,hostinfo,userinfo,procstat,procinfo,bootinfo,role,api,cli,cmd,mod,env,path,chain,routine auto upgrade restart logs conf", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { aaa.White(m, ice.ETC_PATH) aaa.White(m, ice.LICENSE) @@ -251,6 +251,12 @@ func init() { RESTART: {Hand: func(m *ice.Message, arg ...string) { m.Go(func() { m.Sleep("30ms", ice.EXIT, 1) }) }}, + "logs": {Help: "日志", Hand: func(m *ice.Message, arg ...string) { + OpenCmds(m, kit.Format("cd %s", kit.Path("")), "tail -f var/log/bench.log") + }}, + "conf": {Help: "配置", Hand: func(m *ice.Message, arg ...string) { + OpenCmds(m, kit.Format("cd %s", kit.Path("")), "vim etc/init.shy") + }}, 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) @@ -261,8 +267,7 @@ func init() { ctx.DisplayStoryJSON(m) m.Status(mdb.TIME, ice.Info.Make.Time, mdb.HASH, kit.Cut(ice.Info.Hash, 6), nfs.SIZE, ice.Info.Size, - ice.BIN, _system_find(m, os.Args[0]), mdb.NAME, ice.Info.NodeName, - nfs.REMOTE, ice.Info.Make.Remote, nfs.VERSION, ice.Info.Make.Versions(), + mdb.NAME, ice.Info.NodeName, nfs.VERSION, ice.Info.Make.Versions(), ) }}, }) diff --git a/base/web/admin.go b/base/web/admin.go index 1b4bc1cb..d444ffec 100644 --- a/base/web/admin.go +++ b/base/web/admin.go @@ -6,11 +6,13 @@ import ( ) func init() { + const ADMIN = "admin" Index.MergeCommands(ice.Commands{ - "admin": {Name: "admin", Help: "管理", Hand: func(m *ice.Message, arg ...string) { + ADMIN: {Name: ADMIN, Help: "管理", Hand: func(m *ice.Message, arg ...string) { args := []string{} + kit.If(len(arg) == 0, func() { arg = append(arg, SPACE, DOMAIN) }) kit.For(arg[1:], func(v string) { args = append(args, ice.ARG, v) }) - m.Cmdy(SPIDE, ice.OPS, SPIDE_RAW, "/chat/cmd/"+arg[0]+"?debug=true", SPIDE_FORM, args) + m.Cmdy(SPIDE, ice.OPS, SPIDE_RAW, CHAT_CMD+arg[0]+"?debug=true", SPIDE_FORM, args) }}, }) } diff --git a/base/web/render.go b/base/web/render.go index ccb37e19..df4b0592 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -162,6 +162,9 @@ const ( VIEW = "view" CHAT = "chat" + CHAT_POD = "/chat/pod/" + CHAT_CMD = "/chat/cmd/" + CODE_GIT_SERVICE = "web.code.git.service" CODE_GIT_STATUS = "web.code.git.status" CODE_GIT_REPOS = "web.code.git.repos" diff --git a/base/web/space.go b/base/web/space.go index 60ce27f5..437d9d27 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -212,7 +212,7 @@ func init() { } }}, nfs.PS: {Hand: func(m *ice.Message, arg ...string) { _space_fork(m) }}, - }, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,type,name,text,module,version", ctx.ACTION, OPEN, REDIAL, kit.Dict("a", 3000, "b", 1000, "c", 1000)), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) { + }, mdb.HashAction(mdb.LIMIT, 1000, mdb.LEAST, 1000, mdb.SHORT, mdb.NAME, mdb.FIELD, "time,type,name,text,module,version", ctx.ACTION, OPEN, REDIAL, kit.Dict("a", 3000, "b", 1000, "c", 1000)), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) { if len(arg) < 2 { defer m.StatusTimeCount() m.Option(ice.MSG_USERWEB, tcp.PublishLocalhost(m, m.Option(ice.MSG_USERWEB))) diff --git a/core/chat/macos/desktop.css b/core/chat/macos/desktop.css index 55ce6bb6..79e84e12 100644 --- a/core/chat/macos/desktop.css +++ b/core/chat/macos/desktop.css @@ -43,6 +43,7 @@ fieldset.macos.desktop>div.output>div.desktop>fieldset>div.action>div.item.icons fieldset.macos.desktop>div.output>div.desktop>fieldset>div.action>div.item:last-child { margin-right:120px; } fieldset.macos.desktop>div.output>div.desktop>fieldset.web.wiki.feel>div.status { display:none; } fieldset.macos.desktop>div.output>div.desktop>fieldset.web.code.vimer>div.status { display:none; } +fieldset.macos.desktop>div.output>div.desktop>fieldset.web.code.vimer>div.action>div.tabs { display:none; } fieldset.macos.desktop>div.output>div.desktop>fieldset.web.code.xterm>div.status { display:none; } fieldset.web.code.xterm>div.action>div.tabs:only-child { display:none; } fieldset.macos.desktop>div.output>div.desktop>fieldset.web.code.compile>form.option>div.item:last-child { margin-right:120px; } diff --git a/core/code/compile.go b/core/code/compile.go index 584faf64..076e534c 100644 --- a/core/code/compile.go +++ b/core/code/compile.go @@ -74,7 +74,6 @@ func init() { }}, web.DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) { web.DreamProcess(m, []string{}, arg...) }}, }, ctx.ConfAction(cli.ENV, kit.Dict("GOPRIVATE", "shylinux.com,github.com", "GOPROXY", "https://goproxy.cn,direct", "CGO_ENABLED", "0"))), Hand: func(m *ice.Message, arg ...string) { - defer web.ToastProcess(m)() main, file, goos, arch := _compile_target(m, arg...) env := kit.Simple(cli.PATH, cli.BinPath(), cli.HOME, kit.Select(kit.Path(""), kit.Env(cli.HOME)), mdb.Configv(m, cli.ENV), m.Optionv(cli.ENV), cli.GOOS, goos, cli.GOARCH, arch) kit.If(runtime.GOOS == cli.WINDOWS, func() { env = append(env, "GOPATH", kit.HomePath(GO), "GOCACHE", kit.HomePath("go/go-build")) }) diff --git a/core/code/go.go b/core/code/go.go index 5c44913a..e644d13e 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -134,7 +134,10 @@ func init() { } }}, TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { - m.Echo(nfs.Template(m, "demo.go"), path.Base(path.Dir(path.Join(arg[2], arg[1])))) + m.Option("name", kit.TrimExt(path.Base(arg[1]), "go")) + m.Option("zone", path.Base(path.Dir(path.Join(arg[2], arg[1])))) + m.Option("key", kit.Keys("web.code", m.Option("zone"), m.Option("name"))) + m.Echo(nfs.Template(m, "demo.go")) }}, COMPLETE: {Hand: func(m *ice.Message, arg ...string) { _go_complete(m, arg...) }}, NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { diff --git a/core/code/inner.go b/core/code/inner.go index f6deec46..71303166 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -86,7 +86,7 @@ const INNER = "inner" func init() { var bind = []string{"usr/icebergs/core/", "usr/volcanos/plugin/local/"} Index.MergeCommands(ice.Commands{ - INNER: {Name: "inner path=src/@key file=main.go@key line=1 auto exec", Help: "源代码", Actions: ice.MergeActions(ice.Actions{ + INNER: {Name: "inner path=src/@key file=main.go@key line=1 auto show exec", 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: @@ -112,9 +112,8 @@ func init() { } }}, mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(mdb.PLUGIN, arg) - if m.Result() == "" { - m.Cmdy(mdb.PLUGIN, m.Option("parse", strings.ToLower(kit.Split(path.Base(arg[1]), ".")[0])), arg[1:]) + if m.Cmdy(mdb.PLUGIN, arg); m.Result() == "" { + m.Cmdy(mdb.PLUGIN, m.Option("parse", strings.ToLower(kit.Split(path.Base(arg[1]), nfs.PT)[0])), arg[1:]) } }}, mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _inner_show(m, arg[0], arg[1], arg[2]) }}, @@ -132,6 +131,11 @@ func init() { } else if len(arg) < 2 { nfs.Dir(m, nfs.PATH) } else { + if strings.Contains(arg[1], ":") { + ls := strings.Split(arg[1], ":") + m.ProcessRewrite(nfs.LINE, ls[0], nfs.FILE, ls[1]) + return + } arg[1] = strings.Split(arg[1], mdb.FS)[0] _inner_list(m, kit.Ext(arg[1]), arg[1], arg[0]) ctx.DisplayLocal(m, "").Option(REPOS, kit.Join(m.Cmd(REPOS, ice.OptionFields(nfs.PATH)).Sort(nfs.PATH).Appendv(nfs.PATH))) diff --git a/core/code/makefile.go b/core/code/makefile.go index 328c53db..bdfdcdb1 100644 --- a/core/code/makefile.go +++ b/core/code/makefile.go @@ -12,6 +12,9 @@ import ( func _makefile_xterm(m *ice.Message, arg ...string) { ctx.Process(m, XTERM, func() []string { m.Push(ctx.STYLE, html.OUTPUT) + if ls := kit.Simple(kit.UnMarshal(m.Option(ctx.ARGS))); len(ls) > 0 { + return ls + } return []string{mdb.TYPE, "sh", nfs.PATH, kit.Select("", kit.Dir(arg[2], arg[1]), arg[2] != ice.SRC)} }, arg...) } diff --git a/core/code/publish.go b/core/code/publish.go index 31a17dcb..ca5f1013 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -59,7 +59,11 @@ func _publish_contexts(m *ice.Message, arg ...string) { default: // _publish_file(m, ice.ICE_BIN) } - m.EchoScript(strings.TrimSpace(nfs.Template(m, kit.Keys(k, SH)))) + if m.Option("format") == "raw" { + m.Echo(strings.TrimSpace(nfs.Template(m, kit.Keys(k, SH)))) + } else { + m.EchoScript(strings.TrimSpace(nfs.Template(m, kit.Keys(k, SH)))) + } } } diff --git a/core/code/vimer.go b/core/code/vimer.go index ae096b28..5a1ac63d 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -42,7 +42,8 @@ func _vimer_make(m *ice.Message, dir string, msg *ice.Message) { } } } - kit.If(m.Length() == 0, func() { 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)) }) + m.Echo(msg.Append(cli.CMD_OUT)).Echo(msg.Append(cli.CMD_ERR)) } const VIMER = "vimer" @@ -58,7 +59,7 @@ func init() { }}, }) Index.MergeCommands(ice.Commands{ - VIMER: {Name: "vimer path=src/@key file=main.go line=1 list", Help: "编辑器", Meta: kit.Dict(ctx.STYLE, INNER), Actions: ice.MergeActions(ice.Actions{ + VIMER: {Name: "vimer path=src/@key file=main.go@key line=1 list", Help: "编辑器", Meta: kit.Dict(ctx.STYLE, INNER), Actions: ice.MergeActions(ice.Actions{ mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { if mdb.IsSearchPreview(m, arg) { m.PushSearch(mdb.TYPE, nfs.FILE, mdb.NAME, "main", mdb.TEXT, ice.SRC_MAIN_SH) diff --git a/core/code/xterm.go b/core/code/xterm.go index 5b61d22a..2e632336 100644 --- a/core/code/xterm.go +++ b/core/code/xterm.go @@ -73,7 +73,7 @@ const XTERM = "xterm" func init() { Index.MergeCommands(ice.Commands{ - XTERM: {Name: "xterm hash auto terminal", Help: "命令行", Actions: ice.MergeActions(ice.Actions{ + XTERM: {Name: "xterm hash auto install terminal", Help: "命令行", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { kit.If(m.Cmd("").Length() == 0, func() { m.Cmd("", mdb.CREATE, mdb.TYPE, ISH) }) }}, @@ -133,17 +133,16 @@ func init() { ctx.ProcessField(m, m.PrefixKey(), func() string { return m.Cmdx("", mdb.CREATE, arg) }, arg...) } }}, + "install": {Help: "安装", Hand: func(m *ice.Message, arg ...string) { + _xterm_get(m, kit.Select("", arg, 0)).Write([]byte(m.Cmdx(PUBLISH, ice.CONTEXTS, ice.APP, kit.Dict("format", "raw")) + ice.NL)) + ctx.ProcessHold(m) + }}, "terminal": {Help: "本机", Hand: func(m *ice.Message, arg ...string) { if h := kit.Select(m.Option(mdb.HASH), arg, 0); h == "" { cli.Opens(m, "Terminal.app") } else { msg := m.Cmd("", h) - m.Cmd(cli.SYSTEM, "osascript", "-e", kit.Format(` -tell application "Terminal" - do script "%s" - activate -end tell -`, msg.Append(mdb.TYPE))) + cli.OpenCmds(m, msg.Append(mdb.TYPE)) } m.ProcessHold() }}, diff --git a/init.go b/init.go index 0a1af9b5..65065e40 100644 --- a/init.go +++ b/init.go @@ -80,9 +80,16 @@ var Index = &Context{Name: ICE, Help: "冰山模块", Commands: Commands{ }) }}, }, server: &Frame{}} -var Pulse = &Message{time: time.Now(), meta: map[string][]string{}, data: Map{}, source: Index, target: Index} +var Pulse = &Message{meta: map[string][]string{}, data: Map{}, source: Index, target: Index} -func init() { Index.root, Pulse.root = Index, Pulse } +func init() { + Index.root, Pulse.root = Index, Pulse + switch tz := os.Getenv("TZ"); tz { + case "", "Asia/Beijing", "Asia/Shanghai": + time.Local = time.FixedZone(tz, 28800) + } + Pulse.time = time.Now() +} func Run(arg ...string) string { kit.If(len(arg) == 0 && len(os.Args) > 1, func() { arg = kit.Simple(os.Args[1:], kit.Split(kit.Env(CTX_ARG))) }) @@ -102,8 +109,6 @@ func Run(arg ...string) string { } }) kit.If(Pulse._cmd == nil, func() { Pulse._cmd = &Command{RawHand: logs.FileLines(3)} }) - time.Local = time.FixedZone("Beijing", 28800) - Pulse.time = time.Now() switch Index.Merge(Index).Begin(Pulse, arg...); kit.Select("", arg, 0) { case SERVE, SPACE: Pulse.Go(func() { Index.Start(Pulse, arg...) }) diff --git a/option.go b/option.go index 0506be68..a082bf11 100644 --- a/option.go +++ b/option.go @@ -87,7 +87,11 @@ func (m *Message) StatusTimeCountTotal(arg ...Any) *Message { } func (m *Message) Process(cmd string, arg ...Any) *Message { - return m.Options(MSG_PROCESS, cmd, PROCESS_ARG, kit.Simple(arg...)) + if len(arg) == 0 { + return m.Options(MSG_PROCESS, cmd) + } else { + return m.Options(MSG_PROCESS, cmd, PROCESS_ARG, kit.Simple(arg...)) + } } func (m *Message) ProcessLocation(arg ...Any) { m.Process(PROCESS_LOCATION, arg...) } func (m *Message) ProcessReplace(url string, arg ...Any) {