forked from x/icebergs
add trans
This commit is contained in:
parent
8f8a590d7a
commit
2ebe5294d3
@ -1,7 +1,19 @@
|
|||||||
|
" 变量定义
|
||||||
|
func! ShyDefine(name, value)
|
||||||
|
if !exists("name") | exec "let " . a:name . " = \"" . a:value . "\"" | endif
|
||||||
|
endfunc
|
||||||
|
|
||||||
let ctx_url = (len($ctx_dev) > 1? $ctx_dev: "http://127.0.0.1:9095") . "/code/vim"
|
" 输出日志
|
||||||
if !exists("g:ctx_sid") | let ctx_sid = "" | end
|
" call ShyDefine("g:ShyLog", "/dev/null")
|
||||||
|
call ShyDefine("g:ShyLog", "shy.log")
|
||||||
|
fun! ShyLog(...)
|
||||||
|
call writefile([strftime("%Y-%m-%d %H:%M:%S ") . join(a:000, " ")], g:ShyLog, "a")
|
||||||
|
endfun
|
||||||
|
command -nargs=+ ShyLog call writefile([strftime("%Y-%m-%d %H:%M:%S ") . join([<f-args>], " ")], g:ShyLog, "a")
|
||||||
|
|
||||||
|
" 后端通信
|
||||||
|
call ShyDefine("g:ctx_sid", "")
|
||||||
|
call ShyDefine("g:ctx_url", (len($ctx_dev) > 1? $ctx_dev: "http://127.0.0.1:9020") . "/code/vim")
|
||||||
fun! ShySend(arg)
|
fun! ShySend(arg)
|
||||||
if has_key(a:arg, "sub") && a:arg["sub"] != ""
|
if has_key(a:arg, "sub") && a:arg["sub"] != ""
|
||||||
let temp = tempname()
|
let temp = tempname()
|
||||||
@ -10,22 +22,33 @@ fun! ShySend(arg)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
let a:arg["buf"] = bufname("%")
|
let a:arg["buf"] = bufname("%")
|
||||||
let a:arg["pwd"] = getcwd()
|
|
||||||
let a:arg["sid"] = g:ctx_sid
|
let a:arg["sid"] = g:ctx_sid
|
||||||
|
let a:arg["pwd"] = getcwd()
|
||||||
let args = ""
|
let args = ""
|
||||||
for k in keys(a:arg)
|
for k in sort(keys(a:arg))
|
||||||
let args = args . " -F '" . k . "=" . a:arg[k] . "' "
|
let args = args . " -F '" . k . "=" . a:arg[k] . "' "
|
||||||
endfor
|
endfor
|
||||||
return system("curl -s " . g:ctx_url . args . " 2>/dev/null")
|
return system("curl -s " . g:ctx_url . args . " 2>/dev/null")
|
||||||
endfun
|
endfun
|
||||||
|
fun! ShySends(...)
|
||||||
|
let args = {}
|
||||||
|
if len(a:000) > 0 | let args["cmd"] = a:000[0] | endif
|
||||||
|
if len(a:000) > 1 | let args["arg"] = a:000[1] | endif
|
||||||
|
if len(a:000) > 2 | let args["sub"] = a:000[2] | endif
|
||||||
|
return ShySend(args)
|
||||||
|
endfun
|
||||||
|
|
||||||
|
" 用户登录
|
||||||
fun! ShyLogout()
|
fun! ShyLogout()
|
||||||
if g:ctx_sid == "" | return | endif
|
if g:ctx_sid == "" | return | endif
|
||||||
call ShySend({"cmd": "logout"})
|
call ShySends("logout")
|
||||||
endfun
|
endfun
|
||||||
fun! ShyLogin()
|
fun! ShyLogin()
|
||||||
let g:ctx_sid = ShySend({"cmd": "login", "share": $ctx_share, "pid": getpid(), "pane": $TMUX_PANE, "hostname": hostname(), "username": $USER})
|
let g:ctx_sid = ShySend({"cmd": "login", "share": $ctx_share, "pid": getpid(), "pane": $TMUX_PANE, "hostname": hostname(), "username": $USER})
|
||||||
endfun
|
endfun
|
||||||
|
call ShyLogin()
|
||||||
|
|
||||||
|
" 收藏列表
|
||||||
fun! ShyFavor()
|
fun! ShyFavor()
|
||||||
if !exists("g:favor_tab") | let g:favor_tab = "" | endif
|
if !exists("g:favor_tab") | let g:favor_tab = "" | endif
|
||||||
if !exists("g:favor_note") | let g:favor_note = "" | endif
|
if !exists("g:favor_note") | let g:favor_note = "" | endif
|
||||||
@ -46,6 +69,7 @@ fun! ShyFavors()
|
|||||||
if note != "" | lexpr note | lopen | let note = "" | endif
|
if note != "" | lexpr note | lopen | let note = "" | endif
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
|
" 数据同步
|
||||||
fun! ShySync(target)
|
fun! ShySync(target)
|
||||||
if bufname("%") == "ControlP" | return | end
|
if bufname("%") == "ControlP" | return | end
|
||||||
|
|
||||||
@ -77,9 +101,12 @@ fun! ShyCheck(target)
|
|||||||
end
|
end
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
|
" 任务列表
|
||||||
fun! ShyTask()
|
fun! ShyTask()
|
||||||
call ShySend({"cmd": "tasklet", "arg": input("target: "), "sub": input("detail: ")})
|
call ShySend({"cmd": "tasklet", "arg": input("target: "), "sub": input("detail: ")})
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
|
" 标签列表
|
||||||
fun! ShyGrep(word)
|
fun! ShyGrep(word)
|
||||||
if !exists("g:grep_dir") | let g:grep_dir = "./" | endif
|
if !exists("g:grep_dir") | let g:grep_dir = "./" | endif
|
||||||
let g:grep_dir = input("dir: ", g:grep_dir, "file")
|
let g:grep_dir = input("dir: ", g:grep_dir, "file")
|
||||||
@ -88,11 +115,42 @@ endfun
|
|||||||
fun! ShyTag(word)
|
fun! ShyTag(word)
|
||||||
execute "tag " . a:word
|
execute "tag " . a:word
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
|
" 输入转换
|
||||||
|
fun! ShyTrans(code)
|
||||||
|
return split(ShySend({"cmd": "trans", "arg": a:code, "pre": getline("."), "row": line("."), "col": col(".")}), "\n")
|
||||||
|
endfun
|
||||||
|
|
||||||
|
fun! ShyInput()
|
||||||
|
call ShyLog("input", v:char, line("."), col("."))
|
||||||
|
endfun
|
||||||
|
|
||||||
|
" 输入补全
|
||||||
|
fun! ShyComplete(firststart, base)
|
||||||
|
if a:firststart | let line = getline('.') | let start = col('.') - 1
|
||||||
|
" 命令位置
|
||||||
|
if match(trim(line), "ice ") == 0 | return match(line, "ice ") | endif
|
||||||
|
" 符号位置
|
||||||
|
if line[start-1] !~ "\a" | return start - 1 | end
|
||||||
|
" 单词位置
|
||||||
|
while start > 0 && line[start - 1] =~ '\a' | let start -= 1 | endwhile
|
||||||
|
return start
|
||||||
|
endif
|
||||||
|
|
||||||
|
" 符号转换
|
||||||
|
if a:base == "," | return [",", ","] | end
|
||||||
|
if a:base == "." | return ["。", "."] | end
|
||||||
|
" 单词转换
|
||||||
|
return ShyTrans(a:base)
|
||||||
|
endfun
|
||||||
|
set completefunc=ShyComplete
|
||||||
|
|
||||||
|
" 帮助信息
|
||||||
fun! ShyHelp()
|
fun! ShyHelp()
|
||||||
echo ShySend({"cmd": "help"})
|
echo ShySend({"cmd": "help"})
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
call ShyLogin()
|
" 事件回调
|
||||||
autocmd! VimLeave * call ShyLogout()
|
autocmd! VimLeave * call ShyLogout()
|
||||||
autocmd! BufReadPost * call ShySync("bufs")
|
autocmd! BufReadPost * call ShySync("bufs")
|
||||||
autocmd! BufReadPost * call ShySync("read")
|
autocmd! BufReadPost * call ShySync("read")
|
||||||
@ -100,9 +158,14 @@ autocmd! BufWritePre * call ShySync("write")
|
|||||||
autocmd! CmdlineLeave * call ShySync("exec")
|
autocmd! CmdlineLeave * call ShySync("exec")
|
||||||
autocmd! QuickFixCmdPost * call ShyCheck("fixs")
|
autocmd! QuickFixCmdPost * call ShyCheck("fixs")
|
||||||
autocmd! InsertLeave * call ShySync("insert")
|
autocmd! InsertLeave * call ShySync("insert")
|
||||||
|
autocmd! InsertCharPre * call ShyInput()
|
||||||
|
|
||||||
|
" 按键映射
|
||||||
nnoremap <C-G><C-G> :call ShyGrep(expand("<cword>"))<CR>
|
nnoremap <C-G><C-G> :call ShyGrep(expand("<cword>"))<CR>
|
||||||
nnoremap <C-G><C-R> :call ShyCheck("cache")<CR>
|
nnoremap <C-G><C-R> :call ShyCheck("cache")<CR>
|
||||||
nnoremap <C-G><C-F> :call ShyFavor()<CR>
|
nnoremap <C-G><C-F> :call ShyFavor()<CR>
|
||||||
nnoremap <C-G>f :call ShyFavors()<CR>
|
nnoremap <C-G>f :call ShyFavors()<CR>
|
||||||
nnoremap <C-G><C-T> :call ShyTask()<CR>
|
nnoremap <C-G><C-T> :call ShyTask()<CR>
|
||||||
|
inoremap <C-K> <C-X><C-U>
|
||||||
|
vnoremap <C-K> :call ShyTrans()
|
||||||
|
|
||||||
|
@ -283,6 +283,28 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
|||||||
case "tasklet":
|
case "tasklet":
|
||||||
m.Cmd(ice.APP_MISS, m.Option("arg"), m.Option("sub"))
|
m.Cmd(ice.APP_MISS, m.Option("arg"), m.Option("sub"))
|
||||||
|
|
||||||
|
case "trans":
|
||||||
|
if strings.HasPrefix(strings.TrimSpace(m.Option("arg")), "ice ") {
|
||||||
|
arg := kit.Split(strings.TrimPrefix(strings.TrimSpace(m.Option("arg")), "ice "))
|
||||||
|
switch arg[0] {
|
||||||
|
case "add":
|
||||||
|
m.Cmd("cli.input.input", "push", arg[1:])
|
||||||
|
m.Option("arg", arg[2])
|
||||||
|
default:
|
||||||
|
m.Set("append")
|
||||||
|
if m.Cmdy(arg).Table(); strings.TrimSpace(m.Result()) == "" {
|
||||||
|
m.Cmdy(ice.CLI_SYSTEM, arg)
|
||||||
|
}
|
||||||
|
m.Info("trans: --%s--", m.Result())
|
||||||
|
m.Push("_output", "result")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.Cmd("cli.input.match", m.Option("arg")).Table(func(index int, value map[string]string, head []string) {
|
||||||
|
m.Echo("%s\n", value["text"])
|
||||||
|
m.Push("_output", "result")
|
||||||
|
})
|
||||||
|
|
||||||
case "favor":
|
case "favor":
|
||||||
if m.Options("arg") {
|
if m.Options("arg") {
|
||||||
m.Cmd(ice.WEB_FAVOR, m.Option("tab"), "vimrc", m.Option("note"), m.Option("arg"),
|
m.Cmd(ice.WEB_FAVOR, m.Option("tab"), "vimrc", m.Option("note"), m.Option("arg"),
|
||||||
|
@ -18,12 +18,14 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
|
|||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
"input": {Name: "input", Help: "输入法", Value: kit.Data(
|
"input": {Name: "input", Help: "输入法", Value: kit.Data(
|
||||||
"store", "var/input/", "limit", "2000", "least", "1000",
|
"store", "var/input/", "limit", "2000", "least", "1000",
|
||||||
|
kit.MDB_SHORT, "code",
|
||||||
)},
|
)},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Cmd(ice.CTX_CONFIG, "load", "input.json")
|
m.Cmd(ice.CTX_CONFIG, "load", "input.json")
|
||||||
}},
|
}},
|
||||||
|
|
||||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Cmd(ice.CTX_CONFIG, "save", "input.json", "cli.input.input")
|
m.Cmd(ice.CTX_CONFIG, "save", "input.json", "cli.input.input")
|
||||||
}},
|
}},
|
||||||
@ -49,6 +51,10 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case "push":
|
||||||
|
m.Rich("input", nil, kit.Dict(
|
||||||
|
"id", "0", "text", arg[1], "code", arg[2], "weight", kit.Select("99990000", arg, 3),
|
||||||
|
))
|
||||||
case "list":
|
case "list":
|
||||||
// 词汇列表
|
// 词汇列表
|
||||||
m.Option("cache.offend", kit.Select("0", arg, 1))
|
m.Option("cache.offend", kit.Select("0", arg, 1))
|
||||||
@ -65,6 +71,11 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.Info("add %s: %s", arg[0], kit.Hashs(arg[0]))
|
||||||
|
m.Richs("input", nil, arg[0], func(key string, value map[string]interface{}) {
|
||||||
|
m.Push(key, value, []string{"id", "code", "text", "weight"})
|
||||||
|
})
|
||||||
|
|
||||||
// 搜索方法
|
// 搜索方法
|
||||||
method := "word"
|
method := "word"
|
||||||
if len(arg) > 1 {
|
if len(arg) > 1 {
|
||||||
@ -95,9 +106,10 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
|
|||||||
|
|
||||||
// 搜索词汇
|
// 搜索词汇
|
||||||
bio := csv.NewReader(bytes.NewBufferString(m.Cmdx(ice.CLI_SYSTEM, "grep", "-rh", arg[0], m.Conf("input", "meta.store"))))
|
bio := csv.NewReader(bytes.NewBufferString(m.Cmdx(ice.CLI_SYSTEM, "grep", "-rh", arg[0], m.Conf("input", "meta.store"))))
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < kit.Int(kit.Select("100", arg, 2)); i++ {
|
||||||
if line, e := bio.Read(); e != nil {
|
if line, e := bio.Read(); e != nil {
|
||||||
break
|
break
|
||||||
|
} else if len(line) < 3 {
|
||||||
} else {
|
} else {
|
||||||
if method == "word" && i == 0 {
|
if method == "word" && i == 0 {
|
||||||
// 添加收藏
|
// 添加收藏
|
||||||
@ -112,6 +124,7 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m.Sort("weight", "int_r")
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user