forked from x/icebergs
add some
This commit is contained in:
parent
2ee0367f96
commit
1a74b3e936
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -151,7 +151,7 @@ const (
|
||||
FORM = "form"
|
||||
BODY = "body"
|
||||
|
||||
ApplicationJSON = "Application/json"
|
||||
ApplicationJSON = "application/json"
|
||||
ApplicationOctet = "application/octet-stream"
|
||||
)
|
||||
const SERVE = "serve"
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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"))},
|
||||
|
@ -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; }
|
||||
|
@ -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({
|
||||
|
@ -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"))
|
||||
}},
|
||||
|
Loading…
x
Reference in New Issue
Block a user