1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-03-10 22:14:39 +08:00
parent 73ebb10b1e
commit f4507d9a1a
20 changed files with 133 additions and 99 deletions

View File

@ -14,7 +14,7 @@ func _role_keys(key ...string) string {
return strings.TrimPrefix(strings.TrimSuffix(strings.Replace(path.Join(strings.Replace(kit.Keys(key), ice.PT, ice.PS, -1)), ice.PS, ice.PT, -1), ice.PT), ice.PT) return strings.TrimPrefix(strings.TrimSuffix(strings.Replace(path.Join(strings.Replace(kit.Keys(key), ice.PT, ice.PS, -1)), ice.PS, ice.PT, -1), ice.PT), ice.PT)
} }
func _role_set(m *ice.Message, role, zone, key string, status bool) { func _role_set(m *ice.Message, role, zone, key string, status bool) {
m.Logs(mdb.INSERT, mdb.KEY, "aaa.role", ROLE, role, zone, key) m.Logs(mdb.INSERT, mdb.KEY, ROLE, ROLE, role, zone, key)
mdb.HashSelectUpdate(m, role, func(value ice.Map) { value[zone].(ice.Map)[key] = status }) mdb.HashSelectUpdate(m, role, func(value ice.Map) { value[zone].(ice.Map)[key] = status })
} }
func _role_white(m *ice.Message, role, key string) { _role_set(m, role, WHITE, key, true) } func _role_white(m *ice.Message, role, key string) { _role_set(m, role, WHITE, key, true) }
@ -42,17 +42,13 @@ func _role_right(m *ice.Message, role string, key ...string) (ok bool) {
} }
func _role_list(m *ice.Message, role string) *ice.Message { func _role_list(m *ice.Message, role string) *ice.Message {
mdb.HashSelectDetail(m, kit.Select(VOID, role), func(value ice.Map) { mdb.HashSelectDetail(m, kit.Select(VOID, role), func(value ice.Map) {
kit.Fetch(value[WHITE], func(k string, v ice.Any) { kit.For(value[WHITE], func(k string, v ice.Any) {
m.Push(ROLE, kit.Value(value, mdb.NAME)) m.Push(ROLE, kit.Value(value, mdb.NAME))
m.Push(mdb.ZONE, WHITE) m.Push(mdb.ZONE, WHITE).Push(mdb.KEY, k).Push(mdb.STATUS, v)
m.Push(mdb.KEY, k)
m.Push(mdb.STATUS, v)
}) })
kit.Fetch(value[BLACK], func(k string, v ice.Any) { kit.For(value[BLACK], func(k string, v ice.Any) {
m.Push(ROLE, kit.Value(value, mdb.NAME)) m.Push(ROLE, kit.Value(value, mdb.NAME))
m.Push(mdb.ZONE, BLACK) m.Push(mdb.ZONE, BLACK).Push(mdb.KEY, k).Push(mdb.STATUS, v)
m.Push(mdb.KEY, k)
m.Push(mdb.STATUS, v)
}) })
}) })
return m.Sort(mdb.KEY).StatusTimeCount() return m.Sort(mdb.KEY).StatusTimeCount()
@ -75,9 +71,9 @@ func init() {
ROLE: {Name: "role role auto insert", Help: "角色", Actions: ice.MergeActions(ice.Actions{ ROLE: {Name: "role role auto insert", Help: "角色", Actions: ice.MergeActions(ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Cmd("", mdb.CREATE, TECH, VOID) }}, ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Cmd("", mdb.CREATE, TECH, VOID) }},
mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) { mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) {
for _, role := range arg { kit.For(arg, func(role string) {
mdb.Rich(m, ROLE, nil, kit.Dict(mdb.NAME, role, BLACK, kit.Dict(), WHITE, kit.Dict())) mdb.Rich(m, ROLE, nil, kit.Dict(mdb.NAME, role, BLACK, kit.Dict(), WHITE, kit.Dict()))
} })
}}, }},
mdb.INSERT: {Name: "insert role*=void,tech zone*=white,black key*", Hand: func(m *ice.Message, arg ...string) { mdb.INSERT: {Name: "insert role*=void,tech zone*=white,black key*", Hand: func(m *ice.Message, arg ...string) {
_role_set(m, m.Option(ROLE), m.Option(mdb.ZONE), m.Option(mdb.KEY), true) _role_set(m, m.Option(ROLE), m.Option(mdb.ZONE), m.Option(mdb.KEY), true)
@ -88,9 +84,7 @@ func init() {
WHITE: {Hand: func(m *ice.Message, arg ...string) { _role_white(m, arg[0], _role_keys(arg[1:]...)) }}, WHITE: {Hand: func(m *ice.Message, arg ...string) { _role_white(m, arg[0], _role_keys(arg[1:]...)) }},
BLACK: {Hand: func(m *ice.Message, arg ...string) { _role_black(m, arg[0], _role_keys(arg[1:]...)) }}, BLACK: {Hand: func(m *ice.Message, arg ...string) { _role_black(m, arg[0], _role_keys(arg[1:]...)) }},
RIGHT: {Hand: func(m *ice.Message, arg ...string) { RIGHT: {Hand: func(m *ice.Message, arg ...string) {
if _role_right(m, arg[0], kit.Split(_role_keys(arg[1:]...), ice.PT)...) { kit.If(_role_right(m, arg[0], kit.Split(_role_keys(arg[1:]...), ice.PT)...), func() { m.Echo(ice.OK) })
m.Echo(ice.OK)
}
}}, }},
}, mdb.HashAction(mdb.SHORT, mdb.NAME)), Hand: func(m *ice.Message, arg ...string) { }, mdb.HashAction(mdb.SHORT, mdb.NAME)), Hand: func(m *ice.Message, arg ...string) {
_role_list(m, kit.Select("", arg, 0)).PushAction(mdb.DELETE) _role_list(m, kit.Select("", arg, 0)).PushAction(mdb.DELETE)
@ -106,26 +100,22 @@ func RoleAction(key ...string) ice.Actions {
} }
m.Cmd(ROLE, WHITE, VOID, m.PrefixKey()) m.Cmd(ROLE, WHITE, VOID, m.PrefixKey())
m.Cmd(ROLE, BLACK, VOID, m.PrefixKey(), ice.ACTION) m.Cmd(ROLE, BLACK, VOID, m.PrefixKey(), ice.ACTION)
for _, key := range key { m.Cmd(ROLE, WHITE, VOID, strings.TrimPrefix(m.PrefixKey(), "web."))
m.Cmd(ROLE, WHITE, VOID, m.PrefixKey(), ice.ACTION, key) m.Cmd(ROLE, BLACK, VOID, strings.TrimPrefix(m.PrefixKey(), "web."), ice.ACTION)
} kit.For(key, func(key string) { m.Cmd(ROLE, WHITE, VOID, m.PrefixKey(), ice.ACTION, key) })
}}} }}}
} }
func WhiteAction(key ...string) ice.Actions { func WhiteAction(key ...string) ice.Actions {
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(ROLE, WHITE, VOID, m.CommandKey()) m.Cmd(ROLE, WHITE, VOID, m.CommandKey())
m.Cmd(ROLE, BLACK, VOID, m.CommandKey(), ice.ACTION) m.Cmd(ROLE, BLACK, VOID, m.CommandKey(), ice.ACTION)
for _, key := range key { kit.For(key, func(key string) { m.Cmd(ROLE, WHITE, VOID, m.CommandKey(), ice.ACTION, key) })
m.Cmd(ROLE, WHITE, VOID, m.CommandKey(), ice.ACTION, key)
}
}}} }}}
} }
func BlackAction(key ...string) ice.Actions { func BlackAction(key ...string) ice.Actions {
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(ROLE, WHITE, VOID, m.CommandKey()) m.Cmd(ROLE, WHITE, VOID, m.CommandKey())
for _, key := range key { kit.For(key, func(key string) { m.Cmd(ROLE, BLACK, VOID, m.CommandKey(), ice.ACTION, key) })
m.Cmd(ROLE, BLACK, VOID, m.CommandKey(), ice.ACTION, key)
}
}}} }}}
} }
func RoleRight(m *ice.Message, role string, key ...string) bool { func RoleRight(m *ice.Message, role string, key ...string) bool {
@ -136,12 +126,8 @@ func Right(m *ice.Message, key ...ice.Any) bool {
ice.ErrNotRight, kit.Keys(key...), USERROLE, m.Option(ice.MSG_USERROLE), logs.FileLineMeta(-1)) ice.ErrNotRight, kit.Keys(key...), USERROLE, m.Option(ice.MSG_USERROLE), logs.FileLineMeta(-1))
} }
func White(m *ice.Message, key ...string) { func White(m *ice.Message, key ...string) {
for _, key := range key { kit.For(key, func(key string) { m.Cmd(ROLE, WHITE, VOID, key) })
m.Cmd(ROLE, WHITE, VOID, key)
}
} }
func Black(m *ice.Message, key ...string) { func Black(m *ice.Message, key ...string) {
for _, key := range key { kit.For(key, func(key string) { m.Cmd(ROLE, BLACK, VOID, key) })
m.Cmd(ROLE, BLACK, VOID, key)
}
} }

View File

@ -48,7 +48,7 @@ func init() {
CHECK: {Name: "check sessid*", Hand: func(m *ice.Message, arg ...string) { CHECK: {Name: "check sessid*", Hand: func(m *ice.Message, arg ...string) {
_sess_check(m, m.Option(SESSID)) _sess_check(m, m.Option(SESSID))
}}, }},
}, mdb.HashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,username,usernick,userrole,ua,ip", mdb.EXPIRE, "720h"))}, }, mdb.HashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,username,usernick,userrole,ua,ip", mdb.EXPIRE, "720h", mdb.ImportantDataAction()))},
}) })
} }

View File

@ -63,7 +63,7 @@ func init() {
LOGIN: {Name: "login username* password", Hand: func(m *ice.Message, arg ...string) { LOGIN: {Name: "login username* password", Hand: func(m *ice.Message, arg ...string) {
_user_login(m, m.Option(USERNAME), m.Option(PASSWORD)) _user_login(m, m.Option(USERNAME), m.Option(PASSWORD))
}}, }},
}, mdb.HashSearchAction(mdb.SHORT, USERNAME, mdb.FIELD, "time,username,usernick,userzone,userrole"))}, }, mdb.HashSearchAction(mdb.SHORT, USERNAME, mdb.FIELD, "time,username,usernick,userzone,userrole"), mdb.ImportantDataAction())},
}) })
} }

View File

@ -3,6 +3,7 @@ package cli
import ( import (
"io" "io"
"os/exec" "os/exec"
"runtime"
"strings" "strings"
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
@ -149,3 +150,19 @@ func init() {
}}, }},
}) })
} }
func Opens(m *ice.Message, arg ...string) {
switch runtime.GOOS {
case DARWIN:
if kit.Ext(arg[0]) == "app" {
m.Cmd(SYSTEM, OPEN, "-a", arg[0])
} else {
m.Cmd(SYSTEM, OPEN, arg[0])
}
case WINDOWS:
if kit.Ext(arg[0]) == "exe" {
m.Cmd(SYSTEM, arg[0])
} else {
m.Cmd(SYSTEM, "explorer", arg[0])
}
}
}

View File

@ -15,7 +15,16 @@ func _path_sep() string {
return kit.Select(":", ";", strings.Contains(os.Getenv(PATH), ";")) return kit.Select(":", ";", strings.Contains(os.Getenv(PATH), ";"))
} }
func BinPath(arg ...string) string { func BinPath(arg ...string) string {
return kit.Join(kit.Simple(arg, kit.Path(""), kit.Path(ice.BIN), kit.Path(ice.USR_PUBLISH), kit.Path(ice.USR_LOCAL_BIN), kit.Path(ice.USR_LOCAL_GO_BIN), kit.Env(PATH)), _path_sep()) var list = []string{}
push := func(p string) { kit.If(kit.IndexOf(list, p) == -1, func() { list = append(list, p) }) }
for _, p := range arg {
list = append(list, kit.Path(p, ice.BIN), kit.Path(p, ice.USR_PUBLISH), kit.Path(p, ice.USR_LOCAL_BIN), kit.Path(p, ice.USR_LOCAL_GO_BIN))
for _, l := range kit.Revert(strings.Split(ice.Pulse.Cmdx(nfs.CAT, kit.Path(p, ice.ETC_PATH)), ice.NL)) {
kit.If(strings.TrimSpace(l) != "" && !strings.HasPrefix(strings.TrimSpace(l), "#"), func() { push(kit.Path(p, l)) })
}
}
kit.Fetch(strings.Split(kit.Env(PATH), _path_sep()), func(p string) { push(p) })
return kit.Join(list, _path_sep())
} }
const FOREVER = "forever" const FOREVER = "forever"
@ -24,7 +33,7 @@ func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
FOREVER: {Name: "forever auto", Help: "启动", Actions: ice.Actions{ FOREVER: {Name: "forever auto", Help: "启动", Actions: ice.Actions{
START: {Hand: func(m *ice.Message, arg ...string) { START: {Hand: func(m *ice.Message, arg ...string) {
env := []string{PATH, BinPath(), HOME, kit.Select(kit.Path(""), os.Getenv(HOME))} env := []string{PATH, BinPath(""), HOME, kit.Select(kit.Path(""), os.Getenv(HOME))}
for _, k := range ENV_LIST { for _, k := range ENV_LIST {
if kit.Env(k) != "" { if kit.Env(k) != "" {
env = append(env, k, kit.Env(k)) env = append(env, k, kit.Env(k))

View File

@ -37,9 +37,12 @@ func _hash_insert(m *ice.Message, prefix, chain string, arg ...string) string {
} }
if arg[0] == HASH { if arg[0] == HASH {
m.Conf(prefix, kit.Keys(chain, HASH, arg[1]), kit.Data(arg[2:])) m.Conf(prefix, kit.Keys(chain, HASH, arg[1]), kit.Data(arg[2:]))
return m.Echo(arg[1]).Result() m.Echo(arg[1])
} else {
m.Echo(Rich(m, prefix, chain, kit.Data(arg, TARGET, m.Optionv(TARGET))))
} }
return m.Echo(Rich(m, prefix, chain, kit.Data(arg, TARGET, m.Optionv(TARGET)))).Result() SaveImportant(m, prefix, chain, kit.Simple(INSERT, prefix, chain, HASH, TIME, m.Time(), HASH, m.Result(), arg)...)
return m.Result()
} }
func _hash_delete(m *ice.Message, prefix, chain, field, value string) { func _hash_delete(m *ice.Message, prefix, chain, field, value string) {
defer Lock(m, prefix, chain)() defer Lock(m, prefix, chain)()
@ -48,13 +51,17 @@ func _hash_delete(m *ice.Message, prefix, chain, field, value string) {
target.Close() target.Close()
} }
m.Logs(DELETE, KEY, path.Join(prefix, chain), field, value, VALUE, kit.Format(val)) m.Logs(DELETE, KEY, path.Join(prefix, chain), field, value, VALUE, kit.Format(val))
SaveImportant(m, prefix, chain, kit.Simple(DELETE, prefix, chain, HASH, HASH, key)...)
m.Conf(prefix, kit.Keys(chain, HASH, key), "") m.Conf(prefix, kit.Keys(chain, HASH, key), "")
}) })
} }
func _hash_modify(m *ice.Message, prefix, chain string, field, value string, arg ...string) { func _hash_modify(m *ice.Message, prefix, chain string, field, value string, arg ...string) {
m.Logs(MODIFY, KEY, path.Join(prefix, chain), field, value, arg) m.Logs(MODIFY, KEY, path.Join(prefix, chain), field, value, arg)
defer Lock(m, prefix, chain)() defer Lock(m, prefix, chain)()
Richs(m, prefix, chain, value, func(key string, val Map) { _mdb_modify(m, val, field, arg...) }) Richs(m, prefix, chain, value, func(key string, val Map) {
SaveImportant(m, prefix, chain, kit.Simple(MODIFY, prefix, chain, HASH, HASH, key, arg)...)
_mdb_modify(m, val, field, arg...)
})
} }
func _hash_select(m *ice.Message, prefix, chain, field, value string) { func _hash_select(m *ice.Message, prefix, chain, field, value string) {
if field == HASH && value == RANDOM { if field == HASH && value == RANDOM {

View File

@ -330,3 +330,12 @@ func Cache(m *ice.Message, key string, add func() ice.Any) ice.Any {
} }
return nil return nil
} }
func ImportantDataAction() ice.Actions {
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Config("important", ice.TRUE) }}}
}
func SaveImportant(m *ice.Message, key, sub string, arg ...string) {
if m.Conf(key, kit.Keys(sub, META, "important")) == ice.TRUE {
ice.SaveImportant(m, arg...)
}
}

View File

@ -54,9 +54,8 @@ func _dream_show(m *ice.Message, name string) {
defer ToastProcess(m)() defer ToastProcess(m)()
defer m.Sleep3s() defer m.Sleep3s()
m.Options(cli.CMD_DIR, kit.Path(p), cli.CMD_ENV, kit.Simple( m.Options(cli.CMD_DIR, kit.Path(p), cli.CMD_ENV, kit.Simple(
cli.CTX_OPS, "http://localhost:"+m.CmdAppend(SERVE, tcp.PORT), cli.CTX_LOG, ice.VAR_LOG_BOOT_LOG, cli.CTX_OPS, "http://localhost:"+m.CmdAppend(SERVE, tcp.PORT), cli.CTX_LOG, ice.VAR_LOG_BOOT_LOG, cli.CTX_PID, ice.VAR_LOG_ICE_PID,
cli.PATH, cli.BinPath(kit.Path(p, ice.BIN)), cli.USER, ice.Info.Username, cli.PATH, cli.BinPath(p, ""), cli.USER, ice.Info.Username, kit.EnvSimple(cli.HOME, cli.TERM, cli.SHELL), m.Configv(cli.ENV),
kit.EnvSimple(cli.HOME, cli.TERM, cli.SHELL), m.Configv(cli.ENV),
), cli.CMD_OUTPUT, path.Join(p, ice.VAR_LOG_BOOT_LOG)) ), cli.CMD_OUTPUT, path.Join(p, ice.VAR_LOG_BOOT_LOG))
defer m.Options(cli.CMD_DIR, "", cli.CMD_ENV, "", cli.CMD_OUTPUT, "") defer m.Options(cli.CMD_DIR, "", cli.CMD_ENV, "", cli.CMD_OUTPUT, "")
gdb.Event(m, DREAM_CREATE, m.OptionSimple(mdb.NAME, mdb.TYPE)) gdb.Event(m, DREAM_CREATE, m.OptionSimple(mdb.NAME, mdb.TYPE))
@ -138,7 +137,7 @@ func init() {
cli.STOP: {Hand: func(m *ice.Message, arg ...string) { cli.STOP: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(SPACE, mdb.MODIFY, m.OptionSimple(mdb.NAME), mdb.STATUS, cli.STOP) m.Cmd(SPACE, mdb.MODIFY, m.OptionSimple(mdb.NAME), mdb.STATUS, cli.STOP)
m.Go(func() { m.Cmd(SPACE, m.Option(mdb.NAME), ice.EXIT) }) m.Go(func() { m.Cmd(SPACE, m.Option(mdb.NAME), ice.EXIT) })
ctx.ProcessRefresh(m, "1s") m.Sleep("1s")
}}, }},
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
nfs.Trash(m, path.Join(ice.USR_LOCAL_WORK, m.Option(mdb.NAME))) nfs.Trash(m, path.Join(ice.USR_LOCAL_WORK, m.Option(mdb.NAME)))

View File

@ -15,6 +15,7 @@ import (
"shylinux.com/x/icebergs/base/gdb" "shylinux.com/x/icebergs/base/gdb"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/ssh"
"shylinux.com/x/icebergs/base/tcp" "shylinux.com/x/icebergs/base/tcp"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
@ -162,6 +163,9 @@ func _serve_login(m *ice.Message, key string, cmds []string, w http.ResponseWrit
return cmds, aaa.Right(m, key, cmds) return cmds, aaa.Right(m, key, cmds)
} }
} }
func _serve_address(m *ice.Message) string {
return kit.Format("http://localhost:%s", m.Option(tcp.PORT))
}
const ( const (
SERVE_START = "serve.start" SERVE_START = "serve.start"
@ -191,25 +195,20 @@ func init() {
_serve_start(m) _serve_start(m)
}}, }},
SERVE_START: {Hand: func(m *ice.Message, arg ...string) { SERVE_START: {Hand: func(m *ice.Message, arg ...string) {
m.Go(func() { m.Cmd(BROAD, SERVE, m.OptionSimple(tcp.PORT)) }) if m.Go(func() { m.Cmd(BROAD, SERVE, m.OptionSimple(tcp.PORT)) }); m.Option(ice.DEV) == "" {
m.Cmd(ssh.PRINTF, kit.Dict(nfs.CONTENT, ice.NL+ice.Render(m, ice.RENDER_QRCODE, tcp.PublishLocalhost(m, _serve_address(m))))).Cmd(ssh.PROMPT, kit.Dict(ice.LOG_DISABLE, ice.TRUE))
}
go func() { go func() {
opened := false opened := false
for i := 0; i < 3 && !opened; i++ { for i := 0; i < 3 && !opened; i++ {
m.Sleep("1s").Cmd(SPACE, kit.Dict(ice.LOG_DISABLE, ice.TRUE), func(values ice.Maps) { m.Sleep("1s").Cmd(SPACE, kit.Dict(ice.LOG_DISABLE, ice.TRUE), func(values ice.Maps) {
if values[mdb.TYPE] == CHROME { kit.If(values[mdb.TYPE] == CHROME, func() { opened = true })
opened = true
}
}) })
} }
if opened { if opened {
return return
} }
switch host := kit.Format("http://localhost:%s/", m.Option(tcp.PORT)); runtime.GOOS { cli.Opens(m, _serve_address(m))
case cli.DARWIN:
m.Cmd(cli.SYSTEM, "open", host+"?debug=true")
case cli.WINDOWS:
m.Cmd(cli.SYSTEM, "explorer", host)
}
}() }()
}}, }},
SERVE_REWRITE: {Hand: func(m *ice.Message, arg ...string) { SERVE_REWRITE: {Hand: func(m *ice.Message, arg ...string) {
@ -291,7 +290,7 @@ func init() {
PP(REQUIRE_USR): {Name: "/require/usr/", Help: "代码库", Hand: func(m *ice.Message, arg ...string) { PP(REQUIRE_USR): {Name: "/require/usr/", Help: "代码库", Hand: func(m *ice.Message, arg ...string) {
_share_local(m, ice.USR, path.Join(arg...)) _share_local(m, ice.USR, path.Join(arg...))
}}, }},
PP(REQUIRE_SRC): {Name: "/require/src/", Help: "源代码", Actions: ice.MergeActions(ice.Actions{}, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) { PP(REQUIRE_SRC): {Name: "/require/src/", Help: "源代码", Actions: ice.MergeActions(ice.Actions{}, ctx.CmdAction(), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
_share_local(m, ice.SRC, path.Join(arg...)) _share_local(m, ice.SRC, path.Join(arg...))
}}, }},
PP(ice.HELP): {Name: "/help/", Help: "帮助", Actions: ice.MergeActions(ctx.CmdAction(), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) { PP(ice.HELP): {Name: "/help/", Help: "帮助", Actions: ice.MergeActions(ctx.CmdAction(), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) {

View File

@ -34,9 +34,7 @@ func _space_dial(m *ice.Message, dev, name string, arg ...string) {
defer mdb.HashCreateDeferRemove(m, kit.SimpleKV("", MASTER, dev, msg.Append(tcp.HOSTNAME)), kit.Dict(mdb.TARGET, conn))() defer mdb.HashCreateDeferRemove(m, kit.SimpleKV("", MASTER, dev, msg.Append(tcp.HOSTNAME)), kit.Dict(mdb.TARGET, conn))()
if !prints && ice.Info.Colors { if !prints && ice.Info.Colors {
go func() { go func() {
m.Sleep("300ms").Cmd(ssh.PRINTF, kit.Dict(nfs.CONTENT, "\r"+ice.Render(m, ice.RENDER_QRCODE, m.CmdAppend(SPACE, dev, cli.PWD, mdb.LINK)))).Cmd(ssh.PROMPT, kit.Dict( m.Sleep("300ms").Cmd(ssh.PRINTF, kit.Dict(nfs.CONTENT, "\r"+ice.Render(m, ice.RENDER_QRCODE, m.CmdAppend(SPACE, dev, cli.PWD, mdb.LINK)))).Cmd(ssh.PROMPT, kit.Dict(ice.LOG_DISABLE, ice.TRUE))
ice.LOG_DISABLE, ice.TRUE,
))
}() }()
prints = true prints = true
} }

View File

@ -127,6 +127,8 @@ const ( // DIR
VAR_LOG_BOOT_LOG = "var/log/boot.log" VAR_LOG_BOOT_LOG = "var/log/boot.log"
VAR_LOG_ICE_PID = "var/log/ice.pid" VAR_LOG_ICE_PID = "var/log/ice.pid"
VAR_DATA_IMPORTANT = "var/data/.important"
VAR_LOG = "var/log/" VAR_LOG = "var/log/"
VAR_TMP = "var/tmp/" VAR_TMP = "var/tmp/"
VAR_CONF = "var/conf/" VAR_CONF = "var/conf/"

View File

@ -95,17 +95,12 @@ func init() {
"xterm": {Help: "命令", Hand: func(m *ice.Message, arg ...string) { "xterm": {Help: "命令", Hand: func(m *ice.Message, arg ...string) {
ctx.ProcessField(m, web.CODE_XTERM, []string{m.Option(mdb.TEXT)}, arg...) ctx.ProcessField(m, web.CODE_XTERM, []string{m.Option(mdb.TEXT)}, arg...)
}}, }},
cli.OPENS: {Help: "命令", Hand: func(m *ice.Message, arg ...string) { cli.OPENS: {Hand: func(m *ice.Message, arg ...string) { cli.Opens(m, m.Option(mdb.TEXT)) }},
m.Cmdy(cli.DAEMON, cli.OPEN, "-a", m.Option(mdb.TEXT)).ProcessHold(m)
}},
"_new": {Help: "命令", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(cli.DAEMON, cli.OPEN, "-n", "-a", m.Option(mdb.TEXT)).ProcessHold(m)
}},
ice.RUN: {Hand: func(m *ice.Message, arg ...string) { ice.RUN: {Hand: func(m *ice.Message, arg ...string) {
m.Option(mdb.TYPE, mdb.HashSelects(m.Spawn(), m.Option(mdb.HASH)).Append(mdb.TYPE)) m.Option(mdb.TYPE, mdb.HashSelects(m.Spawn(), m.Option(mdb.HASH)).Append(mdb.TYPE))
ctx.Run(m, arg...) ctx.Run(m, arg...)
}}, }},
}, mdb.HashAction(), ctx.CmdAction(), KeyboardAction()), Hand: func(m *ice.Message, arg ...string) { }, mdb.HashAction(), ctx.CmdAction(), KeyboardAction(), mdb.ImportantDataAction()), Hand: func(m *ice.Message, arg ...string) {
if len(arg) > 0 && arg[0] == ctx.ACTION { if len(arg) > 0 && arg[0] == ctx.ACTION {
m.Option(mdb.TYPE, mdb.HashSelects(m.Spawn(), m.Option(mdb.HASH)).Append(mdb.TYPE)) m.Option(mdb.TYPE, mdb.HashSelects(m.Spawn(), m.Option(mdb.HASH)).Append(mdb.TYPE))
gdb.Event(m, FAVOR_ACTION, arg) gdb.Event(m, FAVOR_ACTION, arg)
@ -132,7 +127,7 @@ func init() {
} }
switch value[mdb.TYPE] { switch value[mdb.TYPE] {
case cli.OPENS: case cli.OPENS:
m.PushButton(cli.OPENS, "_new", mdb.REMOVE) m.PushButton(cli.OPENS, mdb.REMOVE)
case ssh.SHELL: case ssh.SHELL:
m.PushButton("xterm", mdb.REMOVE) m.PushButton("xterm", mdb.REMOVE)
case ctx.INDEX: case ctx.INDEX:

View File

@ -1,14 +1,11 @@
package chat package chat
import ( import (
"runtime"
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
) )
const SEARCH = "search" const SEARCH = "search"
@ -16,22 +13,7 @@ const SEARCH = "search"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
web.P(SEARCH): {Name: "/search", Help: "搜索框", Actions: ice.MergeActions(ice.Actions{ web.P(SEARCH): {Name: "/search", Help: "搜索框", Actions: ice.MergeActions(ice.Actions{
cli.OPENS: {Hand: func(m *ice.Message, arg ...string) { cli.OPENS: {Hand: func(m *ice.Message, arg ...string) { cli.Opens(m, arg...) }},
switch runtime.GOOS {
case cli.DARWIN:
if kit.Ext(arg[0]) == "app" {
m.Cmd(cli.SYSTEM, cli.OPEN, "-a", arg[0])
} else {
m.Cmd(cli.SYSTEM, cli.OPEN, arg[0])
}
case cli.WINDOWS:
if kit.Ext(arg[0]) == "exe" {
m.Cmd(cli.SYSTEM, arg[0])
} else {
m.Cmd(cli.SYSTEM, "explorer", arg[0])
}
}
}},
}, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) { }, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(web.Space(m, m.Option(ice.POD)), mdb.SEARCH, arg).StatusTimeCount() m.Cmdy(web.Space(m, m.Option(ice.POD)), mdb.SEARCH, arg).StatusTimeCount()
}}, }},

View File

@ -42,12 +42,12 @@ func _binpack_dir(m *ice.Message, w io.Writer, dir string) {
nfs.DirDeepAll(m, dir, nfs.PWD, func(value ice.Maps) { _binpack_file(m, w, path.Join(dir, value[nfs.PATH])) }) nfs.DirDeepAll(m, dir, nfs.PWD, func(value ice.Maps) { _binpack_file(m, w, path.Join(dir, value[nfs.PATH])) })
} }
func _binpack_all(m *ice.Message) { func _binpack_all(m *ice.Message) {
nfs.OptionFiles(m, nfs.DiskFile)
if w, p, e := nfs.CreateFile(m, ice.SRC_BINPACK_GO); m.Assert(e) { if w, p, e := nfs.CreateFile(m, ice.SRC_BINPACK_GO); m.Assert(e) {
defer w.Close() defer w.Close()
defer m.Echo(p) defer m.Echo(p)
fmt.Fprint(w, nfs.Template(m, ice.SRC_BINPACK_GO)) fmt.Fprint(w, nfs.Template(m, ice.SRC_BINPACK_GO))
defer fmt.Fprint(w, nfs.Template(m, "binpack_end.go")) defer fmt.Fprint(w, nfs.Template(m, "binpack_end.go"))
nfs.OptionFiles(m, nfs.DiskFile)
for _, p := range []string{ice.USR_VOLCANOS, ice.USR_INTSHELL, ice.SRC} { for _, p := range []string{ice.USR_VOLCANOS, ice.USR_INTSHELL, ice.SRC} {
_binpack_dir(m, w, p) _binpack_dir(m, w, p)
} }

View File

@ -169,13 +169,7 @@ func init() {
} }
}) })
}}, }},
cli.OPENS: {Help: "打开", Hand: func(m *ice.Message, arg ...string) { cli.OPENS: {Hand: func(m *ice.Message, arg ...string) { cli.Opens(m, arg...) }},
if strings.HasSuffix(arg[0], ".app") {
m.Cmd(cli.DAEMON, cli.OPEN, "-a", arg[0])
} else {
m.Cmd(cli.DAEMON, cli.OPEN, arg[0])
}
}},
XTERM: {Name: "xterm type=sh name text", Help: "终端", Hand: func(m *ice.Message, arg ...string) { XTERM: {Name: "xterm type=sh name text", Help: "终端", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(XTERM, mdb.CREATE, arg) m.Cmdy(XTERM, mdb.CREATE, arg)
}}, FAVOR: {Help: "收藏"}, "listTags": {Help: "生成索引", Hand: func(m *ice.Message, arg ...string) { m.Cmd("web.code.vim.tags", nfs.LOAD) }}, }}, FAVOR: {Help: "收藏"}, "listTags": {Help: "生成索引", Hand: func(m *ice.Message, arg ...string) { m.Cmd("web.code.vim.tags", nfs.LOAD) }},

View File

@ -14,6 +14,7 @@ import (
"shylinux.com/x/icebergs/base/log" "shylinux.com/x/icebergs/base/log"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/ssh"
"shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
@ -88,9 +89,9 @@ func init() {
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
switch mdb.HashInputs(m, arg); arg[0] { switch mdb.HashInputs(m, arg); arg[0] {
case mdb.TYPE: case mdb.TYPE:
if m.Option(nfs.LINE) != "" && m.Option(nfs.FILE) != "" { m.Cmd(mdb.SEARCH, mdb.FOREACH, ssh.SHELL, ice.OptionFields("type,name,text"), func(value ice.Maps) {
m.Push(arg[0], VIM+" +"+m.Option(nfs.LINE)+ice.SP+m.Option(nfs.PATH)+m.Option(nfs.FILE)) kit.If(value[mdb.TYPE] == ssh.SHELL, func() { m.Push(arg[0], value[mdb.TEXT]) })
} })
m.Push(arg[0], BASH, SH) m.Push(arg[0], BASH, SH)
case mdb.NAME: case mdb.NAME:
m.Push(arg[0], path.Base(m.Option(mdb.TYPE)), ice.Info.Hostname) m.Push(arg[0], path.Base(m.Option(mdb.TYPE)), ice.Info.Hostname)

27
data.go
View File

@ -1,6 +1,8 @@
package ice package ice
import ( import (
"bufio"
"os"
"strings" "strings"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
@ -33,3 +35,28 @@ func (m *Message) ConfigSimple(key ...string) (res []string) {
} }
return return
} }
func loadImportant(m *Message) {
if f, e := os.Open(VAR_DATA_IMPORTANT); e == nil {
defer f.Close()
for bio := bufio.NewScanner(f); bio.Scan(); {
if bio.Text() == "" || strings.HasPrefix(bio.Text(), "# ") {
continue
}
m.Cmd(kit.Split(bio.Text()))
}
}
Info.Important = true
}
func SaveImportant(m *Message, arg ...string) {
if Info.Important != true {
return
}
for i, v := range arg {
if v == "" || strings.Contains(v, SP) {
arg[i] = "\"" + v + "\""
}
}
m.Cmd("nfs.push", VAR_DATA_IMPORTANT, kit.Join(arg, SP), NL)
}
func removeImportant(m *Message) { os.Remove(VAR_DATA_IMPORTANT) }

View File

@ -36,6 +36,8 @@ var Info = struct {
Route Maps Route Maps
Index Map Index Map
Important bool
merges []MergeHandler merges []MergeHandler
render map[string]func(*Message, ...Any) string render map[string]func(*Message, ...Any) string
Save func(m *Message, key ...string) *Message Save func(m *Message, key ...string) *Message

View File

@ -27,6 +27,7 @@ func (s *Frame) Begin(m *Message, arg ...string) Server {
func (s *Frame) Start(m *Message, arg ...string) bool { func (s *Frame) Start(m *Message, arg ...string) bool {
m.Cap(CTX_STREAM, strings.Split(m.Time(), SP)[1]) m.Cap(CTX_STREAM, strings.Split(m.Time(), SP)[1])
m.Cmd(kit.Keys(MDB, CTX_INIT)) m.Cmd(kit.Keys(MDB, CTX_INIT))
m.Cmd(kit.Keys(AAA, CTX_INIT))
m.Cmd(kit.Keys(CLI, CTX_INIT)) m.Cmd(kit.Keys(CLI, CTX_INIT))
m.Cmd(INIT, arg) m.Cmd(INIT, arg)
for _, k := range kit.Split(kit.Select("ctx,log,gdb,ssh", os.Getenv(CTX_DAEMON))) { for _, k := range kit.Split(kit.Select("ctx,log,gdb,ssh", os.Getenv(CTX_DAEMON))) {
@ -63,6 +64,7 @@ var Index = &Context{Name: ICE, Help: "冰山模块", Configs: Configs{HELP: {Va
c._command(m.Spawn(c), c.Commands[CTX_INIT], CTX_INIT, arg...) c._command(m.Spawn(c), c.Commands[CTX_INIT], CTX_INIT, arg...)
} }
}) })
loadImportant(m)
}}, }},
INIT: {Hand: func(m *Message, arg ...string) { INIT: {Hand: func(m *Message, arg ...string) {
m.Cmd(CTX_INIT) m.Cmd(CTX_INIT)
@ -82,6 +84,7 @@ var Index = &Context{Name: ICE, Help: "冰山模块", Configs: Configs{HELP: {Va
c._command(m.Spawn(c), c.Commands[CTX_EXIT], CTX_EXIT, arg...) c._command(m.Spawn(c), c.Commands[CTX_EXIT], CTX_EXIT, arg...)
} }
}) })
removeImportant(m)
}}, }},
}, server: &Frame{}} }, server: &Frame{}}
var Pulse = &Message{time: time.Now(), code: 0, meta: map[string][]string{}, data: Map{}, source: Index, target: Index, Hand: true} var Pulse = &Message{time: time.Now(), code: 0, meta: map[string][]string{}, data: Map{}, source: Index, target: Index, Hand: true}
@ -125,10 +128,10 @@ func Run(arg ...string) string {
if Pulse.Cmdy(INIT).Cmdy(arg); Pulse.IsErrNotFound() { if Pulse.Cmdy(INIT).Cmdy(arg); Pulse.IsErrNotFound() {
Pulse.SetAppend().SetResult().Cmdy(SYSTEM, arg) Pulse.SetAppend().SetResult().Cmdy(SYSTEM, arg)
} }
if strings.TrimSpace(Pulse.Result()) == "" { if strings.TrimSpace(Pulse.Result()) == "" && Pulse.Length() > 0 {
Pulse.Table() Pulse.Table()
} }
if !strings.HasSuffix(Pulse.Result(), NL) { if Pulse.Result() != "" && !strings.HasSuffix(Pulse.Result(), NL) {
Pulse.Echo(NL) Pulse.Echo(NL)
} }
} }

View File

@ -40,18 +40,18 @@ func (w WebView) Menu() bool {
} else { } else {
w.WebView.SetTitle(ice.CONTEXTS) w.WebView.SetTitle(ice.CONTEXTS)
w.WebView.SetSize(200, 60*len(list), webview.HintNone) w.WebView.SetSize(200, 60*len(list), webview.HintNone)
w.WebView.Navigate(kit.Format(`data:text/html,`+m.Cmdx(nfs.CAT, path.Join(ice.SRC_TEMPLATE, "webview", "home.html")), kit.Join(list, ice.NL))) w.WebView.Navigate(kit.Format(`data:text/html,`+ice.Pulse.Cmdx(nfs.CAT, path.Join(ice.SRC_TEMPLATE, "webview", "home.html")), kit.Join(list, ice.NL)))
return true return true
} }
} }
func (w WebView) Title(text string) { w.WebView.SetTitle(text) } func (w WebView) Title(text string) { w.WebView.SetTitle(text) }
func (w WebView) Webview(url string) { w.WebView.Navigate(url) } func (w WebView) Webview(url string) { w.WebView.Navigate(url) }
func (w WebView) Open(url string) { w.WebView.Navigate(url) } func (w WebView) Open(url string) { w.WebView.Navigate(url) }
func (w WebView) OpenUrl(url string) { w.Cmd(cli.SYSTEM, cli.OPEN, url) } func (w WebView) OpenUrl(url string) { cli.Opens(ice.Pulse, url) }
func (w WebView) OpenApp(app string) { w.Cmd(cli.SYSTEM, cli.OPEN, "-a", app) } func (w WebView) OpenApp(app string) { cli.Opens(ice.Pulse, app) }
func (w WebView) OpenCmd(cmd string) { func (w WebView) OpenCmd(cmd string) {
w.Cmd(nfs.SAVE, kit.HomePath(".bash_temp"), cmd) w.Cmd(nfs.SAVE, kit.HomePath(".bash_temp"), cmd)
w.Cmd(cli.SYSTEM, cli.OPEN, "-n", "-a", "Terminal") cli.Opens(ice.Pulse, "Terminal.app", "-n")
} }
func (w WebView) SetSize(width, height int) { func (w WebView) SetSize(width, height int) {
w.Cmd(nfs.SAVE, "etc/webview.size", kit.Format("%v,%v", width, height)) w.Cmd(nfs.SAVE, "etc/webview.size", kit.Format("%v,%v", width, height))
@ -81,7 +81,11 @@ func Run(cb func(*WebView) ice.Any) {
defer w.Destroy() defer w.Destroy()
defer w.Run() defer w.Run()
view := &WebView{Source: "etc/webview.txt", WebView: w, Message: ice.Pulse} view := &WebView{Source: "etc/webview.txt", WebView: w, Message: ice.Pulse}
if cb == nil {
kit.Reflect(view, func(name string, value ice.Any) { w.Bind(name, value) })
} else {
kit.Reflect(cb(view), func(name string, value ice.Any) { w.Bind(name, value) }) kit.Reflect(cb(view), func(name string, value ice.Any) { w.Bind(name, value) })
}
if !view.Menu() { if !view.Menu() {
view.navigate("http://localhost:9020") view.navigate("http://localhost:9020")
} }