1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2024-04-21 16:27:38 +08:00
parent b980d48390
commit b3959aa68d
4 changed files with 21 additions and 1 deletions

View File

@ -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 {

View File

@ -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() {

View File

@ -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:

View File

@ -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 {