From 8065a7dc982c4f30714b11b033efb4341d85afa4 Mon Sep 17 00:00:00 2001 From: shaoying Date: Thu, 24 Oct 2019 09:49:27 +0800 Subject: [PATCH] add grep search --- src/contexts/cli/version.go | 2 +- src/contexts/nfs/nfs.go | 3 +++ src/plugin/redis/index.css | 3 +++ src/plugin/redis/index.go | 36 +++++++++++++++++++++++++ src/plugin/redis/index.js | 3 +++ src/plugin/redis/index.shy | 54 +++++++++++++++++++++++++++++++++++++ usr/librarys/example.js | 19 ++++++++++--- 7 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 src/plugin/redis/index.css create mode 100644 src/plugin/redis/index.go create mode 100644 src/plugin/redis/index.js create mode 100644 src/plugin/redis/index.shy diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go index 54903851..f07ac0d7 100644 --- a/src/contexts/cli/version.go +++ b/src/contexts/cli/version.go @@ -7,5 +7,5 @@ var version = struct { self int }{ []string{"2017-11-01 01:02:03", "2019-07-13 18:02:21"}, - `2019-10-23 08:31:12`, `mac`, 647, + `2019-10-24 08:04:57`, `mac`, 652, } diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index e28530a1..1537a926 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -911,6 +911,9 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", "grep": &ctx.Command{Name: "grep head|tail|hold|more table arg", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { hold := false switch arg[0] { + case "search": + m.Cmdy("cli.system", "grep", arg[1:]) + case "add": m.Confv("grep", []string{arg[1], "list", "-2"}, map[string]interface{}{ "pos": 0, "offset": 0, "file": arg[2], diff --git a/src/plugin/redis/index.css b/src/plugin/redis/index.css new file mode 100644 index 00000000..6b37c639 --- /dev/null +++ b/src/plugin/redis/index.css @@ -0,0 +1,3 @@ +fieldset.item.redis div.output { +} + diff --git a/src/plugin/redis/index.go b/src/plugin/redis/index.go new file mode 100644 index 00000000..95a1e5b1 --- /dev/null +++ b/src/plugin/redis/index.go @@ -0,0 +1,36 @@ +package main + +import ( + "contexts/cli" + "contexts/ctx" + "toolkit" + + "fmt" + "os" +) + +var Index = &ctx.Context{Name: `redis`, 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:])) +} diff --git a/src/plugin/redis/index.js b/src/plugin/redis/index.js new file mode 100644 index 00000000..d4fac8ac --- /dev/null +++ b/src/plugin/redis/index.js @@ -0,0 +1,3 @@ +Script["redis/index.js"] = function(field, option, output) {return { +}} + diff --git a/src/plugin/redis/index.shy b/src/plugin/redis/index.shy new file mode 100644 index 00000000..96794e57 --- /dev/null +++ b/src/plugin/redis/index.shy @@ -0,0 +1,54 @@ +fun download "下载" public \ + text "redis-5.0.5.tar.gz" name src view long \ + button "下载" + + let local = "usr/local/" + let path = $local + $1 - ".tar.gz" + if $(path $path) + return $path + end + + let src = "http://download.redis.io/releases/" + $1 + let usr = $local + $1 + web.get method GET "" $src save $usr + + tar xvf $usr -C $local + make -C $path + return $path +end + +kit dir "目录" public "nfs.dir" _ time size line path \ + text "usr/local/redis-5.0.5" name dir imports plugin_dir action auto view long \ + button "浏览" action auto \ + button "返回" cb Last \ + feature display editor \ + exports dir "" dir + +kit grep "搜索" public "nfs.grep" search _ _ "-rn" "--color" cmd_parse cut 3 ":" "file line word" \ + text "" name txt imports plugin_editor_word \ + text "usr/local/redis-5.0.5" name dir view long \ + button "搜索" \ + exports dir file "" editor_file file "" editor_index line "" + +fun mark "标签" public \ + text "mark" name table \ + text "" name file imports plugin_editor_file view long \ + text "" name index imports plugin_editor_index view tiny \ + text "" name word imports plugin_editor_word \ + text "" name mark view long \ + button "操作" \ + exports dir file "" editor_index index "" editor_word word + + if $5 == "" + copy skip ssh.data show _ + else + copy ssh.data insert _ file _ index _ word _ mark _ + end +end + +fun hello world "" "" public \ + text "" \ + button "执行" + copy pwd + +end diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 9a98d531..2d44c865 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -1204,7 +1204,11 @@ function Plugin(page, pane, field, inits, runs) { }, JSON.parse(meta.exports||'["",""]'), function(event, value, name, line) { var meta = arguments.callee.meta var list = arguments.callee.list - ;(!list[1] || list[1] == name) && page.Sync("plugin_"+list[0]).set(meta[list[2]||""](value, name, line, list)) + if (list[1] && list[1] != name) {return} + + 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)) + } }), onchoice: shy("菜单列表", { "返回": "Last", @@ -1428,15 +1432,21 @@ function Output(plugin, type, msg, cb, target, option) { editor: function(msg, cb) { target.innerHTML = "" output.onimport.meta._table(msg, msg.append) + var current = page.Sync("plugin_editor_index").get() + target.style.maxHeight = "" if (msg.file) { + target.style.maxHeight = "500px" var code = kit.AppendChild(target, [{view: ["code", "table"], list: kit.List(msg.result, function(line, index) { - return {view: ["line", "tr"], list: [{view: ["number", "td", index+1]}, {view: ["code", "td", kit.Color(line)], style: {"white-space": "pre"}}], click: function(event) { + return {view: ["line"+ (current == index+1? " select": ""), "tr"], list: [{view: ["number", "td", index+1]}, {view: ["code", "td", kit.Color(line)], style: {"white-space": "pre"}}], click: function(event) { page.Sync("plugin_editor_file").set(msg.file[0]) page.Sync("plugin_editor_index").set(index+1) page.Sync("plugin_editor_line").set(line) page.Sync("plugin_editor_word").set(kit.CopyText()) }} })}]) + kit.Selector(target, "tr.line.select", function(tr) { + tr.scrollIntoView() + }) } typeof cb == "function" && cb(msg) return @@ -1455,9 +1465,10 @@ function Output(plugin, type, msg, cb, target, option) { "表格": "_table", "绘图": "_canvas", "下载": "Download", + "返回": "Last", "清空": "clear", - }, ["表格", "绘图", "下载", "清空"], function(event, value, meta) { - kit._call(output, output[meta[value]]) + }, ["表格", "绘图", "下载", "返回", "清空"], function(event, value, meta) { + kit._call(output, output[meta[value]], [event]) return true }), onaction: shy("事件列表", {