From 1a74b3e936bf6379b5fc0261c9d2762d7b8bf4ec Mon Sep 17 00:00:00 2001 From: shylinux Date: Sat, 20 May 2023 14:37:37 +0800 Subject: [PATCH] add some --- base/cli/runtime.go | 39 +++++++++++++++++++++++++++++++-- base/nfs/cat.go | 16 ++++++++------ base/nfs/tar.go | 39 +++++++++++++++++++++++++++++---- base/web/serve.go | 2 +- base/web/spide.go | 2 +- core/chat/iframe.go | 5 +++-- core/chat/macos/applications.go | 1 + core/chat/macos/desktop.css | 1 + core/chat/macos/desktop.js | 4 ++-- core/code/xterm.go | 7 +++++- 10 files changed, 96 insertions(+), 20 deletions(-) diff --git a/base/cli/runtime.go b/base/cli/runtime.go index 5ad8b342..91ea1e56 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -1,10 +1,12 @@ package cli import ( + "bytes" "os" "path" "runtime" "strings" + "time" ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/aaa" @@ -53,7 +55,7 @@ func _runtime_init(m *ice.Message) { m.Conf(RUNTIME, mdb.HASH, "") } func _runtime_hostinfo(m *ice.Message) { - m.Push("nCPU", strings.Count(m.Cmdx(nfs.CAT, "/proc/cpuinfo"), "processor")) + m.Push("nCPU", runtime.NumCPU()) for i, ls := range strings.Split(m.Cmdx(nfs.CAT, "/proc/meminfo"), lex.NL) { if vs := kit.Split(ls, ": "); len(vs) > 1 { if m.Push(strings.TrimSpace(vs[0]), kit.FmtSize(kit.Int64(strings.TrimSpace(vs[1]))*1024)); i > 1 { @@ -62,6 +64,15 @@ func _runtime_hostinfo(m *ice.Message) { } } m.Push("uptime", kit.Split(m.Cmdx(SYSTEM, "uptime"), mdb.FS)[0]) + m.Push("GOMAXPROCS", runtime.GOMAXPROCS(0)) + m.Push("NumGoroutine", runtime.NumGoroutine()) + var stats runtime.MemStats + runtime.ReadMemStats(&stats) + m.Push("Sys", kit.FmtSize(int64(stats.Sys))) + m.Push("Alloc", kit.FmtSize(int64(stats.Alloc))) + m.Push("Objects", stats.HeapObjects) + m.Push("NumGC", stats.NumGC) + m.Push("LastGC", time.Unix(int64(stats.LastGC)/int64(time.Second), int64(stats.LastGC)%int64(time.Second))) } func _runtime_diskinfo(m *ice.Message) { m.Spawn().Split(kit.Replace(m.Cmdx(SYSTEM, "df", "-h"), "Mounted on", "Mountedon"), "", lex.SP, lex.NL).Table(func(index int, value ice.Maps, head []string) { @@ -133,7 +144,7 @@ const RUNTIME = "runtime" func init() { Index.MergeCommands(ice.Commands{ - RUNTIME: {Name: "runtime info=bootinfo,ifconfig,diskinfo,hostinfo,userinfo,procinfo,bootinfo,api,cli,cmd,mod,env,path,chain auto", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{ + RUNTIME: {Name: "runtime info=bootinfo,ifconfig,diskinfo,hostinfo,userinfo,procinfo,bootinfo,api,cli,cmd,mod,env,path,chain,routine auto", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { _runtime_init(m) }}, IFCONFIG: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("tcp.host") }}, DISKINFO: {Hand: func(m *ice.Message, arg ...string) { _runtime_diskinfo(m) }}, @@ -181,6 +192,30 @@ func init() { kit.For(ice.Info.Gomod, func(k string, v string) { m.Push(nfs.MODULE, k).Push(nfs.VERSION, v) }) m.StatusTimeCount() }}, + "routine": {Hand: func(m *ice.Message, arg ...string) { + buf := make([]byte, 4096*4096) + runtime.Stack(buf, true) + status := map[string]int{} + 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("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, "Alloc", kit.FmtSize(int64(stats.Alloc)), "Sys", kit.FmtSize(int64(stats.Sys))) + m.Echo("%v", string(buf)) + }}, ENV: {Hand: func(m *ice.Message, arg ...string) { kit.For(os.Environ(), func(v string) { ls := strings.SplitN(v, mdb.EQ, 2) diff --git a/base/nfs/cat.go b/base/nfs/cat.go index ae1a742d..0361f297 100644 --- a/base/nfs/cat.go +++ b/base/nfs/cat.go @@ -89,12 +89,14 @@ const ( CSV = ice.CSV JSON = ice.JSON - CONF = "conf" - XML = "xml" - YML = "yml" - TXT = "txt" - MD = "md" - PY = "py" + PROTO = "proto" + YAML = "yaml" + CONF = "conf" + XML = "xml" + YML = "yml" + TXT = "txt" + MD = "md" + PY = "py" PNG = "png" JPG = "jpg" @@ -111,7 +113,7 @@ const CAT = "cat" func init() { Index.MergeCommands(ice.Commands{ CAT: {Name: "cat path auto", Help: "文件", Actions: ice.MergeActions(ice.Actions{ice.CTX_INIT: mdb.AutoConfig(SOURCE, kit.DictList( - HTML, CSS, JS, GO, SH, PY, SHY, CSV, JSON, CONFIGURE, CONF, XML, YML, TXT, MD, strings.ToLower(ice.LICENSE), strings.ToLower(ice.MAKEFILE), + HTML, CSS, JS, GO, SH, PY, SHY, CSV, JSON, CONFIGURE, PROTO, YAML, CONF, XML, YML, TXT, MD, strings.ToLower(ice.LICENSE), strings.ToLower(ice.MAKEFILE), ))}), Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 || strings.HasSuffix(arg[0], PS) { m.Cmdy(DIR, arg) diff --git a/base/nfs/tar.go b/base/nfs/tar.go index f925c7e5..ee3b03f8 100644 --- a/base/nfs/tar.go +++ b/base/nfs/tar.go @@ -2,6 +2,7 @@ package nfs import ( "archive/tar" + "archive/zip" "compress/gzip" "io" "os" @@ -13,7 +14,20 @@ import ( kit "shylinux.com/x/toolkits" ) -func _tar_list(m *ice.Message, p string, cb func(*tar.Header, *tar.Reader, int)) { +func _zip_list(m *ice.Message, p string, cb func(zip.FileHeader, io.Reader, int)) { + if f, e := zip.OpenReader(p); m.Warn(e, ice.ErrNotValid, p) { + return + } else { + defer f.Close() + for i, f := range f.File { + if r, e := f.Open(); e == nil { + defer r.Close() + cb(f.FileHeader, r, i) + } + } + } +} +func _tar_list(m *ice.Message, p string, cb func(*tar.Header, io.Reader, int)) { Open(m, p, func(r io.Reader) { for { switch kit.Ext(p) { @@ -47,7 +61,8 @@ func _tar_list(m *ice.Message, p string, cb func(*tar.Header, *tar.Reader, int)) } const ( - GZ = "gz" + GZ = "gz" + ZIP = "zip" ) const TAR = "tar" @@ -58,7 +73,23 @@ func init() { mdb.PREV: {Hand: func(m *ice.Message, arg ...string) { mdb.NextPageLimit(m, arg[0], kit.Slice(arg, 1)...) }}, mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) { list, size := kit.Dict(), 0 - _tar_list(m, m.Option(PATH), func(h *tar.Header, r *tar.Reader, i int) { + if kit.Ext(m.Option(PATH)) == ZIP { + _zip_list(m, m.Option(PATH), func(h zip.FileHeader, r io.Reader, i int) { + p := path.Join(path.Dir(m.Option(PATH)), kit.Split(path.Base(m.Option(PATH)), "-.")[0], h.Name) + if strings.HasSuffix(h.Name, PS) { + MkdirAll(m, p) + return + } + kit.IfNoKey(list, path.Dir(p), func(p string) { MkdirAll(m, p) }) + Create(m, p, func(w io.Writer) { + os.Chmod(p, os.FileMode(h.Mode())) + Copy(m, w, r, func(n int) { size += n }) + kit.If(m.Option(FILE), func() { m.Cmdy(DIR, p).Cmdy(CAT, p) }) + }) + }) + return + } + _tar_list(m, m.Option(PATH), func(h *tar.Header, r io.Reader, i int) { if h.Name == m.Option(FILE) || m.Option(FILE) == "" { p := path.Join(path.Dir(m.Option(PATH)), h.Name) if strings.HasSuffix(h.Name, PS) { @@ -80,7 +111,7 @@ func init() { return } page, size := mdb.OptionPages(m, kit.Slice(arg, 2)...) - _tar_list(m, arg[0], func(h *tar.Header, r *tar.Reader, i int) { + _tar_list(m, arg[0], func(h *tar.Header, r io.Reader, i int) { if len(kit.Slice(arg, 0, 2)) > 1 { if h.Name != arg[1] { return diff --git a/base/web/serve.go b/base/web/serve.go index 89c9bc6c..110bb2c1 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -151,7 +151,7 @@ const ( FORM = "form" BODY = "body" - ApplicationJSON = "Application/json" + ApplicationJSON = "application/json" ApplicationOctet = "application/octet-stream" ) const SERVE = "serve" diff --git a/base/web/spide.go b/base/web/spide.go index e0174d6d..1cd7ef6b 100644 --- a/base/web/spide.go +++ b/base/web/spide.go @@ -266,7 +266,7 @@ func init() { MERGE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(kit.MergeURL2(m.Cmdv("", arg[0], CLIENT_URL), arg[1], arg[2:])) }}, - }, mdb.HashAction(mdb.SHORT, CLIENT_NAME, mdb.FIELD, "time,client.name,client.url"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) { + }, mdb.HashAction(mdb.SHORT, CLIENT_NAME, mdb.FIELD, "time,client.name,client.url")), Hand: func(m *ice.Message, arg ...string) { if len(arg) < 2 || arg[0] == "" || (len(arg) > 3 && arg[3] == "") { mdb.HashSelect(m, kit.Slice(arg, 0, 1)...).Sort(CLIENT_NAME) } else { diff --git a/core/chat/iframe.go b/core/chat/iframe.go index f1a0c00e..0dde3d91 100644 --- a/core/chat/iframe.go +++ b/core/chat/iframe.go @@ -23,7 +23,7 @@ func init() { } }}, mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) { - mdb.HashCreate(m, mdb.TYPE, web.LINK, mdb.NAME, kit.ParseURL(m.Option(web.LINK)).Host, m.OptionSimple()) + m.ProcessRewrite(mdb.HASH, mdb.HashCreate(m, mdb.TYPE, web.LINK, mdb.NAME, kit.ParseURL(m.Option(web.LINK)).Host, m.OptionSimple())) }}, mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { switch mdb.HashInputs(m, arg); arg[0] { @@ -31,7 +31,8 @@ func init() { m.Push(arg[0], web.UserWeb(m).Host) case mdb.LINK: m.Push(arg[0], m.Option(ice.MSG_USERWEB)) - m.Copy(m.Cmd(web.SPIDE).CutTo("client.url", arg[0])) + m.Push(arg[0], "http://localhost:20000") + m.Copy(m.Cmd(web.SPIDE).CutTo(web.CLIENT_URL, arg[0])) } }}, FAVOR_INPUTS: {Hand: func(m *ice.Message, arg ...string) { diff --git a/core/chat/macos/applications.go b/core/chat/macos/applications.go index 1be6ab2d..726efa5a 100644 --- a/core/chat/macos/applications.go +++ b/core/chat/macos/applications.go @@ -28,6 +28,7 @@ func init() { AppInstall(m, "Photos", web.WIKI_FEEL) AppInstall(m, "Books", web.WIKI_WORD) AppInstall(m, "", web.CODE_VIMER) + AppInstall(m, "", web.DREAM, mdb.ICON, "usr/icons/Mission Control.png") }}, code.INSTALL: {Hand: func(m *ice.Message, arg ...string) { AppInstall(m, arg[0], arg[1], arg[2:]...) }}, }, CmdHashAction("index,args"))}, diff --git a/core/chat/macos/desktop.css b/core/chat/macos/desktop.css index 89230d2b..f1f8c119 100644 --- a/core/chat/macos/desktop.css +++ b/core/chat/macos/desktop.css @@ -1,4 +1,5 @@ fieldset.macos.desktop { background-size:cover; background-position:center; } +fieldset.macos.desktop>div.output { overflow:hidden; } fieldset.macos.desktop>div.output>fieldset.macos { background-color:transparent; } fieldset.macos.desktop>div.output>fieldset.macos>div.output { background-color:transparent; } fieldset.macos.desktop>div.output>fieldset.macos.menu { font-family:monospace; line-height:25px; border-radius:0; height:25px; width:100%; position:absolute; top:0; overflow:hidden; } diff --git a/core/chat/macos/desktop.js b/core/chat/macos/desktop.js index a0e92ff5..d6d28a3d 100644 --- a/core/chat/macos/desktop.js +++ b/core/chat/macos/desktop.js @@ -53,8 +53,8 @@ Volcanos(chat.ONIMPORT, { }, _window: function(can, item) { if (!item.index) { return } item.left = 100, item.top = 125, item.height = can.base.Min(can.ConfHeight()-345, 480, 800), item.width = can.base.Min(can.ConfWidth()-360, 640, 1000) - if (can.ConfHeight() < 800) { item.top = 25, item.height = can.ConfHeight()-145, item.width = can.ConfWidth()-110 } - if (can.user.isMobile) { item.left = 0, item.top = 25, item.height = can.ConfHeight()-145, item.width = can.ConfWidth() } + if (can.ConfHeight() < 800) { item.top = 25, item.height = can.ConfHeight()-125, item.width = can.ConfWidth()-110 } + if (can.user.isMobile) { item.left = 0, item.top = 25, item.height = can.ConfHeight()-125, item.width = can.ConfWidth() } can.onappend.plugin(can, item, function(sub) { can.ondetail.select(can, sub._target) can.page.style(can, sub._target, html.MIN_WIDTH, 480) var index = 0; can.core.Item({ diff --git a/core/code/xterm.go b/core/code/xterm.go index 805dac68..73772b5c 100644 --- a/core/code/xterm.go +++ b/core/code/xterm.go @@ -71,6 +71,9 @@ const XTERM = "xterm" func init() { Index.MergeCommands(ice.Commands{ XTERM: {Name: "xterm hash auto", 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) }) + }}, mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { mdb.IsSearchForEach(m, arg, func() []string { if nfs.Exists(m, "/bin/bash") { @@ -105,7 +108,9 @@ func init() { m.Cmd(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, "", "", ice.OptionFields(ctx.INDEX), func(value ice.Maps) { push(ctx.INDEX, value[ctx.INDEX]) }) } }}, - mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) { m.ProcessRewrite(mdb.HASH, mdb.HashCreate(m, arg)) }}, + mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) { + m.ProcessRewrite(mdb.HASH, mdb.HashCreate(m, arg)) + }}, web.RESIZE: {Hand: func(m *ice.Message, arg ...string) { _xterm_get(m, "").Setsize(m.OptionDefault("rows", "24"), m.OptionDefault("cols", "80")) }},