forked from x/ContextOS
add code.dream
This commit is contained in:
parent
9a43ee0e40
commit
dd882b96fd
@ -79,6 +79,14 @@ ShySend() {
|
||||
${ctx_curl} -s "${ctx_url}" -F "cmd=sync" -F "arg=$1" -F "args=$*" -F "sub=@$TEMP"\
|
||||
-F "SHELL=${SHELL}" -F "pwd=${PWD}" -F "sid=${ctx_sid}"
|
||||
}
|
||||
ShySends() {
|
||||
local cmd=$1 && shift
|
||||
local arg=$2 && shift
|
||||
local TEMP=`mktemp /tmp/tmp.XXXXXX` && echo "$@" > $TEMP
|
||||
ShyRight "$ctx_silent" || cat $TEMP
|
||||
${ctx_curl} -s "${ctx_url}" -F "cmd=$cmd" -F "arg=$arg" -F "sub=@$TEMP" \
|
||||
-F "SHELL=${SHELL}" -F "pwd=${PWD}" -F "sid=${ctx_sid}"
|
||||
}
|
||||
ShyRun() {
|
||||
ctx_silent=false ShySend "$@"
|
||||
}
|
||||
@ -122,9 +130,7 @@ ShySync() {
|
||||
ctx_tail=`expr $ctx_end - $ctx_begin`
|
||||
ShyEcho "sync $ctx_begin-$ctx_end count $ctx_tail to $ctx_dev"
|
||||
history|tail -n $ctx_tail |while read line; do
|
||||
line=`ShyLine $line`
|
||||
ShyPost arg "$line" cmd historys FORMAT "$HISTTIMEFORMAT"
|
||||
ShyEcho $line
|
||||
ShySends historys sub "$line"
|
||||
done
|
||||
ctx_begin=$ctx_end
|
||||
;;
|
||||
|
@ -27,5 +27,5 @@
|
||||
# 终端配置
|
||||
~cli
|
||||
|
||||
~code
|
||||
~wiki
|
||||
~code
|
||||
|
@ -69,7 +69,7 @@ func format(m *ctx.Message, out *bytes.Buffer) {
|
||||
}
|
||||
m.Table()
|
||||
case "cut":
|
||||
c := byte(kit.Select(" ", m.Optionv("cmd_parse"), 1)[0])
|
||||
c := rune(kit.Select(" ", m.Optionv("cmd_parse"), 1)[0])
|
||||
|
||||
bio := bufio.NewScanner(out)
|
||||
|
||||
@ -254,6 +254,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
}, Help: "服务升级"},
|
||||
"missyou": &ctx.Config{Name: "missyou", Value: map[string]interface{}{
|
||||
"path": "usr/local/work",
|
||||
"local": "usr/local",
|
||||
}, Help: "任务管理"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
@ -1216,6 +1217,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
switch kit.Select("", arg, 1) {
|
||||
case "stop":
|
||||
m.Cmdy("ssh._route", arg[0], "context", "cli", "quit", 0)
|
||||
m.Cmd("web.code.dream", "exit", arg[0])
|
||||
default:
|
||||
m.Echo(arg[0])
|
||||
}
|
||||
@ -1241,6 +1243,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
|
||||
// 启动服务
|
||||
m.Cmdy("cli.system", path.Join(m.Conf("runtime", "boot.ctx_home"), "bin/node.sh"), "start", args)
|
||||
m.Cmd("web.code.dream", "init", arg[0], kit.Select(topic, arg, 1))
|
||||
return
|
||||
}},
|
||||
"version": &ctx.Command{Name: "version", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
|
@ -522,7 +522,9 @@ func (m *Message) Grow(key string, args interface{}, data interface{}) interface
|
||||
|
||||
name := kit.Select(m.Option("cache.store"), meta["store"])
|
||||
f, e := os.OpenFile(name, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)
|
||||
m.Assert(e)
|
||||
if e != nil {
|
||||
f, _, e = kit.Create(name)
|
||||
}
|
||||
defer f.Close()
|
||||
s, e := f.Stat()
|
||||
m.Assert(e)
|
||||
|
@ -331,7 +331,7 @@ func (m *Message) Sort(key string, arg ...string) *Message {
|
||||
return m
|
||||
}
|
||||
func (m *Message) Split(str string, arg ...string) *Message {
|
||||
c := byte(kit.Select(" ", arg, 0)[0])
|
||||
c := rune(kit.Select(" ", arg, 0)[0])
|
||||
lines := strings.Split(str, "\n")
|
||||
|
||||
pos := []int{}
|
||||
|
@ -351,7 +351,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
msg.Option("river", arg[3])
|
||||
msg.Option("storm", arg[1])
|
||||
kit.Map(tool["inputs"], "", func(index int, value map[string]interface{}) {
|
||||
if name := kit.Format(value["name"]); name != "" {
|
||||
if name := kit.Format(value["name"]); name != "" && m.Option(name) != "" {
|
||||
m.Log("info", "%v: %v", name, m.Option(name))
|
||||
msg.Option(name, m.Option(name))
|
||||
}
|
||||
@ -571,6 +571,9 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
m.Cmdy("ssh.data", "save", arg[1])
|
||||
|
||||
case "update":
|
||||
if arg[2] == "" {
|
||||
break
|
||||
}
|
||||
offset := m.Confi("flow", []string{m.Option("river"), "data", arg[1], "meta", "offset"})
|
||||
index := kit.Int(arg[2]) - 1 - offset
|
||||
table, prefix, arg := arg[1], "", arg[3:]
|
||||
|
@ -117,8 +117,50 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"limit": 6,
|
||||
"least": 3,
|
||||
}},
|
||||
"dream": {Name: "dream", Help: "使命必达", Value: map[string]interface{}{
|
||||
"hello": map[string]interface{}{
|
||||
"git": []interface{}{"clone https://github.com/shylinux/context"},
|
||||
"tmux": []interface{}{
|
||||
"split-window -t $dream:1.1",
|
||||
"new-window -t $dream:2",
|
||||
"split-window -t $dream:2.1",
|
||||
"new-window -t $dream:3",
|
||||
"split-window -t $dream:3.1",
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"dream": {Name: "dream", Help: "使令必达", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
|
||||
switch arg[0] {
|
||||
case "init":
|
||||
// 检查会话
|
||||
tmux := kit.Trans(m.Confv("prefix", "tmux"))
|
||||
if !m.Cmds(tmux, "has-session", "-t", arg[1]) {
|
||||
break
|
||||
}
|
||||
|
||||
// 下载代码
|
||||
topic := kit.Select("hello", arg, 2)
|
||||
home := path.Join(m.Conf("missyou", "path"), arg[1], m.Conf("missyou", "local"))
|
||||
git := kit.Trans(m.Confv("prefix", "git"), "cmd_dir", home)
|
||||
m.Confm("dream", []string{topic, "git"}, func(index int, value string) {
|
||||
value = strings.Replace(value, "$dream", arg[1], -1)
|
||||
m.Cmdx(git, strings.Split(value, " "))
|
||||
})
|
||||
|
||||
// 创建终端
|
||||
m.Cmds(tmux, "new-session", "-ds", arg[1], "cmd_env", "TMUX", "", "cmd_dir", home)
|
||||
m.Confm("dream", []string{topic, "tmux"}, func(index int, value string) {
|
||||
value = strings.Replace(value, "$dream", arg[1], -1)
|
||||
m.Cmdx(tmux, strings.Split(value, " "), "cmd_dir", home)
|
||||
})
|
||||
|
||||
case "exit":
|
||||
}
|
||||
return
|
||||
}},
|
||||
|
||||
"login": {Name: "login open|init|list|exit|quit", Help: "登录", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
|
||||
|
||||
switch kit.Select("list", arg, 0) {
|
||||
@ -228,7 +270,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
m.Set("append")
|
||||
case "file":
|
||||
// 文件列表
|
||||
m.Cmd("ssh.data", "show", arg[1:]).Table(func(index int, value map[string]string) {
|
||||
m.Cmd("ssh.data", "show", arg[1]).Table(func(index int, value map[string]string) {
|
||||
m.Push("id", value["id"])
|
||||
m.Push("kind", value["kind"])
|
||||
m.Push("name", value["name"])
|
||||
@ -250,10 +292,14 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
|
||||
case "list":
|
||||
if len(arg) > 2 && arg[2] == "modify" {
|
||||
m.Cmdy("ssh.data", "update", m.Option("favor"), arg[1], arg[3], arg[4])
|
||||
m.Cmdy("ssh._route", m.Option("dream"), "ssh.data", "update", m.Option("favor"), arg[1], arg[3], arg[4])
|
||||
arg = []string{"list", m.Option("dream"), m.Option("favor")}
|
||||
}
|
||||
m.Cmdy("ssh.data", "show", arg[1:])
|
||||
if len(arg) > 1 {
|
||||
m.Cmdy("ssh._route", arg[1], "ssh.data", "show", arg[2:])
|
||||
break
|
||||
}
|
||||
m.Cmdy("ssh.data", "show")
|
||||
}
|
||||
return
|
||||
}},
|
||||
|
@ -17,6 +17,7 @@ var Index = &ctx.Context{Name: "team", Help: "团队中心",
|
||||
if len(arg) > 2 && arg[1] != "" {
|
||||
switch arg[2] {
|
||||
case "prepare", "action", "cancel", "finish":
|
||||
prefix := []string{"ssh._route", m.Option("dream"), "ssh.data", "update"}
|
||||
time := "close_time"
|
||||
switch arg[2] {
|
||||
case "prepare", "action":
|
||||
@ -28,7 +29,7 @@ var Index = &ctx.Context{Name: "team", Help: "团队中心",
|
||||
}
|
||||
|
||||
// 更新任务
|
||||
m.Cmd("ssh.data", "update", m.Option("table"), arg[1], "status", arg[2], time, m.Time())
|
||||
m.Cmd(prefix, m.Option("table"), arg[1], "status", arg[2], time, m.Time())
|
||||
arg = []string{arg[0], m.Option("table")}
|
||||
}
|
||||
}
|
||||
@ -51,7 +52,6 @@ var Index = &ctx.Context{Name: "team", Help: "团队中心",
|
||||
m.Cmdy("ssh.data", "insert", arg[1], "level", arg[2], "class", arg[3],
|
||||
"status", arg[4], "begin_time", arg[5], "close_time", arg[6],
|
||||
"target", arg[7], "detail", arg[8], arg[9:])
|
||||
break
|
||||
}
|
||||
|
||||
arg = []string{arg[1]}
|
||||
@ -59,7 +59,7 @@ var Index = &ctx.Context{Name: "team", Help: "团队中心",
|
||||
default:
|
||||
// 更新任务
|
||||
if len(arg) > 1 && arg[1] == "modify" {
|
||||
m.Cmdy("ssh.data", "update", m.Option("table"), m.Option("index"), arg[2], arg[3])
|
||||
m.Cmdy("ssh.data", "update", m.Option("table"), arg[0], arg[2], arg[3])
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -92,13 +92,13 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
|
||||
|
||||
buffer := bytes.NewBuffer([]byte{})
|
||||
m.Assert(tmpl.ExecuteTemplate(buffer, m.Option("filename", path.Base(which)), m))
|
||||
data := markdown.ToHTML(buffer.Bytes(), nil, nil)
|
||||
m.Echo(string(data))
|
||||
if f, p, e := kit.Create(path.Join("var/tmp/file", which)); e == nil {
|
||||
defer f.Close()
|
||||
f.Write(data)
|
||||
f.Write(buffer.Bytes())
|
||||
m.Log("info", "save %v", p)
|
||||
}
|
||||
data := markdown.ToHTML(buffer.Bytes(), nil, nil)
|
||||
m.Echo(string(data))
|
||||
return
|
||||
}},
|
||||
"note": {Name: "note file|favor|commit", Help: "笔记", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
@ -268,6 +268,7 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
|
||||
}},
|
||||
|
||||
"runs": {Name: "run", Help: "便签", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Option("render", "code")
|
||||
m.Cmdy(arg).Set("append")
|
||||
return
|
||||
}},
|
||||
|
@ -324,6 +324,14 @@ func Map(v interface{}, random string, args ...interface{}) map[string]interface
|
||||
fun(k, val)
|
||||
}
|
||||
}
|
||||
case func(string, int, string):
|
||||
for k, v := range value {
|
||||
if val, ok := v.([]interface{}); ok {
|
||||
for i, v := range val {
|
||||
fun(k, i, Format(v))
|
||||
}
|
||||
}
|
||||
}
|
||||
case func(string, map[string]interface{}):
|
||||
switch random {
|
||||
case "%":
|
||||
|
@ -49,21 +49,22 @@ func Create(p string) (*os.File, string, error) {
|
||||
return f, p, e
|
||||
}
|
||||
|
||||
func Split(str string, c byte, n int) []string {
|
||||
func Split(str string, c rune, n int) []string {
|
||||
res := []string{}
|
||||
for i, j := 0, 0; i < len(str); i++ {
|
||||
if str[i] == c || c == ' ' && unicode.IsSpace(rune(str[i])) {
|
||||
list := []rune(str)
|
||||
for i, j := 0, 0; i < len(list); i++ {
|
||||
if list[i] == c || c == ' ' && unicode.IsSpace(list[i]) {
|
||||
continue
|
||||
}
|
||||
for j = i; j < len(str); j++ {
|
||||
if str[j] == c || c == ' ' && unicode.IsSpace(rune(str[j])) {
|
||||
for j = i; j < len(list); j++ {
|
||||
if list[j] == c || c == ' ' && unicode.IsSpace(list[j]) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if n == len(res)+1 {
|
||||
j = len(str)
|
||||
j = len(list)
|
||||
}
|
||||
res, i = append(res, str[i:j]), j
|
||||
res, i = append(res, string(list[i:j])), j
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
@ -326,6 +326,9 @@ var page = Page({
|
||||
var river = "", storm = 0, input = "", share = ""
|
||||
var temp = ""
|
||||
output.DisplayRaw = true
|
||||
page.Sync("plugin_you").change(function(value) {
|
||||
page.title(value)
|
||||
})
|
||||
return {
|
||||
Show: function() {var pane = field.Pane
|
||||
if (river && storm && field.Pane.Load(river+"."+storm, output)) {return}
|
||||
|
@ -460,3 +460,10 @@ fieldset.item>div.output>div.code div.number {
|
||||
fieldset ul.story li:hover {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset div.output div.story {
|
||||
font-family:monospace;
|
||||
font-size:16px;
|
||||
white-space:pre;
|
||||
padding:16px;
|
||||
border:solid 2px green;
|
||||
}
|
||||
|
32
usr/local/wiki/miss.md
Normal file
32
usr/local/wiki/miss.md
Normal file
@ -0,0 +1,32 @@
|
||||
# {{title "Hello World"}}
|
||||
|
||||
{{runs "help"}}
|
||||
|
||||
## 应用开发
|
||||
|
||||
{{table "hello" `
|
||||
zsh tmux docker git vim
|
||||
code wiki chat team mall
|
||||
src etc bin var usr
|
||||
`}}
|
||||
|
||||
{{table "circle" `
|
||||
传感 编程 控制 设计
|
||||
属性 语言 过程 功能
|
||||
关系 框架 状态 性能
|
||||
规律 平台 特征 智能
|
||||
`}}
|
||||
|
||||
## 系统设计
|
||||
|
||||
{{table "context" `
|
||||
ctx cli aaa web
|
||||
lex yac gdb log
|
||||
tcp nfs ssh mdb
|
||||
`}}
|
||||
|
||||
{{order "" `
|
||||
模块化
|
||||
脚本化
|
||||
自动化
|
||||
`}}
|
@ -13,4 +13,4 @@
|
||||
{{range $i, $line := .Meta.list}}<li>{{$line}}</li>{{end}}
|
||||
</ul>{{end}}
|
||||
|
||||
{{define "code"}}<div>{{results .}}</div>{{end}}
|
||||
{{define "code"}}<div class="story">{{results .}}</div>{{end}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user