mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt some
This commit is contained in:
parent
c3cc658bad
commit
604213d2f0
@ -27,6 +27,12 @@ func init() {
|
||||
env = append(env, k, kit.Env(k))
|
||||
}
|
||||
}
|
||||
for _, v := range os.Environ() {
|
||||
ls := kit.Split(v, "=", "=")
|
||||
if kit.IndexOf(env, ls[0]) == -1 {
|
||||
env = append(env, ls[0], ls[1])
|
||||
}
|
||||
}
|
||||
m.Optionv(CMD_ENV, env)
|
||||
m.Optionv(CMD_INPUT, os.Stdin)
|
||||
m.Optionv(CMD_OUTPUT, os.Stdout)
|
||||
|
@ -2,7 +2,6 @@ package code
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -11,86 +10,73 @@ import (
|
||||
|
||||
pty "shylinux.com/x/creackpty"
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _xterm_socket(m *ice.Message, h, t string) {
|
||||
defer mdb.RLock(m)()
|
||||
m.Option(ice.MSG_DAEMON, m.Conf("", kit.Keys(mdb.HASH, h, mdb.META, mdb.TEXT)))
|
||||
m.Option(mdb.TEXT, t)
|
||||
}
|
||||
func _xterm_get(m *ice.Message, h string, must bool) *os.File {
|
||||
func _xterm_get(m *ice.Message, h string) *os.File {
|
||||
t := mdb.HashSelectField(m, m.Option(mdb.HASH, h), mdb.TYPE)
|
||||
if f, ok := mdb.HashTarget(m, h, func() ice.Any {
|
||||
if !must {
|
||||
return nil
|
||||
}
|
||||
|
||||
ls := kit.Split(kit.Select("sh", t))
|
||||
m.Logs(cli.DAEMON, ice.CMD, ls)
|
||||
mdb.HashModify(m, mdb.TEXT, m.Option(ice.MSG_DAEMON))
|
||||
return mdb.HashTarget(m, h, func() ice.Any {
|
||||
ls := kit.Split(kit.Select(nfs.SH, t))
|
||||
cmd := exec.Command(cli.SystemFind(m, ls[0]), ls[1:]...)
|
||||
m.Logs(cli.DAEMON, ice.CMD, cmd.Path)
|
||||
cmd.Env = append(os.Environ(), "TERM=xterm")
|
||||
|
||||
tty, err := pty.Start(cmd)
|
||||
m.Assert(err)
|
||||
|
||||
m.Go(func() {
|
||||
m.Logs(cli.DAEMON, ice.CMD, ls)
|
||||
defer web.PushNoticeGrow(m, ice.EXIT)
|
||||
mdb.HashSelectUpdate(m, h, func(value ice.Map) {
|
||||
value["_cmd"] = nfs.NewCloser(func() error { return cmd.Process.Kill() })
|
||||
value["_cmd"] = nfs.NewCloser(func() error {
|
||||
m.Option(ice.MSG_DAEMON, mdb.HashSelectField(m, h, mdb.TEXT))
|
||||
web.PushNoticeGrow(m, ice.EXIT)
|
||||
return cmd.Process.Kill()
|
||||
})
|
||||
})
|
||||
|
||||
m.Option("log.disable", ice.TRUE)
|
||||
buf := make([]byte, ice.MOD_BUFS)
|
||||
for {
|
||||
if n, e := tty.Read(buf); !m.Warn(e) {
|
||||
_xterm_socket(m, h, base64.StdEncoding.EncodeToString(buf[:n]))
|
||||
m.Option("raw", string(buf[:n]))
|
||||
web.PushNoticeGrow(m, "data")
|
||||
m.Option(ice.MSG_DAEMON, mdb.HashSelectField(m, h, mdb.TEXT))
|
||||
m.Option(mdb.TEXT, string(buf[:n]))
|
||||
web.PushNoticeGrow(m)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
web.PushNoticeGrow(m, "exit")
|
||||
})
|
||||
return tty
|
||||
}).(*os.File); m.Warn(!ok, ice.ErrNotValid, f) {
|
||||
mdb.HashSelectUpdate(m, h, func(value ice.Map) { delete(value, mdb.TARGET) })
|
||||
return nil
|
||||
} else {
|
||||
return f
|
||||
}
|
||||
}).(*os.File)
|
||||
}
|
||||
|
||||
const XTERM = "xterm"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
XTERM: {Name: "xterm hash refresh", Help: "终端", Actions: ice.MergeActions(ice.Actions{
|
||||
XTERM: {Name: "xterm hash auto", Help: "终端", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelectValue(m, func(value ice.Map) {
|
||||
if c, ok := value["_cmd"].(io.Closer); ok {
|
||||
c.Close()
|
||||
}
|
||||
})
|
||||
m.Conf("", mdb.HASH, "")
|
||||
}},
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch mdb.HashInputs(m, arg); arg[0] {
|
||||
case mdb.TYPE:
|
||||
m.Push(arg[0], "ice.bin source stdio", "node", "python", "bash", "sh")
|
||||
m.Push(arg[0], "ice.bin source stdio", "tmux attach -t miss", "node", "python", "bash", "sh")
|
||||
case mdb.NAME:
|
||||
m.Push(arg[0], path.Base(m.Option(mdb.TYPE)))
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create type name", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, arg, mdb.TEXT, m.Option(ice.MSG_DAEMON))
|
||||
}},
|
||||
mdb.CREATE: {Name: "create type name background", Help: "创建"},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelectDetail(m, m.Option(mdb.HASH), func(value ice.Map) {
|
||||
if c, ok := value["_cmd"].(io.Closer); ok {
|
||||
@ -99,45 +85,32 @@ func init() {
|
||||
})
|
||||
mdb.HashRemove(m)
|
||||
}},
|
||||
"install": {Name: "install", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(mdb.HASH) != "" {
|
||||
u := web.OptionUserWeb(m)
|
||||
host := strings.Split(u.Host, ice.DF)[0]
|
||||
if host == tcp.LOCALHOST {
|
||||
host = m.Cmd(tcp.HOST).Append(aaa.IP)
|
||||
}
|
||||
m.Option("httphost", fmt.Sprintf("%s://%s:%s", u.Scheme, host, kit.Select(kit.Select("443", "80", u.Scheme == ice.HTTP), strings.Split(u.Host, ice.DF), 1)))
|
||||
cmd := kit.Renders(`export ctx_dev={{.Option "httphost"}}{{.Option "ctx_env"}}; ctx_temp=$(mktemp); wget -O $ctx_temp -q $ctx_dev; source $ctx_temp app username {{.Option "user.name"}}`, m)
|
||||
_xterm_get(m, m.Option(mdb.HASH), true).Write([]byte(cmd + "\n"))
|
||||
}
|
||||
m.ProcessHold()
|
||||
}},
|
||||
"rename": {Name: "rename", Help: "重命名", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashModify(m, arg)
|
||||
}},
|
||||
"resize": {Name: "resize", Help: "大小", Hand: func(m *ice.Message, arg ...string) {
|
||||
pty.Setsize(_xterm_get(m, m.Option(mdb.HASH), true), &pty.Winsize{Rows: uint16(kit.Int(m.Option("rows"))), Cols: uint16(kit.Int(m.Option("cols")))})
|
||||
}},
|
||||
"select": {Name: "select", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashModify(m, mdb.TEXT, m.Option(ice.MSG_DAEMON))
|
||||
_xterm_get(m, m.Option(mdb.HASH), true)
|
||||
m.Cmd("", "input", arg)
|
||||
pty.Setsize(_xterm_get(m, m.Option(mdb.HASH)), &pty.Winsize{Rows: uint16(kit.Int(m.Option("rows"))), Cols: uint16(kit.Int(m.Option("cols")))})
|
||||
}},
|
||||
"input": {Name: "input", Help: "输入", Hand: func(m *ice.Message, arg ...string) {
|
||||
if b, e := base64.StdEncoding.DecodeString(strings.Join(arg, "")); !m.Warn(e) {
|
||||
_xterm_get(m, m.Option(mdb.HASH), true).Write(b)
|
||||
mdb.HashModify(m, mdb.TIME, m.Time())
|
||||
_xterm_get(m, m.Option(mdb.HASH)).Write(b)
|
||||
}
|
||||
}},
|
||||
INSTALL: {Name: "install", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
_xterm_get(m, kit.Select(m.Option(mdb.HASH), arg, 0)).Write([]byte(m.Cmdx(PUBLISH, ice.CONTEXTS, INSTALL) + ice.NL))
|
||||
m.ProcessHold()
|
||||
}},
|
||||
}, mdb.HashAction(mdb.FIELD, "time,hash,type,name,text"), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.DisplayLocal(mdb.HashSelect(m, kit.Slice(arg, 0, 1)...), "")
|
||||
if mdb.HashSelect(m, arg...); len(arg) == 0 {
|
||||
m.Action(mdb.CREATE, mdb.PRUNES)
|
||||
} else {
|
||||
m.Action("full", INSTALL)
|
||||
ctx.DisplayLocal(m, "")
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
func ProcessXterm(m *ice.Message, args []string, arg ...string) {
|
||||
if len(arg) > 2 && arg[0] == ice.RUN && arg[1] == ctx.ACTION && arg[2] == mdb.CREATE {
|
||||
arg = append(arg, args...)
|
||||
if len(arg) == 0 || arg[0] != ice.RUN {
|
||||
args = []string{m.Cmdx("web.code.xterm", mdb.CREATE, args)}
|
||||
}
|
||||
ctx.ProcessField(m, "web.code.xterm", nil, arg...)
|
||||
ctx.ProcessField(m, "web.code.xterm", args, arg...)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user