From d784aec6259aeed8949a445868037f644479bf7c Mon Sep 17 00:00:00 2001 From: shylinux Date: Thu, 13 Apr 2023 23:43:52 +0800 Subject: [PATCH] opt story --- base/nfs/cat.go | 2 +- base/nfs/grep.go | 5 +---- core/code/xterm.go | 4 +++- core/wiki/chart.go | 36 +++++++++++------------------------- core/wiki/chart/block.go | 13 +++---------- core/wiki/chart/chain.go | 10 ++-------- core/wiki/chart/label.go | 15 +++------------ core/wiki/draw.go | 7 +++++++ misc/git/spide.go | 2 +- misc/tmux/session.go | 1 + 10 files changed, 33 insertions(+), 62 deletions(-) diff --git a/base/nfs/cat.go b/base/nfs/cat.go index 13c06d07..b256096f 100644 --- a/base/nfs/cat.go +++ b/base/nfs/cat.go @@ -111,7 +111,7 @@ const CAT = "cat" func init() { Index.MergeCommands(ice.Commands{ CAT: {Name: "cat path auto", Help: "文件", Actions: ice.MergeActions(ice.Actions{ice.CTX_INIT: mdb.AutoConfig(SOURCE, kit.DictList( - HTML, CSS, JS, GO, SH, PY, SHY, CSV, JSON, CONFIGURE, CONF, XML, YML, TXT, MD, ice.LICENSE, ice.MAKEFILE, + HTML, CSS, JS, GO, SH, PY, SHY, CSV, JSON, CONFIGURE, CONF, XML, YML, TXT, MD, strings.ToLower(ice.LICENSE), strings.ToLower(ice.MAKEFILE), ))}), Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) { m.Cmdy(DIR, arg) diff --git a/base/nfs/grep.go b/base/nfs/grep.go index 06582d12..a0a47a4c 100644 --- a/base/nfs/grep.go +++ b/base/nfs/grep.go @@ -21,11 +21,8 @@ func init() { GREP: {Name: "grep word file path auto", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { m.Options(mdb.VALUE, arg[0], CMD_DIR, kit.Select("", arg, 2)) kit.For(strings.Split(m.Cmdx("cli.system", GREP, "--exclude=.[a-z]*", "--exclude-dir=.[a-z]*", "-rni", arg[0], kit.Select(ice.PT, arg, 1)), ice.NL), func(s string) { - m.Debug("what %#v", s) if ls := strings.SplitN(s, ice.DF, 3); len(ls) > 2 { - m.Debug("what %#v", ls) - m.Debug("what %v", m.FormatMeta()) - m.Push(FILE, strings.TrimPrefix(ls[0], PWD)).Push(s, ls[1]).Push(mdb.TEXT, ls[2]) + m.Push(FILE, strings.TrimPrefix(ls[0], PWD)).Push(LINE, ls[1]).Push(mdb.TEXT, ls[2]) } }) m.StatusTimeCount(PATH, m.Option(CMD_DIR)) diff --git a/core/code/xterm.go b/core/code/xterm.go index 1393dcf5..911db9a9 100644 --- a/core/code/xterm.go +++ b/core/code/xterm.go @@ -24,6 +24,7 @@ func _xterm_get(m *ice.Message, h string) xterm.XTerm { return mdb.HashSelectTarget(m, h, func(value ice.Maps) ice.Any { text := strings.Split(value[mdb.TEXT], ice.NL) ls := kit.Split(strings.Split(kit.Select(nfs.SH, value[mdb.TYPE]), " # ")[0]) + kit.If(value[nfs.PATH] != "" && !strings.HasSuffix(value[nfs.PATH], nfs.PS), func() { value[nfs.PATH] = path.Dir(value[nfs.PATH]) }) term, e := xterm.Command(m, value[nfs.PATH], cli.SystemFind(m, ls[0]), ls[1:]...) if m.Warn(e) { return nil @@ -31,7 +32,7 @@ func _xterm_get(m *ice.Message, h string) xterm.XTerm { m.Go(func() { defer term.Close() defer mdb.HashRemove(m, mdb.HASH, h) - m.Log("start", strings.Join(term.Args, ice.SP)) + m.Log(cli.START, strings.Join(term.Args, ice.SP)) buf := make([]byte, ice.MOD_BUFS) for { if n, e := term.Read(buf); !m.Warn(e) && e == nil { @@ -55,6 +56,7 @@ func _xterm_get(m *ice.Message, h string) xterm.XTerm { } func _xterm_echo(m *ice.Message, h string, str string) { m.Options(ice.MSG_DAEMON, mdb.HashSelectField(m, h, web.VIEW)) + m.Option(ice.LOG_DISABLE, ice.TRUE) web.PushNoticeGrow(m, h, str) } func _xterm_cmds(m *ice.Message, h string, cmd string, arg ...ice.Any) { diff --git a/core/wiki/chart.go b/core/wiki/chart.go index 04309dd5..bbccf5d7 100644 --- a/core/wiki/chart.go +++ b/core/wiki/chart.go @@ -12,9 +12,7 @@ type Item struct { args []ice.Any } -func NewItem(str string, args ...ice.Any) *Item { - return &Item{[]string{str}, args} -} +func NewItem(str string, args ...ice.Any) *Item { return &Item{[]string{str}, args} } func (item *Item) Push(str string, arg ice.Any) *Item { switch arg := arg.(type) { case string: @@ -41,15 +39,11 @@ type Group struct{ list ice.Messages } func NewGroup(m *ice.Message, arg ...string) *Group { g := &Group{list: ice.Messages{}} - for _, k := range arg { - g.list[k] = m.Spawn() - } + kit.For(arg, func(k string) { g.list[k] = m.Spawn() }) return g } func AddGroupOption(m *ice.Message, group string, arg ...string) { - for i := 0; i < len(arg)-1; i += 2 { - m.Option(kit.Keys(group, arg[i]), arg[i+1]) - } + kit.For(arg, func(k, v string) { m.Option(kit.Keys(group, k), v) }) } func (g *Group) Option(group string, key string, arg ...ice.Any) string { return g.Get(group).Option(kit.Keys(group, key), arg...) @@ -86,7 +80,7 @@ func (g *Group) DefsArrow(group string, height, width int, arg ...string) *ice.M `, kit.Select("arrowhead", arg, 0), height, width, height/2, width, height/2, height) } func (g *Group) Dump(m *ice.Message, group string, arg ...string) *Group { - item := NewItem("") defer m.RenderResult() chart.Draw(m, 0, 0) diff --git a/core/wiki/chart/block.go b/core/wiki/chart/block.go index 17833556..9c49859d 100644 --- a/core/wiki/chart/block.go +++ b/core/wiki/chart/block.go @@ -33,10 +33,7 @@ func (b *Block) Init(m *ice.Message, arg ...string) wiki.Chart { b.Padding = kit.Int(kit.Select("10", m.Option(wiki.PADDING))) b.MarginX = kit.Int(kit.Select("10", m.Option(wiki.MARGINX))) b.MarginY = kit.Int(kit.Select("10", m.Option(wiki.MARGINY))) - - if len(arg) > 0 { - b.Text = arg[0] - } + kit.If(len(arg) > 0, func() { b.Text = arg[0] }) return b } func (b *Block) Data(m *ice.Message, meta ice.Any) wiki.Chart { @@ -49,12 +46,8 @@ func (b *Block) Data(m *ice.Message, meta ice.Any) wiki.Chart { b.RectData += kit.Format("%s='%s' ", wiki.FILL, value) } }) - kit.For(kit.Value(meta, "data"), func(key string, value string) { - b.TextData += kit.Format("%s='%s' ", key, value) - }) - kit.For(kit.Value(meta, "rect"), func(key string, value string) { - b.RectData += kit.Format("%s='%s' ", key, value) - }) + kit.For(kit.Value(meta, "data"), func(key string, value string) { b.TextData += kit.Format("%s='%s' ", key, value) }) + kit.For(kit.Value(meta, "rect"), func(key string, value string) { b.RectData += kit.Format("%s='%s' ", key, value) }) return b } func (b *Block) Draw(m *ice.Message, x, y int) wiki.Chart { diff --git a/core/wiki/chart/chain.go b/core/wiki/chart/chain.go index f3a486bb..2a29a974 100644 --- a/core/wiki/chart/chain.go +++ b/core/wiki/chart/chain.go @@ -36,9 +36,8 @@ func (c *Chain) Init(m *ice.Message, arg ...string) wiki.Chart { func (c *Chain) Draw(m *ice.Message, x, y int) wiki.Chart { gs := wiki.NewGroup(m, SHIP, LINE, RECT, TEXT) wiki.AddGroupOption(m, LINE, wiki.STROKE, gs.Option(SHIP, wiki.STROKE)) - wiki.AddGroupOption(m, TEXT, wiki.FILL, m.Option(wiki.STROKE)) + wiki.AddGroupOption(m, TEXT, wiki.STROKE, m.Option(wiki.STROKE), wiki.FILL, m.Option(wiki.STROKE)) defer gs.DumpAll(m, SHIP, LINE, RECT, TEXT) - c.Height, c.Width = 0, 0 c.draw(m, c.data, x, y, &c.Block, gs) return c @@ -58,12 +57,9 @@ func (c *Chain) draw(m *ice.Message, root ice.Map, x, y int, p *Block, gs *wiki. item := p.Fork(m, kit.Format(meta[mdb.TEXT])) item.x, item.y = x, y+(kit.Int(meta[wiki.HEIGHT])-1)*c.GetHeights()/2 item.Data(m, meta) - if p != nil && p.y != 0 { padding := item.GetHeight() / 2 - if m.Option(SHOW_BLOCK) == ice.TRUE { - padding = 0 - } + kit.If(m.Option(SHOW_BLOCK) == ice.TRUE, func() { padding = 0 }) x4, y4 := item.x+(p.MarginX+item.MarginX)/4, item.y+item.GetHeights()/2+padding x1, y1 := p.x+p.GetWidths()-(p.MarginX+item.MarginX)/4, p.y+p.GetHeights()/2+padding gs.EchoPath(SHIP, "M %d,%d Q %d,%d %d,%d T %d %d", x1, y1, x1+(x4-x1)/4, y1, x1+(x4-x1)/2, y1+(y4-y1)/2, x4, y4) @@ -74,7 +70,6 @@ func (c *Chain) draw(m *ice.Message, root ice.Map, x, y int, p *Block, gs *wiki. gs.EchoLine(LINE, item.x+item.MarginX/2, item.y+item.GetHeights()-item.MarginY/2, item.x+item.GetWidths()-item.MarginX/2, item.y+item.GetHeights()-item.MarginY/2) } gs.EchoTexts(TEXT, item.x+item.GetWidths()/2, item.y+item.GetHeights()/2, item.Text, item.TextData) - h, x := 0, x+item.GetWidths() if kit.For(root[mdb.LIST], func(value ice.Map) { h += c.draw(m, value, x, y+h, item, gs) }); h == 0 { return item.GetHeights() @@ -99,7 +94,6 @@ func init() { m.Option(wiki.MARGINY, "20") m.Option(wiki.PADDING, "10") wiki.AddGroupOption(m, SHIP, wiki.FILL, cli.GLASS) - wiki.AddGroupOption(m, TEXT, wiki.STROKE_WIDTH, "1") return &Chain{} }) } diff --git a/core/wiki/chart/label.go b/core/wiki/chart/label.go index d265a42a..5abc1d2b 100644 --- a/core/wiki/chart/label.go +++ b/core/wiki/chart/label.go @@ -33,15 +33,14 @@ func (s *Label) Init(m *ice.Message, arg ...string) wiki.Chart { } func (s *Label) Draw(m *ice.Message, x, y int) wiki.Chart { gs := wiki.NewGroup(m, RECT, TEXT) - wiki.AddGroupOption(m, TEXT, wiki.FILL, m.Option(wiki.STROKE)) + wiki.AddGroupOption(m, RECT, wiki.STROKE, m.Option(wiki.STROKE), wiki.FILL, m.Option(wiki.FILL)) + wiki.AddGroupOption(m, TEXT, wiki.STROKE, m.Option(wiki.STROKE), wiki.FILL, m.Option(wiki.STROKE)) defer gs.DumpAll(m, RECT, TEXT) - top := y for _, line := range s.data { left, height := x, 0 for i, text := range line { item := s.Fork(m) - ls := kit.SplitWord(text) if item.Init(m, ls[0]); len(ls) > 1 { data := kit.Dict() @@ -50,7 +49,6 @@ func (s *Label) Draw(m *ice.Message, x, y int) wiki.Chart { } item.Data(m, data) } - switch m.Option(COMPACT) { case ice.TRUE: case "max": @@ -58,12 +56,10 @@ func (s *Label) Draw(m *ice.Message, x, y int) wiki.Chart { default: item.Width = s.max[i] } - if m.Option(HIDE_BLOCK) != ice.TRUE { gs.EchoRect(RECT, item.GetHeight(), item.GetWidth(), left+item.MarginX/2, top+item.MarginY/2) } gs.EchoTexts(TEXT, left+item.GetWidths()/2, top+item.GetHeights()/2, item.Text) - if left += item.GetWidths(); item.GetHeights() > height { height = item.GetHeights() } @@ -79,9 +75,4 @@ const ( ) const LABEL = "label" -func init() { - wiki.AddChart(LABEL, func(m *ice.Message) wiki.Chart { - wiki.AddGroupOption(m, TEXT, wiki.STROKE_WIDTH, "1") - return &Label{} - }) -} +func init() { wiki.AddChart(LABEL, func(m *ice.Message) wiki.Chart { return &Label{} }) } diff --git a/core/wiki/draw.go b/core/wiki/draw.go index e8063a67..44ab66bd 100644 --- a/core/wiki/draw.go +++ b/core/wiki/draw.go @@ -5,8 +5,10 @@ import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/ctx" + "shylinux.com/x/icebergs/base/log" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" + "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" ) @@ -22,6 +24,11 @@ func init() { defer m.Echo("").Echo("") m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }}, + mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { + if arg[0] == mdb.FOREACH && arg[1] == "" { + m.PushSearch(mdb.TYPE, web.LINK, mdb.NAME, m.CommandKey(), mdb.TEXT, m.MergePodCmd("", "", log.DEBUG, ice.TRUE)) + } + }}, }, WikiAction("", nfs.SVG), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) { kit.If(!_wiki_list(m, arg...), func() { _wiki_show(m, arg[0]) diff --git a/misc/git/spide.go b/misc/git/spide.go index 91acee49..80022a83 100644 --- a/misc/git/spide.go +++ b/misc/git/spide.go @@ -19,7 +19,7 @@ const SPIDE = "spide" func init() { Index.MergeCommands(ice.Commands{ - SPIDE: {Name: "spide repos auto depend", Help: "构架图", Actions: ice.MergeActions(ice.Actions{ + SPIDE: {Name: "spide repos auto", Help: "构架图", Actions: ice.MergeActions(ice.Actions{ "depend": {Name: "depend path*=icebergs/base pkg=shy,all", Help: "依赖", Hand: func(m *ice.Message, arg ...string) { list, keys := map[string]map[string]bool{}, map[string]bool{} kit.SplitKV(ice.TB, ice.NL, m.Cmdx(cli.SYSTEM, "gotags", "-R", path.Join(ice.USR, m.Option(nfs.PATH))+ice.PS), func(text string, ls []string) { diff --git a/misc/tmux/session.go b/misc/tmux/session.go index ccfdf5da..134e46d5 100644 --- a/misc/tmux/session.go +++ b/misc/tmux/session.go @@ -82,6 +82,7 @@ func init() { SESSION: {Name: "session session window pane cmds auto", Help: "会话", Actions: ice.MergeActions(ice.Actions{ web.DREAM_CREATE: {Hand: func(m *ice.Message, arg ...string) { m.Cmd("", mdb.CREATE) }}, mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { + return if arg[0] == mdb.FOREACH && arg[1] == "" { m.Cmd("", ice.OptionFields(""), func(value ice.Maps) { m.PushSearch(mdb.TYPE, ssh.SHELL, mdb.NAME, value[SESSION], mdb.TEXT, "tmux attach -t "+value[SESSION], value)