From c6e9d8747713f84d2cc8319a751eb4a73a518019 Mon Sep 17 00:00:00 2001 From: shy Date: Mon, 25 Sep 2023 18:45:17 +0800 Subject: [PATCH] opt chat --- base/aaa/role.go | 4 +- base/ctx/config.go | 1 + base/ctx/process.go | 3 +- base/gdb/event.go | 7 +-- base/mdb/hash.go | 11 ++-- base/nfs/cat.go | 1 - base/nfs/dir.go | 4 +- base/ssh/script.go | 1 + base/web/html/html.go | 16 +++++ base/web/route.go | 17 +++++ base/web/space.go | 2 +- core/chat/chat.shy | 14 ++--- core/chat/cmd.go | 14 ++--- core/chat/favor.go | 105 +++++++++++-------------------- core/chat/flows.go | 2 +- core/chat/flows.js | 59 +++++++++-------- core/chat/footer.go | 15 +---- core/chat/grant.go | 2 +- core/chat/iframe.go | 29 +++------ core/chat/location.go | 2 +- core/chat/macos/applications.go | 36 +++-------- core/chat/macos/caculator.css | 30 ++------- core/chat/macos/caculator.go | 5 +- core/chat/macos/caculator.js | 29 +++------ core/chat/macos/clock.go | 5 +- core/chat/macos/desktop.go | 19 +++--- core/chat/macos/desktop.js | 52 ++++++++------- core/chat/macos/dock.go | 21 +++---- core/chat/macos/dock.js | 2 +- core/chat/macos/finder.go | 4 +- core/chat/macos/finder.js | 5 +- core/chat/macos/macos.go | 25 +++----- core/chat/macos/macos.shy | 36 ++++++----- core/chat/macos/menu.go | 7 +-- core/chat/macos/menu.js | 6 +- core/chat/macos/notifications.go | 10 +-- core/chat/macos/notifications.js | 13 ++-- core/chat/macos/opens.go | 21 ------- core/chat/macos/searchs.go | 2 +- core/chat/macos/session.go | 4 +- core/chat/oauth/client.go | 2 +- core/chat/trans.go | 2 +- core/code/vimer.go | 27 +++++++- core/code/xterm.go | 28 ++++++++- core/wiki/feel.go | 31 ++++++++- core/wiki/word.go | 7 +++ render.go | 3 + 47 files changed, 366 insertions(+), 375 deletions(-) delete mode 100644 core/chat/macos/opens.go diff --git a/base/aaa/role.go b/base/aaa/role.go index 88b37b34..43710934 100644 --- a/base/aaa/role.go +++ b/base/aaa/role.go @@ -111,9 +111,9 @@ func WhiteAction(key ...string) ice.Actions { }}} } func Right(m *ice.Message, key ...ice.Any) bool { - if key := kit.Simple(key); len(key) > 2 && key[1] == "action" && kit.IsIn(kit.Format(key[2]), "run", "command") { + if key := kit.Simple(key); len(key) > 2 && key[1] == ice.ACTION && kit.IsIn(kit.Format(key[2]), ice.RUN, ice.COMMAND) { return true - } else if len(key) > 0 && key[0] == "etc/path" { + } else if len(key) > 0 && key[0] == ice.ETC_PATH { return true } return m.Option(ice.MSG_USERROLE) == ROOT || !m.Warn(m.Cmdx(ROLE, RIGHT, m.Option(ice.MSG_USERROLE), key, logs.FileLineMeta(-1)) != ice.OK, diff --git a/base/ctx/config.go b/base/ctx/config.go index f14dd5ee..9efefa47 100644 --- a/base/ctx/config.go +++ b/base/ctx/config.go @@ -103,6 +103,7 @@ func _config_make(m *ice.Message, key string, arg ...string) { m.Echo(FormatPretty(mdb.Confv(msg, key, arg[0]), 0, 1)) } else { m.Echo(FormatPretty(mdb.Confv(msg, key), 0, 1)) + m.StatusTime(mdb.COUNT, kit.Length(mdb.Confv(msg, key, mdb.HASH))) } } func _config_list(m *ice.Message) { diff --git a/base/ctx/process.go b/base/ctx/process.go index 8a86c698..5de5187f 100644 --- a/base/ctx/process.go +++ b/base/ctx/process.go @@ -53,7 +53,8 @@ func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice. } else { m.Cmdy(COMMAND, cmd) } - m.Push(ARGS, kit.Format(_process_args(m, args))).Options(ice.MSG_INDEX, m.PrefixKey()).ProcessField(ACTION, m.ActionKey(), RUN) + m.Push(ARGS, kit.Format(_process_args(m, args))).Options(ice.MSG_INDEX, m.PrefixKey()) + m.ProcessField(ACTION, m.ActionKey(), RUN) } else { if !PodCmd(m, cmd, arg[1:]) { kit.If(aaa.Right(m, cmd, arg[1:]), func() { m.Cmdy(cmd, arg[1:]) }) diff --git a/base/gdb/event.go b/base/gdb/event.go index 8690468c..db521885 100644 --- a/base/gdb/event.go +++ b/base/gdb/event.go @@ -32,9 +32,6 @@ func init() { }, mdb.ZoneAction(mdb.SHORT, EVENT, mdb.FIELD, "time,id,cmd"), mdb.ClearOnExitHashAction())}, }) } -func EventAction(arg ...string) ice.Actions { - return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, _ ...string) { kit.For(arg, func(k string) { Watch(m, k) }) }}} -} func EventsAction(arg ...string) ice.Actions { list := kit.DictList(arg...) return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { @@ -48,10 +45,10 @@ func Watch(m *ice.Message, key string, arg ...string) *ice.Message { return m.Cmd(EVENT, LISTEN, EVENT, key, ice.CMD, kit.Join(arg, ice.SP)) } func Event(m *ice.Message, key string, arg ...ice.Any) *ice.Message { - if list[key] == 0 { + if key = kit.Select(kit.Keys(m.CommandKey(), m.ActionKey()), key); list[key] == 0 { return m } - return m.Cmdy(EVENT, HAPPEN, EVENT, kit.Select(kit.Keys(m.CommandKey(), m.ActionKey()), key), arg, logs.FileLineMeta(-1)) + return m.Cmdy(EVENT, HAPPEN, EVENT, key, arg, logs.FileLineMeta(-1)) } func EventDeferEvent(m *ice.Message, key string, arg ...ice.Any) func(string, ...ice.Any) { Event(m, key, arg...) diff --git a/base/mdb/hash.go b/base/mdb/hash.go index c479e865..67dce3ca 100644 --- a/base/mdb/hash.go +++ b/base/mdb/hash.go @@ -164,11 +164,14 @@ func StatusHashAction(arg ...Any) ice.Actions { func ClearOnExitHashAction() ice.Actions { return ice.MergeActions(ice.Actions{ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { Conf(m, m.PrefixKey(), HASH, "") }}}) } -func ExportHashAction() ice.Actions { - return ice.Actions{ - ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { HashExport(m, arg) }}, +func ExportHashAction(arg ...Any) ice.Actions { + return ice.MergeActions(ice.Actions{ + ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { + Config(m, IMPORTANT, ice.TRUE) + HashExport(m, arg) + }}, ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { HashImport(m, arg) }}, - } + }, HashAction(arg...)) } func HashKey(m *ice.Message) string { diff --git a/base/nfs/cat.go b/base/nfs/cat.go index 9e88c285..38678ba8 100644 --- a/base/nfs/cat.go +++ b/base/nfs/cat.go @@ -123,7 +123,6 @@ func init() { if arg[0] == ice.ACTION { m.Cmdy(DIR, arg) } else { - // } else if !Show(m, arg[0]) { _cat_list(m.Logs(FIND, m.OptionSimple(DIR_ROOT), FILE, arg[0]), arg[0]) } } diff --git a/base/nfs/dir.go b/base/nfs/dir.go index 08b298c3..4deb354c 100644 --- a/base/nfs/dir.go +++ b/base/nfs/dir.go @@ -212,7 +212,9 @@ var bind = []string{ func Relative(m *ice.Message, p string) string { for i := 0; i < len(bind); i += 2 { if strings.HasPrefix(p, bind[i]) { - return strings.Replace(p, bind[i], bind[i+1], 1) + if _p := strings.Replace(p, bind[i], bind[i+1], 1); Exists(m, kit.ExtChange(_p, JS)) { + return _p + } } } return p diff --git a/base/ssh/script.go b/base/ssh/script.go index 43a26c76..6f831382 100644 --- a/base/ssh/script.go +++ b/base/ssh/script.go @@ -158,6 +158,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) { if msg := m.Cmd(nfs.CAT, m.Option(ice.MSG_SCRIPT, f.source)); msg.IsErr() { return } else { + kit.If(m.Option(nfs.CAT_CONTENT), func() { m.Option(nfs.CAT_CONTENT, "") }) buf := bytes.NewBuffer(make([]byte, 0, ice.MOD_BUFS)) f.stdin, f.stdout = bytes.NewBufferString(msg.Result()), buf defer func() { m.Echo(buf.String()) }() diff --git a/base/web/html/html.go b/base/web/html/html.go index b304c112..3640ef5f 100644 --- a/base/web/html/html.go +++ b/base/web/html/html.go @@ -1,5 +1,11 @@ package html +import ( + "strings" + + kit "shylinux.com/x/toolkits" +) + const ( DARK = "dark" LIGHT = "light" @@ -25,3 +31,13 @@ const ( TEXT_PLAIN = "text/plain" ) + +func IsImage(name, mime string) bool { + return strings.HasPrefix(mime, "image/") || kit.ExtIsImage(name) +} +func IsVideo(name, mime string) bool { + return strings.HasPrefix(mime, "video/") || kit.ExtIsVideo(name) +} +func IsAudio(name, mime string) bool { + return strings.HasPrefix(mime, "audio/") +} diff --git a/base/web/route.go b/base/web/route.go index ff35db77..159902c4 100644 --- a/base/web/route.go +++ b/base/web/route.go @@ -55,6 +55,10 @@ func _route_toast(m *ice.Message, space string, args ...string) { }) } +const ( + ONLINE = "online" + OFFLINE = "offline" +) const ROUTE = "route" func init() { @@ -125,6 +129,19 @@ func init() { }) } else if mdb.HashSelect(m, arg...); len(arg) > 0 { m.EchoIFrame(m.MergePod(arg[0])) + } else { + stat := map[string]int{} + list := m.CmdMap(SPACE, mdb.NAME) + m.Table(func(value ice.Maps) { + if _, ok := list[value[SPACE]]; ok { + m.Push(mdb.STATUS, ONLINE) + stat[ONLINE]++ + } else { + m.Push(mdb.STATUS, OFFLINE) + stat[OFFLINE]++ + } + }) + m.StatusTimeCount(stat) } }}, }) diff --git a/base/web/space.go b/base/web/space.go index 0740ac05..4db34afa 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -180,7 +180,7 @@ func init() { kit.If(kit.IsIn(value[mdb.TYPE], WORKER, SERVER), func() { m.Push(arg[0], value[mdb.NAME]) }) }) case mdb.ICON: - m.Cmdy(nfs.DIR, ice.USR_ICONS, nfs.PATH) + m.Cmdy(nfs.DIR, ice.USR_ICONS, nfs.PATH).CutTo(nfs.PATH, arg[0]) case ctx.INDEX: if space := m.Option(SPACE); space != "" { m.Options(SPACE, []string{}).Cmdy(SPACE, space, mdb.INPUTS, arg) diff --git a/core/chat/chat.shy b/core/chat/chat.shy index eb02bf4b..a276cc67 100644 --- a/core/chat/chat.shy +++ b/core/chat/chat.shy @@ -1,27 +1,27 @@ chat.go chat.shy +portal.go header.go footer.go +search.go +action.go river.go storm.go -action.go -search.go -portal.go -iframe.go -trans.go icons.go pod.go cmd.go sso.go grant.go -oauth +trans.go +iframe.go +keyboard.go +oauth macos favor.go flows.go flows.js flows.css -keyboard.go location.go location.shy diff --git a/core/chat/cmd.go b/core/chat/cmd.go index 2623582a..45471b4d 100644 --- a/core/chat/cmd.go +++ b/core/chat/cmd.go @@ -3,9 +3,7 @@ package chat import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/aaa" - "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/web" - kit "shylinux.com/x/toolkits" ) const CMD = "cmd" @@ -15,12 +13,12 @@ func init() { CMD: {Actions: web.ApiWhiteAction(), Hand: func(m *ice.Message, arg ...string) { if len(arg[0]) == 0 || arg[0] == "" { web.RenderMain(m) - } else if m.IsCliUA() { - kit.If(aaa.Right(m, arg), func() { m.Cmdy(arg, m.Optionv(ice.ARG)).RenderResult() }) - } else if arg[0] == web.CHAT_PORTAL { - web.RenderMain(m) - } else if m.Cmdy(ctx.COMMAND, arg[0]); m.Length() > 0 { - web.RenderCmd(m, m.Append(ctx.INDEX), arg[1:]) + } else if aaa.Right(m, arg) { + if m.IsCliUA() { + m.Cmdy(arg, m.Optionv(ice.ARG)).RenderResult() + } else { + web.RenderCmd(m, arg[0], arg[1:]) + } } }}, }) diff --git a/core/chat/favor.go b/core/chat/favor.go index 894c47a6..3da8a798 100644 --- a/core/chat/favor.go +++ b/core/chat/favor.go @@ -4,27 +4,16 @@ import ( "strings" 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/gdb" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" - "shylinux.com/x/icebergs/base/ssh" - "shylinux.com/x/icebergs/base/tcp" "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" ) -func _favor_is_image(m *ice.Message, name, mime string) bool { - return strings.HasPrefix(mime, "image/") || kit.ExtIsImage(name) -} -func _favor_is_video(m *ice.Message, name, mime string) bool { - return strings.HasPrefix(mime, "video/") || kit.ExtIsVideo(name) -} -func _favor_is_audio(m *ice.Message, name, mime string) bool { - return strings.HasPrefix(mime, "audio/") -} - const ( FAVOR_INPUTS = "favor.inputs" FAVOR_TABLES = "favor.tables" @@ -34,7 +23,7 @@ const FAVOR = "favor" func init() { Index.MergeCommands(ice.Commands{ - FAVOR: {Name: "favor hash auto create upload getClipboardData", Help: "收藏夹", Actions: ice.MergeActions(ice.Actions{ + FAVOR: {Name: "favor hash auto create upload getClipboardData", Help: "收藏夹", Icon: "favor.png", Actions: ice.MergeActions(ice.Actions{ mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { if mdb.IsSearchPreview(m, arg) { m.Cmds("", func(value ice.Maps) { @@ -47,11 +36,18 @@ func init() { mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { switch mdb.HashInputs(m, arg); arg[0] { case mdb.TYPE: - m.Push(arg[0], web.LINK, nfs.FILE, mdb.TEXT, ctx.INDEX, ssh.SHELL, cli.OPENS) + m.Push(arg[0], mdb.TEXT, ctx.INDEX, cli.OPENS) case mdb.NAME: switch m.Option(mdb.TYPE) { case ctx.INDEX: - ctx.CmdInputs(m, m.Option(mdb.TYPE)).RenameAppend(ctx.INDEX, arg[0]) + m.Copy(mdb.HashInputs(m.Spawn(), ctx.INDEX).CutTo(ctx.INDEX, arg[0])) + return + } + case mdb.TEXT: + switch m.Option(mdb.TYPE) { + case ctx.INDEX: + m.Option(ctx.INDEX, m.Option(mdb.NAME)) + m.Copy(mdb.HashInputs(m.Spawn(), ctx.ARGS).CutTo(ctx.ARGS, arg[0])) return } } @@ -62,7 +58,7 @@ func init() { "scanQRCode": {Name: "favor create", Help: "扫码"}, "record1": {Name: "favor upload", Help: "截图"}, "record2": {Name: "favor upload", Help: "录屏"}, - mdb.CREATE: {Name: "create type name text*", Hand: func(m *ice.Message, arg ...string) { + mdb.CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) { if strings.HasPrefix(m.Option(mdb.TEXT), ice.HTTP) { m.OptionDefault(mdb.TYPE, mdb.LINK, mdb.NAME, kit.ParseURL(m.Option(mdb.TEXT)).Host) } @@ -74,36 +70,25 @@ func init() { web.DOWNLOAD: {Hand: func(m *ice.Message, arg ...string) { m.ProcessOpen(web.MergeURL2(m, web.SHARE_LOCAL+m.Option(mdb.TEXT), nfs.FILENAME, m.Option(mdb.NAME))) }}, - ctx.DISPLAY: {Help: "预览", Hand: func(m *ice.Message, arg ...string) { - if link := web.SHARE_LOCAL + m.Option(mdb.TEXT); _favor_is_image(m, m.Option(mdb.NAME), m.Option(mdb.TYPE)) { - m.EchoImages(link) - } else if _favor_is_video(m, m.Option(mdb.NAME), m.Option(mdb.TYPE)) { - m.EchoVideos(link) - } else { - m.Echo("