forked from x/icebergs
opt some
This commit is contained in:
parent
faed551a35
commit
2ee0367f96
@ -2,7 +2,7 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"debug/elf"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
@ -10,55 +10,6 @@ import (
|
|||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
type elf struct {
|
|
||||||
EI_CLASS int
|
|
||||||
EI_DATA int
|
|
||||||
EI_VERSION int
|
|
||||||
e_type uint16
|
|
||||||
e_machine uint16
|
|
||||||
e_version uint32
|
|
||||||
e_entry uint64
|
|
||||||
e_phoff uint64
|
|
||||||
e_shoff uint64
|
|
||||||
e_flags uint32
|
|
||||||
e_ehsize uint16
|
|
||||||
e_phentsize uint16
|
|
||||||
e_phnum uint16
|
|
||||||
e_shentsize uint16
|
|
||||||
e_shnum uint16
|
|
||||||
e_shstrndx uint16
|
|
||||||
}
|
|
||||||
|
|
||||||
func read2(buf []byte, offset int) (uint16, int) {
|
|
||||||
return binary.LittleEndian.Uint16(buf[offset : offset+2]), offset + 2
|
|
||||||
}
|
|
||||||
func read4(buf []byte, offset int) (uint32, int) {
|
|
||||||
return binary.LittleEndian.Uint32(buf[offset : offset+4]), offset + 4
|
|
||||||
}
|
|
||||||
func read8(buf []byte, offset int) (uint64, int) {
|
|
||||||
return binary.LittleEndian.Uint64(buf[offset : offset+8]), offset + 8
|
|
||||||
}
|
|
||||||
func readelf(buf []byte) (elf elf) {
|
|
||||||
i := 16
|
|
||||||
elf.EI_CLASS = int(buf[4])
|
|
||||||
elf.EI_DATA = int(buf[5])
|
|
||||||
elf.EI_VERSION = int(buf[6])
|
|
||||||
elf.e_type, i = read2(buf, i)
|
|
||||||
elf.e_machine, i = read2(buf, i)
|
|
||||||
elf.e_version, i = read4(buf, i)
|
|
||||||
elf.e_entry, i = read8(buf, i)
|
|
||||||
elf.e_phoff, i = read8(buf, i)
|
|
||||||
elf.e_shoff, i = read8(buf, i)
|
|
||||||
elf.e_flags, i = read4(buf, i)
|
|
||||||
elf.e_ehsize, i = read2(buf, i)
|
|
||||||
elf.e_phentsize, i = read2(buf, i)
|
|
||||||
elf.e_phnum, i = read2(buf, i)
|
|
||||||
elf.e_shentsize, i = read2(buf, i)
|
|
||||||
elf.e_shnum, i = read2(buf, i)
|
|
||||||
elf.e_shstrndx, i = read2(buf, i)
|
|
||||||
return elf
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.MergeCommands(ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
"readelf": {Name: "readelf path=usr/publish/ice.linux.amd64 auto", Hand: func(m *ice.Message, arg ...string) {
|
"readelf": {Name: "readelf path=usr/publish/ice.linux.amd64 auto", Hand: func(m *ice.Message, arg ...string) {
|
||||||
@ -73,13 +24,15 @@ func init() {
|
|||||||
if m.Warn(e) {
|
if m.Warn(e) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bytes.Equal(buf[:4], []byte{0x7f, 0x45, 0x4c, 0x46}) {
|
kit.If(bytes.Equal(buf[:4], []byte{0x7f, 0x45, 0x4c, 0x46}), func() {
|
||||||
m.Echo("elf %#v", readelf(buf))
|
f, _ := elf.Open(arg[0])
|
||||||
}
|
m.Echo("%v", kit.Formats(f))
|
||||||
|
})
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
kit.If(i%16 == 0, func() { m.Push("addr", kit.Format("%04x", 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]))
|
m.Push(kit.Format("%02x", i%16), kit.Format("%02x", buf[i]))
|
||||||
}
|
}
|
||||||
|
m.StatusTimeCount()
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
@ -147,14 +147,6 @@ func (f *Frame) Begin(m *ice.Message, arg ...string) {
|
|||||||
func (f *Frame) Start(m *ice.Message, arg ...string) {
|
func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||||
m.Optionv(FRAME, f)
|
m.Optionv(FRAME, f)
|
||||||
switch f.source = kit.Select(STDIO, arg, 0); f.source {
|
switch f.source = kit.Select(STDIO, arg, 0); f.source {
|
||||||
case WEBIO:
|
|
||||||
wio := m.Optionv(WEBIO).(io.ReadWriter)
|
|
||||||
r, w, _ := os.Pipe()
|
|
||||||
go func() { io.Copy(w, wio) }()
|
|
||||||
f.pipe, f.stdin, f.stdout = w, r, wio
|
|
||||||
kit.If(f.target == nil, func() { f.target = m.Target() })
|
|
||||||
m.Optionv(ice.MSG_OPTS, ice.MSG_USERNAME, ice.MSG_USERROLE)
|
|
||||||
f.scan(m, STDIO, "")
|
|
||||||
case STDIO:
|
case STDIO:
|
||||||
r, w, _ := os.Pipe()
|
r, w, _ := os.Pipe()
|
||||||
go func() { io.Copy(w, os.Stdin) }()
|
go func() { io.Copy(w, os.Stdin) }()
|
||||||
|
@ -87,20 +87,24 @@ func _space_handle(m *ice.Message, safe bool, name string, c *websocket.Conn) {
|
|||||||
} else { // 上行请求
|
} else { // 上行请求
|
||||||
msg.Option(ice.MSG_USERROLE, aaa.VOID)
|
msg.Option(ice.MSG_USERROLE, aaa.VOID)
|
||||||
}
|
}
|
||||||
if msg.Option("_exec") == "go" {
|
|
||||||
m.Go(func() { _space_exec(msg, source, target, c) }, strings.Join(kit.Simple(SPACE, name, msg.Detailv()), lex.SP))
|
m.Go(func() { _space_exec(msg, source, target, c) }, strings.Join(kit.Simple(SPACE, name, msg.Detailv()), lex.SP))
|
||||||
|
// if msg.Option("_exec") == "go" {
|
||||||
|
// m.Go(func() { _space_exec(msg, source, target, c) }, strings.Join(kit.Simple(SPACE, name, msg.Detailv()), lex.SP))
|
||||||
|
// } else {
|
||||||
|
// _space_exec(msg, source, target, c)
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
_space_exec(msg, source, target, c)
|
done := false
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m.Warn(!mdb.HashSelectDetail(m, next, func(value ice.Map) {
|
m.Warn(!mdb.HashSelectDetail(m, next, func(value ice.Map) {
|
||||||
switch c := value[mdb.TARGET].(type) {
|
switch c := value[mdb.TARGET].(type) {
|
||||||
case (*websocket.Conn): // 转发报文
|
case (*websocket.Conn): // 转发报文
|
||||||
_space_echo(msg, source, target, c)
|
_space_echo(msg, source, target, c)
|
||||||
case ice.Handler: // 接收响应
|
case ice.Handler: // 接收响应
|
||||||
|
done = true
|
||||||
c(msg)
|
c(msg)
|
||||||
}
|
}
|
||||||
}), ice.ErrNotFound, next)
|
}), ice.ErrNotFound, next)
|
||||||
|
kit.If(done, func() { mdb.HashRemove(m, mdb.HASH, next) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,12 +137,11 @@ func _space_echo(m *ice.Message, source, target []string, c *websocket.Conn) {
|
|||||||
m.Log(tcp.SEND, "%v->%v %v %v", source, target, m.Detailv(), m.FormatsMeta(nil))
|
m.Log(tcp.SEND, "%v->%v %v %v", source, target, m.Detailv(), m.FormatsMeta(nil))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func _space_send(m *ice.Message, name string, arg ...string) {
|
func _space_send(m *ice.Message, name string, arg ...string) (h string) {
|
||||||
wait, done := m.Wait(func(msg *ice.Message, arg ...string) {
|
wait, done := m.Wait(func(msg *ice.Message, arg ...string) {
|
||||||
m.Cost(kit.Format("%v->[%v] %v %v", m.Optionv(ice.MSG_SOURCE), name, m.Detailv(), msg.FormatSize())).Copy(msg)
|
m.Cost(kit.Format("%v->[%v] %v %v", m.Optionv(ice.MSG_SOURCE), name, m.Detailv(), msg.FormatSize())).Copy(msg)
|
||||||
})
|
})
|
||||||
h := mdb.HashCreate(m.Spawn(), mdb.TYPE, tcp.SEND, mdb.NAME, kit.Keys(name, m.Target().ID()), mdb.TEXT, kit.Join(arg, lex.SP), kit.Dict(mdb.TARGET, done))
|
h = mdb.HashCreate(m.Spawn(), mdb.TYPE, tcp.SEND, mdb.NAME, kit.Keys(name, m.Target().ID()), mdb.TEXT, kit.Join(arg, lex.SP), kit.Dict(mdb.TARGET, done))
|
||||||
defer mdb.HashRemove(m, mdb.HASH, h)
|
|
||||||
if target := kit.Split(name, nfs.PT, nfs.PT); mdb.HashSelectDetail(m, target[0], func(value ice.Map) {
|
if target := kit.Split(name, nfs.PT, nfs.PT); mdb.HashSelectDetail(m, target[0], func(value ice.Map) {
|
||||||
if c, ok := value[mdb.TARGET].(*websocket.Conn); !m.Warn(!ok, ice.ErrNotValid, mdb.TARGET) {
|
if c, ok := value[mdb.TARGET].(*websocket.Conn); !m.Warn(!ok, ice.ErrNotValid, mdb.TARGET) {
|
||||||
kit.For(m.Optionv(ice.MSG_OPTS), func(k string) { m.Optionv(k, m.Optionv(k)) })
|
kit.For(m.Optionv(ice.MSG_OPTS), func(k string) { m.Optionv(k, m.Optionv(k)) })
|
||||||
@ -149,6 +152,7 @@ func _space_send(m *ice.Message, name string, arg ...string) {
|
|||||||
} else {
|
} else {
|
||||||
m.Warn(kit.IndexOf([]string{ice.OPS, ice.DEV}, target[0]) == -1, ice.ErrNotFound, name)
|
m.Warn(kit.IndexOf([]string{ice.OPS, ice.DEV}, target[0]) == -1, ice.ErrNotFound, name)
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -71,8 +71,8 @@ Volcanos(chat.ONIMPORT, {
|
|||||||
sub.onexport.record = function(sub, value, key, item) { can.onimport._window(can, item) }
|
sub.onexport.record = function(sub, value, key, item) { can.onimport._window(can, item) }
|
||||||
sub.onexport.marginTop = function() { return 25 }
|
sub.onexport.marginTop = function() { return 25 }
|
||||||
sub.onexport.actionHeight = function(sub) { return can.page.ClassList.has(can, sub._target, html.OUTPUT)? 0: html.ACTION_HEIGHT+20 },
|
sub.onexport.actionHeight = function(sub) { return can.page.ClassList.has(can, sub._target, html.OUTPUT)? 0: html.ACTION_HEIGHT+20 },
|
||||||
sub.onmotion.resize(can, sub._target, function(height, width) { sub.onimport.size(sub, height, width) }, 25)
|
can.onmotion.move(can, sub._target, {"z-index": 10, top: item.top, left: item.left}), sub.onmotion.resize(can, sub._target, function(height, width) { sub.onimport.size(sub, height, width) }, 25)
|
||||||
sub.onimport.size(sub, item.height, item.width, true), can.onmotion.move(can, sub._target, {"z-index": 10, top: item.top, left: item.left})
|
sub.onimport.size(sub, item.height, item.width, true)
|
||||||
sub._target.onclick = function(event) { can.page.Select(can, sub._target.parentNode, html.FIELDSET, function(target) { can.page.style(can, target, "z-index", target == sub._target? "10": "9") }) }
|
sub._target.onclick = function(event) { can.page.Select(can, sub._target.parentNode, html.FIELDSET, function(target) { can.page.style(can, target, "z-index", target == sub._target? "10": "9") }) }
|
||||||
}, can.ui.desktop)
|
}, can.ui.desktop)
|
||||||
},
|
},
|
||||||
|
@ -99,6 +99,13 @@ const GO = "go"
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.MergeCommands(ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
|
"godoc": {Name: "godoc key auto", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
if len(arg) == 0 {
|
||||||
|
m.Cmdy(cli.SYSTEM, "go", "list", "std")
|
||||||
|
} else {
|
||||||
|
m.Cmdy(cli.SYSTEM, "go", "doc", arg)
|
||||||
|
}
|
||||||
|
}},
|
||||||
GO: {Name: "go path auto", Help: "后端编程", Actions: ice.MergeActions(ice.Actions{
|
GO: {Name: "go path auto", Help: "后端编程", Actions: ice.MergeActions(ice.Actions{
|
||||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
if arg[1] == "main.go" {
|
if arg[1] == "main.go" {
|
||||||
|
@ -40,7 +40,7 @@ func _xterm_get(m *ice.Message, h string) xterm.XTerm {
|
|||||||
if cmd := text[0]; text[0] != "" {
|
if cmd := text[0]; text[0] != "" {
|
||||||
m.Go(func() {
|
m.Go(func() {
|
||||||
m.Sleep30ms()
|
m.Sleep30ms()
|
||||||
term.Write(cmd + lex.NL)
|
term.Writeln(cmd)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
text = text[1:]
|
text = text[1:]
|
||||||
@ -113,7 +113,7 @@ func init() {
|
|||||||
if b, e := base64.StdEncoding.DecodeString(strings.Join(arg, "")); !m.Warn(e) {
|
if b, e := base64.StdEncoding.DecodeString(strings.Join(arg, "")); !m.Warn(e) {
|
||||||
// m.Debug("what ---%o--- ---[%v]---", b, string(b))
|
// m.Debug("what ---%o--- ---[%v]---", b, string(b))
|
||||||
m.Debug("what ---%o---", b)
|
m.Debug("what ---%o---", b)
|
||||||
_xterm_get(m, "").Write(string(b))
|
_xterm_get(m, "").Write(b)
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
web.OUTPUT: {Help: "全屏", Hand: func(m *ice.Message, arg ...string) {
|
web.OUTPUT: {Help: "全屏", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
@ -35,25 +35,28 @@ type iterm struct {
|
|||||||
*idata
|
*idata
|
||||||
}
|
}
|
||||||
|
|
||||||
func newiterm(m *ice.Message) (XTerm, error) {
|
func NewITerm(m *ice.Message) (XTerm, error) {
|
||||||
r, w, e := os.Pipe()
|
r, w, e := os.Pipe()
|
||||||
return &iterm{m: m, r: r, w: w, idata: &idata{cmds: kit.Simple(
|
return &iterm{m: m, r: r, w: w, idata: &idata{cmds: kit.Simple(
|
||||||
kit.SortedKey(ice.Info.Index),
|
kit.SortedKey(ice.Info.Index),
|
||||||
m.Cmd(ctx.COMMAND).Appendv(ctx.INDEX),
|
m.Cmd(ctx.COMMAND).Appendv(ctx.INDEX),
|
||||||
m.Cmd(nfs.DIR, "/bin", mdb.NAME).Appendv(mdb.NAME),
|
m.Cmd(nfs.DIR, "/bin", mdb.NAME).Appendv(mdb.NAME),
|
||||||
|
strings.Split(m.Cmdx(nfs.CAT, kit.HomePath(".bash_history")), lex.NL),
|
||||||
)}}, e
|
)}}, e
|
||||||
}
|
}
|
||||||
func (s iterm) Setsize(rows, cols string) error {
|
func (s iterm) Setsize(rows, cols string) error {
|
||||||
s.w.Write([]byte(s.prompt()))
|
s.w.Write([]byte(s.prompt()))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (s iterm) Writeln(data string, arg ...ice.Any) { s.Write(kit.Format(data, arg...) + lex.NL) }
|
func (s iterm) Writeln(str string, arg ...ice.Any) {
|
||||||
func (s iterm) Write(data string) (int, error) {
|
s.Write([]byte(kit.Format(str, arg...) + lex.NL))
|
||||||
|
}
|
||||||
|
func (s iterm) Write(buf []byte) (int, error) {
|
||||||
if s.pipe != nil {
|
if s.pipe != nil {
|
||||||
return s.pipe.Write([]byte(data))
|
return s.pipe.Write(buf)
|
||||||
}
|
}
|
||||||
res, ctrl := "", ""
|
res, ctrl := "", ""
|
||||||
for _, c := range data {
|
for _, c := range string(buf) {
|
||||||
switch c := string(c); c {
|
switch c := string(c); c {
|
||||||
case SOH: // Ctrl+A
|
case SOH: // Ctrl+A
|
||||||
res += s.repeat(s.arg)
|
res += s.repeat(s.arg)
|
||||||
@ -176,7 +179,7 @@ func (s iterm) Write(data string) (int, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.w.Write([]byte(res))
|
s.w.Write([]byte(res))
|
||||||
return len(data), nil
|
return len(buf), nil
|
||||||
}
|
}
|
||||||
func (s iterm) Read(buf []byte) (int, error) {
|
func (s iterm) Read(buf []byte) (int, error) {
|
||||||
return s.r.Read(buf)
|
return s.r.Read(buf)
|
||||||
|
@ -21,7 +21,7 @@ type Winsize struct {
|
|||||||
type XTerm interface {
|
type XTerm interface {
|
||||||
Setsize(rows, cols string) error
|
Setsize(rows, cols string) error
|
||||||
Writeln(data string, arg ...ice.Any)
|
Writeln(data string, arg ...ice.Any)
|
||||||
Write(data string) (int, error)
|
Write(buf []byte) (int, error)
|
||||||
Read(buf []byte) (int, error)
|
Read(buf []byte) (int, error)
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
@ -33,14 +33,14 @@ type xterm struct {
|
|||||||
func (s xterm) Setsize(rows, cols string) error {
|
func (s xterm) Setsize(rows, cols string) error {
|
||||||
return Setsize(s.File, &Winsize{Rows: uint16(kit.Int(rows)), Cols: uint16(kit.Int(cols))})
|
return Setsize(s.File, &Winsize{Rows: uint16(kit.Int(rows)), Cols: uint16(kit.Int(cols))})
|
||||||
}
|
}
|
||||||
func (s xterm) Writeln(data string, arg ...ice.Any) { s.Write(kit.Format(data, arg...) + lex.NL) }
|
func (s xterm) Writeln(str string, arg ...ice.Any) { s.Write([]byte(kit.Format(str, arg...) + lex.NL)) }
|
||||||
func (s xterm) Write(data string) (int, error) { return s.File.Write([]byte(data)) }
|
func (s xterm) Write(buf []byte) (int, error) { return s.File.Write(buf) }
|
||||||
func (s xterm) Read(buf []byte) (int, error) { return s.File.Read(buf) }
|
func (s xterm) Read(buf []byte) (int, error) { return s.File.Read(buf) }
|
||||||
func (s xterm) Close() error { return s.Cmd.Process.Kill() }
|
func (s xterm) Close() error { return s.Cmd.Process.Kill() }
|
||||||
|
|
||||||
func Command(m *ice.Message, dir string, cli string, arg ...string) (XTerm, error) {
|
func Command(m *ice.Message, dir string, cli string, arg ...string) (XTerm, error) {
|
||||||
if path.Base(cli) == "ish" {
|
if path.Base(cli) == "ish" {
|
||||||
return newiterm(m)
|
return NewITerm(m)
|
||||||
}
|
}
|
||||||
cmd := exec.Command(cli, arg...)
|
cmd := exec.Command(cli, arg...)
|
||||||
cmd.Dir = nfs.MkdirAll(m, kit.Path(dir))
|
cmd.Dir = nfs.MkdirAll(m, kit.Path(dir))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user