From e077dcfca57b8a9fb9f6d0c7e3039d53df15a135 Mon Sep 17 00:00:00 2001 From: shaoying Date: Wed, 23 Oct 2019 09:33:40 +0800 Subject: [PATCH] opt dir --- src/contexts/cli/version.go | 2 +- src/contexts/nfs/nfs.go | 37 +++++++++++++++++++++++++++++++----- src/contexts/yac/yac.go | 2 +- src/plugin/context/index.shy | 3 ++- usr/librarys/chat.js | 9 +++++++-- usr/librarys/example.css | 7 +++++++ usr/librarys/example.js | 14 ++++++++++++++ usr/librarys/toolkit.js | 5 ++++- 8 files changed, 68 insertions(+), 11 deletions(-) diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go index 3ab75263..54903851 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-21 14:20:01`, `centos`, 633, + `2019-10-23 08:31:12`, `mac`, 647, } diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index 84b652bd..e28530a1 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -623,7 +623,11 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", "dir": &ctx.Command{Name: "dir [path [fields...]]", Help: []string{ "查看目录, path: 路径, fields...: 查询字段, time|type|full|path|name|tree|size|line|hash|hashs", "dir_deep: 递归查询", "dir_type both|file|dir|all: 文件类型", "dir_reg reg: 正则表达式", "dir_sort field order: 排序"}, - Form: map[string]int{"dir_deep": 0, "dir_type": 1, "dir_reg": 1, "dir_sort": 2, "dir_sed": -1, "dir_select": -1}, + Form: map[string]int{"dir_deep": 0, "dir_type": 1, "dir_reg": 1, "dir_sort": 2, "dir_sed": -1, "dir_select": -1, + "offset": 1, "limit": 1, + "match_begin": 1, + "match_end": 1, + }, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { if len(arg) == 0 { arg = append(arg, "") @@ -657,11 +661,34 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", } } m.Log("info", "open %v", p0) - - for bio := bufio.NewScanner(f); bio.Scan(); { - m.Echo(bio.Text()) - } m.Append("file", p) + + if m.Has("match_begin") { + m.Option("match_begin") + begin, _ := regexp.Compile(m.Option("match_begin")) + end, _ := regexp.Compile(m.Option("match_end")) + start := false + for bio := bufio.NewScanner(f); bio.Scan(); { + if start = start || begin.MatchString(bio.Text()); m.Option("match_begin") == "" || start { + if m.Echo(bio.Text()); m.Option("match_end") != "" && end.MatchString(bio.Text()) { + break + } + } + } + + } else { + offset := m.Optioni("offset") + limit := m.Optioni("limit") + for bio, i := bufio.NewScanner(f), 0; bio.Scan(); i++ { + if i >= offset && (limit == 0 || i < offset+limit) { + m.Echo(bio.Text()) + } + m.Append("line", i+1) + m.Append("offset", offset) + m.Append("limit", limit) + } + } + m.Append("size", s.Size()) m.Append("time", s.ModTime().Format(m.Conf("time", "format"))) skip = true diff --git a/src/contexts/yac/yac.go b/src/contexts/yac/yac.go index f14d4c7f..2f60f17c 100644 --- a/src/contexts/yac/yac.go +++ b/src/contexts/yac/yac.go @@ -676,7 +676,7 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", if e1 == nil && e2 == nil { result = fmt.Sprintf("%d", v1-v2) } else { - result = strings.Replace(arg[0], arg[1], "", -1) + result = strings.Replace(arg[0], arg[2], "", -1) } case "*": result = arg[0] diff --git a/src/plugin/context/index.shy b/src/plugin/context/index.shy index f8654097..526d1e52 100644 --- a/src/plugin/context/index.shy +++ b/src/plugin/context/index.shy @@ -53,11 +53,12 @@ kit dir "目录" private "ssh._route" _ "nfs.dir" _ time size line path \ text "usr/script" name dir imports plugin_dir action auto view long \ button "浏览" action auto \ button "返回" cb Last \ + feature display editor \ exports dir "" dir kit git "版本" private "ssh._route" _ "nfs.git" __ \ text "" name pod imports plugin_pod action auto \ select "" values status values diff commit values values log values init action auto \ text "" name txt action auto \ - button "查看" + button "查看" diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js index 66ffdde4..114ed1cf 100644 --- a/usr/librarys/chat.js +++ b/usr/librarys/chat.js @@ -468,8 +468,13 @@ var page = Page({ var status = JSON.parse(line.status) kit.Selector(page.action, "fieldset.item", function(field, index) { var args = status[index].args - kit.Selector(field, ".args", function(input, index) { - input.value = args[index]||"" + args = args.slice(kit.Selector(field, ".args", function(input, index) { + return input.value = args[index]||"" + }).length) + + kit.List(args, function(arg) { + field.Plugin.Append({type: "text"}, "", arg) + }) }) }, diff --git a/usr/librarys/example.css b/usr/librarys/example.css index e9442996..5ac4e7bf 100644 --- a/usr/librarys/example.css +++ b/usr/librarys/example.css @@ -445,3 +445,10 @@ fieldset pre code, fieldset code pre { display:block; } +fieldset.item>div.output>code.div { +} + +fieldset.item>div.output>div.code div.number { + float:left; +} + diff --git a/usr/librarys/example.js b/usr/librarys/example.js index f0fcc170..9a98d531 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -1426,6 +1426,20 @@ function Output(plugin, type, msg, cb, target, option) { typeof cb == "function" && cb(msg) }, editor: function(msg, cb) { + target.innerHTML = "" + output.onimport.meta._table(msg, msg.append) + if (msg.file) { + 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) { + 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()) + }} + })}]) + } + typeof cb == "function" && cb(msg) + return (target.innerHTML = "", Editor(plugin.Run, plugin, option, target, target.clientWidth-40, 400, 10, msg)) }, canvas: function(msg, cb) { diff --git a/usr/librarys/toolkit.js b/usr/librarys/toolkit.js index b2d57d61..f3a98114 100644 --- a/usr/librarys/toolkit.js +++ b/usr/librarys/toolkit.js @@ -444,10 +444,11 @@ kit = toolkit = (function() {var kit = {__proto__: document, } text = window.getSelection().toString() - if (text == "") {return} + if (text == "") {return ""} kit.History("txt", -1) && kit.History("txt", -1).data == text || kit.History("txt", -1, text) && document.execCommand("copy") input && document.body.removeChild(input) + return text }, DelText: function(target, start, count) { target.value = target.value.substring(0, start)+target.value.substring(start+(count||target.value.length), target.value.length) @@ -538,6 +539,8 @@ kit = toolkit = (function() {var kit = {__proto__: document, s = s.replace(/\033\[31m/g, "") s = s.replace(/\033\[0m/g, "") s = s.replace(/\033\[m/g, "") + s = s.replace(//g, ">") return s }, Value: function() {