1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00

opt xterm.go

This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-03-14 12:09:00 +08:00
parent df16437a34
commit 62e4fa032d
19 changed files with 97 additions and 51 deletions

View File

@ -45,6 +45,7 @@ func ProcessFloat(m *ice.Message, arg ...string) {
m.Option(ice.PROCESS_ARG, arg)
m.Cmdy(COMMAND, arg[0])
}
func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) {
if cmd = kit.Select(m.ActionKey(), cmd); len(arg) == 0 || arg[0] != ice.RUN {
m.Option("_index", m.PrefixKey())

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"io"
"path"
"strings"
ice "shylinux.com/x/icebergs"
kit "shylinux.com/x/toolkits"
@ -184,7 +185,7 @@ func HashInputs(m *ice.Message, arg ...Any) *ice.Message {
}
func HashCreate(m *ice.Message, arg ...Any) string {
if len(arg) == 0 {
arg = append(arg, m.OptionSimple(HashField(m)))
arg = append(arg, m.OptionSimple(strings.Replace(HashField(m), "hash,", "", 1)))
}
return m.Echo(m.Cmdx(append(kit.List(INSERT, m.PrefixKey(), "", HASH, logs.FileLineMeta(-1)), arg...)...)).Result()
}
@ -270,7 +271,7 @@ func HashSelectField(m *ice.Message, key string, field string) (value string) {
if field == HASH {
value = key
} else {
value = kit.Format(val[field])
value = kit.Format(kit.Value(val, field))
}
})
return
@ -293,6 +294,8 @@ func HashSelectTarget(m *ice.Message, key string, create Any) (target Any) {
switch create := create.(type) {
case func(ice.Map) ice.Any:
target = create(value)
case func(ice.Maps) ice.Any:
target = create(ToMaps(value))
case func() ice.Any:
target = create()
default:

View File

@ -33,6 +33,13 @@ func _mdb_modify(m *ice.Message, value ice.Map, field string, arg ...string) {
}
})
}
func ToMaps(value ice.Map) ice.Maps {
res := Maps{}
for k, v := range value {
res[k] = kit.Format(v)
}
return res
}
func _mdb_select(m *ice.Message, cb Any, key string, value Map, fields []string, val Map) {
switch value, val = kit.GetMeta(value), kit.GetMeta(val); cb := cb.(type) {
case func([]string, Map):
@ -48,11 +55,7 @@ func _mdb_select(m *ice.Message, cb Any, key string, value Map, fields []string,
case func(Any):
cb(value[TARGET])
case func(Maps):
res := Maps{}
for k, v := range value {
res[k] = kit.Format(v)
}
cb(res)
cb(ToMaps(value))
case string, []string, []ice.Any, nil:
if m.FieldsIsDetail() {
m.Push(ice.FIELDS_DETAIL, value)

View File

@ -166,9 +166,14 @@ func OptionLoad(m *ice.Message, file string) *ice.Message {
return m
}
func Template(m *ice.Message, file string, arg ...ice.Any) string {
type templateMessage interface {
PrefixKey(arg ...ice.Any) string
Cmdx(arg ...ice.Any) string
}
func Template(m templateMessage, file string, arg ...ice.Any) string {
return kit.Renders(kit.Format(TemplateText(m, file), arg...), m)
}
func TemplateText(m *ice.Message, file string) string {
func TemplateText(m templateMessage, file string) string {
return m.Cmdx(CAT, path.Join(m.PrefixKey(), path.Base(file)), kit.Dict(DIR_ROOT, ice.SRC_TEMPLATE))
}

View File

@ -103,8 +103,9 @@ func ReadDir(m Message, p string) ([]os.FileInfo, error) {
}
return list, e
}
func MkdirAll(m Message, p string) error {
return OptionFiles(m).MkdirAll(p, ice.MOD_DIR)
func MkdirAll(m Message, p string) string {
OptionFiles(m).MkdirAll(p, ice.MOD_DIR)
return p
}
func RemoveAll(m Message, p string) error {
return OptionFiles(m).RemoveAll(p)

View File

@ -160,6 +160,7 @@ func init() {
if len(arg) == 0 {
_dream_list(m)
} else if arg[0] == ctx.ACTION {
m.Option(ice.POD, m.Option(nfs.NAME))
gdb.Event(m, DREAM_ACTION, arg)
} else {
m.Cmdy(nfs.CAT, arg[1:], kit.Dict(nfs.DIR_ROOT, path.Join(ice.USR_LOCAL_WORK, arg[0])))

View File

@ -151,7 +151,11 @@ func _serve_domain(m *ice.Message) string {
}
func _serve_login(m *ice.Message, key string, cmds []string, w http.ResponseWriter, r *http.Request) ([]string, bool) {
if aaa.SessCheck(m, m.Option(ice.MSG_SESSID)); m.Option(ice.MSG_USERNAME) == "" && r.URL.Path != PP(SPACE) && !strings.HasPrefix(r.URL.Path, "/sync") {
gdb.Event(m, SERVE_LOGIN)
if m.Conf(SERVE, kit.Keym(tcp.LOCALHOST)) == ice.TRUE && tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) {
aaa.UserRoot(m)
} else {
gdb.Event(m, SERVE_LOGIN)
}
}
if _, ok := m.Target().Commands[WEB_LOGIN]; ok {
return cmds, !m.Target().Cmd(m, WEB_LOGIN, kit.Simple(key, cmds)...).IsErr()
@ -228,11 +232,6 @@ func init() {
}
}
}},
SERVE_LOGIN: {Hand: func(m *ice.Message, arg ...string) {
if m.Option(ice.MSG_USERNAME) == "" && m.Config(tcp.LOCALHOST) == ice.TRUE && tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) {
aaa.UserRoot(m)
}
}},
DOMAIN: {Hand: func(m *ice.Message, arg ...string) {
if len(arg) > 0 {
m.Config(tcp.LOCALHOST, ice.FALSE)

View File

@ -192,6 +192,8 @@ func init() {
case aaa.LOGIN:
}
})
} else if arg[0] == mdb.FOREACH && arg[1] == ssh.SHELL {
m.PushSearch(mdb.TYPE, ssh.SHELL, mdb.TEXT, "ice.bin space dial dev ops")
}
}},
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {

View File

@ -281,6 +281,12 @@ func init() {
m.Cmd("", mdb.CREATE, ice.SHY, kit.Select(kit.Select("https://shylinux.com", ice.Info.Make.Remote), conf[cli.CTX_SHY]))
}},
mdb.CREATE: {Name: "create name address", Hand: func(m *ice.Message, arg ...string) { _spide_create(m, m.Option(mdb.NAME), m.Option(ADDRESS)) }},
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
if arg[0] == mdb.FOREACH && arg[1] == "" {
m.PushSearch(mdb.TYPE, LINK, mdb.NAME, ice.DEV, mdb.TEXT, mdb.HashSelectField(m, ice.COM, CLIENT_ORIGIN))
m.PushSearch(mdb.TYPE, LINK, mdb.NAME, ice.SHY, mdb.TEXT, mdb.HashSelectField(m, ice.SHY, CLIENT_ORIGIN))
}
}},
tcp.CLIENT: {Hand: func(m *ice.Message, arg ...string) {
msg := m.Cmd("", kit.Select(ice.DEV, arg, 0))
ls := kit.Split(msg.Append(kit.Keys(SPIDE_CLIENT, tcp.HOST)), ice.DF)

View File

@ -86,11 +86,7 @@ func init() {
ctx.ProcessField(m, ls[0], ls[1:], arg...)
}},
"vimer": {Help: "源码", Hand: func(m *ice.Message, arg ...string) {
args := []string{}
if len(arg) == 0 || arg[0] != ice.RUN {
args = nfs.SplitPath(m, m.Option(mdb.TEXT))
}
ctx.ProcessField(m, web.CODE_VIMER, args, arg...)
ctx.ProcessField(m, web.CODE_VIMER, []string{m.Option(mdb.TEXT)}, arg...)
}},
"xterm": {Help: "命令", Hand: func(m *ice.Message, arg ...string) {
ctx.ProcessField(m, web.CODE_XTERM, []string{m.Option(mdb.TEXT)}, arg...)

View File

@ -13,7 +13,7 @@ import (
func _c_show(m *ice.Message, arg ...string) {
target := path.Join(ice.BIN, kit.TrimExt(arg[1], arg[0]))
if msg := m.Cmd(cli.SYSTEM, "gcc", "-o", target, path.Join(arg[2], arg[1])); cli.IsSuccess(msg) {
_xterm_show(m, nfs.SH, target, path.Join(arg[2], arg[1]))
ProcessXterm(m, nfs.SH, target, path.Join(arg[2], arg[1]))
} else {
_vimer_make(m, arg[2], msg)
}

View File

@ -109,7 +109,7 @@ func init() {
} else {
text = "cli.system go run " + path.Join(arg[2], arg[1])
}
_xterm_show(m, cmds, text)
ProcessXterm(m, cmds, text)
}},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
if cmd := ctx.GetFileCmd(path.Join(arg[2], arg[1])); cmd != "" {

View File

@ -18,7 +18,7 @@ func init() {
JS: {Name: "js path auto", Help: "前端", Actions: ice.MergeActions(ice.Actions{
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
cmds, text := "node", kit.Format(`require("./usr/volcanos/proto.js"), require("./usr/volcanos/publish/client/nodejs/proto.js"), Volcanos.meta._main("%s")`, path.Join(ice.PS, arg[2], arg[1]))
_xterm_show(m, cmds, text)
ProcessXterm(m, cmds, text)
}},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
if arg[2] == ice.USR_VOLCANOS {

View File

@ -31,7 +31,7 @@ func init() {
}},
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
cmds, text := "python -i "+path.Join(arg[2], arg[1]), ""
_xterm_show(m, cmds, text)
ProcessXterm(m, cmds, text)
}},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
_py_exec(m, path.Join(arg[2], arg[1]))

View File

@ -30,9 +30,16 @@ const SH = nfs.SH
func init() {
Index.MergeCommands(ice.Commands{
SH: {Name: "sh path auto", Help: "命令", Actions: ice.MergeActions(ice.Actions{
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
if arg[0] == mdb.FOREACH && (arg[1] == "" || arg[1] == ssh.SHELL) {
m.Cmd(nfs.CAT, "/etc/shells", func(text string) {
kit.If(text != "" && !strings.HasPrefix(text, "#"), func() { m.PushSearch(mdb.TYPE, ssh.SHELL, mdb.NAME, path.Base(text), mdb.TEXT, path.Base(text)) })
})
}
}},
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
cmds, text := _sh_cmds(m, path.Join(arg[2], arg[1]))
_xterm_show(m, cmds, text, path.Join(arg[2], arg[1]))
ProcessXterm(m, cmds, text, path.Join(arg[2], arg[1]))
}},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
cmds, text := _sh_cmds(m, path.Join(arg[2], arg[1]))

View File

@ -56,8 +56,11 @@ func init() {
VIMER: {Name: "vimer path=src/@key file=main.go 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 arg[0] == mdb.FOREACH && arg[1] == "" {
m.PushSearch(mdb.TYPE, web.LINK, mdb.TEXT, kit.MergeURL(m.Option(ice.MSG_USERHOST)+ice.PS, log.DEBUG, ice.TRUE))
m.PushSearch(mdb.TYPE, web.LINK, mdb.TEXT, web.MergePodCmds(m, "", web.CODE_VIMER, log.DEBUG, ice.TRUE))
m.PushSearch(mdb.TYPE, nfs.FILE, mdb.NAME, "main", mdb.TEXT, ice.SRC_MAIN_GO)
m.PushSearch(mdb.TYPE, nfs.FILE, mdb.NAME, "main", mdb.TEXT, ice.SRC_MAIN_SH)
m.PushSearch(mdb.TYPE, nfs.FILE, mdb.NAME, "main", mdb.TEXT, ice.SRC_MAIN_JS)
m.PushSearch(mdb.TYPE, web.LINK, mdb.NAME, "admin", mdb.TEXT, kit.MergeURL(m.Option(ice.MSG_USERHOST)+ice.PS, log.DEBUG, ice.TRUE))
m.PushSearch(mdb.TYPE, web.LINK, mdb.NAME, VIMER, mdb.TEXT, web.MergePodCmds(m, "", web.CODE_VIMER, log.DEBUG, ice.TRUE))
}
}},
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
@ -218,7 +221,8 @@ func init() {
kit.Switch(m.Option(mdb.TYPE), kit.Simple(web.SERVER, web.WORKER), func() { m.PushButton(kit.Dict(m.CommandKey(), "源码")) })
}},
web.DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) {
kit.If(arg[1] == m.CommandKey(), func() { web.ProcessWebsite(m, m.Option(mdb.NAME), m.PrefixKey()) })
// kit.If(arg[1] == m.CommandKey(), func() { web.ProcessWebsite(m, m.Option(mdb.NAME), m.PrefixKey()) })
kit.If(arg[1] == m.CommandKey(), func() { ctx.ProcessField(m, m.PrefixKey(), []string{}, arg...) })
}},
}, web.DreamAction(), mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path"), aaa.RoleAction(ctx.COMMAND)), Hand: func(m *ice.Message, arg ...string) {
if m.Cmdy(INNER, arg); arg[0] != ctx.ACTION {

View File

@ -37,16 +37,15 @@ func (s _xterm) Close() error {
return s.Cmd.Process.Kill()
}
func _xterm_get(m *ice.Message, h string) _xterm {
if h = kit.Select(m.Option(mdb.HASH), h); m.Assert(h != "") {
if mdb.HashSelectField(m, m.Option(mdb.HASH, h), mdb.TYPE) == "" {
mdb.HashCreate(m, mdb.HASH, h, m.OptionSimple("type,name,text"))
}
mdb.HashModify(m, web.VIEW, m.Option(ice.MSG_DAEMON))
if h = kit.Select(m.Option(mdb.HASH), h); m.Assert(h != "") && mdb.HashSelectField(m, m.Option(mdb.HASH, h), mdb.TYPE) == "" {
mdb.HashCreate(m, m.OptionSimple(mdb.HashField(m)))
}
t := mdb.HashSelectField(m, m.Option(mdb.HASH, h), mdb.TYPE)
return mdb.HashSelectTarget(m, h, func() ice.Any {
ls := kit.Split(kit.Select(nfs.SH, strings.Split(t, " # ")[0]))
mdb.HashModify(m, mdb.TIME, m.Time(), web.VIEW, m.Option(ice.MSG_DAEMON))
return mdb.HashSelectTarget(m, h, func(value ice.Maps) ice.Any {
text := strings.Split(value[mdb.TEXT], ice.NL)
ls := kit.Split(kit.Select(nfs.SH, strings.Split(value[mdb.TYPE], " # ")[0]))
cmd := exec.Command(cli.SystemFind(m, ls[0]), ls[1:]...)
cmd.Dir = nfs.MkdirAll(m, kit.Path(value[nfs.PATH]))
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Env = append(cmd.Env, "TERM=xterm")
tty, err := pty.Start(cmd)
@ -54,24 +53,28 @@ func _xterm_get(m *ice.Message, h string) _xterm {
m.Go(func() {
defer tty.Close()
defer mdb.HashRemove(m, mdb.HASH, h)
m.Log(cli.START, strings.Join(cmd.Args, ice.SP))
m.Option(ice.LOG_DISABLE, ice.TRUE)
buf := make([]byte, ice.MOD_BUFS)
for {
if n, e := tty.Read(buf); !m.Warn(e) && e == nil {
_xterm_echo(m, h, string(buf[:n]))
if _xterm_echo(m, h, string(buf[:n])); len(text) > 0 {
if text[0] != "" {
tty.Write([]byte(text[0] + ice.NL))
}
text = text[1:]
}
} else {
_xterm_echo(m, h, "~~~end~~~")
break
}
}
})
m.Go(func() { _xterm_cmds(m.Sleep("1s"), h, mdb.HashSelectField(m, h, mdb.TEXT)) })
return _xterm{cmd, tty}
}).(_xterm)
}
func _xterm_echo(m *ice.Message, h string, str string) {
m.Options(ice.MSG_DAEMON, mdb.HashSelectField(m, h, web.VIEW))
mdb.HashModify(m, mdb.HASH, h, mdb.TIME, m.Time())
web.PushNoticeGrow(m, h, str)
}
func _xterm_cmds(m *ice.Message, h string, cmd string, arg ...ice.Any) {
@ -95,16 +98,22 @@ func init() {
m.Push(arg[0], BASH, SH)
case mdb.NAME:
m.Push(arg[0], path.Base(m.Option(mdb.TYPE)), ice.Info.Hostname)
case nfs.PATH:
m.Cmdy(nfs.DIR, ice.USR_LOCAL_WORK, nfs.PATH)
m.Cmdy(nfs.DIR, ice.USR_LOCAL_REPOS, nfs.PATH)
m.Cmdy(nfs.DIR, ice.USR_LOCAL_DAEMON, nfs.PATH)
}
}},
mdb.CREATE: {Name: "create type*=sh name text theme:textarea", Hand: func(m *ice.Message, arg ...string) { mdb.HashCreate(m) }},
web.DREAM_CREATE: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd("", mdb.CREATE, mdb.TYPE, BASH, m.OptionSimple(mdb.NAME), nfs.PATH, path.Join(ice.USR_LOCAL_WORK, m.Option(mdb.NAME)))
}},
mdb.CREATE: {Name: "create type*=sh name text path theme:textarea", Hand: func(m *ice.Message, arg ...string) { mdb.HashCreate(m) }},
web.RESIZE: {Hand: func(m *ice.Message, arg ...string) {
_xterm_get(m, "").Setsize(m.OptionDefault("rows", "24"), m.OptionDefault("cols", "80"))
}},
web.INPUT: {Hand: func(m *ice.Message, arg ...string) {
if b, e := base64.StdEncoding.DecodeString(strings.Join(arg, "")); !m.Warn(e) {
_xterm_get(m, "").Write(string(b))
mdb.HashModify(m, mdb.TIME, m.Time())
}
}},
INSTALL: {Hand: func(m *ice.Message, arg ...string) {
@ -113,28 +122,33 @@ func init() {
log.DEBUG: {Hand: func(m *ice.Message, arg ...string) {
_xterm_cmds(m, kit.Select("", arg, 0), "cd ~/contexts; tail -f var/log/bench.log")
}},
web.OUTPUT: {Hand: func(m *ice.Message, arg ...string) {
web.OUTPUT: {Help: "全屏", Hand: func(m *ice.Message, arg ...string) {
web.ProcessWebsite(m, "", "", m.OptionSimple(mdb.HASH), ctx.STYLE, web.OUTPUT)
}},
web.DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) {
kit.Switch(m.Option(mdb.TYPE), kit.Simple(web.SERVER, web.WORKER), func() { m.PushButton(kit.Dict(m.CommandKey(), "命令")) })
}},
web.DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) {
kit.If(arg[1] == m.CommandKey(), func() { ctx.ProcessField(m, m.PrefixKey(), []string{}, arg...) })
}},
ctx.PROCESS: {Hand: func(m *ice.Message, arg ...string) {
ctx.ProcessField(m, m.PrefixKey(), func() string { return m.Cmdx("", mdb.CREATE, arg) }, arg...)
}},
}, mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,view,theme", mdb.TOOLS, FAVOR), ctx.ProcessAction()), Hand: func(m *ice.Message, arg ...string) {
}, mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,path,view,theme"), web.DreamAction(), ctx.ProcessAction(), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
if mdb.HashSelect(m, arg...); len(arg) == 0 {
m.PushAction(web.OUTPUT, mdb.REMOVE).Action(mdb.CREATE, mdb.PRUNES)
} else {
if m.Length() == 0 {
arg[0] = m.Cmdx("", mdb.CREATE, mdb.TYPE, arg[0])
mdb.HashSelect(m, arg[0]).Push(mdb.HASH, arg[0])
arg[0] = m.Cmdx("", mdb.CREATE, arg)
mdb.HashSelect(m, arg[0])
}
m.Push(mdb.HASH, arg[0])
// m.Action(INSTALL, log.DEBUG)
ctx.DisplayLocal(m, "")
}
}},
})
}
func _xterm_show(m *ice.Message, cmds, text string, arg ...string) {
func ProcessXterm(m *ice.Message, cmds, text string, arg ...string) {
m.Cmdy(ctx.COMMAND, XTERM).Push(ctx.ARGS, kit.Format([]string{m.Cmdx(XTERM, mdb.CREATE, mdb.TYPE, cmds, mdb.NAME, kit.Select("", arg, 0), mdb.TEXT, text)})).ProcessField(XTERM)
}

View File

@ -160,6 +160,11 @@ func (m *Message) Push(key string, value Any, arg ...Any) *Message {
m.Add(MSG_APPEND, KEY, key)
m.Add(MSG_APPEND, VALUE, kit.Format(value))
} else {
if m.ActionKey() == "inputs" {
if kit.IndexOf(m.meta[key], v) > -1 {
continue
}
}
m.Add(MSG_APPEND, key, v)
}
}

View File

@ -279,13 +279,12 @@ func init() {
_git_cmd(m, "config", "--global", "url."+m.Option(nfs.TO)+".insteadof", m.Option(nfs.FROM))
}
}},
"token": {Name: "token token", Help: "切换", Hand: func(m *ice.Message, arg ...string) {
"token": {Name: "token token", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
list := []string{m.Option(TOKEN)}
m.Cmd(nfs.CAT, kit.HomePath(".git-credentials"), func(line string) { list = append(list, line) })
m.Cmd(nfs.SAVE, kit.HomePath(".git-credentials"), strings.Join(list, ice.NL)+ice.NL)
ctx.ProcessHold(m)
}},
"branch_switch": {Help: "切换", Hand: func(m *ice.Message, arg ...string) {
_repos_cmd(m, m.Option(REPOS), "checkout", m.Option(BRANCH))
}},