1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00
This commit is contained in:
shylinux 2019-04-16 08:41:34 +08:00
parent 5c5ea7d85e
commit 5e39c39bb2
15 changed files with 554 additions and 693 deletions

View File

@ -1,13 +0,0 @@
#!/usr/bin/env bash
bench=bench
[ -e bin/bench ] && bench=bin/bench
echo "bench: $bench"> var/boot.log
while true; do
$bench 2>var/error.log && break
echo "bench run error"
echo "restarting..."
sleep 3
done

View File

@ -1,3 +1,5 @@
~ssh
config trust up true
~mdb
note model favor spirit spirit relate relate
note model money expend expend amount amount

View File

@ -1,24 +0,0 @@
set showtabindices
imap <C-h> deleteChar
imap <C-d> deleteForwardChar
imap <C-w> deleteWord
imap <C-a> beginningOfLine
imap <C-k> deleteToEnd
map w :tabnew
map m :tabnew
map t goToTab
map q goToTab
map p goToTab
map v nextTab
map c previousTab
map <C-j> nextTab
map <C-k> previousTab
map <C-o> goBack
map <C-i> goForward
map <C-f> createTabbedHint
map s scrollPageUp
map a :history
map e :tabnew google

View File

@ -1,142 +0,0 @@
snippet p
package ${1:main}
${2}
snippet i
import (
"${1}"
)
${2}
snippet t
type ${1} struct {
${2}
}
${3}
snippet ti
type ${1} interface {
${2}
}
${3}
snippet c
package `Filename()`
import (
"context"
)
type `toupper(substitute(expand("%:t"), ".go", "", ""))` struct {
*ctx.Message
*ctx.Context
}
func (`Filename()` *`toupper(substitute(expand("%:t"), ".go", "", ""))`) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server {
c.Caches = map[string]*ctx.Cache{}
c.Configs = map[string]*ctx.Config{}
s := new(`toupper(substitute(expand("%:t"), ".go", "", ""))`)
s.Context = c
return s
}
func (`Filename()` *`toupper(substitute(expand("%:t"), ".go", "", ""))`) Begin(m *ctx.Message, arg ...string) ctx.Server {
if `Filename()`.Context == Index {
Pulse = m
}
`Filename()`.Message = m
return `Filename()`
}
func (`Filename()` *`toupper(substitute(expand("%:t"), ".go", "", ""))`) Start(m *ctx.Message, arg ...string) bool {
`Filename()`.Message = m
return false
}
func (`Filename()` *`toupper(substitute(expand("%:t"), ".go", "", ""))`) Close(m *ctx.Message, arg ...string) bool {
switch `Filename()`.Context {
case m.Target():
case m.Source():
}
return true
}
var Pulse *ctx.Message
var Index = &ctx.Context{Name: "`Filename()`", Help: "${1}",
Caches: map[string]*ctx.Cache{},
Configs: map[string]*ctx.Config{},
Commands: map[string]*ctx.Command{},
}
func init() {
`Filename()` := &`toupper(substitute(expand("%:t"), ".go", "", ""))`{}
`Filename()`.Context = Index
ctx.Index.Register(Index, `Filename()`)
}
snippet cmd
"${1}": &ctx.Command{Name: "${2}", Help: "${3}", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) string {
${4}
return ""
}},
snippet conf
"${1}": &ctx.Config{Name: "${2}", Value: "${3}", Help: "${4}", Hand: func(m *ctx.Message, x *ctx.Config, arg ...string) string {
if len(arg) > 0 {
${5}
return arg[0]
}
return x.Value
}},
snippet cap
"${1}": &ctx.Cache{Name: "${2}", Value: "${3}", Help: "${4}", Hand: func(m *ctx.Message, x *ctx.Cache, arg ...string) string {
if len(arg) > 0 {
${5}
return arg[0]
}
return x.Value
}},
snippet v
var (
${1}
)
${2}
snippet m
func main() {
${1}
}
snippet h
func(w http.ResponseWriter, r *http.Request) {
${1}
})
snippet f
func${1}(${2}) ${3}{
${4}
}${5}
snippet (
(${1})${2}
snippet [
[${1}]${2}
snippet {
{${1}}${2}
snippet if
if ${1} {
${2}
}
${3}
snippet for
for ${1}{
${2}
}
${3}
snippet switch
switch ${1}{
case ${2}:
${3}
}
${4}
snippet select
select {
case ${1}:
${2}
}
${3}

View File

@ -3,7 +3,7 @@
~code
config load tmp/flash.json flash
source common.shy
source etc/common.shy
~ssh
remote auto
source local.shy

View File

@ -1,50 +0,0 @@
~web
spide add weather "http://weather.sina.com.cn/%s" "div.blk_fc_c0_i"\
sub_parse date "p.wt_fc_c0_i_date" text\
sub_parse day "p.wt_fc_c0_i_day" text\
sub_parse weather "p.wt_fc_c0_i_icons.clearfix img" title\
sub_parse temp "p.wt_fc_c0_i_temp" text\
sub_parse wind "p.wt_fc_c0_i_tip" text\
sub_parse pm "ul.wt_fc_c0_i_level li.l" text\
sub_parse env "ul.wt_fc_c0_i_level li.r" text\
offset 0 limit 5 fields "date day weather temp"
spide add topic "https://s.weibo.com/top/summary?cate=realtimehot" "table tr"\
sub_parse mark "td.td-03" text\
sub_parse count "td.td-02 span" text\
sub_parse rank "td.td-01" text\
sub_parse topic "td.td-02 a" text\
offset 0 limit 22
spide add pedia "https://zh.wikipedia.org/wiki/%s" "div.mw-parser-output>p,div.mw-parser-output>ul"\
sub_parse content "" text\
offset 0 limit 3
spide add baike "http://www.baike.com/wiki/%s&prd=button_doc_entry" "div.summary p, #content h2, #content h3, #content p"\
sub_parse content "" text\
offset 0 limit 3
spide add baidu "http://www.baidu.com/s?wd=%s&rsv_spt=1&rsv_iqid=0xa47ffeff0000e033&issp=1&f=8&rsv_bp=0&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_sug3=19&rsv_sug1=34&rsv_sug7=101&rsv_t=a131Qznttosl8wF0vyMrsGkYevt2bH0XIskFZst3BRmlrWXhmH5zmhgyonPQO%%2BM7kn7j&rsv_sug2=0&inputT=9889&rsv_sug4=12120"\
"#content_left div.result.c-container "\
sub_parse link "a.c-showurl" text\
sub_parse title "h3" text\
sub_parse content "div.c-abstract" text\
offset 0 limit 10 fields "link title"
spide add zhihu "https://www.zhihu.com/search?type=content&q=%s&utm_content=search_preset" "div.SearchMain div.Card"\
sub_parse up "div.ContentItem-actions button.VoteButton--up" text\
sub_parse title "h2.ContentItem-title" text\
sub_parse com "div.ContentItem-actions button.ContentItem-action" text\
sub_parse content "div.RichContent span.RichText" text\
offset 1 limit 10 fields "title up com"
spide add toutiao "https://www.toutiao.com/search/?keyword=%s"\
"div.articleCard"\
sub_parse content "" text\
offset 0 limit 10
spide add 12306 "https://kyfw.12306.cn/otn/leftTicket/init?linktypeid=dc&fs=%s,%s&ts=%s,%s&date=2018-12-23&flag=N,N,Y"\
"div.t-list table tr"\
sub_parse content "" text\
offset 0 limit 10

View File

@ -309,6 +309,49 @@ var CGI = template.FuncMap{
}
return ""
},
"options": func(arg ...interface{}) string {
if len(arg) == 0 {
return ""
}
switch m := arg[0].(type) {
case *Message:
if len(arg) == 1 {
return kit.Format(m.Meta["option"])
}
switch value := arg[1].(type) {
case int:
if 0 <= value && value < len(m.Meta["option"]) {
return kit.Format(m.Meta["option"][value])
}
case string:
if len(arg) == 2 {
return kit.Format(m.Optionv(value))
}
switch val := arg[2].(type) {
case int:
if 0 <= val && val < len(m.Meta[value]) {
return kit.Format(m.Meta[value][val])
}
}
}
case map[string][]string:
if len(arg) == 1 {
return strings.Join(m["option"], "")
}
switch value := arg[1].(type) {
case string:
return strings.Join(m[value], "")
}
case []string:
return strings.Join(m, "")
default:
return kit.Format(m)
}
return ""
},
"result": func(arg ...interface{}) interface{} {
if len(arg) == 0 {
return ""

View File

@ -862,7 +862,16 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
case 0:
m.Cmdy("ctx.config", "componet")
case 1:
m.Cmdy("ctx.config", "componet", arg[0])
m.Confm("componet", arg[0], func(index int, val map[string]interface{}) {
m.Add("append", "ctx", val["componet_ctx"])
m.Add("append", "cmd", val["componet_cmd"])
m.Add("append", "name", val["componet_name"])
m.Add("append", "help", val["componet_help"])
m.Add("append", "tmpl", val["componet_tmpl"])
m.Add("append", "view", val["componet_view"])
m.Add("append", "init", val["componet_init"])
})
m.Table()
case 2:
m.Cmdy("ctx.config", "componet", strings.Join(arg, "."))
default:
@ -875,18 +884,13 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
default:
componet := m.Confm("componet", arg[:2])
for i := 2; i < len(arg)-1; i += 2 {
componet[arg[i]] = arg[i+1]
kit.Chain(componet, arg[i], arg[i+1])
}
}
}
return
}},
"/proxy/": &ctx.Command{Name: "/proxy/which/method/url", Help: "服务代理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
fields := strings.Split(key, "/")
m.Cmdy("web.get", "which", fields[2], "method", fields[3], strings.Join(fields, "/"))
return
}},
"/render": &ctx.Command{Name: "/render template", Help: "渲染模板, template: 模板名称", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if m.Options("toolkit") {
if kit, ok := m.Confv("toolkit", m.Option("toolkit")).(map[string]interface{}); ok {
@ -937,7 +941,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
for _, v := range m.Confv("componet", group).([]interface{}) {
val := v.(map[string]interface{})
if order != "" && val["name"].(string) != order {
if order != "" && val["componet_name"].(string) != order {
continue
}
@ -945,7 +949,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
msg := m.Find(kit.Select(m.Cap("module"), val["componet_ctx"]))
// 默认变量
msg.Option("componet_name", val["name"].(string))
for k, v := range val {
if msg.Option(k) != "" {
continue
@ -968,7 +971,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
}
}
}
msg.Log("fuck", "what %v", msg.Option("componet_name"))
msg.Log("fuck", "what %v", val)
// 添加设备
arg = arg[:0]
@ -983,7 +986,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
arg = append(arg, kit.Trans(m.Optionv("cmds"))...)
}
// 添加参数
for _, v := range kit.Trans(val["arguments"]) {
for _, v := range kit.Trans(val["componet_args"]) {
arg = append(arg, msg.Parse(v))
}
@ -1014,8 +1017,8 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
return
} else if accept_json {
list = append(list, msg.Meta)
} else if val["template"] != nil {
m.Assert(tmpl.ExecuteTemplate(w, val["template"].(string), msg))
} else if val["componet_tmpl"] != nil {
m.Assert(tmpl.ExecuteTemplate(w, val["componet_tmpl"].(string), msg))
}
}
@ -1055,6 +1058,11 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
http.ServeFile(w, r, p)
return
}},
"/proxy/": &ctx.Command{Name: "/proxy/which/method/url", Help: "服务代理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
fields := strings.Split(key, "/")
m.Cmdy("web.get", "which", fields[2], "method", fields[3], strings.Join(fields, "/"))
return
}},
"/shadow": &ctx.Command{Name: "/shadow", Help: "暗网", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Confm("runtime", "node.port", func(index int, value string) {
m.Add("append", "ports", value)

View File

@ -16,6 +16,135 @@ import (
var Index = &ctx.Context{Name: "code", Help: "代码中心",
Caches: map[string]*ctx.Cache{},
Configs: map[string]*ctx.Config{
"skip_login": &ctx.Config{Name: "skip_login", Value: map[string]interface{}{"/consul": "true"}, Help: "免密登录"},
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
"login": []interface{}{
map[string]interface{}{"componet_name": "code", "componet_tmpl": "head", "metas": []interface{}{
map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no"},
}, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
map[string]interface{}{"componet_name": "login", "componet_help": "login", "componet_tmpl": "componet",
"componet_ctx": "aaa", "componet_cmd": "auth", "componet_args": []interface{}{"@sessid", "ship", "username", "@username", "password", "@password"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "username", "value": "", "label": "username"},
map[string]interface{}{"type": "password", "name": "password", "value": "", "label": "password"},
map[string]interface{}{"type": "button", "value": "login"},
},
"display_append": "", "display_result": "",
},
map[string]interface{}{"componet_name": "tail", "componet_tmpl": "tail",
"scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
},
},
"flash": []interface{}{
map[string]interface{}{"componet_name": "flash", "componet_tmpl": "head", "metas": []interface{}{
map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no"},
}, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
map[string]interface{}{"componet_name": "ask", "componet_help": "ask", "componet_tmpl": "componet",
"componet_view": "FlashText", "componet_init": "initFlashText",
"componet_ctx": "web.code", "componet_cmd": "flash", "componet_args": []interface{}{"text", "@text"}, "inputs": []interface{}{
map[string]interface{}{"type": "textarea", "name": "text", "value": "", "cols": 50, "rows": 5},
map[string]interface{}{"type": "button", "value": "添加请求"},
},
"display_result": "", "display_append": "",
},
map[string]interface{}{"componet_name": "tip", "componet_help": "tip", "componet_tmpl": "componet",
"componet_view": "FlashList", "componet_init": "initFlashList",
"componet_ctx": "web.code", "componet_cmd": "flash",
"display_result": "", "display_append": "",
},
map[string]interface{}{"componet_name": "tail", "componet_tmpl": "tail",
"scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
},
},
"index": []interface{}{
map[string]interface{}{"componet_name": "code", "componet_tmpl": "head", "metas": []interface{}{
map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no"},
}, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
map[string]interface{}{"componet_name": "toolkit", "componet_help": "Ctrl+B", "componet_tmpl": "toolkit",
"componet_view": "KitList", "componet_init": "initKitList",
},
// map[string]interface{}{"componet_name": "login", "componet_help": "login", "componet_tmpl": "componet",
// "componet_ctx": "aaa", "componet_cmd": "login", "componet_args": []interface{}{"@username", "@password"},
// "inputs": []interface{}{
// map[string]interface{}{"type": "text", "name": "username", "label": "username"},
// map[string]interface{}{"type": "password", "name": "password", "label": "password"},
// map[string]interface{}{"type": "button", "value": "login"},
// },
// "display_append": "", "display_result": "",
// },
// map[string]interface{}{"componet_name": "userinfo", "componet_help": "userinfo", "componet_tmpl": "componet",
// "componet_ctx": "aaa", "componet_cmd": "login", "componet_args": []interface{}{"@sessid"},
// "pre_run": true,
// },
map[string]interface{}{"componet_name": "buffer", "componet_help": "buffer", "componet_tmpl": "componet",
"componet_view": "BufList", "componet_init": "initBufList",
"componet_ctx": "cli", "componet_cmd": "tmux", "componet_args": []interface{}{"buffer"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "limit", "value": "3", "label": "limit"},
map[string]interface{}{"type": "text", "name": "index", "value": "0", "label": "index"},
map[string]interface{}{"type": "button", "value": "refresh"},
},
"pre_run": true,
},
map[string]interface{}{"componet_name": "dir", "componet_help": "dir", "componet_tmpl": "componet",
"componet_view": "DirList", "componet_init": "initDirList",
"componet_ctx": "nfs", "componet_cmd": "dir", "componet_args": []interface{}{"@dir", "dir_sort", "@sort_field", "@sort_order"}, "inputs": []interface{}{
map[string]interface{}{"type": "choice", "name": "dir_type", "value": "both", "label": "dir_type", "choice": []interface{}{
map[string]interface{}{"name": "all", "value": "all"},
map[string]interface{}{"name": "both", "value": "both"},
map[string]interface{}{"name": "file", "value": "file"},
map[string]interface{}{"name": "dir", "value": "dir"},
}},
map[string]interface{}{"type": "text", "name": "dir", "value": "@current.dir", "label": "dir"},
map[string]interface{}{"type": "button", "value": "refresh"},
},
"pre_run": false, "display_result": "",
},
map[string]interface{}{"componet_name": "upload", "componet_help": "upload", "componet_tmpl": "componet",
"componet_view": "PutFile", "componet_init": "initPutFile",
"componet_ctx": "web", "componet_cmd": "upload", "form_type": "upload", "inputs": []interface{}{
map[string]interface{}{"type": "file", "name": "upload"},
map[string]interface{}{"type": "submit", "value": "submit"},
},
"display_result": "",
},
map[string]interface{}{"componet_name": "pod", "componet_help": "pod", "componet_tmpl": "componet",
"componet_view": "PodList", "componet_init": "initPodList",
"componet_ctx": "ssh", "componet_cmd": "remote", "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "value": "@current.pod"},
map[string]interface{}{"type": "button", "value": "refresh"},
},
"pre_run": true, "display_result": "",
},
map[string]interface{}{"componet_name": "ctx", "componet_help": "ctx", "componet_tmpl": "componet",
"componet_view": "CtxList", "componet_init": "initCtxList",
"componet_pod": "true", "componet_ctx": "ssh", "componet_cmd": "context", "componet_args": []interface{}{"@ctx", "list"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "ctx", "value": "@current.ctx"},
map[string]interface{}{"type": "button", "value": "refresh"},
},
"display_result": "",
},
map[string]interface{}{"componet_name": "cmd", "componet_help": "cmd", "componet_tmpl": "componet",
"componet_view": "CmdList", "componet_init": "initCmdList",
"componet_ctx": "cli.shy", "componet_cmd": "source", "componet_args": []interface{}{"@cmd"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "cmd", "value": "", "class": "cmd", "clipstack": "void"},
},
},
// map[string]interface{}{"componet_name": "mp", "componet_tmpl": "mp"},
map[string]interface{}{"componet_name": "tail", "componet_tmpl": "tail",
"scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
},
},
}, Help: "组件列表"},
"componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"},
"flash": &ctx.Config{Name: "flash", Value: map[string]interface{}{
"data": []interface{}{},
"view": map[string]interface{}{"default": []interface{}{"index", "time", "text", "code", "output"}},
}, Help: "闪存"},
"mux": &ctx.Config{Name: "mux", Value: map[string]interface{}{
"cmd_timeout": "100ms",
"view": map[string]interface{}{
@ -74,155 +203,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
},
},
}, Help: "文档管理"},
"skip_login": &ctx.Config{Name: "skip_login", Value: map[string]interface{}{
"/consul": "true",
}, Help: "免登录"},
"counter": &ctx.Config{Name: "counter", Value: map[string]interface{}{
"nopen": "0", "nsave": "0",
}, Help: "counter"},
"counter_service": &ctx.Config{Name: "counter_service", Value: "http://localhost:9094/code/counter", 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"},
}, Help: "web_site"},
"componet_command": &ctx.Config{Name: "component_command", Value: "pwd", Help: "默认命令"},
"componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"},
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
"login": []interface{}{
map[string]interface{}{"name": "code", "template": "head", "metas": []interface{}{
map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7"},
map[string]interface{}{"name": "user-scalable", "content": "no"},
}, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
map[string]interface{}{"name": "login", "help": "login", "template": "componet",
"componet_ctx": "aaa", "componet_cmd": "auth", "arguments": []interface{}{"@sessid", "ship", "username", "@username", "password", "@password"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "username", "label": "username", "value": ""},
map[string]interface{}{"type": "password", "name": "password", "label": "password", "value": ""},
map[string]interface{}{"type": "button", "value": "login"},
},
"display_append": "", "display_result": "",
},
map[string]interface{}{"name": "tail", "template": "tail",
"scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
},
},
"flash": []interface{}{
map[string]interface{}{"name": "flash", "template": "head"},
map[string]interface{}{"name": "ask", "help": "ask", "template": "componet",
"componet_view": "flasktext", "componet_init": "initFlashText",
"componet_ctx": "web.code", "componet_cmd": "flash", "arguments": []interface{}{"text", "@text"}, "inputs": []interface{}{
map[string]interface{}{"type": "textarea", "name": "text", "value": "", "cols": 50, "rows": 5},
map[string]interface{}{"type": "button", "value": "添加请求"},
},
"display_result": "", "display_append": "",
},
map[string]interface{}{"name": "tip", "help": "tip", "template": "componet",
"componet_view": "flasklist", "componet_init": "initFlashList",
"componet_ctx": "web.code", "componet_cmd": "flash", "arguments": []interface{}{}, "inputs": []interface{}{
// map[string]interface{}{"type": "button", "value": "refresh"},
},
"display_result": "", "display_append": "",
},
map[string]interface{}{"name": "tail", "template": "tail"},
},
"index": []interface{}{
map[string]interface{}{"name": "code", "template": "head", "metas": []interface{}{
map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7"},
map[string]interface{}{"name": "user-scalable", "content": "no"},
}, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
map[string]interface{}{"name": "toolkit", "help": "Ctrl+B", "template": "toolkit",
"componet_view": "KitList", "componet_init": "initKitList",
},
// map[string]interface{}{"name": "login", "help": "login", "template": "componet",
// "componet_ctx": "aaa", "componet_cmd": "login", "arguments": []interface{}{"@username", "@password"},
// "inputs": []interface{}{
// map[string]interface{}{"type": "text", "name": "username", "label": "username"},
// map[string]interface{}{"type": "password", "name": "password", "label": "password"},
// map[string]interface{}{"type": "button", "value": "login"},
// },
// "display_append": "", "display_result": "",
// },
// map[string]interface{}{"name": "userinfo", "help": "userinfo", "template": "componet",
// "componet_ctx": "aaa", "componet_cmd": "login", "arguments": []interface{}{"@sessid"},
// "pre_run": true,
// },
map[string]interface{}{"name": "buffer", "help": "buffer", "template": "componet",
"componet_ctx": "cli", "componet_cmd": "tmux", "arguments": []interface{}{"buffer"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "limit", "label": "limit", "value": "3"},
map[string]interface{}{"type": "text", "name": "index", "label": "index"},
map[string]interface{}{"type": "button", "value": "refresh"},
},
"pre_run": true,
},
map[string]interface{}{"name": "dir", "help": "dir", "template": "componet",
"componet_view": "DirList", "componet_init": "initDirList",
"pre_run": false, "componet_ctx": "nfs", "componet_cmd": "dir", "arguments": []interface{}{"@current.dir", "dir_sort", "@sort_field", "@sort_order"}, "inputs": []interface{}{
map[string]interface{}{"type": "choice", "name": "dir_type",
"label": "dir_type", "value": "both", "choice": []interface{}{
map[string]interface{}{"name": "all", "value": "all"},
map[string]interface{}{"name": "both", "value": "both"},
map[string]interface{}{"name": "file", "value": "file"},
map[string]interface{}{"name": "dir", "value": "dir"},
},
},
map[string]interface{}{"type": "choice", "name": "sort_field",
"label": "sort_field", "value": "time", "choice": []interface{}{
map[string]interface{}{"name": "filename", "value": "filename"},
map[string]interface{}{"name": "is_dir", "value": "type"},
map[string]interface{}{"name": "line", "value": "line"},
map[string]interface{}{"name": "size", "value": "size"},
map[string]interface{}{"name": "time", "value": "time"},
},
},
map[string]interface{}{"type": "choice", "name": "sort_order",
"label": "sort_order", "value": "time_r", "choice": []interface{}{
map[string]interface{}{"name": "str", "value": "str"},
map[string]interface{}{"name": "str_r", "value": "str_r"},
map[string]interface{}{"name": "int", "value": "int"},
map[string]interface{}{"name": "int_r", "value": "int_r"},
map[string]interface{}{"name": "time", "value": "time"},
map[string]interface{}{"name": "time_r", "value": "time_r"},
},
},
map[string]interface{}{"type": "text", "name": "current.dir", "value": "@current.dir", "label": "dir"},
},
"display_result": "",
},
map[string]interface{}{"name": "upload", "help": "upload", "template": "componet",
"componet_ctx": "web", "componet_cmd": "upload", "form_type": "upload", "inputs": []interface{}{
map[string]interface{}{"type": "file", "name": "upload"},
map[string]interface{}{"type": "submit", "value": "submit"},
},
"display_result": "",
},
map[string]interface{}{"name": "pod", "help": "pod", "template": "componet",
"componet_view": "PodList", "componet_init": "initPodList",
"pre_run": true, "componet_ctx": "ssh", "componet_cmd": "remote", "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "value": "@current.pod"},
map[string]interface{}{"type": "button", "value": "refresh"},
},
"display_result": "",
},
map[string]interface{}{"name": "ctx", "help": "ctx", "template": "componet",
"componet_view": "CtxList", "componet_init": "initCtxList",
"componet_pod": "true", "componet_ctx": "ssh", "componet_cmd": "context", "arguments": []interface{}{"@ctx", "list"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "ctx", "value": "@current.ctx"},
map[string]interface{}{"type": "button", "value": "refresh"},
},
"display_result": "",
},
map[string]interface{}{"name": "cmd", "help": "cmd", "template": "componet",
"componet_view": "CmdList", "componet_init": "initCmdList",
"componet_ctx": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmd"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "cmd", "value": "", "class": "cmd", "clipstack": "void"},
},
},
// map[string]interface{}{"name": "mp", "template": "mp"},
map[string]interface{}{"name": "tail", "template": "tail",
"scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
},
},
}, Help: "组件列表"},
"upgrade": &ctx.Config{Name: "upgrade", Value: map[string]interface{}{
"system": []interface{}{"exit_shy", "common_shy", "init_shy", "bench", "boot_sh"},
"portal": []interface{}{"code_tmpl", "code_js", "context_js"},
@ -239,12 +220,73 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"context_js": "usr/librarys/context.js",
},
}, Help: "日志地址"},
"flash": &ctx.Config{Name: "flash", Value: map[string]interface{}{
"data": []interface{}{},
"view": map[string]interface{}{"default": []interface{}{"index", "time", "text", "code", "output"}},
}, Help: "闪存"},
"counter": &ctx.Config{Name: "counter", Value: map[string]interface{}{
"nopen": "0", "nsave": "0",
}, Help: "counter"},
"counter_service": &ctx.Config{Name: "counter_service", Value: "http://localhost:9094/code/counter", Help: "counter"},
},
Commands: map[string]*ctx.Command{
"flash": &ctx.Command{Name: "flash", Help: "闪存", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
total := len(m.Confv("flash", "data").([]interface{}))
// 查看列表
if len(arg) == 0 {
if index := m.Option("flash_index"); index != "" {
arg = append(arg, index)
} else {
m.Confm("flash", "data", func(index int, item map[string]interface{}) {
for _, k := range kit.View([]string{}, m.Confm("flash", "view")) {
m.Add("append", k, kit.Format(item[k]))
}
})
m.Table()
return
}
}
index, item := -1, map[string]interface{}{"time": m.Time()}
if i, e := strconv.Atoi(arg[0]); e == nil && 0 <= i && i < total {
// 查看索引
index, arg = total-1-i, arg[1:]
if item = m.Confm("flash", []interface{}{"data", index}); len(arg) == 0 {
// 查看数据
for _, k := range kit.View([]string{}, m.Confm("flash", "view")) {
m.Add("append", k, kit.Format(item[k]))
}
m.Table()
return e
}
}
switch arg[0] {
case "vim": // 编辑数据
name := m.Cmdx("nfs.temp", kit.Format(item[kit.Select("code", arg, 1)]))
m.Cmd("cli.system", "vi", name)
item[kit.Select("code", arg, 1)] = m.Cmdx("nfs.load", name)
m.Cmd("nfs.trash", name)
case "run": // 运行代码
code := kit.Format(item[kit.Select("code", arg, 1)])
if code == "" {
break
}
name := m.Cmdx("nfs.temp", code)
m.Cmdy("cli.system", "python", name)
item["output"] = m.Result(0)
m.Cmd("nfs.trash", name)
default:
// 修改数据
for i := 0; i < len(arg)-1; i += 2 {
item[arg[i]] = arg[i+1]
}
m.Conf("flash", []interface{}{"data", index}, item)
item["index"] = total - 1 - index
m.Echo("%d", total-1-index)
}
return
}},
"mux": &ctx.Command{Name: "mux [session [window [pane]]] args...", Help: "终端管理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 { // 会话列表
view := kit.View([]string{"session"}, m.Confm("mux", "view"))
@ -332,6 +374,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
m.Cmdy("cli.system", "tmux", "send-keys", "-t", target, arg[3:])
return
}},
"update": &ctx.Command{Name: "update", Help: "更新代码", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
return
}},
@ -393,7 +436,6 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}
return
}},
"/counter": &ctx.Command{Name: "/counter", Help: "/counter", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) > 0 {
m.Option("name", arg[0])
@ -419,67 +461,6 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}
return
}},
"flash": &ctx.Command{Name: "flash", Help: "闪存", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
total := len(m.Confv("flash", "data").([]interface{}))
// 查看列表
if len(arg) == 0 {
if index := m.Option("flash_index"); index != "" {
arg = append(arg, index)
} else {
m.Confm("flash", "data", func(index int, item map[string]interface{}) {
for _, k := range kit.View([]string{}, m.Confm("flash", "view")) {
m.Add("append", k, kit.Format(item[k]))
}
})
m.Table()
return
}
}
index, item := -1, map[string]interface{}{"time": m.Time()}
if i, e := strconv.Atoi(arg[0]); e == nil && 0 <= i && i < total {
// 查看索引
index, arg = total-1-i, arg[1:]
if item = m.Confm("flash", []interface{}{"data", index}); len(arg) == 0 {
// 查看数据
for _, k := range kit.View([]string{}, m.Confm("flash", "view")) {
m.Add("append", k, kit.Format(item[k]))
}
m.Table()
return e
}
}
switch arg[0] {
case "vim": // 编辑数据
name := m.Cmdx("nfs.temp", kit.Format(item[kit.Select("code", arg, 1)]))
m.Cmd("cli.system", "vi", name)
item[kit.Select("code", arg, 1)] = m.Cmdx("nfs.load", name)
m.Cmd("nfs.trash", name)
case "run": // 运行代码
code := kit.Format(item[kit.Select("code", arg, 1)])
if code == "" {
break
}
name := m.Cmdx("nfs.temp", code)
m.Cmdy("cli.system", "python", name)
item["output"] = m.Result(0)
m.Cmd("nfs.trash", name)
default:
// 修改数据
for i := 0; i < len(arg)-1; i += 2 {
item[arg[i]] = arg[i+1]
}
m.Conf("flash", []interface{}{"data", index}, item)
item["index"] = total - 1 - index
m.Echo("%d", total-1-index)
}
return
}},
},
}

View File

@ -68,21 +68,21 @@
height:2em;
}
/* ----- FlashList ----- */
fieldset.flasktext {
fieldset.FlashList {
}
fieldset.flasklist div.detail {
fieldset.FlashList div.detail {
border:ridge 2px green;
border-bottom:0px;
margin-top:20px;
padding:5px;
}
fieldset.flasklist div.action {
fieldset.FlashList div.action {
border:ridge 2px green;
border-top:0px;
border-bottom:0px;
}
fieldset.flasklist code.output pre {
fieldset.FlashList code.output pre {
border:ridge 2px green;
margin:0px;
padding:5px;
@ -100,7 +100,6 @@
overflow:scroll;
position:fixed;
}
fieldset.KitList:hover, fieldset.KitList.max {}
fieldset.KitList div:hover, fieldset.KitList li li:hover {
background-color:red;
}

View File

@ -1,23 +1,25 @@
var page = Page({
initFlashText: function(page, field, option, append, result) {
option.onactions = function(msg) {
option.ondaemon = function(msg) {
page.reload()
}
},
initFlashList: function(page, field, option, append, result) {
initFlashList: function(page, field, option) {
option.dataset.flash_index = ctx.Search("flash_index")
option.onactions = function(msg) {
page.showFlashList(msg, option, append, result)
option.ondaemon = function(msg) {
page.showFlashList(msg, field, option)
}
ctx.Run(page, option.dataset, [], option.onactions)
ctx.Runs(page, option)
},
showFlashList: function(msg, option, append, result) {
showFlashList: function(msg, field, option) {
var page = this
var result = field.querySelector("div.result")
result.innerHTML = ""
ctx.Table(msg, function(tip) {
var ui = kit.AppendChild(result, [{"list": [
{"view": ["detail", "div", tip.text]},
{"code": [tip.output, "result", "result"]},
{"text": [tip.text, "div", "detail"]},
{"code": [tip.code, "result", "result"]},
{"view": ["action"], "list": [
{"button": ["查看详情", function(event) {
ctx.Search("flash_index", tip.index)
@ -36,88 +38,53 @@ var page = Page({
})
},
initDirList: function(page, field, option, append, result) {
var history = []
function change(value) {
option["current.dir"].value = value
ctx.Runs(page, option)
ctx.Current("dir", value)
return value
}
function brow(value, dir, event) {
option["current.dir"].value = value
ctx.Runs(page, option)
option["current.dir"].value = dir
ctx.Runs(page, option)
}
return {
"button": ["root", "back"], "action": function(value) {
switch (value) {
case "back": history.length > -1 && change(history.pop() || "/"); break
case "root": change("/"); break
}
},
"table": {"filename": function(value, key, row, index, event) {
var dir = option["current.dir"].value
var file = dir + ((dir && !dir.endsWith("/"))? "/": "") + value
file.endsWith("/")? history.push(change(file)): brow(file, dir, event)
}},
}
},
initPodList: function(page, field, option, append, result) {
function change(value) {
option.pod.value = value
ctx.Runs(page, option)
ctx.Current("pod", value)
}
return {"table": {"key": change}}
},
initCtxList: function(page, field, option, append, result) {
function change(value) {
option.ctx.value = value
ctx.Runs(page, option)
ctx.Current("ctx", value)
}
return {"button": ["ctx", "shy", "web", "mdb"], "action": change, "table": {"names": change}}
},
initKitList: function(page, field, option, append, result) {
var ui = kit.AppendChild(field, [{"type": "ul", "list": [
{"fork": ["粘贴板", [
{"leaf": ["+ 保存粘贴板(Ctrl+S)", function(event) {
console.log("save_txt")
}]},
{"leaf": ["+ 添加粘贴板(Ctrl+Y)", function(event) {
console.log("create_txt")
}]},
{"leaf": ["+ 快捷粘贴板(Ctrl+P)", function(event) {
console.log("quick_txt")
}]},
]]},
{"fork": ["命令行", [
{"leaf": ["+ 折叠命令行(Ctrl+Z)", function(event, target) {
target.className = page.conf.show_result? "": "stick"
page.showResult(page)
}]},
{"leaf": ["+ 添加命令行(Ctrl+M)", function(event) {
page.addCmdList("cmd", page.conf.ncommand++)
}]},
]]},
{"fork": ["工作流", [
{"leaf": ["+ 刷新工作流(Ctrl+R)", function(event) {
console.log("refresh_fly")
}]},
{"leaf": ["+ 添加工作流(Ctrl+T)", function(event) {
console.log("create_fly")
}]},
{"leaf": ["+ 命名工作流", function(event) {
console.log("rename_fly")
}]},
{"leaf": ["+ 删除工作流", function(event) {
console.log("remove_fly")
}]},
]]},
]}])
var ui = kit.AppendChild(field, [
{"styles": {
"fieldset.KitList": {
"top": conf.toolkit_view.top, "left": conf.toolkit_view.left,
},
"fieldset.KitList:hover, fieldset.KitList.max": {
"width": conf.toolkit_view.width, "height": conf.toolkit_view.height,
},
}},
{"type": "ul", "list": [
{"fork": ["粘贴板", [
{"leaf": ["+ 保存粘贴板(Ctrl+S)", function(event) {
console.log("save_txt")
}]},
{"leaf": ["+ 添加粘贴板(Ctrl+Y)", function(event) {
console.log("create_txt")
}]},
{"leaf": ["+ 快捷粘贴板(Ctrl+P)", function(event) {
console.log("quick_txt")
}]},
]]},
{"fork": ["命令行", [
{"leaf": ["+ 折叠命令行(Ctrl+Z)", function(event, target) {
target.className = page.conf.show_result? "": "stick"
page.showResult(page)
}]},
{"leaf": ["+ 添加命令行(Ctrl+M)", function(event) {
page.addCmdList("cmd", page.conf.ncommand++)
}]},
]]},
{"fork": ["工作流", [
{"leaf": ["+ 刷新工作流(Ctrl+R)", function(event) {
console.log("refresh_fly")
}]},
{"leaf": ["+ 添加工作流(Ctrl+T)", function(event) {
console.log("create_fly")
}]},
{"leaf": ["+ 命名工作流", function(event) {
console.log("rename_fly")
}]},
{"leaf": ["+ 删除工作流", function(event) {
console.log("remove_fly")
}]},
]]},
]},
])
/*
<li><div>命令行</div>
<ul class="cmd">
@ -270,49 +237,81 @@ var page = Page({
})
return
},
initDirList: function(page, field, option, append, result) {
var history = []
function change(value) {
return page.setCurrent(page, option, "dir", value)
}
function brow(value, dir, event) {
page.setCurrent(page, option, "dir", value)
page.setCurrent(page, option, "dir", dir)
}
return {
"button": ["root", "back"], "action": function(value) {
switch (value) {
case "back": history.length > -1 && change(history.pop() || "/"); break
case "root": change("/"); break
}
},
"table": {"filename": function(value, key, row, index, event) {
var dir = option.dir.value
var file = dir + ((dir && !dir.endsWith("/"))? "/": "") + value
file.endsWith("/")? history.push(change(file)): brow(file, dir, event)
}},
}
},
initPodList: function(page, field, option, append, result) {
return {"button": ["local"], "action": function(value) {
value == "local" && (value = "''")
page.setCurrent(page, option, "pod", value)
}, "table": {"key": function(value) {
page.setCurrent(page, option, "pod", value)
}}}
},
initCtxList: function(page, field, option, append, result) {
return {"button": ["ctx", "shy", "web", "mdb"], "action": function(value) {
page.setCurrent(page, option, "ctx", value)
}, "table": {"names": function(value) {
page.setCurrent(page, option, "ctx", value)
}}}
},
setCurrent: function(page, option, type, value) {
option[type].value = ctx.Current(type, value)
page.History.add(type, value)
ctx.Runs(page, option)
return value
},
initCmdList: function(page, field, option, append, result) {
option.dataset["componet_name_alias"] = "cmd"
option.dataset["componet_name_order"] = 0
option.onactions = function(msg) {
page.showCmdList(msg, option, append, result)
}
var cmd = option.querySelector("input[name=cmd]")
cmd.onkeyup = function(event) {
page.onCmdList(event, cmd, "input", option, append, result)
page.onCmdList(event, cmd, "input", field, option, append, result)
}
var action = conf.bench_data.action
if (action && action["cmd"]) {
cmd.value = action["cmd"].cmd[1]
ctx.Runs(page, option)
page.History.add("cmd", cmd.value)
}
action && action["cmd"] && page.runCmdList(page, option, cmd, action["cmd"].cmd[1])
var max = 0
for (var k in action) {
var order = parseInt(action[k].order)
if (order > max) {
max = order
}
order > max && (max = order)
}
for (var i = 1; i <= max; i++) {
var ui = page.addCmdList("cmd", i)
if (action["cmd"+i]) {
ui.cmd.value = action["cmd"+i].cmd[1]
ctx.Runs(page, ui.option)
page.History.add("cmd", ui.cmd.value)
}
action["cmd"+i] && page.runCmdList(page, ui.option, ui.cmd, action["cmd"+i].cmd[1])
}
page.conf.ncommand = i
return
},
showCmdList: function(msg, option, append, result) {
append.innerHTML = ""
msg && msg.append && kit.AppendTable(append, ctx.Table(msg), msg.append)
result.innerText = (msg && msg.result)? msg.result.join(""): ""
return
runCmdList: function(page, option, target, value) {
target.value = value
target.dataset.history_last = page.History.add("cmd", target.value)
ctx.Runs(page, option)
},
getCmdList: function(input, step, cmd) {
var history = kit.History.get("cmd")
@ -327,23 +326,26 @@ var page = Page({
addCmdList: function(name, order) {
var page = this
var alias = name+order
var ui = kit.AppendChild(document.querySelector("body"), [{"type": "fieldset", "data": {}, "list": [
var ui = kit.AppendChild(document.body, [{"view": ["CmdList", "fieldset"], "list": [
{"text": [alias, "legend"]},
{"view": ["option "+alias, "form", "", "option"], "data": {"dataset": {
"componet_group": "index", "componet_name": name, "componet_name_alias": alias, "componet_name_order": order,
}, "onactions": function(msg) {
page.showCmdList(msg, ui.option, ui.append, ui.result)
}}, "list": [
{"type": "input", "data": {"style": {"display": "none"}}},
{"name": "cmd", "type": "input", "data": {"name": "cmd", "className": "cmd", "onkeyup": function(event) {
page.onCmdList(event, ui.cmd, "input", ui.option, ui.append, ui.result)
}}},
]},
{"view": ["option "+alias, "form", "", "option"],
"data": {"dataset": {
"componet_group": "index", "componet_name": name, "componet_name_alias": alias, "componet_name_order": order,
}},
"list": [
{"type": "input", "data": {"style": {"display": "none"}}},
{"name": "cmd", "type": "input", "data": {"name": "cmd", "className": "cmd", "onkeyup": function(event) {
page.onCmdList(event, ui.cmd, "input", ui.field, ui.option, ui.append, ui.result)
}}},
]
},
{"view": ["append "+alias, "table", "", "append"]},
{"code": ["", "result", "result "+alias]},
]}])
page.OrderForm(page, ui.field, ui.option, ui.append, ui.result)
page.OrderTable(ui.append)
page.OrderCode(ui.code)
page.OrderCode(ui.result)
ui.cmd.focus()
return ui
},
@ -367,7 +369,7 @@ var page = Page({
}
}
},
onCmdList: function(event, target, action, option, append, result) {
onCmdList: function(event, target, action, field, option, append, result) {
var page = this
var order = option.dataset.componet_name_order
var prev_order = (parseInt(order)-1+page.conf.ncommand)%page.conf.ncommand||""
@ -375,13 +377,13 @@ var page = Page({
switch (action) {
case "input":
kit.History.add("key", (event.ctrlKey? "Control+": "")+(event.shiftKey? "Shift+": "")+event.key)
if (event.key == "Escape") {
target.blur()
} else if (event.key == "Enter") {
target.dataset.history_last = page.History.get("cmd").length
page.History.add("cmd", target.value)
ctx.Runs(page, option)
page.runCmdList(page, option, target, target.value)
} else if (event.ctrlKey) {
switch (event.key) {
@ -426,6 +428,13 @@ var page = Page({
}
target.dataset.search_last = ""
break
case "y":
case "v":
case "s":
case "t":
break
case "a":
case "e":
case "f":
@ -452,6 +461,7 @@ var page = Page({
}
kit.DelText(target, i+1, end-i)
break
case "c":
append.innerHTML = ""
result.innerHTML = ""
@ -460,9 +470,7 @@ var page = Page({
append.innerHTML = ""
result.innerHTML = ""
case "j":
target.dataset.history_last = page.History.get("cmd").length
page.History.add("cmd", target.value)
ctx.Runs(page, option)
page.runCmdList(page, option, target, target.value)
break
case "l":
window.scrollTo(0, option.parentElement.offsetTop)
@ -486,11 +494,11 @@ var page = Page({
break
case "q":
page.delCmdList("cmd", order)
break
default:
return
}
} else {
kit.History.add("key", event.key)
if (kit.HitText(target, "jk")) {
kit.DelText(target, target.selectionStart-2, 2)
target.blur()
@ -504,65 +512,23 @@ var page = Page({
var page = this
switch (action) {
case "scroll":
if (event.target != document.body) {
return
if (event.target == document.body) {
kit.ScrollPage(event, page.conf)
}
switch (event.key) {
case "h":
if (event.ctrlKey) {
window.scrollBy(-page.conf.scroll_x*10, 0)
} else {
window.scrollBy(-page.conf.scroll_x, 0)
}
break
case "H":
window.scrollBy(-body.scrollWidth, 0)
break
case "l":
if (event.ctrlKey) {
window.scrollBy(page.conf.scroll_x*10, 0)
} else {
window.scrollBy(page.conf.scroll_x, 0)
}
break
case "L":
window.scrollBy(body.scrollWidth, 0)
break
case "j":
if (event.ctrlKey) {
window.scrollBy(0, page.conf.scroll_y*10)
} else {
window.scrollBy(0, page.conf.scroll_y)
}
break
case "J":
window.scrollBy(0, body.scrollHeight)
break
case "k":
if (event.ctrlKey) {
window.scrollBy(0, -page.conf.scroll_y*10)
} else {
window.scrollBy(0, -page.conf.scroll_y)
}
break
case "K":
window.scrollBy(0, -body.scrollHeight)
break
}
return
break
case "keymap":
if (event.key == "Escape") {
}
if (event.key == "Enter") {
}
if (event.ctrlKey) {
} else if (event.key == "Enter") {
} else if (event.ctrlKey) {
switch (event.key) {
case "m":
page.addCmdList("cmd", page.conf.ncommand++)
return
break
case "z":
page.showResult(page)
return
break
case "0":
case "1":
case "2":
@ -574,7 +540,7 @@ var page = Page({
case "8":
case "9":
document.querySelector("form.option.cmd"+(event.key||"")+" input[name=cmd]").focus()
return
break
}
}
}
@ -599,7 +565,7 @@ var page = Page({
var option = field.querySelector("form.option")
var append = field.querySelector("table.append")
var result = field.querySelector("code.result pre")
page.OrderForm(page, option, append, result)
page.OrderForm(page, field, option, append, result)
page.OrderTable(append)
page.OrderCode(result)
@ -616,12 +582,7 @@ var page = Page({
kit.InsertChild(field, append, "div", buttons)
}
if (conf && conf["table"]) {
option.onactions = function(msg) {
append.innerHTML = ""
kit.AppendTable(append, ctx.Table(msg), msg.append, function(value, key, row, index, event) {
typeof conf["table"][key] == "function" && conf["table"][key](value, key, row, index, event)
})
}
option.daemon_action = conf["table"]
ctx.Runs(page, option)
}
}

View File

@ -21,7 +21,7 @@ ctx = context = {
data[form[i].name] = form[i].value
}
}
this.Run(page, data, [], cb || form.onactions)
this.Run(page, data, [], cb || form.ondaemon)
},
Table: function(msg, cb) {
var ret = []

View File

@ -7,8 +7,6 @@ exp = example = {
reload: function() {
location.reload()
},
_exit: function(page) {
},
}
function Page(page) {

View File

@ -1,10 +1,10 @@
kit = toolkit = {
History: {cmd: [], txt: [], key: [],
History: {dir: [], pod: [], ctx: [], cmd: [], txt: [], key: [],
add: function(type, data) {
var list = this[type] || []
data && list.push({time: Date.now(), data: data})
this[type] = list
return list.length
return list.length-1
},
get: function(type, index) {
var list = this[type] || []
@ -21,6 +21,8 @@ kit = toolkit = {
return args
},
isMobile: navigator.userAgent.indexOf("Mobile") > -1,
CreateStyle: function(style) {
},
ModifyNode: function(which, html) {
var node = typeof which == "string"? document.querySelector(which): which
@ -52,8 +54,9 @@ kit = toolkit = {
return elm
}
// include require styles style
// tree, code, text, view, click
// type, name, data, list
// type, name, data, list, style
var kit = this
subs = subs || {}
@ -61,18 +64,61 @@ kit = toolkit = {
child.data = child.data || {}
child.type = child.type || "div"
if (child.button) {
if (child.style) {
var str = []
for (var k in child.style) {
str.push(k)
str.push(":")
str.push(child.style[k] + (typeof child.style[k] == "number"? "px": ""))
str.push(";")
}
child.data["style"] = str.join("")
}
if (child.include) {
child.data["src"] = child.include[0]
child.data["type"] = "text/javascript"
child.include.length > 1 && (child.data["onload"] = child.include[1])
child.type = "script"
} else if (child.require) {
child.data["href"] = child.require[0]
child.data["rel"] = child.require.length > 1? child.require[1]: "stylesheet"
child.data["type"] = child.require.length > 2? child.require[2]: "text/css"
child.type = "link"
} else if (child.styles) {
var str = []
for (var key in child.styles) {
str.push(key)
str.push(" {")
for (var k in child.styles[key]) {
str.push(k)
str.push(":")
str.push(child.styles[key][k] + (typeof child.styles[key][k] == "number"? "px": ""))
str.push(";")
}
str.push("}\n")
}
child.data["innerHTML"] = str.join("")
child.data["type"] = "text/css"
child.type = "style"
} else if (child.button) {
child.type = "button"
child.data["innerText"] = child.button[0]
child.data["onclick"] = child.button[1]
} else if (child.click) {
child.data["onclick"] = child.click[0]
} else if (child.fork) {
child.type = "li"
child.list = [
{"text": [child.fork[0], "div"]},
{"type": "ul", "list": child.fork[1]},
]
} else if (child.leaf) {
child.type = "li"
child.data["innerText"] = child.leaf[0]
@ -81,15 +127,18 @@ kit = toolkit = {
child.leaf[1](event, node)
}
}
} else if (child.view) {
child.data["className"] = child.view[0]
child.type = child.view.length > 1? child.view[1]: "div"
child.view.length > 2 && (child.data["innerText"] = child.view[2])
child.view.length > 3 && (child.name = child.view[3])
} else if (child.text) {
child.data["innerText"] = child.text[0]
child.type = child.text.length > 1? child.text[1]: "pre"
child.text.length > 2 && (child.data["className"] = child.text[2])
} else if (child.code) {
child.type = "code"
child.list = [{"type": "pre" ,"data": {"innerText": child.code[0]}, "name": child.code[1]}]
@ -99,6 +148,7 @@ kit = toolkit = {
var node = kit.CreateNode(child.type, child.data)
child.list && kit.AppendChild(node, child.list, subs)
child.name && (subs[child.name] = node)
subs.field || (subs.field = node)
parent.append(node)
})
return subs
@ -109,6 +159,9 @@ kit = toolkit = {
return parent.insertBefore(elm, position || parent.firstElementChild)
},
AppendStyle: function(parent, style) {
return node
},
AppendTable: function(table, data, fields, cb) {
if (!data || !fields) {
return
@ -227,20 +280,20 @@ kit = toolkit = {
kit.CopyText()
}
},
OrderForm: function(page, form, append, result) {
if (!form) {return}
form.onactions = form.onactions || function(msg) {
if (!msg) {return}
OrderForm: function(page, field, option, append, result) {
if (!option) {return}
option.ondaemon = option.ondaemon || function(msg) {
append.innerHTML = ""
kit.AppendTable(append, ctx.Table(msg), msg.append)
result.innerHTML = ""
result.innerText = msg.result.join("")
msg && msg.append && kit.AppendTable(append, ctx.Table(msg), msg.append, function(value, key, row, index, event) {
typeof option.daemon_action[key] == "function" && option.daemon_action[key](value, key, row, index, event)
})
result && (result.innerText = (msg && msg.result)? msg.result.join(""): "")
}
form.querySelectorAll("select").forEach(function(select, index, array) {
select.onchange = function(event) {
option.querySelectorAll("select").forEach(function(select, index, array) {
select.onchange = select.onchange || function(event) {
if (index == array.length-1) {
page.Runs(page, form)
page.Runs(page, option)
return
}
if (array[index+1].type == "button") {
@ -250,17 +303,17 @@ kit = toolkit = {
array[index+1].focus()
}
})
form.querySelectorAll("input").forEach(function(input, index, array) {
option.querySelectorAll("input").forEach(function(input, index, array) {
switch (input.type) {
case "button":
input.onclick = function(event) {
input.onclick = input.onclick || function(event) {
if (index == array.length-1) {
if (input.value == "login") {
form.onactions = function(msg) {
option.ondaemon = function(msg) {
page.reload()
}
}
page.Runs(page, form)
page.Runs(page, option)
return
}
if (array[index+1].type == "button") {
@ -270,12 +323,12 @@ kit = toolkit = {
array[index+1].focus()
}
default:
input.onkeyup = function(event) {
input.onkeyup = input.onkeyup || function(event) {
if (event.key != "Enter") {
return
}
if (index == array.length-1) {
page.Runs(page, form)
page.Runs(page, option)
return
}
if (array[index+1].type == "button") {
@ -291,7 +344,6 @@ kit = toolkit = {
CopyText: function(text) {
text = window.getSelection().toString()
if (text == "") {return}
kit.Log(text)
kit.History.add("txt", text)
document.execCommand("copy")
},
@ -309,6 +361,52 @@ kit = toolkit = {
}
return true
},
ScrollPage: function(event, conf) {
switch (event.key) {
case "h":
if (event.ctrlKey) {
window.scrollBy(-conf.scroll_x*10, 0)
} else {
window.scrollBy(-conf.scroll_x, 0)
}
break
case "H":
window.scrollBy(-document.body.scrollWidth, 0)
break
case "l":
if (event.ctrlKey) {
window.scrollBy(conf.scroll_x*10, 0)
} else {
window.scrollBy(conf.scroll_x, 0)
}
break
case "L":
window.scrollBy(document.body.scrollWidth, 0)
break
case "j":
if (event.ctrlKey) {
window.scrollBy(0, conf.scroll_y*10)
} else {
window.scrollBy(0, conf.scroll_y)
}
break
case "J":
window.scrollBy(0, document.body.scrollHeight)
break
case "k":
if (event.ctrlKey) {
window.scrollBy(0, -conf.scroll_y*10)
} else {
window.scrollBy(0, -conf.scroll_y)
}
break
case "K":
window.scrollBy(0, -document.body.scrollHeight)
break
}
return true
},
}
function right(arg) {

View File

@ -6,8 +6,8 @@
<meta name="{{index $meta "name"}}" content="{{index $meta "content"}}">
{{end}}
<title>{{option . "componet_name"|meta}}</title>
<link rel="shortcut icon" type="image/ico" href="/static/librarys/{{option . "favicon"|meta}}">
<title>{{options . "componet_name"}}</title>
<link rel="shortcut icon" type="image/ico" href="/static/librarys/{{options . "favicon"}}">
{{range $index, $lib := option . "styles"}}
<link rel="stylesheet" type="text/css" href="/static/librarys/{{$lib}}"></link>
{{end}}
@ -21,19 +21,19 @@
</script>
{{end}}
{{define "toolkit"}}
<fieldset class="{{option . "componet_view"|meta}}" data-init="{{option . "componet_init"|meta}}">
<div>{{option .Meta "name"}}({{option .Meta "help"}})</div>
<fieldset class="{{options . "componet_view"}}" data-init="{{options . "componet_init"}}">
<div>{{options . "componet_name"}}({{options . "componet_help"}})</div>
</fieldset>
{{end}}
{{define "componet"}}
<fieldset class="{{option . "componet_view"|meta}}" data-init="{{option . "componet_init"|meta}}">
<legend title="{{option .Meta "help"}}">{{option .Meta "name"}}({{option .Meta "help"}})</legend>
{{$msg := .}} {{$form_type := option . "form_type"|meta}}
<fieldset class="{{options . "componet_view"}}" data-init="{{options . "componet_init"}}">
<legend title="{{options . "componet_help"}}">{{options . "componet_name"}}({{options . "componet_help"}})</legend>
{{$msg := .}}
<form class="option {{option .Meta "componet_name"}}"
data-componet_group="{{option . "componet_group"|meta}}"
data-componet_name="{{option . "componet_name"|meta}}"
{{if eq $form_type "upload"}}
<form class="option {{options . "componet_name"}}"
data-componet_group="{{options . "componet_group"}}"
data-componet_name="{{options . "componet_name"}}"
{{$form_type := options . "form_type"}} {{if eq $form_type "upload"}}
method="POST" action="/upload" enctype="multipart/form-data" target="_blank"
{{end}}>
@ -72,8 +72,8 @@
<hr/>
</form>
{{if index .Meta "display_append"}} {{option .Meta "display_append"}} {{else}}
<table class="append {{option .Meta "componet_name"}}"> {{$msg := .}}
{{if index .Meta "display_append"}} {{options . "display_append"}} {{else}}
<table class="append {{options . "componet_name"}}"> {{$msg := .}}
<tr>{{range $field := append .}}<th>{{$field}}</th>{{end}}</tr>
{{range $line := table .}}
<tr>{{range $field := append $msg}}<td>{{index $line $field|unescape}}</td>{{end}}</tr>
@ -81,12 +81,12 @@
</table>
{{end}}
{{if index .Meta "display_result"}} {{option .Meta "display_result"}} {{else}}
<code class="result {{option .Meta "componet_name"}}"><pre>{{result .Meta}}</pre></code>
{{if index .Meta "display_result"}} {{options . "display_result"}} {{else}}
<code class="result {{options . "componet_name"}}"><pre>{{result .Meta}}</pre></code>
{{end}}
{{if index .Meta "display_div"}} {{option .Meta "display_div"}} {{else}}
<div class="result {{option .Meta "componet_name"}}"></div>
{{if index .Meta "display_div"}} {{options . "display_div"}} {{else}}
<div class="result {{options . "componet_name"}}"></div>
{{end}}
</fieldset>
{{end}}