mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 01:04:06 +08:00
mac add code.counter
This commit is contained in:
parent
8a9f29878c
commit
d22cf113a6
@ -166,14 +166,19 @@ endfunction
|
||||
call ColorNext()
|
||||
command! NN call ColorNext()<CR>
|
||||
|
||||
" autocmd BufWritePost * call NCount("/home/shaoying/.nwrite")
|
||||
" autocmd BufReadPost * call NCount("/home/shaoying/.nread")
|
||||
function! NCount(filename)
|
||||
let l:lines = readfile(a:filename)
|
||||
if len(l:lines) == 0
|
||||
let l:lines = [0]
|
||||
endif
|
||||
let l:nwrite = l:lines[0] + 1
|
||||
call writefile([l:nwrite], a:filename)
|
||||
" function! NCount(filename)
|
||||
" let l:filename = expand(a:filename)
|
||||
" call writefile([exists(l:filename) ? 1: readfile(l:filename)[0]+1], l:filename)
|
||||
" endfunction
|
||||
" autocmd BufReadPost * call NCount("~/.nread")
|
||||
" autocmd BufReadPost * call NCount("~/.nwrite")
|
||||
"
|
||||
|
||||
let g:bench_code = "http://localhost:9094/code/"
|
||||
function! BenchCode(path, args)
|
||||
exe "silent !bench web.get " . g:bench_code . a:path . " " . join(a:args, " ")
|
||||
endfunction
|
||||
|
||||
autocmd FileReadPost * call BenchCode("counter", ["name", "nopen", "count", 1])
|
||||
autocmd FileWritePost * call BenchCode("counter", ["name", "nsave", "count", 1])
|
||||
"}}}
|
||||
|
@ -2,8 +2,6 @@ package cli
|
||||
|
||||
import (
|
||||
"contexts/ctx"
|
||||
"io/ioutil"
|
||||
"syscall"
|
||||
"toolkit"
|
||||
|
||||
"fmt"
|
||||
@ -32,6 +30,57 @@ type CLI struct {
|
||||
*ctx.Context
|
||||
}
|
||||
|
||||
func init_yac(m *ctx.Message) *ctx.Message {
|
||||
yac := m.Sess("yac")
|
||||
if yac.Cap("status") != "start" {
|
||||
yac.Target().Start(yac)
|
||||
yac.Cmd("train", "void", "void", "[\t ]+")
|
||||
|
||||
yac.Cmd("train", "key", "key", "[A-Za-z_][A-Za-z_0-9]*")
|
||||
yac.Cmd("train", "num", "num", "mul{", "0", "-?[1-9][0-9]*", "0[0-9]+", "0x[0-9]+", "}")
|
||||
yac.Cmd("train", "str", "str", "mul{", "\"[^\"]*\"", "'[^']*'", "}")
|
||||
yac.Cmd("train", "exe", "exe", "mul{", "$", "@", "}", "key")
|
||||
|
||||
yac.Cmd("train", "op1", "op1", "mul{", "-z", "-n", "}")
|
||||
yac.Cmd("train", "op1", "op1", "mul{", "-e", "-f", "-d", "}")
|
||||
yac.Cmd("train", "op1", "op1", "mul{", "-", "+", "}")
|
||||
yac.Cmd("train", "op2", "op2", "mul{", ":=", "=", "+=", "}")
|
||||
yac.Cmd("train", "op2", "op2", "mul{", "+", "-", "*", "/", "%", "}")
|
||||
yac.Cmd("train", "op2", "op2", "mul{", "<", "<=", ">", ">=", "==", "!=", "}")
|
||||
yac.Cmd("train", "op2", "op2", "mul{", "~", "!~", "}")
|
||||
|
||||
yac.Cmd("train", "val", "val", "opt{", "op1", "}", "mul{", "num", "key", "str", "exe", "}")
|
||||
yac.Cmd("train", "exp", "exp", "val", "rep{", "op2", "val", "}")
|
||||
yac.Cmd("train", "map", "map", "key", ":", "\\[", "rep{", "key", "}", "\\]")
|
||||
yac.Cmd("train", "exp", "exp", "\\{", "rep{", "map", "}", "\\}")
|
||||
yac.Cmd("train", "val", "val", "opt{", "op1", "}", "(", "exp", ")")
|
||||
|
||||
yac.Cmd("train", "stm", "var", "var", "key", "opt{", "=", "exp", "}")
|
||||
yac.Cmd("train", "stm", "let", "let", "key", "opt{", "=", "exp", "}")
|
||||
yac.Cmd("train", "stm", "var", "var", "key", "<-")
|
||||
yac.Cmd("train", "stm", "var", "var", "key", "<-", "opt{", "exe", "}")
|
||||
yac.Cmd("train", "stm", "let", "let", "key", "<-", "opt{", "exe", "}")
|
||||
|
||||
yac.Cmd("train", "stm", "if", "if", "exp")
|
||||
yac.Cmd("train", "stm", "else", "else")
|
||||
yac.Cmd("train", "stm", "end", "end")
|
||||
yac.Cmd("train", "stm", "for", "for", "opt{", "exp", ";", "}", "exp")
|
||||
yac.Cmd("train", "stm", "for", "for", "index", "exp", "opt{", "exp", "}", "exp")
|
||||
yac.Cmd("train", "stm", "label", "label", "exp")
|
||||
yac.Cmd("train", "stm", "goto", "goto", "exp", "opt{", "exp", "}", "exp")
|
||||
|
||||
yac.Cmd("train", "stm", "echo", "echo", "rep{", "exp", "}")
|
||||
yac.Cmd("train", "stm", "return", "return", "rep{", "exp", "}")
|
||||
|
||||
yac.Cmd("train", "word", "word", "mul{", "~", "!", "=", "\\?\\?", "\\?", "<", ">$", ">@", ">", "\\|", "%", "exe", "str", "[a-zA-Z0-9_/\\-.:]+", "}")
|
||||
yac.Cmd("train", "cmd", "cmd", "rep{", "word", "}")
|
||||
yac.Cmd("train", "exe", "exe", "$", "(", "cmd", ")")
|
||||
|
||||
yac.Cmd("train", "line", "line", "opt{", "mul{", "stm", "cmd", "}", "}", "mul{", ";", "\n", "#[^\n]*\n", "}")
|
||||
}
|
||||
return yac
|
||||
}
|
||||
|
||||
func (cli *CLI) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server {
|
||||
c.Caches = map[string]*ctx.Cache{
|
||||
"level": &ctx.Cache{Name: "level", Value: "0", Help: "嵌套层级"},
|
||||
@ -342,8 +391,8 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
|
||||
m.Target().Message().Set("result").Set("append").Copy(msg, "result").Copy(msg, "append")
|
||||
m.Copy(msg, "result").Copy(msg, "append")
|
||||
m.Capi("last_msg", 0, msg.Code())
|
||||
m.Capi("ps_count", 1)
|
||||
// m.Capi("last_msg", 0, msg.Code())
|
||||
// m.Capi("ps_count", 1)
|
||||
}
|
||||
}},
|
||||
"str": &ctx.Command{Name: "str word", Help: "解析字符串", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
@ -577,53 +626,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
m.Add("append", "return", arg[1:])
|
||||
}},
|
||||
"source": &ctx.Command{Name: "source [stdio [init.shy [exit.shy]]]|[filename [async]]|string", Help: "解析脚本, filename: 文件名, async: 异步执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
yac := m.Sess("yac")
|
||||
if yac.Cap("status") != "start" {
|
||||
yac.Target().Start(yac)
|
||||
yac.Cmd("train", "void", "void", "[\t ]+")
|
||||
|
||||
yac.Cmd("train", "key", "key", "[A-Za-z_][A-Za-z_0-9]*")
|
||||
yac.Cmd("train", "num", "num", "mul{", "0", "-?[1-9][0-9]*", "0[0-9]+", "0x[0-9]+", "}")
|
||||
yac.Cmd("train", "str", "str", "mul{", "\"[^\"]*\"", "'[^']*'", "}")
|
||||
yac.Cmd("train", "exe", "exe", "mul{", "$", "@", "}", "key")
|
||||
|
||||
yac.Cmd("train", "op1", "op1", "mul{", "-z", "-n", "}")
|
||||
yac.Cmd("train", "op1", "op1", "mul{", "-e", "-f", "-d", "}")
|
||||
yac.Cmd("train", "op1", "op1", "mul{", "-", "+", "}")
|
||||
yac.Cmd("train", "op2", "op2", "mul{", ":=", "=", "+=", "}")
|
||||
yac.Cmd("train", "op2", "op2", "mul{", "+", "-", "*", "/", "%", "}")
|
||||
yac.Cmd("train", "op2", "op2", "mul{", "<", "<=", ">", ">=", "==", "!=", "}")
|
||||
yac.Cmd("train", "op2", "op2", "mul{", "~", "!~", "}")
|
||||
|
||||
yac.Cmd("train", "val", "val", "opt{", "op1", "}", "mul{", "num", "key", "str", "exe", "}")
|
||||
yac.Cmd("train", "exp", "exp", "val", "rep{", "op2", "val", "}")
|
||||
yac.Cmd("train", "map", "map", "key", ":", "\\[", "rep{", "key", "}", "\\]")
|
||||
yac.Cmd("train", "exp", "exp", "\\{", "rep{", "map", "}", "\\}")
|
||||
yac.Cmd("train", "val", "val", "opt{", "op1", "}", "(", "exp", ")")
|
||||
|
||||
yac.Cmd("train", "stm", "var", "var", "key", "opt{", "=", "exp", "}")
|
||||
yac.Cmd("train", "stm", "let", "let", "key", "opt{", "=", "exp", "}")
|
||||
yac.Cmd("train", "stm", "var", "var", "key", "<-")
|
||||
yac.Cmd("train", "stm", "var", "var", "key", "<-", "opt{", "exe", "}")
|
||||
yac.Cmd("train", "stm", "let", "let", "key", "<-", "opt{", "exe", "}")
|
||||
|
||||
yac.Cmd("train", "stm", "if", "if", "exp")
|
||||
yac.Cmd("train", "stm", "else", "else")
|
||||
yac.Cmd("train", "stm", "end", "end")
|
||||
yac.Cmd("train", "stm", "for", "for", "opt{", "exp", ";", "}", "exp")
|
||||
yac.Cmd("train", "stm", "for", "for", "index", "exp", "opt{", "exp", "}", "exp")
|
||||
yac.Cmd("train", "stm", "label", "label", "exp")
|
||||
yac.Cmd("train", "stm", "goto", "goto", "exp", "opt{", "exp", "}", "exp")
|
||||
|
||||
yac.Cmd("train", "stm", "echo", "echo", "rep{", "exp", "}")
|
||||
yac.Cmd("train", "stm", "return", "return", "rep{", "exp", "}")
|
||||
|
||||
yac.Cmd("train", "word", "word", "mul{", "~", "!", "=", "\\?\\?", "\\?", "<", ">$", ">@", ">", "\\|", "%", "exe", "str", "[a-zA-Z0-9_/\\-.:]+", "}")
|
||||
yac.Cmd("train", "cmd", "cmd", "rep{", "word", "}")
|
||||
yac.Cmd("train", "exe", "exe", "$", "(", "cmd", ")")
|
||||
|
||||
yac.Cmd("train", "line", "line", "opt{", "mul{", "stm", "cmd", "}", "}", "mul{", ";", "\n", "#[^\n]*\n", "}")
|
||||
}
|
||||
init_yac(m)
|
||||
|
||||
if arg[0] != "stdio" {
|
||||
if !m.Sess("nfs").Cmd("path", arg[0]).Results(0) {
|
||||
@ -633,7 +636,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
m.Set("append").Copy(msg, "append").Set("result").Copy(msg, "result")
|
||||
}
|
||||
return nil
|
||||
}, "parse", "line", "void", arg)
|
||||
}, "parse", "line", "void", strings.Join(arg, " "))
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -862,32 +865,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
}
|
||||
}
|
||||
}},
|
||||
"sysinfo": &ctx.Command{Name: "sysinfo", Help: "sysinfo", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
sys := &syscall.Sysinfo_t{}
|
||||
syscall.Sysinfo(sys)
|
||||
|
||||
d, e := time.ParseDuration(fmt.Sprintf("%ds", sys.Uptime))
|
||||
m.Assert(e)
|
||||
m.Append("NumCPU", runtime.NumCPU())
|
||||
m.Append("uptime", d)
|
||||
m.Append("procs", sys.Procs)
|
||||
|
||||
m.Append("total", kit.FmtSize(sys.Totalram))
|
||||
m.Append("free", kit.FmtSize(sys.Freeram))
|
||||
m.Append("mper", fmt.Sprintf("%d%%", sys.Freeram*100/sys.Totalram))
|
||||
|
||||
fs := &syscall.Statfs_t{}
|
||||
syscall.Statfs("./", fs)
|
||||
m.Append("blocks", kit.FmtSize(fs.Blocks*uint64(fs.Bsize)))
|
||||
m.Append("bavail", kit.FmtSize(fs.Bavail*uint64(fs.Bsize)))
|
||||
m.Append("bper", fmt.Sprintf("%d%%", fs.Bavail*100/fs.Blocks))
|
||||
|
||||
m.Append("files", fs.Files)
|
||||
m.Append("ffree", fs.Ffree)
|
||||
m.Append("fper", fmt.Sprintf("%d%%", fs.Ffree*100/fs.Files))
|
||||
|
||||
m.Table()
|
||||
}},
|
||||
"sysinfo": &ctx.Command{Name: "sysinfo", Help: "sysinfo", Hand: sysinfo},
|
||||
"runtime": &ctx.Command{Name: "runtime", Help: "runtime", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
mem := &runtime.MemStats{}
|
||||
runtime.ReadMemStats(mem)
|
||||
@ -914,10 +892,6 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
m.Append("ncommand", strings.Count(m.Spawn().Cmd("system", "tmux", "list-commands").Result(0), "\n"))
|
||||
m.Append("nkey", strings.Count(m.Spawn().Cmd("system", "tmux", "list-keys").Result(0), "\n"))
|
||||
m.Append("nbuffer", strings.Count(m.Spawn().Cmd("system", "tmux", "list-buffers").Result(0), "\n"))
|
||||
nw, _ := ioutil.ReadFile("var/.nwrite")
|
||||
m.Append("nwrite", string(nw))
|
||||
nr, _ := ioutil.ReadFile("var/.nread")
|
||||
m.Append("nread", string(nr))
|
||||
m.Table()
|
||||
}},
|
||||
|
||||
|
25
src/contexts/cli/cli_darwin.go
Normal file
25
src/contexts/cli/cli_darwin.go
Normal file
@ -0,0 +1,25 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"contexts/ctx"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"toolkit"
|
||||
)
|
||||
|
||||
func sysinfo(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
m.Append("NumCPU", runtime.NumCPU())
|
||||
|
||||
fs := &syscall.Statfs_t{}
|
||||
syscall.Statfs("./", fs)
|
||||
m.Append("blocks", kit.FmtSize(fs.Blocks*uint64(fs.Bsize)))
|
||||
m.Append("bavail", kit.FmtSize(fs.Bavail*uint64(fs.Bsize)))
|
||||
m.Append("bper", fmt.Sprintf("%d%%", fs.Bavail*100/fs.Blocks))
|
||||
|
||||
m.Append("files", fs.Files)
|
||||
m.Append("ffree", fs.Ffree)
|
||||
m.Append("fper", fmt.Sprintf("%d%%", fs.Ffree*100/fs.Files))
|
||||
|
||||
m.Table()
|
||||
}
|
36
src/contexts/cli/cli_linux.go
Normal file
36
src/contexts/cli/cli_linux.go
Normal file
@ -0,0 +1,36 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"contexts/ctx"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"toolkit"
|
||||
)
|
||||
|
||||
func sysinfo(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
sys := &syscall.Sysinfo_t{}
|
||||
syscall.Sysinfo(sys)
|
||||
|
||||
d, e := time.ParseDuration(fmt.Sprintf("%ds", sys.Uptime))
|
||||
m.Assert(e)
|
||||
m.Append("NumCPU", runtime.NumCPU())
|
||||
m.Append("uptime", d)
|
||||
m.Append("procs", sys.Procs)
|
||||
|
||||
m.Append("total", kit.FmtSize(sys.Totalram))
|
||||
m.Append("free", kit.FmtSize(sys.Freeram))
|
||||
m.Append("mper", fmt.Sprintf("%d%%", sys.Freeram*100/sys.Totalram))
|
||||
|
||||
fs := &syscall.Statfs_t{}
|
||||
syscall.Statfs("./", fs)
|
||||
m.Append("blocks", kit.FmtSize(fs.Blocks*uint64(fs.Bsize)))
|
||||
m.Append("bavail", kit.FmtSize(fs.Bavail*uint64(fs.Bsize)))
|
||||
m.Append("bper", fmt.Sprintf("%d%%", fs.Bavail*100/fs.Blocks))
|
||||
|
||||
m.Append("files", fs.Files)
|
||||
m.Append("ffree", fs.Ffree)
|
||||
m.Append("fper", fmt.Sprintf("%d%%", fs.Ffree*100/fs.Files))
|
||||
|
||||
m.Table()
|
||||
}
|
@ -3072,16 +3072,24 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||
switch val := value.(type) {
|
||||
case map[string]interface{}:
|
||||
for k, v := range val {
|
||||
m.Add("append", "key", k)
|
||||
m.Add("append", "value", v)
|
||||
m.Add("append", k, v)
|
||||
}
|
||||
m.Sort("key", "str").Table()
|
||||
m.Table()
|
||||
// for k, v := range val {
|
||||
// m.Add("append", "key", k)
|
||||
// m.Add("append", "value", v)
|
||||
// }
|
||||
// m.Sort("key", "str").Table()
|
||||
case map[string]string:
|
||||
for k, v := range val {
|
||||
m.Add("append", "key", k)
|
||||
m.Add("append", "value", v)
|
||||
m.Add("append", k, v)
|
||||
}
|
||||
m.Sort("key", "str").Table()
|
||||
m.Table()
|
||||
// for k, v := range val {
|
||||
// m.Add("append", "key", k)
|
||||
// m.Add("append", "value", v)
|
||||
// }
|
||||
// m.Sort("key", "str").Table()
|
||||
case []interface{}:
|
||||
for i, v := range val {
|
||||
switch value := v.(type) {
|
||||
@ -3343,23 +3351,35 @@ func Start(args ...string) {
|
||||
Pulse.Sess("yac", "yac")
|
||||
Pulse.Sess("cli", "cli")
|
||||
|
||||
Pulse.Sess("ssh", "ssh")
|
||||
Pulse.Sess("mdb", "mdb")
|
||||
Pulse.Sess("aaa", "aaa")
|
||||
Pulse.Sess("web", "web")
|
||||
Pulse.Sess("log", "log")
|
||||
|
||||
if len(args) > 0 {
|
||||
Pulse.Sess("cli", false).Conf("init.shy", args[0])
|
||||
args = args[1:]
|
||||
if _, e := os.Stat(args[0]); e == nil {
|
||||
Pulse.Sess("cli", false).Conf("init.shy", args[0])
|
||||
args = args[1:]
|
||||
}
|
||||
}
|
||||
if len(args) > 0 {
|
||||
Pulse.Sess("log", false).Conf("bench.log", args[0])
|
||||
args = args[1:]
|
||||
if _, e := os.Stat(args[0]); e == nil {
|
||||
Pulse.Sess("log", false).Conf("bench.log", args[0])
|
||||
args = args[1:]
|
||||
}
|
||||
}
|
||||
|
||||
Pulse.Options("log", true)
|
||||
log := Pulse.Sess("log", false)
|
||||
log.target.Start(log)
|
||||
if len(args) > 0 {
|
||||
cmd := Pulse.Sess("cli", false).Cmd("source", args)
|
||||
for _, v := range cmd.Meta["result"] {
|
||||
fmt.Printf("%v", v)
|
||||
}
|
||||
} else {
|
||||
Pulse.Options("log", true)
|
||||
log := Pulse.Sess("log", false)
|
||||
log.target.Start(log)
|
||||
|
||||
Pulse.Options("terminal_color", true)
|
||||
Pulse.Sess("cli", false).Cmd("source", "stdio")
|
||||
Pulse.Sess("cli", false).Cmd("source", "stdio")
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ func (log *LOG) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
||||
return log
|
||||
}
|
||||
func (log *LOG) Start(m *ctx.Message, arg ...string) bool {
|
||||
defer func() {
|
||||
e := recover()
|
||||
_ = e
|
||||
}()
|
||||
log.out = m.Sess("nfs").Cmd("open", m.Confx("bench.log", arg, 0)).Optionv("out").(*os.File)
|
||||
log.out.Truncate(0)
|
||||
fmt.Fprintln(log.out, "\n\n")
|
||||
|
@ -940,9 +940,11 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
"open": &ctx.Command{Name: "open file name", Help: "打开文件, file: 文件名, name: 模块名", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
file := arg[0]
|
||||
if m.Has("io") {
|
||||
} else if p, f, e := open(m, file, os.O_RDWR|os.O_CREATE); m.Assert(e) {
|
||||
} else if p, f, e := open(m, file, os.O_RDWR|os.O_CREATE); e == nil {
|
||||
m.Put("option", "in", f).Put("option", "out", f)
|
||||
file = p
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
m.Start(m.Confx("nfs_name", arg, 1), fmt.Sprintf("file %s", file), "open", file)
|
||||
|
@ -258,6 +258,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
},
|
||||
Configs: map[string]*ctx.Config{
|
||||
"login_right": &ctx.Config{Name: "login_right", Value: "1", Help: "缓存大小"},
|
||||
"log_uri": &ctx.Config{Name: "log_uri", Value: "false", Help: "缓存大小"},
|
||||
"multipart_bsize": &ctx.Config{Name: "multipart_bsize", Value: "102400", Help: "缓存大小"},
|
||||
"body_response": &ctx.Config{Name: "body_response", Value: "response", Help: "响应缓存"},
|
||||
"method": &ctx.Config{Name: "method", Value: "GET", Help: "请求方法"},
|
||||
@ -380,7 +381,9 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
}
|
||||
|
||||
m.Log("info", "%s %s", req.Method, req.URL)
|
||||
m.Echo("%s: %s\n", req.Method, req.URL)
|
||||
if m.Confs("log_uri") {
|
||||
m.Echo("%s: %s\n", req.Method, req.URL)
|
||||
}
|
||||
for k, v := range req.Header {
|
||||
m.Log("info", "%s: %s", k, v)
|
||||
}
|
||||
@ -389,6 +392,9 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
web.Client = &http.Client{}
|
||||
}
|
||||
res, e := web.Client.Do(req)
|
||||
if e != nil {
|
||||
return
|
||||
}
|
||||
m.Assert(e)
|
||||
|
||||
for _, v := range res.Cookies() {
|
||||
|
@ -3,11 +3,16 @@ package code
|
||||
import (
|
||||
"contexts/ctx"
|
||||
"contexts/web"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
Caches: map[string]*ctx.Cache{},
|
||||
Configs: map[string]*ctx.Config{
|
||||
"counter": &ctx.Config{Name: "counter", Value: map[string]interface{}{
|
||||
"nopen": "0", "nsave": "0",
|
||||
}, Help: "counter"},
|
||||
"web_site": &ctx.Config{Name: "web_site", Value: []interface{}{
|
||||
map[string]interface{}{"_name": "MDN", "site": "https://developer.mozilla.org"},
|
||||
map[string]interface{}{"_name": "github", "site": "https://github.com"},
|
||||
@ -57,6 +62,14 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"pre_run": true,
|
||||
"display_result": "",
|
||||
},
|
||||
map[string]interface{}{"name": "develop", "help": "develop", "template": "componet",
|
||||
"context": "web.code", "command": "config", "arguments": []interface{}{"counter"},
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||
},
|
||||
"pre_run": true,
|
||||
"display_result": "",
|
||||
},
|
||||
map[string]interface{}{"name": "clipbaord", "help": "clipbaord", "template": "clipboard"},
|
||||
map[string]interface{}{"name": "buffer", "help": "buffer", "template": "componet",
|
||||
"context": "cli", "command": "tmux", "arguments": []interface{}{"buffer"}, "inputs": []interface{}{
|
||||
@ -139,7 +152,20 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
},
|
||||
}, Help: "组件列表"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"/counter": &ctx.Command{Name: "/counter", Help: "/counter", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
if m.Has("name") && m.Has("count") {
|
||||
count := m.Optioni("count")
|
||||
switch v := m.Confv("counter", m.Option("name")).(type) {
|
||||
case string:
|
||||
i, e := strconv.Atoi(v)
|
||||
m.Assert(e)
|
||||
count += i
|
||||
}
|
||||
m.Log("info", "%v: %v", m.Option("name"), m.Confv("counter", m.Option("name"), fmt.Sprintf("%d", count)))
|
||||
}
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user