diff --git a/base/cli/daemon.go b/base/cli/daemon.go index 9d7ad9da..ee09ae46 100644 --- a/base/cli/daemon.go +++ b/base/cli/daemon.go @@ -86,6 +86,7 @@ const ( RELOAD = "reload" RESTART = "restart" + DELAY = "delay" BEGIN = "begin" START = "start" OPEN = "open" diff --git a/base/cli/forever.go b/base/cli/forever.go index 8b92c279..47db66bc 100644 --- a/base/cli/forever.go +++ b/base/cli/forever.go @@ -48,6 +48,7 @@ func init() { }}, RESTART: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(gdb.SIGNAL, gdb.RESTART) }}, STOP: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(gdb.SIGNAL, gdb.STOP) }}, + DELAY: {Hand: func(m *ice.Message, arg ...string) { m.Sleep(arg[0]).Cmdy(arg[1:]) }}, }, Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 { m.Cmdy(RUNTIME, BOOTINFO) diff --git a/base/log/debug.go b/base/log/debug.go new file mode 100644 index 00000000..da0bb3f3 --- /dev/null +++ b/base/log/debug.go @@ -0,0 +1,73 @@ +package log + +import ( + "strings" + + ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/ctx" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/nfs" + kit "shylinux.com/x/toolkits" +) + +const DEBUG = "debug" + +func init() { + Index.MergeCommands(ice.Commands{ + DEBUG: {Name: "debug level=watch,bench,watch,error,trace offset filter auto doc", Help: "后台日志", Actions: ice.Actions{ + "doc": {Help: "文档", Hand: func(m *ice.Message, arg ...string) { m.ProcessOpen("https://pkg.go.dev/std") }}, + }, Hand: func(m *ice.Message, arg ...string) { + offset := kit.Int(kit.Select("0", arg, 1)) + switch arg[0] { + case "bench", ERROR, "trace": + m.Cmd(nfs.CAT, ice.VAR_LOG+arg[0]+".log", func(line string, index int) { + if len(arg) > 2 && !strings.Contains(line, arg[2]) || index < offset { + return + } + ls := strings.SplitN(line, ice.SP, 6) + m.Push(mdb.TIME, ls[0]+ice.SP+ls[1]) + m.Push(mdb.ID, ls[2]) + m.Push("ship", ls[3]) + + i := strings.LastIndex(ls[5], ice.SP) + if strings.HasPrefix(ls[5][i+1:], "base") || strings.HasPrefix(ls[5][i+1:], "core") || strings.HasPrefix(ls[5][i+1:], "misc") { + m.Push(nfs.PATH, ice.USR_ICEBERGS) + m.Push(nfs.FILE, strings.TrimSpace(strings.Split(ls[5][i:], ice.DF)[0])) + m.Push(nfs.LINE, strings.TrimSpace(strings.Split(ls[5][i:], ice.DF)[1])) + ls[5] = ls[5][:i] + } else if strings.HasPrefix(ls[5][i+1:], "usr/icebergs/") { + m.Push(nfs.PATH, ice.USR_ICEBERGS) + m.Push(nfs.FILE, strings.TrimPrefix(strings.TrimSpace(strings.Split(ls[5][i:], ice.DF)[0]), ice.USR_ICEBERGS)) + m.Push(nfs.LINE, strings.TrimSpace(strings.Split(ls[5][i:], ice.DF)[1])) + ls[5] = ls[5][:i] + } else { + m.Push(nfs.PATH, ice.USR_ICEBERGS) + m.Push(nfs.FILE, "init.go") + m.Push(nfs.LINE, "90") + } + m.Push(ctx.ACTION, ls[4]) + m.Push(mdb.TEXT, ls[5]) + }) + case WATCH: + m.Cmd(nfs.CAT, ice.VAR_LOG+arg[0]+".log", func(line string, index int) { + if len(arg) > 2 && !strings.Contains(line, arg[2]) || index < offset { + return + } + ls := strings.SplitN(line, ice.SP, 6) + m.Push(mdb.TIME, ls[0]+ice.SP+ls[1]) + m.Push(mdb.ID, ls[2]) + m.Push("ship", ls[3]) + + i := strings.LastIndex(ls[5], ice.SP) + m.Push(nfs.PATH, ice.USR_ICEBERGS) + m.Push(nfs.FILE, strings.TrimSpace(strings.Split(ls[5][i:], ice.DF)[0])) + m.Push(nfs.LINE, strings.TrimSpace(strings.Split(ls[5][i:], ice.DF)[1])) + + m.Push(ctx.ACTION, ls[4]) + m.Push(mdb.TEXT, ls[5][:i]) + }) + } + m.StatusTimeCountTotal(offset + m.Length()) + }}, + }) +} diff --git a/conf.go b/conf.go index 89a841c4..be5b99c9 100644 --- a/conf.go +++ b/conf.go @@ -144,6 +144,7 @@ const ( // DIR SRC_MAIN_GO = "src/main.go" SRC_VERSION_GO = "src/version.go" SRC_BINPACK_GO = "src/binpack.go" + SRC_WEBVIEW_GO = "src/webview.go" SRC_RELAY_GO = "src/relay.go" README_MD = "README.md" MAKEFILE = "Makefile" diff --git a/core/code/js.go b/core/code/js.go index 415ba510..959276ff 100644 --- a/core/code/js.go +++ b/core/code/js.go @@ -10,6 +10,7 @@ import ( "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" + "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" ) @@ -74,9 +75,13 @@ func _js_show(m *ice.Message, arg ...string) { m.StatusTimeCount() } func _js_exec(m *ice.Message, arg ...string) { - if arg[2] == "usr/volcanos/" && strings.HasPrefix(arg[1], "plugin/local/") { - key := "web." + strings.Replace(strings.TrimSuffix(strings.TrimPrefix(arg[1], "plugin/local/"), ".js"), ice.PS, ice.PT, -1) - ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, key), kit.Simple()) + if arg[2] == ice.USR_VOLCANOS { + if strings.HasPrefix(arg[1], "plugin/local/") { + key := "web." + strings.Replace(strings.TrimSuffix(strings.TrimPrefix(arg[1], "plugin/local/"), ".js"), ice.PS, ice.PT, -1) + ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, key), kit.Simple()) + } else { + m.EchoIFrame(web.MergeURL2(m, "/chat/cmd/web.code.vimer", "debug", "true")) + } return } ctx.DisplayBase(m, path.Join("/require", path.Join(arg[2], arg[1]))) diff --git a/core/code/vimer.go b/core/code/vimer.go index 25e1d672..500ec207 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -63,6 +63,10 @@ func init() { switch arg[0] { case ctx.INDEX: m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, ice.OptionFields(ctx.INDEX)) + case ctx.ARGS: + if m.Option(ctx.INDEX) != "" { + m.Cmdy(m.Option(ctx.INDEX)) + } case nfs.PATH: m.Cmdy(INNER, mdb.INPUTS, arg).Cut("path,size,time") case nfs.FILE: @@ -159,13 +163,18 @@ func init() { m.Cmdy(AUTOGEN, nfs.MODULE, arg) }}, COMPILE: {Help: "编译", Hand: func(m *ice.Message, arg ...string) { + const app, _app = "usr/publish/contexts.app", "Contents/MacOS/contexts" + isWebview := func() bool { return strings.HasSuffix(os.Args[0], _app) } cmds := []string{COMPILE, ice.SRC_MAIN_GO, ice.BIN_ICE_BIN} - if strings.HasSuffix(os.Args[0], "contexts.app/Contents/MacOS/contexts") { - m.Option(cli.ENV, "CGO_ENABLED", "1", cli.HOME, kit.Env(cli.HOME), cli.PATH, kit.Path("usr/local/go/bin")+ice.DF+kit.Env(cli.PATH)) - cmds = []string{COMPILE, "src/webview.go", "usr/publish/contexts.app/Contents/MacOS/contexts"} + if isWebview() { + m.Option(cli.ENV, "CGO_ENABLED", "1", cli.HOME, kit.Env(cli.HOME), cli.PATH, kit.Path(ice.USR_LOCAL_GO_BIN)+ice.DF+kit.Env(cli.PATH)) + cmds = []string{COMPILE, ice.SRC_WEBVIEW_GO, path.Join(app, _app)} } if msg := m.Cmd(cmds); cli.IsSuccess(msg) { - m.Cmd(UPGRADE, cli.RESTART) + if isWebview() { + m.Go(func() { m.Cmd(cli.SYSTEM, "./bin/ice.bin", cli.FOREVER, cli.DELAY, "300ms", cli.SYSTEM, cli.OPEN, app) }) + } + m.Go(func() { m.Sleep("10ms").Cmd(UPGRADE, cli.RESTART) }) } else { _vimer_make(m, nfs.PWD, msg) }