From 1f748b17b396fd989e602247c047e5f9adf2a0d9 Mon Sep 17 00:00:00 2001 From: shaoying Date: Wed, 1 Jul 2020 09:58:33 +0800 Subject: [PATCH] opt chrome --- base/web/dream.go | 3 +- core/wiki/draw.go | 2 +- misc/chrome/chrome.go | 71 +++++++++--------------------------- misc/input/input.go | 12 ++++++- misc/vim/auto.vim | 83 +++++++++++++++++-------------------------- misc/vim/vim.go | 77 ++++++++++++++------------------------- 6 files changed, 88 insertions(+), 160 deletions(-) diff --git a/base/web/dream.go b/base/web/dream.go index 0096510e..3e9e1b42 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -4,7 +4,6 @@ import ( ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/base/gdb" - "github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/nfs" kit "github.com/shylinux/toolkits" @@ -25,7 +24,7 @@ func _dream_list(m *ice.Message) { m.Push(kit.MDB_STATUS, gdb.STOP) } for _, k := range []string{"start", "stop", "restart"} { - m.Push(k, m.Cmdx(mdb.RENDER, RENDER.Button, k)) + m.Push(k, m.Cmdx("_render", RENDER.Button, k)) } }) m.Sort(kit.MDB_NAME) diff --git a/core/wiki/draw.go b/core/wiki/draw.go index 59e6da2b..756db2ac 100644 --- a/core/wiki/draw.go +++ b/core/wiki/draw.go @@ -35,7 +35,7 @@ func init() { Commands: map[string]*ice.Command{ DRAW: {Name: "draw path=hi.svg auto", Help: "思维导图", Meta: kit.Dict(mdb.PLUGIN, DrawPlugin), Action: map[string]*ice.Action{ nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) { - _wiki_save(m, DATA, arg[0], kit.Select(m.Option("content"), arg, 1)) + _wiki_save(m, DRAW, arg[0], kit.Select(m.Option("content"), arg, 1)) }}, "run": {Name: "show zone type name text", Help: "运行", Hand: func(m *ice.Message, arg ...string) { _draw_show(m, arg[0], arg[1], arg[2], arg[3], arg[4:]...) diff --git a/misc/chrome/chrome.go b/misc/chrome/chrome.go index aa0e336a..1bed9e16 100644 --- a/misc/chrome/chrome.go +++ b/misc/chrome/chrome.go @@ -9,6 +9,8 @@ import ( ) const CHROME = "chrome" +const HISTORY = "history" +const BOOKMARK = "bookmark" var Index = &ice.Context{Name: "chrome", Help: "浏览器", Configs: map[string]*ice.Config{ @@ -18,80 +20,39 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器", }, Commands: map[string]*ice.Command{ "/crx": {Name: "/crx", Help: "/crx", Action: map[string]*ice.Action{ - "history": {Name: "history", Help: "历史记录", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(web.SPIDE, "dev", "/code/chrome/favor", "cmds", "insert", "name", arg[1], "note", arg[2], - "tab", m.Conf(CHROME, "meta.favor"), "sid", m.Option("sid")) + web.HISTORY: {Name: "history", Help: "历史记录", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(web.SPIDE, "dev", "/code/chrome/favor", "cmds", mdb.INSERT, + "tab", m.Conf(CHROME, "meta.favor"), "name", arg[1], "note", arg[2], + "sid", m.Option("sid")) }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, "/favor": {Name: "/favor", Help: "收藏", Action: map[string]*ice.Action{ mdb.INSERT: {Name: "insert", Help: "插入", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(web.FAVOR, mdb.INSERT, m.Option("tab"), web.SPIDE, m.Option("name"), m.Option("note")) }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, - CHROME: {Name: "chrome", Help: "浏览器", List: kit.List( - kit.MDB_INPUT, "text", "name", "name", "action", "auto", - kit.MDB_INPUT, "text", "name", "wid", "action", "auto", - kit.MDB_INPUT, "text", "name", "url", - kit.MDB_INPUT, "button", "name", "查看", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - ), Meta: kit.Dict("detail", []string{"编辑", "goBack", "goForward", "duplicate", "reload", "remove"}), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + CHROME: {Name: "chrome name=chrome wid=auto url auto", Help: "浏览器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { // 窗口列表 - m.Richs(web.SPACE, nil, "*", func(key string, value map[string]interface{}) { - if kit.Format(value["type"]) == "chrome" { - m.Push(key, value, []string{"time", "name"}) + m.Richs(web.SPACE, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) { + if kit.Format(value[kit.MDB_TYPE]) == CHROME { + m.Push(key, value, []string{kit.MDB_TIME, kit.MDB_NAME}) } }) return } - if arg[0] == "action" { - // 命令转换 - m.Cmdy(web.SPACE, m.Option("name"), "tabs", m.Option("tid"), arg[1]) - arg = []string{m.Option("name"), m.Option("wid")} - } // 下发命令 - m.Cmdy(web.SPACE, arg[0], "wins", arg[1:]) + m.Cmdy(web.SPACE, arg[0], CHROME, arg[1:]) }}, - "cookie": {Name: "cookie", Help: "数据", List: kit.List( - kit.MDB_INPUT, "text", "name", "name", "action", "auto", - kit.MDB_INPUT, "text", "name", "id", "action", "auto", - kit.MDB_INPUT, "button", "name", "查看", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - ), Meta: kit.Dict("detail", []string{"编辑", "删除"}), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + BOOKMARK: {Name: "bookmark name=chrome auto", Help: "书签", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { // 窗口列表 - m.Cmdy("chrome") + m.Cmdy(CHROME) return } - if arg[0] == "action" { - // 命令转换 - m.Cmdy(web.SPACE, m.Option("name"), "cookie", arg[1:]) - arg = []string{m.Option("name"), m.Option("id")} - } // 下发命令 - m.Cmdy(web.SPACE, arg[0], "cookie", arg[1:]) - }}, - "bookmark": {Name: "bookmark", Help: "书签", List: kit.List( - kit.MDB_INPUT, "text", "name", "name", "action", "auto", - kit.MDB_INPUT, "text", "name", "id", "action", "auto", - kit.MDB_INPUT, "button", "name", "查看", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - ), Meta: kit.Dict("detail", []string{"编辑", "删除"}), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) == 0 { - // 窗口列表 - m.Cmdy("chrome") - return - } - if arg[0] == "action" { - // 命令转换 - m.Cmdy(web.SPACE, m.Option("name"), "bookmark", arg[1:]) - arg = []string{m.Option("name"), m.Option("id")} - } - // 下发命令 - m.Cmdy(web.SPACE, arg[0], "bookmark", arg[1:]) + m.Cmdy(web.SPACE, arg[0], BOOKMARK, arg[1:]) }}, }, } diff --git a/misc/input/input.go b/misc/input/input.go index 626f9cd2..25131959 100644 --- a/misc/input/input.go +++ b/misc/input/input.go @@ -33,6 +33,16 @@ func _input_list(m *ice.Message, lib string) { }) } func _input_push(m *ice.Message, lib, text, code, weight string) { + if m.Richs(INPUT, "", lib, nil) == nil { + m.Rich(INPUT, "", kit.Data( + kit.MDB_STORE, path.Join(m.Conf(INPUT, "meta.store"), lib), + kit.MDB_FSIZE, m.Conf(INPUT, "meta.fsize"), + kit.MDB_LIMIT, m.Conf(INPUT, "meta.limit"), + kit.MDB_LEAST, m.Conf(INPUT, "meta.least"), + kit.MDB_ZONE, lib, + )) + } + m.Richs(INPUT, "", lib, func(key string, value map[string]interface{}) { prefix := kit.Keys(kit.MDB_HASH, key) m.Conf(INPUT, kit.Keys(prefix, "meta.limit"), 0) @@ -140,7 +150,7 @@ func _input_load(m *ice.Message, file string, libs ...string) { kit.MDB_FSIZE, m.Conf(INPUT, "meta.fsize"), kit.MDB_LIMIT, m.Conf(INPUT, "meta.limit"), kit.MDB_LEAST, m.Conf(INPUT, "meta.least"), - "zone", lib, + kit.MDB_ZONE, lib, ))) // 缓存配置 diff --git a/misc/vim/auto.vim b/misc/vim/auto.vim index 9ed85a8d..7e5e9ff8 100644 --- a/misc/vim/auto.vim +++ b/misc/vim/auto.vim @@ -10,7 +10,6 @@ fun! ShyLog(...) endfun " 后端通信 -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(cmd, arg) if has_key(a:arg, "sub") && a:arg["sub"] != "" @@ -19,7 +18,6 @@ fun! ShySend(cmd, arg) let a:arg["sub"] = "@" . temp endif - let a:arg["sid"] = g:ctx_sid let a:arg["pwd"] = getcwd() let a:arg["buf"] = bufname("%") let a:arg["row"] = line(".") @@ -31,18 +29,6 @@ fun! ShySend(cmd, arg) return system("curl -s " . g:ctx_url . a:cmd . args . " 2>/dev/null") endfun -" 用户登录 -fun! ShyLogout() - if g:ctx_sid != "" | call ShySend("logout", {}) | endif -endfun -fun! ShyLogin() - let g:ctx_sid = ShySend("login", {"share": $ctx_share, "pid": getpid(), "pane": $TMUX_PANE, "hostname": hostname(), "username": $USER}) -endfun -fun! ShyHelp() - echo ShySend("help", {}) -endfun -call ShyLogin() - " 数据同步 fun! ShySync(target) if bufname("%") == "ControlP" | return | end @@ -128,22 +114,6 @@ fun! ShyFavors() botright lopen if l:view == 1 | only | endif endfun -fun! ShyCheck(target) - if a:target == "cache" - call ShySync("bufs") - call ShySync("regs") - call ShySync("marks") - call ShySync("tags") - elseif a:target == "fixs" - let l = len(getqflist()) - if l > 0 - execute "copen " . (l > 10? 10: l + 1) - call ShySync("fixs") - else - cclose - end - end -endfun " 搜索 call ShyDefine("g:grep_dir", "./") @@ -154,20 +124,24 @@ fun! ShyGrep(word) copen endfun - -" 任务列表 -fun! ShyTask() - call ShySend({"cmd": "tasklet", "arg": input("target: "), "sub": input("detail: ")}) -endfun - -" 标签列表 -fun! ShyTag(word) - execute "tag " . a:word -endfun - " 自动刷新 let ShyComeList = {} fun! ShyCome(buf, row, action, extra) + " 低配命令 + if !exists("appendbufline") + execute a:extra["row"] + + if a:extra["count"] > 0 + execute "+1,+" . a:extra["count"] ."delete" + endif + + let a:extra["count"] = 0 + for line in reverse(split(ShySend("sync", {"cmds": "trans", "arg": getline(".")}), "\n")) + let a:extra["count"] += 1 + call append(".", line) + endfor + return + endif if a:action == "refresh" " 清空历史 if a:extra["count"] > 0 | call deletebufline(a:buf, a:row+1, a:row+a:extra["count"]) | endif @@ -188,13 +162,6 @@ fun! ShyUpdate(timer) call ShyCome(what["buf"], what["row"], what["action"], what) endfun fun! ShyComes(action) - " 低配命令 - if !exists("appendbufline") - for line in reverse(split(ShySend({"cmd": "trans", "arg": getline(".")}), "\n")) - call append(".", line) - endfor - return - endif if !exists("b:timer") | let b:timer = -1 | endif " 清除定时 if b:timer > 0 | call timer_stop(b:timer) | let b:timer = -2 | return | endif @@ -203,9 +170,24 @@ fun! ShyComes(action) let g:ShyComeList[b:timer] = {"buf": bufname("."), "row": line("."), "pre": getline("."), "action": a:action, "count": 0} call ShyLog("new timer", b:timer) endfun +fun! ShyCheck(target) + if a:target == "cache" + call ShySync("bufs") + call ShySync("regs") + call ShySync("marks") + call ShySync("tags") + elseif a:target == "fixs" + let l = len(getqflist()) + if l > 0 + execute "copen " . (l > 10? 10: l + 1) + call ShySync("fixs") + else + cclose + end + end +endfun " 事件回调 -autocmd! VimLeave * call ShyLogout() autocmd! BufReadPost * call ShySync("bufs") autocmd! BufReadPost * call ShySync("read") autocmd! BufWritePre * call ShySync("write") @@ -218,11 +200,10 @@ endif autocmd! InsertLeave * call ShySync("insert") " 按键映射 +nnoremap :call ShyGrep(expand("")) nnoremap :call ShyFavor() nnoremap f :call ShyFavors() -nnoremap :call ShyGrep(expand("")) " nnoremap :call ShyCheck("cache") -" nnoremap :call ShyTask() nnoremap :call ShyComes("refresh") inoremap diff --git a/misc/vim/vim.go b/misc/vim/vim.go index 2f3d2669..17976ac9 100644 --- a/misc/vim/vim.go +++ b/misc/vim/vim.go @@ -1,24 +1,25 @@ package vim import ( - "fmt" - ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/core/code" kit "github.com/shylinux/toolkits" + "fmt" "io/ioutil" "os" "path" "strings" ) +const VIM = "vim" + var Index = &ice.Context{Name: "vim", Help: "编辑器", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ - "vim": {Name: "vim", Help: "编辑器", Value: kit.Data( + VIM: {Name: "vim", Help: "编辑器", Value: kit.Data( "source", "ftp://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2", "target", "usr/local", "version", "vim81", "config", []interface{}{ "--enable-pythoninterp=yes", @@ -84,52 +85,23 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器", code.PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }}, - web.LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if f, _, e := m.R.FormFile("sub"); e == nil { - defer f.Close() - // 文件参数 - if b, e := ioutil.ReadAll(f); e == nil { - m.Option("sub", string(b)) - } - } - - ls := strings.Split(m.Option("pwd"), "/") - m.Option("you", ls[len(ls)-1]) - m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) { - // 查找空间 - m.Option("you", kit.Select(m.Option("you"), value["you"])) - }) - - m.Logs(ice.LOG_AUTH, "you", m.Option("you"), "url", m.Option(ice.MSG_USERURL), "cmd", m.Optionv("cmds"), "sub", m.Optionv("sub")) - m.Option(ice.MSG_OUTPUT, ice.RENDER_RESULT) - }}, - "/help": {Name: "/help", Help: "帮助", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Cmdy("help") - }}, - "/login": {Name: "/login", Help: "登录", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Cmdy("login", "init", c.Name) - }}, - "/logout": {Name: "/logout", Help: "登出", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Cmdy("login", "exit") - }}, - "/sync": {Name: "/sync", Help: "同步", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Render(ice.RENDER_RESULT) switch arg[0] { case "read", "write", "exec", "insert": - m.Cmd(web.FAVOR, m.Conf("vim", "meta.history"), web.TYPE_VIMRC, arg[0], kit.Select(m.Option("arg"), m.Option("sub")), - "sid", m.Option("sid"), "pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col")) - - default: - m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) { - kit.Value(value, kit.Keys("sync", arg[0]), kit.Dict( - "time", m.Time(), "text", m.Option("sub"), - "pwd", m.Option("pwd"), "buf", m.Option("buf"), - )) - }) + m.Cmd(web.FAVOR, m.Conf(VIM, "meta.history"), web.TYPE_VIMRC, arg[0], kit.Select(m.Option("arg"), m.Option("sub")), + "pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col")) + case "trans": + if m.Cmdy(kit.Split(m.Option("arg"))); m.Result() == "" { + m.Table() + } } }}, "/input": {Name: "/input", Help: "补全", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if strings.HasPrefix(strings.TrimSpace(arg[0]), "ice ") { + m.Render(ice.RENDER_RESULT) + arg[0] = strings.TrimSpace(arg[0]) + + if strings.HasPrefix(arg[0], "ice ") { list := kit.Split(strings.TrimSpace(arg[0])) switch list[1] { case "add": @@ -137,8 +109,9 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器", m.Cmd("web.code.input.push", list[2:]) arg[0] = list[4] default: - // 执行命令 + // ice add person 想你 shwq if m.Cmdy(list[1:]); m.Result() == "" { + m.Echo("%s\n", arg[0]) m.Table() } return @@ -151,6 +124,7 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器", }) }}, "/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Render(ice.RENDER_RESULT) if m.Options("arg") { // 添加收藏 m.Cmdy(web.FAVOR, kit.Select(m.Conf("vim", "meta.history"), m.Option("tab")), @@ -160,12 +134,15 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器", } // 查看收藏 - m.Cmd(web.PROXY, m.Option("you"), web.FAVOR, m.Option("tab"), "extra", "extra.pwd", "extra.buf", "extra.row", "extra.col").Table(func(index int, value map[string]string, head []string) { - switch value["type"] { - case web.TYPE_VIMRC: - m.Echo("%v\n", m.Option("tab")).Echo("%v:%v:%v:(%v): %v\n", - value["extra.buf"], value["extra.row"], value["extra.col"], value["name"], value["text"]) - } + m.Richs(web.FAVOR, nil, m.Option("tab"), func(key string, val map[string]interface{}) { + m.Grows(web.FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) { + extra := value["extra"].(map[string]interface{}) + switch value[kit.MDB_TYPE] { + case web.TYPE_VIMRC: + m.Echo("%v\n", m.Option("tab")).Echo("%v:%v:%v:(%v): %v\n", + extra["buf"], extra["row"], extra["col"], value["name"], value["text"]) + } + }) }) }}, },