From e93b45073bcaf8d32f167bbf11d4239f42bace8b Mon Sep 17 00:00:00 2001 From: shaoying Date: Tue, 28 Jul 2020 08:26:43 +0800 Subject: [PATCH] opt some --- base/cli/system.go | 5 ++++- base/ssh/ssh.go | 7 +++++-- base/web/render.go | 2 +- core/wiki/chart.go | 21 +++++++++++++++++++-- core/wiki/wiki.go | 5 ++++- core/wiki/word.go | 37 +++++++++++++++++++++++++++++++++++++ misc/chrome/chrome.shy | 9 ++++++++- misc/git/git.shy | 7 +++++++ misc/vim/vim.go | 19 +++++++++++++++++++ misc/vim/vim.shy | 20 ++++++++++++++++---- 10 files changed, 120 insertions(+), 12 deletions(-) create mode 100644 misc/git/git.shy diff --git a/base/cli/system.go b/base/cli/system.go index 42add028..704f134a 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -96,7 +96,10 @@ func init() { m.Push("ip", strings.TrimSuffix(ls[1], ")")) } - t, _ := time.ParseInLocation("2006 Jan 2 15:04", "2020 "+ls[0], time.Local) + t, e := time.ParseInLocation("2006 Jan 2 15:04", "2020 "+ls[0], time.Local) + if e != nil { + t, _ = time.ParseInLocation("2006-01-02 15:04", ls[0], time.Local) + } m.Push("begin", t.Format("2006-01-02 15:04:05")) d := time.Since(t) d = d / time.Millisecond * time.Millisecond diff --git a/base/ssh/ssh.go b/base/ssh/ssh.go index e3c39be9..7cb51f35 100644 --- a/base/ssh/ssh.go +++ b/base/ssh/ssh.go @@ -205,8 +205,11 @@ func (f *Frame) parse(m *ice.Message, line string) string { continue } - // 执行命令 - msg.Cmdy(ls[0], ls[1:]) + if strings.HasPrefix(line, "<") { + msg.Resultv(line) + } else if msg.Cmdy(ls[0], ls[1:]); strings.HasPrefix(msg.Result(), "warn: ") && m.Option("render") == "raw" { + msg.Resultv(line) + } // 渲染引擎 _args, _ := msg.Optionv(ice.MSG_ARGS).([]interface{}) diff --git a/base/web/render.go b/base/web/render.go index 9f8332bb..f75b3da8 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -132,7 +132,7 @@ func init() { m.Echo(`
%s(%s)
`, arg[0], arg[1]) }}, RENDER.Frame: {Hand: func(m *ice.Message, arg ...string) { - m.Echo(``, arg[0]) + m.Echo(``, arg[0]) }}, RENDER.Button: {Hand: func(m *ice.Message, arg ...string) { m.Echo(``, arg[0]) diff --git a/core/wiki/chart.go b/core/wiki/chart.go index 5323f54c..db8afb3a 100644 --- a/core/wiki/chart.go +++ b/core/wiki/chart.go @@ -112,8 +112,8 @@ func (b *Label) Init(m *ice.Message, arg ...string) Chart { // 解析数据 b.max = map[int]int{} - for _, v := range kit.Split(arg[0], "\n") { - l := kit.Split(v) + for _, v := range strings.Split(arg[0], "\n") { + l := kit.Split(v, " ", " ") for i, v := range l { switch data := kit.Parse(nil, "", kit.Split(v)...).(type) { case map[string]interface{}: @@ -135,6 +135,10 @@ func (b *Label) Init(m *ice.Message, arg ...string) Chart { return b } func (b *Label) Draw(m *ice.Message, x, y int) Chart { + m.Debug("arg %v", m.Option("order")) + order, _ := kit.Parse(nil, "", kit.Split(m.Option("order"))...).(map[string]interface{}) + m.Debug("order", order) + top := y for _, line := range b.data { left := x @@ -147,6 +151,19 @@ func (b *Label) Draw(m *ice.Message, x, y int) Chart { MarginX: b.MarginX, MarginY: b.MarginY, } + if order != nil { + if w := kit.Int(kit.Value(order, "index")); w != 0 && i%w == 0 { + for k, v := range order { + switch k { + case "fg": + item.FontColor = kit.Format(v) + case "bg": + item.BackGround = kit.Format(v) + } + } + } + } + switch data := kit.Parse(nil, "", kit.Split(text)...).(type) { case map[string]interface{}: item.Init(m, kit.Select(text, data["text"])).Data(m, data) diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index a8274f04..b2bd9b5d 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -44,11 +44,14 @@ func reply(m *ice.Message, cmd string, arg ...string) bool { m.Sort("time", "time_r") if len(arg) == 0 || strings.HasSuffix(arg[0], "/") { + m.Option("_display", "table") + if m.Option(nfs.DIR_DEEP) == "true" { + return true + } // 目录列表 m.Option(nfs.DIR_REG, "") m.Option(nfs.DIR_TYPE, "dir") m.Cmdy(nfs.DIR, kit.Select("./", arg, 0)) - m.Option("_display", "table") return true } return false diff --git a/core/wiki/word.go b/core/wiki/word.go index 9ebfa8f4..e978ae38 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -4,6 +4,7 @@ import ( ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/base/ctx" + "github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/nfs" "github.com/shylinux/icebergs/base/ssh" "github.com/shylinux/icebergs/base/web" @@ -125,6 +126,12 @@ func _chart_show(m *ice.Message, kind, name, text string, arg ...string) { for i := 0; i < len(arg)-1; i++ { m.Option(arg[i], arg[i+1]) } + if m.Option("fg") != "" { + m.Option("stroke", m.Option("fg")) + } + if m.Option("bg") != "" { + m.Option("fill", m.Option("bg")) + } // 计算尺寸 chart.Init(m, text) @@ -247,6 +254,14 @@ func _video_show(m *ice.Message, name, text string, arg ...string) { _option(m, VIDEO, name, text, arg...) m.Render(ice.RENDER_TEMPLATE, m.Conf(VIDEO, "meta.template")) } +func _baidu_show(m *ice.Message, name, text string, arg ...string) { + _option(m, BAIDU, name, text, arg...) + m.Cmdy(mdb.RENDER, web.RENDER.Frame, kit.Format("https://baidu.com/s?wd=%s", text)) +} +func _other_show(m *ice.Message, name, text string, arg ...string) { + _option(m, OTHER, name, text, arg...) + m.Cmdy(mdb.RENDER, web.RENDER.Frame, text) +} func _word_show(m *ice.Message, name string, arg ...string) { m.Set(ice.MSG_RESULT) @@ -273,6 +288,9 @@ const ( IMAGE = "image" VIDEO = "video" + BAIDU = "baidu" + OTHER = "other" + PREMENU = "premenu" CHAPTER = "chapter" SECTION = "section" @@ -335,6 +353,9 @@ func init() { _brief_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) }}, REFER: {Name: "refer name `[name url]...`", Help: "参考", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) == 1 { + arg = []string{"", arg[0]} + } _refer_show(m, arg[0], arg[1], arg[2:]...) }}, SPARK: {Name: "spark [name] text", Help: "感悟", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -349,6 +370,9 @@ func init() { }}, CHART: {Name: "chart label|chain name text arg...", Help: "图表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) == 2 { + arg = []string{arg[0], "", arg[1]} + } _chart_show(m, arg[0], arg[1], arg[2], arg[3:]...) }}, FIELD: {Name: "field name cmd", Help: "插件", Action: map[string]*ice.Action{ @@ -410,6 +434,19 @@ func init() { _video_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) }}, + BAIDU: {Name: "baidu word", Help: "百度", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) == 1 { + arg = []string{"", arg[0]} + } + _baidu_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) + }}, + OTHER: {Name: "other word", Help: "网页", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) == 1 { + arg = []string{"", arg[0]} + } + _other_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) + }}, + WORD: {Name: "word path=demo/hi.shy auto", Help: "语言文字", Meta: kit.Dict( "display", "/plugin/local/wiki/word.js", ), Action: map[string]*ice.Action{ diff --git a/misc/chrome/chrome.shy b/misc/chrome/chrome.shy index 61eac4e7..3da810ec 100644 --- a/misc/chrome/chrome.shy +++ b/misc/chrome/chrome.shy @@ -7,4 +7,11 @@ refer "官网" ` 插件 chrome://extensions ` - +chapter "应用" +section "启动本地应用" +refer ` +终端 terminal:// +博客 https://www.cnblogs.com/lymvv/p/8431238.html +` +other "https://www.cnblogs.com/lymvv/p/8431238.html" +baidu "html" diff --git a/misc/git/git.shy b/misc/git/git.shy new file mode 100644 index 00000000..084c71bc --- /dev/null +++ b/misc/git/git.shy @@ -0,0 +1,7 @@ +title "git" + +refer "官网" ` +官网 https://git-scm.com/ +文档 https://git-scm.com/docs +源码 https://github.com/git/git +` diff --git a/misc/vim/vim.go b/misc/vim/vim.go index 17976ac9..c54a4eea 100644 --- a/misc/vim/vim.go +++ b/misc/vim/vim.go @@ -3,6 +3,8 @@ package vim import ( ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/cli" + "github.com/shylinux/icebergs/base/mdb" + "github.com/shylinux/icebergs/base/nfs" "github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/core/code" kit "github.com/shylinux/toolkits" @@ -26,6 +28,15 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器", "--enable-luainterp=yes", "--enable-cscope=yes", }, "history", "vim.history", + "plug", kit.Dict( + "prefix", kit.Dict( + "\"", "comment", + ), + "keyword", kit.Dict( + "highlight", "keyword", + "syntax", "keyword", + ), + ), )}, }, Commands: map[string]*ice.Command{ @@ -50,6 +61,14 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器", } }})) }}, + VIM: {Name: VIM, Help: "vim", Action: map[string]*ice.Action{ + mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { + m.Echo(m.Conf(VIM, "meta.plug")) + }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) + }}, + }}, code.INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { p := path.Join(m.Conf("install", "meta.path"), m.Conf("vim", "meta.version")) if _, e := os.Stat(p); e != nil { diff --git a/misc/vim/vim.shy b/misc/vim/vim.shy index 5117ee1a..7b50e590 100644 --- a/misc/vim/vim.shy +++ b/misc/vim/vim.shy @@ -1,9 +1,21 @@ title "vim" refer "官网" ` -官网 https://www.vim.org/ -下载 https://www.vim.org/download.php -源码 ftp://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2 +官网 https://www.vim.org +源码 https://github.com/vim/vim +文档 http://vimdoc.sourceforge.net/htmldoc/usr_toc.html ` -spark terminal +field "启动配置" web.code.inner args `[ etc/conf/ vimrc ]` + +chapter "配置" + +chapter "插件" + +refer ` +插件管理器 https://github.com/junegunn/vim-plug +` +section "状态栏" +refer ` +插件管理器 https://github.com/vim-airline/vim-airline +`