From b3959aa68d6a5962a15533b1602f994086c1b61b Mon Sep 17 00:00:00 2001 From: shylinux Date: Sun, 21 Apr 2024 16:27:38 +0800 Subject: [PATCH] opt some --- base/cli/system.go | 5 +++++ base/web/serve.go | 5 ++++- init.go | 8 ++++++++ logs.go | 4 ++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/base/cli/system.go b/base/cli/system.go index ba082eaa..a5fdeb3c 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -7,7 +7,9 @@ import ( "os" "os/exec" "path" + "runtime" "strings" + "syscall" ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/aaa" @@ -65,6 +67,9 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd { } kit.For(env, func(k, v string) { cmd.Env = append(cmd.Env, kit.Format("%s=%s", k, v)) }) kit.If(len(cmd.Env) > 0 && m.IsDebug(), func() { m.Logs(EXEC, CMD_ENV, kit.Format(cmd.Env)) }) + if runtime.GOOS == "windows" { + cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} + } return cmd } func _system_out(m *ice.Message, out string) io.Writer { diff --git a/base/web/serve.go b/base/web/serve.go index d885d43f..a89e5c02 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -3,6 +3,7 @@ package web import ( "net/http" "net/url" + "os" "path" "regexp" "runtime" @@ -232,6 +233,8 @@ func init() { tcp.HOST: {Help: "公网", Hand: func(m *ice.Message, arg ...string) { m.Echo(kit.Formats(PublicIP(m))) }}, cli.SYSTEM: {Help: "系统", Hand: func(m *ice.Message, arg ...string) { cli.Opens(m, "System Settings.app") }}, cli.START: {Name: "start dev proto host port=9020 nodename username usernick", Hand: func(m *ice.Message, arg ...string) { + m.Cmd(cli.SYSTEM, "echo", "-ne", kit.Format("\033]0;%s %s serve start %s\007", + path.Base(kit.Path("")), strings.TrimPrefix(kit.Path(os.Args[0]), kit.Path("")+nfs.PS), kit.JoinCmdArgs(arg...))) if runtime.GOOS == cli.LINUX { m.Cmd(nfs.SAVE, nfs.ETC_LOCAL_SH, m.Spawn(ice.Maps{cli.PWD: kit.Path(""), aaa.USER: kit.UserName(), ctx.ARGS: kit.JoinCmds(arg...)}).Template("local.sh")+lex.NL) m.Cmd("", PROXY_CONF, ice.Info.NodeName) @@ -240,7 +243,7 @@ func init() { }}, SERVE_START: {Hand: func(m *ice.Message, arg ...string) { kit.If(m.Option(ice.DEMO) == ice.TRUE, func() { m.Cmd(CHAT_HEADER, ice.DEMO) }) - m.Go(func() { ssh.PrintQRCode(m, tcp.PublishLocalhost(m, _serve_address(m))) }) + kit.If(os.Getenv(cli.TERM), func() { m.Go(func() { ssh.PrintQRCode(m, tcp.PublishLocalhost(m, _serve_address(m))) }) }) m.Cmd(SPIDE, mdb.CREATE, HostPort(m, tcp.LOCALHOST, m.Option(tcp.PORT)), ice.OPS, nfs.USR_ICONS_CONTEXTS, nfs.REPOS, "") m.Cmds(SPIDE).Table(func(value ice.Maps) { kit.If(value[CLIENT_NAME] != ice.OPS && value[TOKEN] != "", func() { diff --git a/init.go b/init.go index 179f95bf..69c66ce4 100644 --- a/init.go +++ b/init.go @@ -99,6 +99,10 @@ func init() { Index.root, Pulse.root, Pulse.time = Index, Pulse, time.Now() } +func Runs(cb func(), arg ...string) string { + Pulse.Optionv("main.routine", cb) + return Run(arg...) +} func Run(arg ...string) string { kit.If(len(arg) == 0 && len(os.Args) > 1, func() { arg = os.Args[1:] }) kit.If(len(arg) == 0, func() { arg = append(arg, FOREVER, START) }) @@ -115,6 +119,10 @@ func Run(arg ...string) string { _forever = true logs.Disable(false) Pulse.Go(func() { Index.Start(Pulse, arg...) }) + switch cb := Pulse.Optionv("main.routine").(type) { + case func(): + cb() + } conf.Wait() os.Exit(kit.Int(Pulse.Option(EXIT))) default: diff --git a/logs.go b/logs.go index 6b25a319..7678f886 100644 --- a/logs.go +++ b/logs.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "net/http" + "os" "runtime" "strings" "time" @@ -65,6 +66,9 @@ func (m *Message) log(level string, str string, arg ...Any) *Message { } _source := logs.FileLineMeta(3) kit.If(Info.Log != nil, func() { Info.Log(m, m.FormatPrefix(traceid), level, logs.Format(str, append(args, _source)...)) }) + if os.Getenv("TERM") == "" { + return m + } prefix, suffix := "", "" if Info.Colors { switch level {