1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-25 17:18:05 +08:00
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"
"os/exec" "os/exec"
"path" "path"
"runtime"
"strings" "strings"
"syscall"
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa" "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.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)) }) 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 return cmd
} }
func _system_out(m *ice.Message, out string) io.Writer { func _system_out(m *ice.Message, out string) io.Writer {

View File

@ -3,6 +3,7 @@ package web
import ( import (
"net/http" "net/http"
"net/url" "net/url"
"os"
"path" "path"
"regexp" "regexp"
"runtime" "runtime"
@ -232,6 +233,8 @@ func init() {
tcp.HOST: {Help: "公网", Hand: func(m *ice.Message, arg ...string) { m.Echo(kit.Formats(PublicIP(m))) }}, 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.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) { 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 { 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(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) m.Cmd("", PROXY_CONF, ice.Info.NodeName)
@ -240,7 +243,7 @@ func init() {
}}, }},
SERVE_START: {Hand: func(m *ice.Message, arg ...string) { SERVE_START: {Hand: func(m *ice.Message, arg ...string) {
kit.If(m.Option(ice.DEMO) == ice.TRUE, func() { m.Cmd(CHAT_HEADER, ice.DEMO) }) 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.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) { m.Cmds(SPIDE).Table(func(value ice.Maps) {
kit.If(value[CLIENT_NAME] != ice.OPS && value[TOKEN] != "", func() { 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() 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 { func Run(arg ...string) string {
kit.If(len(arg) == 0 && len(os.Args) > 1, func() { arg = os.Args[1:] }) 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) }) kit.If(len(arg) == 0, func() { arg = append(arg, FOREVER, START) })
@ -115,6 +119,10 @@ func Run(arg ...string) string {
_forever = true _forever = true
logs.Disable(false) logs.Disable(false)
Pulse.Go(func() { Index.Start(Pulse, arg...) }) Pulse.Go(func() { Index.Start(Pulse, arg...) })
switch cb := Pulse.Optionv("main.routine").(type) {
case func():
cb()
}
conf.Wait() conf.Wait()
os.Exit(kit.Int(Pulse.Option(EXIT))) os.Exit(kit.Int(Pulse.Option(EXIT)))
default: default:

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"os"
"runtime" "runtime"
"strings" "strings"
"time" "time"
@ -65,6 +66,9 @@ func (m *Message) log(level string, str string, arg ...Any) *Message {
} }
_source := logs.FileLineMeta(3) _source := logs.FileLineMeta(3)
kit.If(Info.Log != nil, func() { Info.Log(m, m.FormatPrefix(traceid), level, logs.Format(str, append(args, _source)...)) }) 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 := "", "" prefix, suffix := "", ""
if Info.Colors { if Info.Colors {
switch level { switch level {