diff --git a/Makefile b/Makefile index c32e8e49..c1ed62af 100644 --- a/Makefile +++ b/Makefile @@ -14,3 +14,8 @@ install: build: go build $(BENCH) + +win32: + GOARCH=386 GOOS=windows go build $(BENCH) +win64: + GOARCH=amd64 GOOS=windows go build $(BENCH) diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index 554e77da..c6294efc 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -740,6 +740,27 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", } // }}} }}, + "system": &ctx.Command{Name: "system word", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { + cmd := exec.Command(arg[0], arg[1:]...) + + if false { + cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr + if e := cmd.Start(); e != nil { + m.Echo("error: ") + m.Echo("%s\n", e) + } else if e := cmd.Wait(); e != nil { + m.Echo("error: ") + m.Echo("%s\n", e) + } + } else { + if out, e := cmd.CombinedOutput(); e != nil { + m.Echo("error: ") + m.Echo("%s\n", e) + } else { + m.Echo(string(out)) + } + } + }}, "login": &ctx.Command{Name: "login username password", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { m.Sess("aaa", false).Cmd("login", arg[0], arg[1]) }}, diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index 4b60bc3e..88afd5f9 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -15,6 +15,7 @@ import ( // {{{ "os" "os/exec" "path" + "runtime" "strconv" "strings" "unicode" @@ -211,6 +212,11 @@ func (nfs *NFS) print(str string) bool { // {{{ // }}} func (nfs *NFS) prompt(arg ...string) string { // {{{ + ps := nfs.Option("prompt") + if nfs.Caps("windows") { + nfs.color(ps) + return ps + } line, rest := "", "" if len(arg) > 0 { line = arg[0] @@ -226,7 +232,6 @@ func (nfs *NFS) prompt(arg ...string) string { // {{{ nfs.escape("2K").escape("G").escape("?25h") } - ps := nfs.Option("prompt") if len(nfs.pages) > 0 { nfs.pages = nfs.pages[:len(nfs.pages)-1] } @@ -585,26 +590,35 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{ m.Capi("size", int(s.Size())) if m.Cap("stream", arg[1]) == "stdio" { - termbox.Init() - defer termbox.Close() - nfs.width, nfs.height = termbox.Size() - nfs.Cap("termbox", "true") - nfs.Conf("color", "true") nfs.out = m.Optionv("out").(*os.File) + if !m.Caps("windows", runtime.GOOS == "windows") { + termbox.Init() + defer termbox.Close() + nfs.width, nfs.height = termbox.Size() + nfs.Cap("termbox", "true") + nfs.Conf("color", "true") + } for _, v := range []string{ - "say you are so pretty", + // "say you are so pretty", "context web serve ./ :9094", - // "context web right add shy command /upload dir usr", - // "open 'http://localhost:9094/'", } { m.Back(m.Spawn(m.Source()).Set("detail", v)) } - nfs.history = append(nfs.history, "open 'http://localhost:9094'") - m.Capi("nline", 1) - nfs.print(fmt.Sprintf("your are so pretty\n")) - nfs.print(fmt.Sprintf("your can open 'http://localhost:9094'\n")) - nfs.print(fmt.Sprintf("press C-P then C-J\n")) + for _, v := range []string{ + "say you are so pretty", + "context web brow 'http://localhost:9094'", + } { + nfs.history = append(nfs.history, v) + m.Capi("nline", 1) + } + for _, v := range []string{ + "say you are so pretty\n", + "your can brow 'http://localhost:9094'\n", + "press \"brow\" then press Enter\n", + } { + nfs.print(fmt.Sprintf(v)) + } } line := "" diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 5b7835ea..0e45b7dd 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -3,6 +3,7 @@ package web // {{{ import ( // {{{ "contexts" "regexp" + "runtime" "strconv" "toolkit" @@ -902,6 +903,21 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", msg.Cmd("get", "method", "POST", "evaluating_add/", "questions", qs) m.Add("append", "hi", "hello") }}, + "brow": &ctx.Command{Name: "brow url", Help: "浏览器网页", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { + url := fmt.Sprintf("http://localhost:9094") + if len(arg) > 0 { + url = arg[0] + } + m.Log("fucK", "os %v", runtime.GOOS) + switch runtime.GOOS { + case "windows": + m.Find("cli").Cmd("system", "explorer", url) + case "darwin": + m.Find("cli").Cmd("system", "open", url) + case "linux": + m.Spawn().Cmd("open", url) + } + }}, }, }