mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt story
This commit is contained in:
parent
2f77add671
commit
d784aec625
@ -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)
|
||||
|
@ -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))
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
</defs>`, 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("<g name=%s", group)
|
||||
item := NewItem("<g class=%s", group)
|
||||
for _, k := range kit.Simple(STROKE_DASHARRAY, STROKE_WIDTH, STROKE, FILL, FONT_SIZE, FONT_FAMILY, arg) {
|
||||
item.Push(kit.Format(`%s="%%v"`, k), m.Option(kit.Keys(group, k)))
|
||||
}
|
||||
@ -94,9 +88,7 @@ func (g *Group) Dump(m *ice.Message, group string, arg ...string) *Group {
|
||||
return g
|
||||
}
|
||||
func (g *Group) DumpAll(m *ice.Message, group ...string) {
|
||||
for _, grp := range group {
|
||||
g.Dump(m, grp)
|
||||
}
|
||||
kit.For(group, func(grp string) { g.Dump(m, grp) })
|
||||
}
|
||||
|
||||
type Chart interface {
|
||||
@ -110,21 +102,15 @@ var chart_list = map[string]func(m *ice.Message) Chart{}
|
||||
|
||||
func AddChart(name string, hand func(m *ice.Message) Chart) { chart_list[name] = hand }
|
||||
|
||||
func _chart_show(m *ice.Message, kind, text string, arg ...string) {
|
||||
m.Option(FONT_SIZE, "24")
|
||||
m.Option(STROKE_WIDTH, "2")
|
||||
chart := chart_list[kind](m)
|
||||
for i := 0; i < len(arg)-1; i++ {
|
||||
m.Option(arg[i], arg[i+1])
|
||||
}
|
||||
func _chart_show(m *ice.Message, name, text string, arg ...string) {
|
||||
m.Options(FONT_SIZE, "24", STROKE_WIDTH, "2")
|
||||
kit.For(arg, func(k, v string) { m.Option(k, v) })
|
||||
m.Option(FILL, kit.Select(m.Option(FILL), m.Option(BG)))
|
||||
m.Option(STROKE, kit.Select(m.Option(STROKE), m.Option(FG)))
|
||||
|
||||
chart := chart_list[name](m)
|
||||
chart.Init(m, text)
|
||||
m.Option(WIDTH, chart.GetWidth())
|
||||
m.Option(HEIGHT, chart.GetHeight())
|
||||
|
||||
_wiki_template(m, "", "", text, arg...)
|
||||
m.Options(HEIGHT, chart.GetHeight(), WIDTH, chart.GetWidth())
|
||||
_wiki_template(m, "", name, text, arg...)
|
||||
defer m.Echo("</svg>")
|
||||
defer m.RenderResult()
|
||||
chart.Draw(m, 0, 0)
|
||||
|
@ -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 {
|
||||
|
@ -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{}
|
||||
})
|
||||
}
|
||||
|
@ -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{} }) }
|
||||
|
@ -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("<html><body>").Echo("</body></html>")
|
||||
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])
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user