From 4ef21b479ea86acc8b157ebfed219bcc2d1a41ba Mon Sep 17 00:00:00 2001 From: shylinux Date: Fri, 21 Jul 2023 15:48:55 +0800 Subject: [PATCH] opt some --- base/ctx/process.go | 20 +++++++------------- base/ssh/render.go | 14 +++++++------- base/ssh/script.go | 23 +++++++---------------- core/chat/macos/desktop.css | 1 + core/code/xterm.go | 6 +++--- core/wiki/chart/block.go | 2 +- core/wiki/chart/chain.go | 8 ++++---- meta.go | 11 +++++++++++ misc/xterm/iterm.go | 4 ++-- option.go | 2 +- 10 files changed, 44 insertions(+), 47 deletions(-) diff --git a/base/ctx/process.go b/base/ctx/process.go index 4c81b962..9dfe3dd0 100644 --- a/base/ctx/process.go +++ b/base/ctx/process.go @@ -11,6 +11,13 @@ const PROCESS = "process" var _process = map[string]ice.Any{} func AddProcess(key string, val ice.Any) { _process[key] = val } +func ProcessAction() ice.Actions { + return ice.Actions{ + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { AddProcess(m.CommandKey(), m.PrefixKey()) }}, + PROCESS: {Hand: func(m *ice.Message, arg ...string) { ProcessField(m, m.PrefixKey(), arg, arg...) }}, + } +} + func _process_args(m *ice.Message, args ice.Any) []string { switch cb := args.(type) { case func() string: @@ -51,9 +58,6 @@ func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice. } return m } -func ProcessFloat(m *ice.Message, arg ...string) { - m.Cmdy(COMMAND, arg[0]).Options(ice.MSG_PROCESS, ice.PROCESS_FLOAT, ice.PROCESS_ARG, arg) -} func ProcessCommand(m *ice.Message, cmd string, args []string, arg ...string) { if !kit.HasPrefixList(arg, ice.RUN) { m.Cmdy(COMMAND, cmd).Push(ice.ARG, kit.Format(args)).ProcessField(cmd, ice.RUN) @@ -61,18 +65,8 @@ func ProcessCommand(m *ice.Message, cmd string, args []string, arg ...string) { m.Cmdy(cmd, arg[1:]) } } -func ProcessCmds(m *ice.Message, cmd string, arg ...string) { - m.Cmdy(COMMAND, cmd).Push(ice.ARG, kit.Format(arg)).ProcessField(ACTION, ice.RUN, cmd) -} func ProcessRefresh(m *ice.Message, arg ...string) { m.ProcessRefresh(arg...) } func ProcessRewrite(m *ice.Message, arg ...ice.Any) { m.ProcessRewrite(arg...) } func ProcessHold(m *ice.Message, text ...ice.Any) { m.Process(ice.PROCESS_HOLD, text...) } func ProcessOpen(m *ice.Message, url string) { m.Process(ice.PROCESS_OPEN, url) } - -func ProcessAction() ice.Actions { - return ice.Actions{ - ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { AddProcess(m.CommandKey(), m.PrefixKey()) }}, - PROCESS: {Hand: func(m *ice.Message, arg ...string) { ProcessField(m, m.PrefixKey(), arg, arg...) }}, - } -} diff --git a/base/ssh/render.go b/base/ssh/render.go index 9f32a324..e40c0d2b 100644 --- a/base/ssh/render.go +++ b/base/ssh/render.go @@ -9,20 +9,20 @@ import ( kit "shylinux.com/x/toolkits" ) -func Render(msg *ice.Message, cmd string, arg ...ice.Any) (res string) { +func Render(m *ice.Message, cmd string, arg ...ice.Any) (res string) { switch args := kit.Simple(arg...); cmd { case ice.RENDER_RESULT: - kit.If(len(args) > 0, func() { msg.Resultv(args) }) - res = msg.Result() + kit.If(len(args) > 0, func() { m.Resultv(args) }) + res = m.Result() case ice.RENDER_VOID: return res default: - if res = msg.Result(); res == "" { - res = msg.TableEcho().Result() + if res = m.Result(); res == "" { + res = m.TableEchoWithStatus().Result() } } - if fmt.Fprint(msg.O, res); !strings.HasSuffix(res, lex.NL) { - fmt.Fprint(msg.O, lex.NL) + if fmt.Fprint(m.O, res); !strings.HasSuffix(res, lex.NL) { + fmt.Fprint(m.O, lex.NL) } return res } diff --git a/base/ssh/script.go b/base/ssh/script.go index a1b8d173..43a26c76 100644 --- a/base/ssh/script.go +++ b/base/ssh/script.go @@ -102,11 +102,11 @@ func (f *Frame) parse(m *ice.Message, h, line string) string { return "" } func (f *Frame) scan(m *ice.Message, h, line string) *Frame { - // kit.If(f.source == STDIO, func() { m.Options(MESSAGE, m, ice.LOG_DISABLE, ice.TRUE) }) + kit.If(f.source == STDIO, func() { m.Option(ice.LOG_DISABLE, ice.TRUE) }) f.ps1 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS1))) f.ps2 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS2))) - m.I, m.O = f.stdin, f.stdout ps, bio := f.ps1, bufio.NewScanner(f.stdin) + m.I, m.O = f.stdin, f.stdout for f.prompt(m, ps...); f.stdin != nil && bio.Scan(); f.prompt(m, ps...) { if len(bio.Text()) == 0 && h == STDIO { continue @@ -116,20 +116,16 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame { line += lex.NL ps = f.ps2 continue - } - if len(bio.Text()) == 0 { + } else if len(bio.Text()) == 0 { continue - } - if strings.HasSuffix(bio.Text(), "\\") { + } else if strings.HasSuffix(bio.Text(), "\\") { line += bio.Text()[:len(bio.Text())-1] ps = f.ps2 continue - } - if strings.HasPrefix(strings.TrimSpace(line), "#") { + } else if strings.HasPrefix(strings.TrimSpace(line), "#") { line = "" continue - } - if ps = f.ps1; f.stdout == os.Stdout && ice.Info.Colors { + } else if ps = f.ps1; f.stdout == os.Stdout && ice.Info.Colors { f.printf(m, "\033[0m") } line = f.parse(m, h, line) @@ -138,12 +134,7 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame { } func (f *Frame) Begin(m *ice.Message, arg ...string) { - switch strings.Split(os.Getenv(cli.TERM), "-")[0] { - case "xterm", "screen": - ice.Info.Colors = true - default: - ice.Info.Colors = false - } + ice.Info.Colors = kit.IsIn(strings.Split(os.Getenv(cli.TERM), "-")[0], "xterm", "screen") } func (f *Frame) Start(m *ice.Message, arg ...string) { m.Optionv(FRAME, f) diff --git a/core/chat/macos/desktop.css b/core/chat/macos/desktop.css index 32a953cf..a8dea722 100644 --- a/core/chat/macos/desktop.css +++ b/core/chat/macos/desktop.css @@ -23,6 +23,7 @@ fieldset.macos.desktop>div.output>div.desktop>div.item:hover { background-color: fieldset.macos.desktop>div.output>div.desktop>div.item img { width:80px; border-radius:80px; } fieldset.macos.desktop>div.output>div.desktop>div.item>div.name { font-size:12px; width:80px; overflow:hidden; } fieldset.macos.desktop>div.output>div.desktop>fieldset { border-radius:10px; position:absolute; } +fieldset.macos.desktop>div.output>div.desktop>fieldset input:not([type=button]) {width: 150px;} fieldset.macos.desktop>div.output>div.desktop>fieldset>div.output>table.content { width:100%; } fieldset.macos.desktop>div.output>div.desktop>fieldset>div.output>table.content th { padding:10px; } fieldset.macos.desktop>div.output>div.desktop>fieldset>div.output>table.content td { padding:10px; } diff --git a/core/code/xterm.go b/core/code/xterm.go index 54fe28a3..b608dfdc 100644 --- a/core/code/xterm.go +++ b/core/code/xterm.go @@ -22,9 +22,9 @@ func _xterm_get(m *ice.Message, h string) xterm.XTerm { h = kit.Select(m.Option(mdb.HASH), h) m.Assert(h != "") if m.Option(ice.MSG_USERPOD) == "" { - mdb.HashModify(m, mdb.TIME, m.Time(), cli.DAEMON, kit.Keys(m.Option("__target"), m.Option(ice.MSG_DAEMON))) - } else { mdb.HashModify(m, mdb.TIME, m.Time(), cli.DAEMON, kit.Keys(m.Option(ice.MSG_DAEMON))) + } else { + mdb.HashModify(m, mdb.TIME, m.Time(), cli.DAEMON, kit.Keys(kit.Slice(kit.Simple(m.Optionv("__target")), 0, -1), m.Option(ice.MSG_DAEMON))) } return mdb.HashSelectTarget(m, h, func(value ice.Maps) ice.Any { text := strings.Split(value[mdb.TEXT], lex.NL) @@ -60,7 +60,7 @@ func _xterm_get(m *ice.Message, h string) xterm.XTerm { }).(xterm.XTerm) } func _xterm_echo(m *ice.Message, h string, str string) { - m.Options(ice.MSG_DAEMON, mdb.HashSelectField(m, h, cli.DAEMON)) + m.Options(ice.LOG_DISABLE, ice.TRUE, "__target", "", ice.MSG_DAEMON, mdb.HashSelectField(m, h, cli.DAEMON)) web.PushNoticeGrow(m, h, str) } func _xterm_cmds(m *ice.Message, h string, cmd string, arg ...ice.Any) { diff --git a/core/wiki/chart/block.go b/core/wiki/chart/block.go index a02b035c..8eb25f98 100644 --- a/core/wiki/chart/block.go +++ b/core/wiki/chart/block.go @@ -79,7 +79,7 @@ func (b *Block) GetWidth(str ...string) int { s := kit.Select(b.Text, str, 0) cn := (len(s) - len([]rune(s))) / 2 en := len([]rune(s)) - cn - return cn*b.FontSize + en*b.FontSize*10/16 + b.Padding + return cn*b.FontSize + en*b.FontSize*12/16 + b.Padding } func (b *Block) GetWidths(str ...string) int { return b.GetWidth(str...) + b.MarginX diff --git a/core/wiki/chart/chain.go b/core/wiki/chart/chain.go index 58dfe1a4..a8147c2d 100644 --- a/core/wiki/chart/chain.go +++ b/core/wiki/chart/chain.go @@ -89,10 +89,10 @@ const CHAIN = "chain" func init() { wiki.AddChart(CHAIN, func(m *ice.Message) wiki.Chart { - m.Option(wiki.FONT_SIZE, "18") - m.Option(wiki.MARGINX, "60") - m.Option(wiki.MARGINY, "16") - m.Option(wiki.PADDING, "10") + m.OptionDefault(wiki.FONT_SIZE, "18") + m.OptionDefault(wiki.MARGINX, "60") + m.OptionDefault(wiki.MARGINY, "16") + m.OptionDefault(wiki.PADDING, "10") wiki.AddGroupOption(m, SHIP, wiki.FILL, cli.GLASS) return &Chain{} }) diff --git a/meta.go b/meta.go index e33937c6..2aa89ff4 100644 --- a/meta.go +++ b/meta.go @@ -288,6 +288,17 @@ func (m *Message) TableEcho() *Message { } return m } +func (m *Message) TableEchoWithStatus() *Message { + m.TableEcho() + list := []string{} + kit.For(kit.UnMarshal(m.Option(MSG_STATUS)), func(index int, value Map) { + list = append(list, kit.Format("%s: %s", value[NAME], value[VALUE])) + }) + if len(list) > 0 { + m.Echo(strings.Join(list, SP)).Echo(NL) + } + return m +} const ( STR = "str" diff --git a/misc/xterm/iterm.go b/misc/xterm/iterm.go index 176bec42..338d561e 100644 --- a/misc/xterm/iterm.go +++ b/misc/xterm/iterm.go @@ -276,9 +276,9 @@ func (s iterm) exec(m *ice.Message, res string) string { res, s.pipe = "", w env := kit.EnvList( "TERM", "xterm", + "SHELL", "/bin/ish", "LINES", m.Option("rows"), "COLUMNS", m.Option("cols"), - "SHELL", "/bin/ish", "USER", m.Option(ice.MSG_USERNAME), ) m.Cmd(cli.SYSTEM, arg, kit.Dict(cli.CMD_INPUT, r, cli.CMD_OUTPUT, nfs.Pipe(m, func(buf []byte) { @@ -286,7 +286,7 @@ func (s iterm) exec(m *ice.Message, res string) string { end = bytes.HasSuffix(buf, []byte(lex.NL)) }), cli.CMD_ENV, env)) } else { - kit.If(msg.Result() == "", func() { msg.TableEcho() }) + kit.If(msg.Result() == "", func() { msg.TableEchoWithStatus() }) res += strings.ReplaceAll(msg.Result(), lex.NL, CRNL) end = strings.HasSuffix(res, lex.NL) } diff --git a/option.go b/option.go index 0ce9ac28..0506be68 100644 --- a/option.go +++ b/option.go @@ -47,7 +47,7 @@ func (m *Message) MergePod(pod string, arg ...Any) string { ls := []string{"chat"} kit.If(kit.Keys(m.Option(MSG_USERPOD), pod), func(p string) { ls = append(ls, POD, p) }) kit.If(m.Option(DEBUG) == TRUE, func() { arg = append([]Any{DEBUG, TRUE}, arg...) }) - return kit.MergeURL2(strings.Split(kit.Select(Info.Domain, m.Option(MSG_USERWEB)), QS)[0], PS+kit.Join(ls, PS), arg...) + return kit.MergeURL2(strings.Split(kit.Select("http://localhost:9020", Info.Domain, m.Option(MSG_USERWEB)), QS)[0], PS+kit.Join(ls, PS), arg...) } func (m *Message) MergePodCmd(pod, cmd string, arg ...Any) string { ls := []string{"chat"}