forked from x/ContextOS
mac add cli.system
This commit is contained in:
parent
5549683902
commit
e81cc507b5
5
Makefile
5
Makefile
@ -14,3 +14,8 @@ install:
|
|||||||
|
|
||||||
build:
|
build:
|
||||||
go build $(BENCH)
|
go build $(BENCH)
|
||||||
|
|
||||||
|
win32:
|
||||||
|
GOARCH=386 GOOS=windows go build $(BENCH)
|
||||||
|
win64:
|
||||||
|
GOARCH=amd64 GOOS=windows go build $(BENCH)
|
||||||
|
@ -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) {
|
"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])
|
m.Sess("aaa", false).Cmd("login", arg[0], arg[1])
|
||||||
}},
|
}},
|
||||||
|
@ -15,6 +15,7 @@ import ( // {{{
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
@ -211,6 +212,11 @@ func (nfs *NFS) print(str string) bool { // {{{
|
|||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
func (nfs *NFS) prompt(arg ...string) string { // {{{
|
func (nfs *NFS) prompt(arg ...string) string { // {{{
|
||||||
|
ps := nfs.Option("prompt")
|
||||||
|
if nfs.Caps("windows") {
|
||||||
|
nfs.color(ps)
|
||||||
|
return ps
|
||||||
|
}
|
||||||
line, rest := "", ""
|
line, rest := "", ""
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
line = arg[0]
|
line = arg[0]
|
||||||
@ -226,7 +232,6 @@ func (nfs *NFS) prompt(arg ...string) string { // {{{
|
|||||||
nfs.escape("2K").escape("G").escape("?25h")
|
nfs.escape("2K").escape("G").escape("?25h")
|
||||||
}
|
}
|
||||||
|
|
||||||
ps := nfs.Option("prompt")
|
|
||||||
if len(nfs.pages) > 0 {
|
if len(nfs.pages) > 0 {
|
||||||
nfs.pages = nfs.pages[:len(nfs.pages)-1]
|
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()))
|
m.Capi("size", int(s.Size()))
|
||||||
|
|
||||||
if m.Cap("stream", arg[1]) == "stdio" {
|
if m.Cap("stream", arg[1]) == "stdio" {
|
||||||
|
nfs.out = m.Optionv("out").(*os.File)
|
||||||
|
if !m.Caps("windows", runtime.GOOS == "windows") {
|
||||||
termbox.Init()
|
termbox.Init()
|
||||||
defer termbox.Close()
|
defer termbox.Close()
|
||||||
nfs.width, nfs.height = termbox.Size()
|
nfs.width, nfs.height = termbox.Size()
|
||||||
nfs.Cap("termbox", "true")
|
nfs.Cap("termbox", "true")
|
||||||
nfs.Conf("color", "true")
|
nfs.Conf("color", "true")
|
||||||
nfs.out = m.Optionv("out").(*os.File)
|
}
|
||||||
|
|
||||||
for _, v := range []string{
|
for _, v := range []string{
|
||||||
"say you are so pretty",
|
// "say you are so pretty",
|
||||||
"context web serve ./ :9094",
|
"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))
|
m.Back(m.Spawn(m.Source()).Set("detail", v))
|
||||||
}
|
}
|
||||||
nfs.history = append(nfs.history, "open 'http://localhost:9094'")
|
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)
|
m.Capi("nline", 1)
|
||||||
nfs.print(fmt.Sprintf("your are so pretty\n"))
|
}
|
||||||
nfs.print(fmt.Sprintf("your can open 'http://localhost:9094'\n"))
|
for _, v := range []string{
|
||||||
nfs.print(fmt.Sprintf("press C-P then C-J\n"))
|
"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 := ""
|
line := ""
|
||||||
|
@ -3,6 +3,7 @@ package web // {{{
|
|||||||
import ( // {{{
|
import ( // {{{
|
||||||
"contexts"
|
"contexts"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"toolkit"
|
"toolkit"
|
||||||
|
|
||||||
@ -902,6 +903,21 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
msg.Cmd("get", "method", "POST", "evaluating_add/", "questions", qs)
|
msg.Cmd("get", "method", "POST", "evaluating_add/", "questions", qs)
|
||||||
m.Add("append", "hi", "hello")
|
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)
|
||||||
|
}
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user