forked from x/ContextOS
add plugin vim
This commit is contained in:
parent
df1ba45a6d
commit
6d7886770f
@ -71,7 +71,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"least": "10",
|
||||
}},
|
||||
"txts": map[string]interface{}{"meta": map[string]interface{}{
|
||||
"fields": "time sid text line col file pwd",
|
||||
"fields": "time sid word line col file pwd",
|
||||
"store": "var/tmp/vim/txts.csv",
|
||||
"limit": "30",
|
||||
"least": "10",
|
||||
@ -81,7 +81,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"fields": "sid buf tag file line",
|
||||
}},
|
||||
"regs": map[string]interface{}{"meta": map[string]interface{}{
|
||||
"fields": "sid reg text",
|
||||
"fields": "sid reg word",
|
||||
}},
|
||||
"marks": map[string]interface{}{"meta": map[string]interface{}{
|
||||
"fields": "sid mark line col file",
|
||||
@ -90,7 +90,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"fields": "sid tag line file",
|
||||
}},
|
||||
"fixs": map[string]interface{}{"meta": map[string]interface{}{
|
||||
"fields": "sid fix file line text",
|
||||
"fields": "sid fix file line word",
|
||||
}},
|
||||
}},
|
||||
"cache": {Name: "cache", Help: "缓存默认的全局配置", Value: map[string]interface{}{
|
||||
@ -668,9 +668,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
}
|
||||
fields := strings.Split(kit.Select(m.Conf("vim", arg[0]+".meta.fields"), arg, 3), " ")
|
||||
m.Confm("vim", []string{arg[0], "hash"}, func(key string, index int, value map[string]interface{}) {
|
||||
m.Log("fuck", "what %v ---%v--- %v", arg, value[arg[1]], strings.HasPrefix(kit.Format(value[arg[1]]), arg[2]))
|
||||
if value["sid"] = key; len(arg) == 1 || arg[1] == "" || strings.HasPrefix(kit.Format(value[arg[1]]), arg[2]) {
|
||||
m.Log("fuck", "----what %v %v %v", arg, len(arg), arg[1] == "")
|
||||
m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
|
||||
}
|
||||
})
|
||||
@ -722,7 +720,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
m.Grow("vim", "txts", map[string]interface{}{
|
||||
"time": m.Time(),
|
||||
"sid": m.Option("sid"),
|
||||
"text": m.Option("arg"),
|
||||
"word": m.Option("arg"),
|
||||
"line": m.Option("row"),
|
||||
"col": m.Option("col"),
|
||||
"file": m.Option("buf"),
|
||||
@ -737,14 +735,14 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
m.Conf("vim", []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{
|
||||
"buf": value["id"],
|
||||
"tag": value["tag"],
|
||||
"file": value["name"],
|
||||
"file": strings.TrimSuffix(strings.TrimPrefix(value["name"], "\""), "\""),
|
||||
"line": value["line"],
|
||||
})
|
||||
})
|
||||
case "regs":
|
||||
m.Split(strings.TrimPrefix(m.Option("sub"), "\n--- Registers ---\n"), " ", "2", "name text").Table(func(index int, value map[string]string) {
|
||||
m.Split(strings.TrimPrefix(m.Option("sub"), "\n--- Registers ---\n"), " ", "2", "name word").Table(func(index int, value map[string]string) {
|
||||
m.Conf("vim", []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{
|
||||
"text": strings.Replace(strings.Replace(value["text"], "^I", "\t", -1), "^J", "\n", -1),
|
||||
"word": strings.Replace(strings.Replace(value["word"], "^I", "\t", -1), "^J", "\n", -1),
|
||||
"reg": strings.TrimPrefix(value["name"], "\""),
|
||||
})
|
||||
})
|
||||
@ -769,13 +767,13 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
if strings.HasPrefix(m.Option("sub"), "\nError") {
|
||||
break
|
||||
}
|
||||
m.Split(strings.TrimPrefix(m.Option("sub"), "\n"), " ", "3", "id file text").Table(func(index int, value map[string]string) {
|
||||
m.Split(strings.TrimPrefix(m.Option("sub"), "\n"), " ", "3", "id file word").Table(func(index int, value map[string]string) {
|
||||
vs := strings.Split(kit.Format(value["file"]), ":")
|
||||
m.Conf("vim", []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{
|
||||
"fix": value["id"],
|
||||
"file": vs[0],
|
||||
"line": vs[1],
|
||||
"text": value["text"],
|
||||
"word": value["word"],
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -119,14 +119,18 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
|
||||
}
|
||||
return
|
||||
}},
|
||||
"tip": {Name: "tip", Help: "便签", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
"tip": {Name: "tip action table index ...", Help: "便签", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
switch arg[0] {
|
||||
case "show":
|
||||
m.Cmdy("ssh.data", "show", arg[1], arg[2:])
|
||||
if len(arg) == 1 || arg[2] == "" {
|
||||
m.Cmdy("ssh.data", "show", arg[1])
|
||||
} else {
|
||||
m.Cmdy("ssh.data", "show", arg[1], arg[2])
|
||||
}
|
||||
case "insert":
|
||||
m.Cmdy("ssh.data", "insert", arg[1], arg[2:])
|
||||
m.Cmdy("ssh.data", "insert", arg[1], arg[3:])
|
||||
case "update":
|
||||
m.Cmdy("ssh.data", "update", arg[1], arg[2:])
|
||||
m.Cmdy("ssh.data", "update", arg[1], arg[2], arg[3:])
|
||||
}
|
||||
return
|
||||
}},
|
||||
|
3
src/plugin/vim/index.css
Normal file
3
src/plugin/vim/index.css
Normal file
@ -0,0 +1,3 @@
|
||||
fieldset.item.vim div.output {
|
||||
}
|
||||
|
36
src/plugin/vim/index.go
Normal file
36
src/plugin/vim/index.go
Normal file
@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"contexts/cli"
|
||||
"contexts/ctx"
|
||||
"toolkit"
|
||||
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
var Index = &ctx.Context{Name: `vim`, Help: `plugin`,
|
||||
Caches: map[string]*ctx.Cache{},
|
||||
Configs: map[string]*ctx.Config{
|
||||
"_index": &ctx.Config{Name: "index", Value: []interface{}{
|
||||
map[string]interface{}{"name": "demo", "help": "demo",
|
||||
"tmpl": "componet", "view": "", "init": "",
|
||||
"type": "public", "ctx": "demo", "cmd": "demo",
|
||||
"args": []interface{}{}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "pod", "value": "hello world"},
|
||||
map[string]interface{}{"type": "button", "value": "执行"},
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"demo": {Name: "demo", Help: "demo", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Echo(kit.Select("hello world", arg, 0))
|
||||
return
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Print(cli.Index.Plugin(Index, os.Args[1:]))
|
||||
}
|
3
src/plugin/vim/index.js
Normal file
3
src/plugin/vim/index.js
Normal file
@ -0,0 +1,3 @@
|
||||
Script["vim/index.js"] = function(field, option, output) {return {
|
||||
}}
|
||||
|
86
src/plugin/vim/index.shy
Normal file
86
src/plugin/vim/index.shy
Normal file
@ -0,0 +1,86 @@
|
||||
|
||||
fun tips "便签" private \
|
||||
select "" name "action" values "show" values "insert" values "update" \
|
||||
text "tip" name table \
|
||||
text "" name index imports plugin_view_tip_id view tiny \
|
||||
text "" name file imports plugin_vim_file view long \
|
||||
text "" name line imports plugin_vim_line view tiny \
|
||||
text "" name word imports plugin_vim_word view long \
|
||||
textarea "" name note \
|
||||
feature detail "修改" "复制" "下载" \
|
||||
exports tip_id id "" vim_file file "" vim_line line "" vim_word word "" \
|
||||
button "记录" action auto
|
||||
|
||||
if $1 == "show"
|
||||
copy skip ssh.data _ _
|
||||
end
|
||||
if $1 == "insert"
|
||||
copy skip ssh.data insert $2 file $4 line $5 word $6 note $7
|
||||
end
|
||||
if $1 == "update"
|
||||
copy skip ssh.data update $2 $3 file $4 line $5 word $6 note $7
|
||||
end
|
||||
if $2 == "modify"
|
||||
copy skip ssh.data update $table $1 $3 $4
|
||||
end
|
||||
end
|
||||
|
||||
kit editor "编辑器" private "web.code.vim" editor \
|
||||
text "times status pid pane" name fields \
|
||||
button "查看" action auto
|
||||
|
||||
kit opens "文件记录" private "web.code.vim" opens \
|
||||
text "10" name limit view tiny \
|
||||
text "0" name offset view tiny \
|
||||
text "times action files" name fields \
|
||||
button "查看" action auto
|
||||
|
||||
kit cmds "命令记录" private "web.code.vim" cmds \
|
||||
text "10" name limit view tiny \
|
||||
text "0" name offset view tiny \
|
||||
text "times cmd files" name fields \
|
||||
exports vim_word cmd \
|
||||
button "查看" action auto
|
||||
|
||||
kit txts "插入记录" private "web.code.vim" txts \
|
||||
text "10" name limit view tiny \
|
||||
text "0" name offset view tiny \
|
||||
text "times word files" name fields \
|
||||
exports vim_word word \
|
||||
button "查看" action auto
|
||||
|
||||
kit bufs "文件缓存" private "web.code.vim" bufs \
|
||||
text "tag" name key view tiny \
|
||||
text "" name value \
|
||||
text "sids tag file line" name fields \
|
||||
exports vim_file file "" vim_line line \
|
||||
button "查看" action auto
|
||||
|
||||
kit regs "粘贴缓存" private "web.code.vim" regs \
|
||||
text "reg" name key view tiny \
|
||||
text "" name value \
|
||||
text "sids reg word" name fields \
|
||||
exports vim_word word \
|
||||
button "查看" action auto
|
||||
|
||||
kit marks "文件标记" private "web.code.vim" marks \
|
||||
text "mark" name key view tiny \
|
||||
text "" name value \
|
||||
text "sids mark line file" name fields \
|
||||
exports vim_file file "" vim_line line "" \
|
||||
button "查看" action auto
|
||||
|
||||
kit tags "语法标记" private "web.code.vim" tags \
|
||||
text "tag" name key view tiny \
|
||||
text "" name value \
|
||||
text "sids tag line file" name fields \
|
||||
exports vim_file file "" vim_line line "" vim_word tag "" \
|
||||
button "查看" action auto
|
||||
|
||||
kit fixs "项目索引" private "web.code.vim" fixs \
|
||||
text "files" name key view tiny \
|
||||
text "" name value \
|
||||
text "sids word line file" name fields \
|
||||
exports vim_file file "" vim_line line "" vim_word word "" \
|
||||
button "查看" action auto
|
||||
|
@ -4,7 +4,7 @@ ctx = context = (function(kit) {var ctx = {__proto__: kit,
|
||||
|
||||
var option = {"cmds": cmd}
|
||||
msg.option && msg.option.forEach(function(item) {
|
||||
msg.option[item] && (option[item] = msg.option[item])
|
||||
msg[item] && (option[item] = msg[item])
|
||||
})
|
||||
for (var k in dataset) {
|
||||
option[k] = dataset[k].split(",")
|
||||
@ -48,6 +48,13 @@ ctx = context = (function(kit) {var ctx = {__proto__: kit,
|
||||
Format: function() {
|
||||
return msg.append && msg.append[0]? ["table", JSON.stringify(msg.Table())]: ["code", msg.result? msg.result.join(""): ""]
|
||||
},
|
||||
Option: function(key, val) {
|
||||
msg.option = msg.option || []
|
||||
kit.List(msg.option, function(k) {
|
||||
if (k == key) {return k}
|
||||
}).length > 0 || msg.option.push(key)
|
||||
msg[key] = kit.List(arguments).slice(1)
|
||||
},
|
||||
Result: function() {return msg.result? msg.result.join(""): ""},
|
||||
Results: function() {return kit.Color(msg.Result().replace(/</g, "<").replace(/>/g, ">"))},
|
||||
Table: function(cb) {if (!msg.append || !msg.append.length || !msg[msg.append[0]]) {return}
|
||||
|
@ -1242,6 +1242,7 @@ function Plugin(page, pane, field, inits, runs) {
|
||||
var list = arguments.callee.list
|
||||
|
||||
for (var i = 0; i < list.length; i += 3) {if (list[i+1] == name || list[i+2]) {
|
||||
plugin.ontoast(list[i+1]? line[list[i+1]]: value, list[i+1]||name)
|
||||
for (var i = 0; i < list.length; i += 3) {
|
||||
page.Sync("plugin_"+list[i]).set(meta[list[i+2]||""](list[i+1]? line[list[i+1]]: value, list[i+1]||name, line, list))
|
||||
}
|
||||
@ -1481,12 +1482,17 @@ function Output(plugin, type, msg, cb, target, option) {
|
||||
var text = td.innerText.trim()
|
||||
if (typeof meta[item] == "function") {meta[item](event, text); return}
|
||||
|
||||
item == "修改"? (text = kit.AppendChilds(td, [{type: "input", value: text, data: {onkeydown: function(event) {
|
||||
item == "修改"? (text = kit.AppendChilds(td, [{type: "input", value: text, style: {width: td.clientWidth+"px"}, data: {onkeydown: function(event) {
|
||||
if (event.key == "Enter") {
|
||||
var id = ""
|
||||
for (var i = 0; i < exports.length-1; i += 3) {
|
||||
id = (id || line[exports[i+1]] || "").trim()
|
||||
}
|
||||
|
||||
var msg = plugin.Event(event)
|
||||
kit.Selector(option, ".args", function(item) {
|
||||
msg.Option(item.name, item.value)
|
||||
})
|
||||
plugin.Run(event, [id, meta[item], name, event.target.value], function(msg) {
|
||||
td.innerHTML = event.target.value
|
||||
plugin.ontoast("修改成功")
|
||||
|
Loading…
x
Reference in New Issue
Block a user