From f06013c0c284840648b484faf8d5833d73a97230 Mon Sep 17 00:00:00 2001 From: shylinux Date: Fri, 19 Aug 2022 19:18:54 +0800 Subject: [PATCH] opt some --- base/ssh/script.go | 17 ++++++++--------- base/web/serve.go | 9 +++++++++ base/web/space.go | 2 +- base/web/web.go | 3 ++- init.go | 2 +- misc/git/spide.go | 15 ++++++--------- misc/git/status.go | 9 +++++---- 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/base/ssh/script.go b/base/ssh/script.go index 0b643815..8316f915 100644 --- a/base/ssh/script.go +++ b/base/ssh/script.go @@ -13,6 +13,7 @@ import ( ice "shylinux.com/x/icebergs" "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" kit "shylinux.com/x/toolkits" @@ -108,14 +109,11 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame { f.ps2 = kit.Simple(m.Confv(PROMPT, kit.Keym(PS2))) ps := f.ps1 - if h == STDIO { - m.Sleep("800ms") - pwd := ice.Render(m, ice.RENDER_QRCODE, m.Cmdx("space", "domain")) - m.Sleep("100ms") - f.printf(m, pwd+ice.NL) + if m.I, m.O = f.stdin, f.stdout; h == STDIO { + gdb.Event(m, SOURCE_STDIO) + m.Sleep("1.1s") } - m.I, m.O = f.stdin, f.stdout bio := bufio.NewScanner(f.stdin) for f.prompt(m, ps...); f.stdin != nil && bio.Scan(); f.prompt(m, ps...) { if len(bio.Text()) == 0 && h == STDIO { @@ -206,6 +204,8 @@ const ( STDIO = "stdio" PS1 = "PS1" PS2 = "PS2" + + SOURCE_STDIO = "source.stdio" ) const ( SCRIPT = "script" @@ -237,13 +237,12 @@ func init() { }}, PROMPT: {Name: "prompt arg run", Help: "命令提示", Hand: func(m *ice.Message, arg ...string) { if f, ok := m.Optionv(FRAME).(*Frame); ok { - f.ps1 = arg - f.prompt(m) + f.prompt(m, arg...) } }}, PRINTF: {Name: "printf run text", Help: "输出显示", Hand: func(m *ice.Message, arg ...string) { if f, ok := m.Optionv(FRAME).(*Frame); ok { - f.printf(m, arg[0]) + f.printf(m, kit.Select(m.Option(nfs.CONTENT), arg, 0)) } }}, SCREEN: {Name: "screen run text", Help: "输出命令", Hand: func(m *ice.Message, arg ...string) { diff --git a/base/web/serve.go b/base/web/serve.go index f30d2a36..2109ec67 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -12,9 +12,11 @@ import ( "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/lex" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" + "shylinux.com/x/icebergs/base/ssh" "shylinux.com/x/icebergs/base/tcp" kit "shylinux.com/x/toolkits" "shylinux.com/x/toolkits/logs" @@ -347,6 +349,13 @@ func init() { m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, p) } _serve_rewrite(m) + gdb.Watch(m, ssh.SOURCE_STDIO) + }}, + ssh.SOURCE_STDIO: {Name: "source.stdio", Help: "终端", Hand: func(m *ice.Message, arg ...string) { + m.Go(func() { + m.Sleep("1s") + m.Cmd(ssh.PRINTF, kit.Dict(nfs.CONTENT, ice.Render(m, ice.RENDER_QRCODE, m.Cmdx(SPACE, DOMAIN))+ice.NL)) + }) }}, DOMAIN: {Name: "domain", Help: "域名", Hand: func(m *ice.Message, arg ...string) { ice.Info.Domain = m.Conf(SHARE, kit.Keym(DOMAIN, m.Config(DOMAIN, arg[0]))) diff --git a/base/web/space.go b/base/web/space.go index 3cc42f92..93cf6d1d 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -37,7 +37,7 @@ func _space_domain(m *ice.Message) (link string) { } } if link == "" { - link = kit.Format("http://localhost:%s", m.Cmd(SERVE).Append(tcp.PORT)) + link = kit.Format("http://localhost:%s", kit.Select(m.Option(tcp.PORT), m.Cmd(SERVE).Append(tcp.PORT))) } return tcp.ReplaceLocalhost(m, link) } diff --git a/base/web/web.go b/base/web/web.go index f5ee72cb..377fc75b 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -103,9 +103,10 @@ func (frame *Frame) Start(m *ice.Message, arg ...string) bool { case func(http.Handler): cb(frame) // 启动框架 default: + mdb.HashCreate(m, mdb.NAME, WEB, arg, m.OptionSimple(tcp.PROTO, ice.DEV), cli.STATUS, tcp.START) m.Cmd(tcp.SERVER, tcp.LISTEN, mdb.TYPE, WEB, m.OptionSimple(mdb.NAME, tcp.HOST, tcp.PORT), func(l net.Listener) { - mdb.HashCreate(m, mdb.NAME, WEB, arg, m.OptionSimple(tcp.PROTO, ice.DEV), cli.STATUS, tcp.START, kit.Dict(mdb.TARGET, l)) defer mdb.HashModify(m, m.OptionSimple(mdb.NAME), cli.STATUS, tcp.STOP) + mdb.HashTarget(m, m.Option(mdb.NAME), func() ice.Any { return l }) m.Warn(frame.Server.Serve(l)) // 启动服务 }) } diff --git a/init.go b/init.go index e7417328..03a03c59 100644 --- a/init.go +++ b/init.go @@ -46,7 +46,7 @@ func (f *Frame) Close(m *Message, arg ...string) bool { } }) conf.Close() - go func() { m.Sleep("3s"); os.Exit(kit.Int(Pulse.Option(EXIT))) }() + go func() { m.Sleep("1s"); os.Exit(kit.Int(Pulse.Option(EXIT))) }() return true } diff --git a/misc/git/spide.go b/misc/git/spide.go index fde4431f..634501cd 100644 --- a/misc/git/spide.go +++ b/misc/git/spide.go @@ -87,16 +87,16 @@ func init() { for k, v := range list { m.Push("pkg", k) - m.Push("count", len(v)) + m.Push(mdb.COUNT, len(v)) for _, i := range item { - m.Push(i, kit.Select("", "ok", v[i])) + m.Push(i, kit.Select("", ice.OK, v[i])) } } - m.SortIntR("count") + m.SortIntR(mdb.COUNT) m.ProcessInner() }}, code.INNER: {Name: "web.code.inner"}, }, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) { - if arg = kit.Slice(arg, 0, 1); len(arg) == 0 { // 仓库列表 + if len(kit.Slice(arg, 0, 1)) == 0 { // 仓库列表 m.Cmdy(REPOS) return } @@ -106,9 +106,9 @@ func init() { } else { m.Option(nfs.DIR_ROOT, path.Join(ice.USR, arg[0])+ice.PS) } - ctx.DisplayStory(m, "spide.js", "field", "path", "root", arg[0]) + ctx.DisplayStory(m, "spide.js", mdb.FIELD, nfs.PATH, "root", arg[0]) - if len(arg) == 1 { // 目录列表 + if len(arg) == 1 || !strings.HasSuffix(arg[1], arg[2]) { // 目录列表 m.Option(nfs.DIR_DEEP, ice.TRUE) color := []string{cli.YELLOW, cli.BLUE, cli.CYAN, cli.RED} nfs.Dir(m, nfs.PATH).Tables(func(value ice.Maps) { @@ -116,9 +116,6 @@ func init() { }) return } - if !strings.HasSuffix(arg[1], arg[2]) { - return - } // 语法解析 switch m.Option(cli.CMD_DIR, m.Option(nfs.DIR_ROOT)); kit.Ext(arg[1]) { diff --git a/misc/git/status.go b/misc/git/status.go index 909dfb91..f473871a 100644 --- a/misc/git/status.go +++ b/misc/git/status.go @@ -6,6 +6,7 @@ import ( "time" 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" @@ -61,7 +62,7 @@ func _status_tags(m *ice.Message, repos string) { return text } if v, ok := vs[kit.Slice(strings.Split(ls[0], ice.PS), -1)[0]]; ok && ls[1] != v { - m.Logs("upgrade", "repos", ls[0], "from", ls[1], "to", v) + m.Logs(mdb.MODIFY, REPOS, ls[0], "from", ls[1], "to", v) text = strings.ReplaceAll(text, ls[1], v) change = true } @@ -218,15 +219,15 @@ func init() { for _, v := range kit.Split(m.Option(nfs.FILE), " /") { m.Push(mdb.TEXT, v) } - case "username": + case aaa.USERNAME: m.Push(arg[0], kit.Select(m.Option(ice.MSG_USERNAME), _configs_get(m, "user.name"))) case "email": m.Push(arg[0], _configs_get(m, "user.email")) } }}, CONFIGS: {Name: "configs email username", Help: "配置", Hand: func(m *ice.Message, arg ...string) { - _configs_set(m, "user.name", m.Option("username")) - _configs_set(m, "user.email", m.Option("email")) + _configs_set(m, "user.name", m.Option(aaa.USERNAME)) + _configs_set(m, "user.email", m.Option(aaa.EMAIL)) }}, CLONE: {Name: "clone repos='https://shylinux.com/x/volcanos' path=", Help: "克隆", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(REPOS, mdb.CREATE)