1
0
forked from x/icebergs
This commit is contained in:
harveyshao 2022-05-14 15:23:44 +08:00
parent 6698cf3e0d
commit ef81d0b5a2
22 changed files with 466 additions and 373 deletions

View File

@ -163,8 +163,8 @@ func init() {
if len(arg) == 1 {
arg = kit.Split(arg[0])
}
if strings.HasSuffix(arg[0], ".sh") {
arg = []string{"sh", path.Join("src", arg[0])}
if kit.Ext(arg[0]) == nfs.SH && arg[0] != nfs.SH {
arg = []string{nfs.SH, path.Join(ice.SRC, arg[0])}
}
_system_exec(m, _system_cmd(m, arg...))
}},

View File

@ -1,6 +1,7 @@
package ctx
import (
"path"
"strings"
ice "shylinux.com/x/icebergs"
@ -13,10 +14,17 @@ import (
func _command_list(m *ice.Message, name string) {
switch kit.Ext(name) {
case nfs.JS:
m.Push("display", ice.FileURI(name))
name = ice.GetFileCmd(name)
m.Push(DISPLAY, ice.FileURI(name))
name = kit.Select(CAN_PLUGIN, ice.GetFileCmd(name))
case nfs.GO:
name = ice.GetFileCmd(name)
default:
if file, msg := name, m.Cmd(mdb.RENDER, kit.Ext(name)); msg.Length() > 0 && kit.FileExists(path.Join(ice.SRC, name)) {
m.Push(ARGS, kit.Format(kit.List(file)))
name = kit.Keys(msg.Append(mdb.TEXT), msg.Append(mdb.NAME))
}
}
if strings.HasPrefix(name, "can.") {
m.Push(mdb.INDEX, name)
@ -78,11 +86,13 @@ func CmdAction(fields ...string) map[string]*ice.Action {
}
const (
ACTION = "action"
STYLE = "style"
INDEX = "index"
ARGS = "args"
STYLE = "style"
DISPLAY = "display"
ACTION = "action"
CAN_PLUGIN = "can.plugin"
)
const COMMAND = "command"

View File

@ -5,7 +5,6 @@ import (
"strings"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
@ -14,50 +13,29 @@ import (
)
func _cmd_file(m *ice.Message, arg ...string) bool {
if mdb.HashSelect(m.Spawn(), path.Join(arg...)).Table(func(index int, value map[string]string, head []string) {
m.RenderCmd(value[mdb.NAME])
}).Length() > 0 {
return true
}
p := path.Join(m.Config(nfs.PATH), path.Join(arg...))
if mdb.HashSelect(m.Spawn(), kit.Ext(p)).Table(func(index int, value map[string]string, head []string) {
m.RenderCmd(value[mdb.NAME], p)
}).Length() > 0 {
return true
}
// if mdb.HashSelect(m.Spawn(), path.Join(arg...)).Table(func(index int, value map[string]string, head []string) {
// m.RenderCmd(value[mdb.NAME])
// }).Length() > 0 {
// return true
// }
//
// p := path.Join(m.Config(nfs.PATH), path.Join(arg...))
// if mdb.HashSelect(m.Spawn(), kit.Ext(p)).Table(func(index int, value map[string]string, head []string) {
// m.RenderCmd(value[mdb.NAME], p)
// }).Length() > 0 {
// return true
// }
//
switch p := path.Join(arg...); kit.Ext(p) {
case nfs.HTML:
m.RenderResult(m.Cmdx(nfs.CAT, p))
case nfs.CSS:
case nfs.JS:
m.Display(ice.FileURI(p))
if cmd := ice.GetFileCmd(p); cmd != "" {
m.RenderCmd(cmd)
} else {
m.RenderCmd("can.info")
}
m.RenderCmd(kit.Select(ctx.CAN_PLUGIN, ice.GetFileCmd(p)))
case nfs.GO:
if cmd := ice.GetFileCmd(p); cmd != "" {
m.RenderCmd(cmd)
}
m.RenderCmd(ice.GetFileCmd(p))
case nfs.SH:
if cmd := ice.GetFileCmd(p); cmd != "" {
msg := m.Cmd(cmd, ice.OptionFields(""))
if msg.Length() > 0 {
msg.Table()
}
m.Cmdy(cli.SYSTEM, "sh", p, msg.Result())
m.RenderResult()
}
case nfs.ZML:
m.RenderCmd("can.parse", m.Cmdx(nfs.CAT, p))
case nfs.SHY:
m.RenderCmd("web.wiki.word", p)
case nfs.IML:
if m.Option(ice.MSG_USERPOD) == "" {
@ -68,7 +46,15 @@ func _cmd_file(m *ice.Message, arg ...string) bool {
m.Option(ice.MSG_ARGS, m.Option(ice.MSG_ARGS))
}
case nfs.ZML:
m.RenderCmd("can.parse", m.Cmdx(nfs.CAT, p))
default:
p = strings.TrimPrefix(p, ice.SRC+ice.PS)
if msg := m.Cmd(mdb.RENDER, kit.Ext(p)); msg.Length() > 0 && kit.FileExists(path.Join(ice.SRC, p)) {
m.Cmdy(mdb.RENDER, kit.Ext(p), p, ice.SRC+ice.PS).RenderResult()
break
}
return false
}
return true

View File

@ -139,6 +139,9 @@ func init() {
for _, k := range []string{aaa.LANGUAGE, aaa.BACKGROUND, aaa.AVATAR, aaa.USERNICK} {
m.Option(k, msg.Append(k))
}
if m.Option(aaa.AVATAR) == "" && m.R.Header.Get("Staffname") != "" {
m.Option(aaa.AVATAR, kit.Format("https://dayu.oa.com/avatars/%s/profile.jpg", m.R.Header.Get("Staffname")))
}
if m.Option(GRANT) != "" {
if m.Cmd(GRANT, m.Option(ice.POD), 1).Length() > 0 {

View File

@ -49,48 +49,14 @@ func _website_parse(m *ice.Message, text string, args ...string) (map[string]int
}
}
data := kit.Dict()
switch display := ice.DisplayRequire(1, ls[0])[ctx.DISPLAY]; kit.Ext(ls[0]) {
switch kit.Ext(ls[0]) {
case nfs.JS:
key := ice.GetFileCmd(display)
if key == "" {
if ls := strings.Split(display, ice.PS); len(ls) > 4 {
ls[3] = ice.USR
key = ice.GetFileCmd(path.Join(ls[3:]...))
}
}
if key == "" {
for p, k := range ice.Info.File {
if strings.HasPrefix(p, path.Dir(display)) {
key = k
}
}
}
ls[0] = kit.Select("can.code.inner.plugin", key)
data[ctx.DISPLAY] = display
data[ctx.DISPLAY] = ice.FileURI(ls[0])
ls[0] = kit.Select(ctx.CAN_PLUGIN, ice.GetFileCmd(ls[0]))
case nfs.GO:
key := ice.GetFileCmd(display)
if key == "" {
for k, v := range ice.Info.File {
if strings.HasSuffix(k, ls[0]) {
key = v
}
}
}
ls[0] = key
case nfs.SH:
key := ice.GetFileCmd(display)
if key == "" {
key = "cli.system"
}
data[ctx.ARGS] = kit.List(ls[0])
ls[0] = key
case nfs.SHY:
data[ctx.ARGS] = kit.List(ls[0])
data[mdb.NAME] = kit.TrimExt(ls[0], ".shy")
if data[mdb.NAME] == "main" {
data[mdb.NAME] = strings.TrimSuffix(strings.Split(ls[0], ice.PS)[1], "-story")
}
ls[0] = "web.wiki.word"
ls[0] = ice.GetFileCmd(ls[0])
case "~":
prefix = ls[1]
ls = ls[1:]
@ -100,6 +66,10 @@ func _website_parse(m *ice.Message, text string, args ...string) (map[string]int
last[mdb.LIST] = append(last[mdb.LIST].([]interface{}), kit.Dict(mdb.INDEX, kit.Keys(prefix, v), "order", len(last)))
}
return ls
default:
if msg := m.Cmd(mdb.RENDER, kit.Ext(ls[0])); msg.Length() > 0 {
ls[0], data[ctx.ARGS] = kit.Keys(msg.Append(mdb.TEXT), msg.Append(mdb.NAME)), kit.List(ls[0])
}
}
if ls[0] == "" {

View File

@ -77,6 +77,9 @@ func init() {
}
ice.Info.Dump = func(w io.Writer, name string, cb func(string)) bool {
if strings.HasPrefix(name, ice.SRC) && kit.FileExists(name) {
return false
}
for _, key := range []string{name, strings.TrimPrefix(name, ice.USR_VOLCANOS)} {
if b, ok := ice.Info.Pack[key]; ok {
if cb != nil {

View File

@ -193,9 +193,11 @@ func init() {
}, PlugAction())},
SUM: {Name: "sum", Help: "版本", Action: ice.MergeAction(map[string]*ice.Action{
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _sum_show(m, path.Join(arg[2], arg[1])) }},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _sum_show(m, path.Join(arg[2], arg[1])) }},
}, PlugAction())},
MOD: {Name: "mod", Help: "模块", Action: ice.MergeAction(map[string]*ice.Action{
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _mod_show(m, path.Join(arg[2], arg[1])) }},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _mod_show(m, path.Join(arg[2], arg[1])) }},
}, PlugAction())},
GO: {Name: "go", Help: "后端", Action: ice.MergeAction(map[string]*ice.Action{
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {

View File

@ -68,12 +68,12 @@ func LoadPlug(m *ice.Message, language ...string) {
})
}
}
func PlugAction(fields ...string) map[string]*ice.Action {
return ice.SelectAction(map[string]*ice.Action{
func PlugAction() map[string]*ice.Action {
return map[string]*ice.Action{
mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { m.Echo(m.Config(PLUG)) }},
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }},
}, fields...)
}
}
const (
@ -87,6 +87,8 @@ const (
SPLIT = "split"
PREFIX = "prefix"
SUFFIX = "suffix"
SPACE = "space"
OPERATE = "operate"
)
const (
PLUG = "plug"

View File

@ -6,38 +6,60 @@ import (
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
kit "shylinux.com/x/toolkits"
)
const PY = "py"
func _py_main_script(m *ice.Message, arg ...string) {
const PYTHON2 = "python2"
if kit.FileExists(kit.Path(arg[2], arg[1])) {
m.Cmdy(cli.SYSTEM, PYTHON2, kit.Path(arg[2], arg[1]))
} else if b, ok := ice.Info.Pack[path.Join(arg[2], arg[1])]; ok && len(b) > 0 {
m.Cmdy(cli.SYSTEM, PYTHON2, "-c", string(b))
}
if m.StatusTime(); cli.IsSuccess(m) {
m.SetAppend()
}
m.Echo(ice.NL)
}
const PY = nfs.PY
func init() {
const PYTHON2 = "python2"
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
PY: {Name: "py", Help: "脚本", Action: map[string]*ice.Action{
PY: {Name: "py path auto", Help: "脚本", Action: ice.MergeAction(map[string]*ice.Action{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.ENGINE, mdb.CREATE, PY, m.PrefixKey())
m.Cmd(mdb.RENDER, mdb.CREATE, PY, m.PrefixKey())
}},
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
if kit.FileExists(kit.Path(arg[2], arg[1])) {
m.Cmdy(cli.SYSTEM, PYTHON2, kit.Path(arg[2], arg[1]))
} else if b, ok := ice.Info.Pack[path.Join(arg[2], arg[1])]; ok && len(b) > 0 {
m.Cmdy(cli.SYSTEM, PYTHON2, "-c", string(b))
}
if cli.IsSuccess(m) {
m.SetAppend()
}
m.Echo(ice.NL)
}},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
if kit.FileExists(kit.Path(arg[2], arg[1])) {
m.Cmdy(cli.SYSTEM, PYTHON2, kit.Path(arg[2], arg[1]))
} else if b, ok := ice.Info.Pack[path.Join(arg[2], arg[1])]; ok && len(b) > 0 {
m.Cmdy(cli.SYSTEM, PYTHON2, "-c", string(b))
_py_main_script(m, arg...)
}},
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
_py_main_script(m, arg...)
}},
}, PlugAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 && kit.Ext(arg[0]) == PY {
_py_main_script(m, PY, arg[0], ice.SRC)
return
}
m.Echo(ice.NL)
}},
m.Option(nfs.DIR_DEEP, ice.TRUE)
m.Option(nfs.DIR_ROOT, ice.SRC)
m.Option(nfs.DIR_REG, ".*.(py)$")
m.Cmdy(nfs.DIR, arg)
}},
}, Configs: map[string]*ice.Config{
PY: {Name: PY, Help: "脚本", Value: kit.Data(PLUG, kit.Dict(
SPLIT, kit.Dict(SPACE, " ", OPERATE, "{[(.,;!|<>)]}"),
PREFIX, kit.Dict("#!", COMMENT, "# ", COMMENT), SUFFIX, kit.Dict(" {", COMMENT),
PREPARE, kit.Dict(
KEYWORD, kit.Simple(
"import", "from", "return",
),
FUNCTION, kit.Simple(
"print",
),
), KEYWORD, kit.Dict(),
))},
}})
}

View File

@ -6,6 +6,7 @@ import (
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
kit "shylinux.com/x/toolkits"
)
@ -15,27 +16,25 @@ func _sh_main_script(m *ice.Message, arg ...string) (res []string) {
} else if b, ok := ice.Info.Pack[path.Join(arg[2], arg[1])]; ok && len(b) > 0 {
res = append(res, string(b))
}
m.Cmdy(cli.SYSTEM, SH, "-c", kit.Join(res, ice.NL))
if m.StatusTime(); cli.IsSuccess(m) {
m.SetAppend()
}
return
}
const SH = "sh"
const SH = nfs.SH
func init() {
Index.Register(&ice.Context{Name: SH, Help: "命令", Commands: map[string]*ice.Command{
SH: {Name: SH, Help: "命令", Action: ice.MergeAction(map[string]*ice.Action{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
Index.Merge(&ice.Context{Name: SH, Help: "命令", Commands: map[string]*ice.Command{
SH: {Name: "sh path auto", Help: "命令", Action: ice.MergeAction(map[string]*ice.Action{
ice.CTX_INIT: {Name: "_init", Help: "初始化", Hand: func(m *ice.Message, arg ...string) {
for _, cmd := range []string{mdb.SEARCH, mdb.ENGINE, mdb.RENDER, mdb.PLUGIN} {
m.Cmd(cmd, mdb.CREATE, SH, m.PrefixKey())
m.Cmd(cmd, mdb.CREATE, m.CommandKey(), m.PrefixKey())
}
LoadPlug(m, SH)
LoadPlug(m, m.CommandKey())
}},
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(cli.SYSTEM, SH, "-c", kit.Join(_sh_main_script(m, arg...), ice.NL)).SetAppend()
}},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(cli.SYSTEM, SH, "-c", kit.Join(_sh_main_script(m, arg...), ice.NL)).SetAppend()
}},
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
if arg[0] == mdb.FOREACH {
return
}
@ -45,37 +44,37 @@ func init() {
_go_find(m, kit.Select(cli.MAIN, arg, 1), arg[2])
_go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2])
}},
MAN: {Hand: func(m *ice.Message, arg ...string) {
m.Echo(_c_help(m, arg[0], arg[1]))
mdb.ENGINE: {Name: "engine", Help: "引擎", Hand: func(m *ice.Message, arg ...string) {
_sh_main_script(m, arg...)
}},
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
_sh_main_script(m, arg...)
}},
}, PlugAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 && kit.Ext(arg[0]) == SH {
_sh_main_script(m, SH, arg[0], ice.SRC)
return
}
m.Option(nfs.DIR_DEEP, ice.TRUE)
m.Option(nfs.DIR_ROOT, ice.SRC)
m.Option(nfs.DIR_REG, ".*.(sh)$")
m.Cmdy(nfs.DIR, arg)
}},
}, PlugAction())},
}, Configs: map[string]*ice.Config{
SH: {Name: SH, Help: "命令", Value: kit.Data(PLUG, kit.Dict(
SPLIT, kit.Dict("space", " ", "operator", "{[(.,;!|<>)]}"),
PREFIX, kit.Dict("#", COMMENT),
SUFFIX, kit.Dict("{", COMMENT),
SPLIT, kit.Dict(SPACE, " ", OPERATE, "{[(.,;!|<>)]}"),
PREFIX, kit.Dict("#!", COMMENT, "# ", COMMENT), SUFFIX, kit.Dict(" {", COMMENT),
PREPARE, kit.Dict(
KEYWORD, kit.Simple(
"export",
"source",
"require",
"require", "source", "return", "local", "export", "env",
"if",
"then",
"else",
"fi",
"for",
"while",
"do",
"done",
"esac",
"case",
"in",
"return",
"if", "then", "else", "fi",
"for", "while", "do", "done",
"esac", "case", "in",
"shift",
"local",
"echo",
"read",
"eval",
"kill",
"let",
@ -83,18 +82,15 @@ func init() {
),
FUNCTION, kit.Simple(
"xargs",
"date",
"find",
"grep",
"sed",
"awk",
"date", "uptime", "uname", "whoami",
"find", "grep", "sed", "awk",
"pwd",
"ps",
"ls",
"ps",
"rm",
"go",
),
), KEYWORD, kit.Dict(),
))},
}}, nil)
}})
}

View File

@ -14,7 +14,7 @@ const SHY = "shy"
func init() {
Index.Register(&ice.Context{Name: SHY, Help: "脚本", Commands: map[string]*ice.Command{
SHY: {Name: SHY, Help: "脚本", Action: ice.MergeAction(map[string]*ice.Action{
SHY: {Name: "shy path auto", Help: "脚本", Action: ice.MergeAction(map[string]*ice.Action{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
for _, cmd := range []string{mdb.SEARCH, mdb.ENGINE, mdb.RENDER, mdb.PLUGIN} {
m.Cmd(cmd, mdb.CREATE, SHY, m.PrefixKey())
@ -33,7 +33,13 @@ func init() {
_go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2])
}
}},
}, PlugAction())},
}, PlugAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 && kit.Ext(arg[0]) == m.CommandKey() {
m.Cmdy("web.wiki.word", path.Join(ice.SRC, arg[0]))
return
}
m.Cmdy("web.wiki.word", arg)
}},
}, Configs: map[string]*ice.Config{
SHY: {Name: SHY, Help: "脚本", Value: kit.Data(PLUG, kit.Dict(
mdb.RENDER, kit.Dict(),
@ -42,7 +48,7 @@ func init() {
"source", "return",
"title", "premenu", "chapter", "section",
"refer", "spark", "field",
"chart", "label", "chain",
"chart", "label", "chain", "sequence",
"image",
),
), KEYWORD, kit.Dict(),

View File

@ -13,6 +13,73 @@ import (
kit "shylinux.com/x/toolkits"
)
func _vimer_inputs(m *ice.Message, arg ...string) {
switch m.Option(ctx.ACTION) {
case web.DREAM:
m.Cmdy(web.DREAM, mdb.INPUTS, arg)
case "script":
switch arg[0] {
case nfs.FILE:
file, ext := m.Option(nfs.FILE), kit.Ext(m.Option(nfs.FILE))
for _, t := range []string{nfs.SH, nfs.SHY, nfs.PY, nfs.JS} {
m.Push(nfs.FILE, strings.ReplaceAll(file, ice.PT+ext, ice.PT+t))
}
case mdb.TEXT:
switch kit.Ext(m.Option(nfs.FILE)) {
case nfs.SH:
m.Push(mdb.TEXT, `echo "hello world"`)
case nfs.SHY:
m.Push(mdb.TEXT, `chapter "hi"`)
case nfs.PY:
m.Push(mdb.TEXT, `print "hello world"`)
case nfs.JS:
m.Push(mdb.TEXT, `Volcanos("onimport", {help: "导入数据", list:[], _init: function(can, msg, cb, target) {
msg.Echo("hello world")
can.onappend.table(can, msg)
can.onappend.board(can, msg)
}})`)
}
}
case "website":
switch arg[0] {
case nfs.FILE:
m.Push(nfs.FILE, "hi.zml")
m.Push(nfs.FILE, "hi.iml")
case mdb.TEXT:
switch kit.Ext(m.Option(nfs.FILE)) {
case nfs.ZML:
m.Push(mdb.TEXT, `
left
username
系统
命令 index cli.system
共享 index cli.qrcode
代码
趋势 index web.code.git.trend args icebergs action auto
状态 index web.code.git.status args icebergs
main
`)
case nfs.IML:
m.Push(mdb.TEXT, `
系统
命令
cli.system
环境
cli.runtime
开发
模块
hi/hi.go
脚本
hi/hi.sh
hi/hi.js
`)
}
}
default:
}
}
const VIMER = "vimer"
func init() {
@ -21,7 +88,7 @@ func init() {
nfs.SAVE: {Name: "save type file path", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(nfs.SAVE, path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)))
}},
AUTOGEN: {Name: "create main=src/main.go zone name=hi help type=Zone,Hash,Lists,Data,Code key", Help: "模块", Hand: func(m *ice.Message, arg ...string) {
AUTOGEN: {Name: "create main=src/main.go zone name=hi help=示例 type=Zone,Hash,Lists,Data,Code key", Help: "模块", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(AUTOGEN, mdb.CREATE, arg)
}},
COMPILE: {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) {
@ -53,79 +120,48 @@ func init() {
}
}},
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
switch m.Option(ctx.ACTION) {
case web.DREAM:
m.Cmdy(web.DREAM, mdb.INPUTS, arg)
case "script":
switch arg[0] {
case nfs.FILE:
file, ext := m.Option(nfs.FILE), kit.Ext(m.Option(nfs.FILE))
for _, t := range []string{nfs.SH, nfs.SHY, nfs.PY, nfs.JS} {
m.Push(nfs.FILE, strings.ReplaceAll(file, ice.PT+ext, ice.PT+t))
}
case mdb.TEXT:
m.Push(mdb.TEXT, `echo "hello world"`)
m.Push(mdb.TEXT, `chapter "hi"`)
m.Push(mdb.TEXT, `print "hello world"`)
m.Push(mdb.TEXT, `Volcanos("onimport", {help: "导入数据", list:[], _init: function(can, msg, cb, target) {
msg.Echo("hello world")
can.onappend.table(can, msg)
can.onappend.board(can, msg)
}})`)
}
case "website":
switch arg[0] {
case nfs.FILE:
m.Push(nfs.FILE, "hi.zml")
m.Push(nfs.FILE, "hi.iml")
case mdb.TEXT:
m.Push(mdb.TEXT, `
hi
he
cli.runtime
cli.system
hi/hi.sh
hi/hi.go
hi/hi.js
`)
m.Push(mdb.TEXT, `
left
username
系统
命令 index cli.system
共享 index cli.qrcode
代码
趋势 index web.code.git.trend args icebergs action auto
状态 index web.code.git.status args icebergs
main
`)
}
default:
}
_vimer_inputs(m, arg...)
}},
"complete": {Name: "complete", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
left := kit.Slice(kit.Split(m.Option("pre")), -1)[0]
switch kit.Ext(m.Option(nfs.FILE)) {
case nfs.GO:
switch m.Option("key") {
case "ice", "*ice":
m.Push("name", "Message")
m.Push("name", "Context")
default:
if strings.HasSuffix(m.Option("pre"), " index ") {
m.OptionFields("index")
m.Push(mdb.NAME, "Message")
m.Push(mdb.NAME, "Context")
}
case nfs.SHY:
switch left {
case cli.FG, cli.BG:
m.Push(mdb.NAME, cli.RED)
m.Push(mdb.NAME, cli.BLUE)
m.Push(mdb.NAME, cli.GREEN)
}
case nfs.ZML:
switch left {
case ctx.INDEX:
m.OptionFields(ctx.INDEX)
m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, "", "")
} else if strings.HasSuffix(m.Option("pre"), " action ") {
m.Push("name", "auto")
} else if strings.HasSuffix(m.Option("pre"), " type ") {
m.Push("name", "menu")
} else if strings.HasSuffix(m.Option("pre"), " ") {
m.Push("name", "index")
m.Push("name", "action")
m.Push("name", "args")
m.Push("name", "type")
case ctx.ACTION:
m.Push(mdb.NAME, "auto")
m.Push(mdb.NAME, "push")
m.Push(mdb.NAME, "open")
case mdb.TYPE:
m.Push(mdb.NAME, "menu")
default:
if strings.HasSuffix(m.Option("pre"), " ") {
m.Push(mdb.NAME, "index")
m.Push(mdb.NAME, "action")
m.Push(mdb.NAME, "args")
m.Push(mdb.NAME, "type")
} else if m.Option("pre") == "" {
m.Push("name", "left")
m.Push("name", "head")
m.Push("name", "main")
m.Push("name", "foot")
m.Push(mdb.NAME, "left")
m.Push(mdb.NAME, "head")
m.Push(mdb.NAME, "main")
m.Push(mdb.NAME, "foot")
}
}
}
}},

View File

@ -54,38 +54,53 @@ func NewGroup(m *ice.Message, arg ...string) *Group {
}
func AddGroupOption(m *ice.Message, group string, arg ...string) {
for i := 0; i < len(arg)-1; i += 2 {
m.Option(group+"-"+arg[i], arg[i+1])
m.Option(kit.Keys(group, arg[i]), arg[i+1])
}
}
func (g *Group) Option(group string, key string, arg ...interface{}) string {
return g.Get(group).Option(group+"-"+key, arg...)
return g.Get(group).Option(kit.Keys(group, key), arg...)
}
func (g *Group) Get(group string) *ice.Message { return g.list[group] }
func (g *Group) DefsArrow(group string, height, width int, arg ...string) *ice.Message { // name
return g.Echo(group, `<defs>
<marker id="%s" markerHeight="%d" markerWidth="%d" refX="0" refY="%d" orient="auto"><polygon points="0 0, %d %d, 0 %d"/></marker>
</defs>`, kit.Select("arrowhead", arg, 0), height, width, height/2, width, height/2, height)
}
func (g *Group) Echo(group string, str string, arg ...interface{}) *ice.Message {
return g.Get(group).Echo(str, arg...)
}
func (g *Group) EchoText(group string, x, y int, text string) *ice.Message {
return g.Echo(group, "<text x=%d y=%d>%s</text>", x, y, text)
}
func (g *Group) EchoRect(group string, height, width, x, y int, arg ...string) *ice.Message { // rx ry
return g.Echo(group, `<rect height=%d width=%d rx=%s ry=%s x=%d y=%d />`, height, width, kit.Select("4", arg, 0), kit.Select("4", arg, 1), x, y)
}
func (g *Group) EchoLine(group string, x1, y1, x2, y2 int) *ice.Message {
return g.Echo(group, "<line x1=%d y1=%d x2=%d y2=%d></line>", x1, y1, x2, y2)
}
func (g *Group) EchoText(group string, x, y int, text string, arg ...string) *ice.Message {
if text == "" {
return g.Get(group)
}
return g.Echo(group, "<text x=%d y=%d>%s</text>", x, y, text)
}
func (g *Group) EchoTexts(group string, x, y int, text string, arg ...string) *ice.Message {
m := g.Get(group)
float := kit.Int(kit.Select("2", "7", kit.Contains(m.Option(ice.MSG_USERUA), "iPhone")))
return g.EchoText(group, x, y+float, text, arg...)
}
func (g *Group) DefsArrow(group string, height, width int, arg ...string) *ice.Message { // name
return g.Echo(group, `<defs>
<marker id="%s" markerHeight="%d" markerWidth="%d" refX="0" refY="%d" stroke-dasharray="none" orient="auto"><polygon points="0 0, %d %d, 0 %d"/></marker>
</defs>`, kit.Select("arrowhead", arg, 0), height, width, height/2, width, height/2, height)
}
func (g *Group) EchoArrowLine(group string, x1, y1, x2, y2 int, arg ...string) *ice.Message { // marker-end
return g.Echo(group, "<line x1=%d y1=%d x2=%d y2=%d marker-end='url(#%s)'></line>", x1, y1, x2, y2, kit.Select("arrowhead", arg, 0))
}
func (g *Group) Dump(m *ice.Message, group string, arg ...string) *Group {
item := NewItem([]string{"<g name=%s"}, group)
for _, k := range kit.Simple(STROKE_DASHARRAY, STROKE_WIDTH, STROKE, FILL, FONT_SIZE, arg) {
item.Push(kit.Format(`%s="%%v"`, k), m.Option(group+"-"+k))
for _, k := range kit.Simple(STROKE_DASHARRAY, STROKE_WIDTH, STROKE, FILL, FONT_SIZE, FONT_FAMILY, arg) {
v := m.Option(kit.Keys(group, k))
switch k {
case STROKE:
v = kit.Select(m.Option(kit.Keys(group, k)), m.Option(kit.Keys(group, FG)))
case FILL:
v = kit.Select(m.Option(kit.Keys(group, k)), m.Option(kit.Keys(group, BG)))
}
item.Push(kit.Format(`%s="%%v"`, k), v)
}
item.Echo(">").Dump(m).Copy(g.Get(group)).Echo("</g>")
return g
@ -102,9 +117,7 @@ type Chart interface {
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 AddChart(name string, hand func(m *ice.Message) Chart) { chart_list[name] = hand }
func _chart_show(m *ice.Message, kind, text string, arg ...string) {
// 默认参数
@ -154,6 +167,7 @@ const (
const (
LABEL = "label"
CHAIN = "chain"
SEQUENCE = "sequence"
)
const CHART = "chart"
@ -166,8 +180,8 @@ func init() {
}},
}, Configs: map[string]*ice.Config{
CHART: {Name: CHART, Help: "图表", Value: kit.Data(
nfs.TEMPLATE, `<svg {{.OptionTemplate}}
vertion="1.1" xmlns="http://www.w3.org/2000/svg" height="{{.Option "height"}}" width="{{.Option "width"}}"
nfs.TEMPLATE, `<svg xmlns="http://www.w3.org/2000/svg" vertion="1.1"
{{.OptionTemplate}} height="{{.Option "height"}}" width="{{.Option "width"}}"
stroke-width="{{.Option "stroke-width"}}" stroke="{{.Option "stroke"}}" fill="{{.Option "fill"}}"
font-size="{{.Option "font-size"}}" font-family="{{.Option "font-family"}}" text-anchor="middle" dominant-baseline="middle">`,
)},

View File

@ -58,11 +58,13 @@ func (b *Block) Data(m *ice.Message, meta interface{}) wiki.Chart {
}
func (b *Block) Draw(m *ice.Message, x, y int) wiki.Chart {
float := kit.Int(kit.Select("2", "7", strings.Contains(m.Option(ice.MSG_USERUA), "iPhone")))
if m.Option(HIDE_BLOCK) != ice.TRUE {
if m.Option(SHOW_BLOCK) == ice.TRUE {
item := wiki.NewItem([]string{`<rect height="%d" width="%d" rx="4" ry="4" x="%d" y="%d"`}, b.GetHeight(), b.GetWidth(), x+b.MarginX/2, y+b.MarginY/2)
item.Push(`fill="%s"`, b.BackGround).Push(`%v`, b.RectData).Echo("/>").Dump(m)
}
item := wiki.NewItem([]string{`<text x="%d" y="%d"`}, x+b.GetWidths()/2, y+b.GetHeights()/2+float)
item.Push(`fill="%s"`, kit.Select(m.Option(wiki.STROKE), b.FontColor))
item.Push(`stroke-width="%d"`, 1)
item.Push(`stroke="%s"`, b.FontColor).Push(`fill="%s"`, b.FontColor).Push("%v", b.TextData).Push(`>%v</text>`, b.Text).Dump(m)
return b
}

View File

@ -12,38 +12,47 @@ import (
type Chain struct {
data map[string]interface{}
Group *wiki.Group
gs *wiki.Group
Block
}
func (c *Chain) Init(m *ice.Message, arg ...string) wiki.Chart {
(&c.Block).Init(m)
// 解析数据
m.Option(nfs.CAT_CONTENT, arg[0])
m.Option(lex.SPLIT_SPACE, "\t \n")
m.Option(lex.SPLIT_BLOCK, "\t \n")
m.Option(lex.SPLIT_BLOCK, ice.SP)
max, stack := 0, kit.List(kit.Dict("_deep", -1, "width", "0"))
m.OptionCB(lex.SPLIT, func(deep int, ls []string, data map[string]interface{}) []string {
for deep <= kit.Int(kit.Value(stack[len(stack)-1], "_deep")) {
stack = stack[:len(stack)-1]
}
width := kit.Int(kit.Value(stack[len(stack)-1], "width")) + c.GetWidths(ls[0])
stack = append(stack, kit.Dict("_deep", deep, "width", width))
if width > max {
max = width
}
return ls
})
c.data = lex.Split(m, "", mdb.TEXT)
// 计算尺寸
c.Height = c.size(m, c.data) * c.GetHeights()
c.Draw(m, 0, 0)
c.Width += 200
m.Set(ice.MSG_RESULT)
c.Height, c.Width = c.size(m, c.data)*c.GetHeights(), max
return c
}
func (c *Chain) Draw(m *ice.Message, x, y int) wiki.Chart {
c.Group = wiki.NewGroup(m, SHIP)
defer c.Group.Dump(m, SHIP)
c.gs = wiki.NewGroup(m, SHIP, RECT, LINE, TEXT)
wiki.AddGroupOption(m, LINE, wiki.STROKE, c.gs.Option(SHIP, wiki.STROKE))
wiki.AddGroupOption(m, TEXT, wiki.FILL, m.Option(wiki.STROKE), wiki.STROKE_WIDTH, "1")
defer func() { c.gs.Dump(m, SHIP).Dump(m, RECT).Dump(m, LINE).Dump(m, TEXT) }()
c.Height, c.Width = 0, 0
c.draw(m, c.data, x, y, &c.Block)
return c
}
func (c *Chain) size(m *ice.Message, root map[string]interface{}) (height int) {
meta := kit.GetMeta(root)
if list, ok := root[mdb.LIST].([]interface{}); ok && len(list) > 0 {
kit.Fetch(root[mdb.LIST], func(index int, value map[string]interface{}) {
height += c.size(m, value)
})
kit.Fetch(root[mdb.LIST], func(index int, value map[string]interface{}) { height += c.size(m, value) })
} else {
height = 1
}
@ -52,44 +61,32 @@ func (c *Chain) size(m *ice.Message, root map[string]interface{}) (height int) {
}
func (c *Chain) draw(m *ice.Message, root map[string]interface{}, x, y int, p *Block) int {
meta := kit.GetMeta(root)
c.Height, c.Width = 0, 0
if kit.Format(meta[wiki.FG]) != "" {
items := wiki.NewItem([]string{"<g"})
items.Push("stroke=%s", meta[wiki.FG])
items.Push("fill=%s", meta[wiki.FG])
items.Echo(">").Dump(m)
defer m.Echo("</g>")
}
// 当前节点
item := &Block{
FontSize: p.FontSize,
Padding: p.Padding,
MarginX: p.MarginX,
MarginY: p.MarginY,
}
item := &Block{FontSize: p.FontSize, Padding: p.Padding, MarginX: p.MarginX, MarginY: p.MarginY}
item.x, item.y = x, y+(kit.Int(meta[wiki.HEIGHT])-1)*c.GetHeights()/2
item.Init(m, kit.Format(meta[mdb.TEXT])).Data(m, meta)
item.Draw(m, item.x, item.y)
// 画面尺寸
if item.y+item.GetHeight()+c.MarginY > c.Height {
c.Height = item.y + item.GetHeight() + c.MarginY
}
if item.x+item.GetWidth()+c.MarginX > c.Width {
c.Width = item.x + item.GetWidth() + c.MarginX
item.Text = kit.Format(meta[mdb.TEXT])
if m.Option(SHOW_BLOCK) == ice.TRUE { // 方框
c.gs.EchoRect(RECT, item.GetHeight(), item.GetWidth(), item.x+item.MarginX/2, item.y+item.MarginY/2)
} else { // 横线
c.gs.EchoLine(LINE, item.x+item.MarginX/2, item.y+item.GetHeight()+item.Padding/2, item.x+item.GetWidths()-item.MarginX/2, item.y+item.GetHeight()+item.Padding/2)
}
// 模块连线
if p != nil && p.y != 0 {
// 文本
c.gs.EchoTexts(TEXT, item.x+item.GetWidths()/2, item.y+item.GetHeights()/2, kit.Format(meta[mdb.TEXT]))
if p != nil && p.y != 0 { // 连线
if m.Option(SHOW_BLOCK) == ice.TRUE {
x1, y1 := p.x+p.GetWidths()-(p.MarginX+item.MarginX)/4, p.y+p.GetHeights()/2
x4, y4 := item.x+(p.MarginX+item.MarginX)/4, item.y+item.GetHeights()/2
c.Group.Echo(SHIP, `<path d="M %d,%d Q %d,%d %d,%d T %d %d"></path>`,
x1, y1, x1+(x4-x1)/4, y1, x1+(x4-x1)/2, y1+(y4-y1)/2, x4, y4)
c.gs.Echo(SHIP, `<path d="M %d,%d Q %d,%d %d,%d T %d %d"></path>`, x1, y1, x1+(x4-x1)/4, y1, x1+(x4-x1)/2, y1+(y4-y1)/2, x4, y4)
} else {
x1, y1 := p.x+p.GetWidths()-(p.MarginX+item.MarginX)/4, p.y+p.GetHeight()+item.Padding/2
x4, y4 := item.x+(p.MarginX+item.MarginX)/4, item.y+item.GetHeight()+item.Padding/2
c.gs.Echo(SHIP, `<path d="M %d,%d Q %d,%d %d,%d T %d %d"></path>`, x1, y1, x1+(x4-x1)/4, y1, x1+(x4-x1)/2, y1+(y4-y1)/2, x4, y4)
}
}
// 递归节点
// 递归
h, x := 0, x+item.GetWidths()
if kit.Fetch(root[mdb.LIST], func(index int, value map[string]interface{}) {
h += c.draw(m, value, x, y+h, item)
@ -101,21 +98,16 @@ func (c *Chain) draw(m *ice.Message, root map[string]interface{}, x, y int, p *B
const (
SHIP = "ship"
HIDE_BLOCK = "hide-block"
)
const CHAIN = "chain"
func init() {
wiki.AddChart(CHAIN, func(m *ice.Message) wiki.Chart {
m.Option(wiki.STROKE_WIDTH, "1")
m.Option(wiki.FILL, cli.BLUE)
m.Option(wiki.STROKE_WIDTH, "2")
m.Option(wiki.STROKE, cli.BLUE)
m.Option(wiki.MARGINX, "40")
m.Option(wiki.MARGINY, "0")
m.Option(COMPACT, ice.TRUE)
m.Option(HIDE_BLOCK, ice.TRUE)
wiki.AddGroupOption(m, SHIP, wiki.STROKE_WIDTH, "1", wiki.STROKE, cli.CYAN, wiki.FILL, "none")
m.Option(wiki.MARGINY, "10")
wiki.AddGroupOption(m, SHIP, wiki.STROKE, cli.RED, wiki.FILL, cli.GLASS)
return &Chain{}
})
}

View File

@ -1,10 +1,10 @@
package chart
import (
"strings"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/lex"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/core/wiki"
kit "shylinux.com/x/toolkits"
)
@ -20,8 +20,8 @@ func (l *Label) Init(m *ice.Message, arg ...string) wiki.Chart {
// 解析数据
l.max = map[int]int{}
for _, v := range strings.Split(arg[0], ice.NL) {
ls := kit.Split(v, ice.SP, ice.SP)
m.Option(lex.SPLIT_BLOCK, ice.SP)
m.Cmd(lex.SPLIT, "", kit.Dict(nfs.CAT_CONTENT, arg[0]), func(ls []string, data map[string]interface{}) []string {
l.data = append(l.data, ls)
for i, v := range ls {
@ -33,7 +33,8 @@ func (l *Label) Init(m *ice.Message, arg ...string) wiki.Chart {
l.max[i] = w
}
}
}
return ls
})
// 计算尺寸
l.Height = len(l.data) * l.GetHeights()
@ -43,6 +44,10 @@ func (l *Label) Init(m *ice.Message, arg ...string) wiki.Chart {
return l
}
func (l *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))
defer func() { gs.Dump(m, RECT).Dump(m, TEXT) }()
var item *Block
top := y
for _, line := range l.data {
@ -58,16 +63,20 @@ func (l *Label) Draw(m *ice.Message, x, y int) wiki.Chart {
item.Init(m, text)
}
// 输出
// 尺寸
switch m.Option(COMPACT) {
case "max":
item.Width = l.Width/len(line) - l.MarginX
case ice.TRUE:
default:
item.Width = l.max[i]
}
item.Draw(m, left, top)
// 输出
if m.Option(SHOW_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)
left += item.GetWidths()
}
@ -77,12 +86,17 @@ func (l *Label) Draw(m *ice.Message, x, y int) wiki.Chart {
}
const (
SHOW_BLOCK = "show-block"
COMPACT = "compact"
)
const LABEL = "label"
func init() {
wiki.AddChart(LABEL, func(m *ice.Message) wiki.Chart {
m.Option(SHOW_BLOCK, ice.TRUE)
wiki.AddGroupOption(m, TEXT, wiki.FILL, m.Option(wiki.STROKE))
wiki.AddGroupOption(m, TEXT, wiki.STROKE_WIDTH, "1")
wiki.AddGroupOption(m, TEXT, wiki.FONT_FAMILY, m.Option(wiki.FONT_FAMILY))
return &Label{}
})
}

View File

@ -11,16 +11,18 @@ import (
)
type Sequence struct {
Head []string
List [][]map[string]interface{}
head []string
list [][]map[string]interface{}
pos []int
max int
Block
}
func (s *Sequence) push(m *ice.Message, list string, arg ...interface{}) map[string]interface{} {
node, node_list := kit.Dict(arg...), kit.Int(list)
s.List[node_list] = append(s.List[node_list], node)
_max := kit.Max(len(s.List[node_list])-1, s.pos[node_list])
s.list[node_list] = append(s.list[node_list], node)
// _max := kit.Max(len(s.list[node_list])-1, s.pos[node_list])
_max := kit.Max(len(s.list[node_list])-1, s.max)
node[ORDER], s.pos[node_list] = _max, _max+1
return node
}
@ -28,98 +30,114 @@ func (s *Sequence) Init(m *ice.Message, arg ...string) wiki.Chart {
(&s.Block).Init(m)
// 解析数据
m.Option(lex.SPLIT_BLOCK, ice.SP)
m.Cmd(lex.SPLIT, "", kit.Dict(nfs.CAT_CONTENT, arg[0]), func(ls []string, data map[string]interface{}) []string {
if len(s.Head) == 0 {
s.Head, s.pos = ls, make([]int, len(ls))
if len(s.head) == 0 { // 添加标题
s.head, s.pos = ls, make([]int, len(ls))
for i := 0; i < len(ls); i++ {
s.List = append(s.List, []map[string]interface{}{})
s.list = append(s.list, []map[string]interface{}{})
}
return ls
}
from_node := s.push(m, ls[0])
list := map[string]map[string]interface{}{ls[0]: from_node}
for i := 1; i < len(ls)-1; i += 2 {
for step, i := 0, 1; i < len(ls)-1; i += 2 {
to_node := list[ls[i+1]]
if to_node == nil {
to_node = s.push(m, ls[i+1])
list[ls[i+1]] = to_node
step++
_max := kit.Max(kit.Int(from_node[ORDER]), kit.Int(to_node[ORDER]))
// 层级
_max := kit.Max(kit.Int(from_node[ORDER]), kit.Int(to_node[ORDER]), s.max)
s.pos[kit.Int(ls[i-1])], s.pos[kit.Int(ls[i+1])] = _max+1, _max+1
from_node[ORDER], to_node[ORDER] = _max, _max
from_node[mdb.TEXT], from_node[mdb.NEXT] = ls[i], ls[i+1]
// 连接
from_node[mdb.TEXT], from_node[mdb.NEXT] = kit.Format("%d.%d %s", s.max+1, step, ls[i]), ls[i+1]
to_node[ECHO], to_node[PREV] = "", ls[i-1]
} else {
from_node[ECHO], from_node[PREV] = ls[i], ls[i+1]
}
from_node = to_node
}
s.max++
return ls
})
// 计算尺寸
width := 0
for _, v := range s.Head {
for _, v := range s.head {
width += s.Block.GetWidths(v)
}
rect_height := kit.Int(m.Option(RECT + "-" + wiki.HEIGHT))
rect_height := kit.Int(m.Option(kit.Keys(RECT, wiki.HEIGHT)))
s.Width, s.Height = width, kit.Max(s.pos...)*(rect_height+s.MarginY)+s.MarginY+s.GetHeights()
return s
}
func (s *Sequence) Draw(m *ice.Message, x, y int) wiki.Chart {
g := wiki.NewGroup(m, ARROW, HEAD, LINE, RECT, NEXT, PREV, TEXT, ECHO)
arrow_height := kit.Int(g.Option(ARROW, wiki.HEIGHT))
arrow_width := kit.Int(g.Option(ARROW, wiki.WIDTH))
rect_height := kit.Int(g.Option(RECT, wiki.HEIGHT))
rect_width := kit.Int(g.Option(RECT, wiki.WIDTH))
g.DefsArrow(NEXT, arrow_height, arrow_width)
gs := wiki.NewGroup(m, HEAD, TITLE, LINE, RECT, NEXT, PREV, TEXT, ECHO, ARROW)
wiki.AddGroupOption(m, TITLE, wiki.FILL, m.Option(wiki.STROKE))
wiki.AddGroupOption(m, TEXT, wiki.FILL, m.Option(wiki.STROKE))
wiki.AddGroupOption(m, ECHO, wiki.FILL, m.Option(wiki.STROKE))
defer func() { // 输出
gs.Dump(m, HEAD).Dump(m, TITLE).Dump(m, LINE)
gs.Dump(m, RECT).Dump(m, NEXT).Dump(m, PREV)
gs.Dump(m, TEXT).Dump(m, ECHO)
}()
rect_width := kit.Int(gs.Option(RECT, wiki.WIDTH))
rect_height := kit.Int(gs.Option(RECT, wiki.HEIGHT))
text_size := kit.Int(gs.Option(TEXT, wiki.FONT_SIZE))
echo_size := kit.Int(gs.Option(ECHO, wiki.FONT_SIZE))
arrow_height := kit.Int(gs.Option(ARROW, wiki.HEIGHT))
arrow_width := kit.Int(gs.Option(ARROW, wiki.WIDTH))
gs.DefsArrow(NEXT, arrow_height, arrow_width, NEXT)
gs.DefsArrow(PREV, arrow_height, arrow_width, PREV)
height := s.Height
s.Block.Height, s.Block.Width = 0, 0
line_pos := make([]int, len(s.List))
for i := range s.List {
s.Block.Text = s.Head[i]
s.Block.Draw(g.Get(HEAD), x, y)
line_pos := make([]int, len(s.list))
for i := range s.list { // 标题
s.Block.Text = s.head[i]
gs.EchoRect(HEAD, s.Block.GetHeight(), s.Block.GetWidth(), x+s.Block.MarginX/2, y+s.Block.MarginY/2)
gs.EchoTexts(TITLE, x+s.Block.GetWidths()/2, y+s.Block.GetHeights()/2, s.head[i])
line_pos[i], x = x+s.Block.GetWidths()/2, x+s.Block.GetWidths()
}
y += s.Block.GetHeight() + s.MarginY/2
for _, x := range line_pos {
g.EchoLine(LINE, x, y, x, height-s.MarginY/2)
for _, x := range line_pos { // 竖线
gs.EchoLine(LINE, x, y, x, height-s.MarginY/2)
}
for i, x := range line_pos {
for _, v := range s.List[i] {
for _, v := range s.list[i] {
pos := kit.Int(v[ORDER])
g.EchoRect(RECT, rect_height, rect_width, x-rect_width/2, y+pos*(rect_height+s.MarginY)+s.MarginY, "2", "2")
gs.EchoRect(RECT, rect_height, rect_width, x-rect_width/2, y+pos*(rect_height+s.MarginY)+s.MarginY, "2", "2")
yy := y + pos*(rect_height+s.MarginY) + s.MarginY + rect_height/4
if kit.Format(v[mdb.NEXT]) != "" {
if kit.Format(v[mdb.NEXT]) != "" { // 请求
xx := line_pos[kit.Int(v[mdb.NEXT])]
if x < xx {
g.EchoArrowLine(NEXT, x+rect_width/2, yy, xx-rect_width/2-arrow_width, yy)
gs.EchoArrowLine(NEXT, x+rect_width/2, yy, xx-rect_width/2-arrow_width, yy, NEXT)
} else {
g.EchoArrowLine(NEXT, x-rect_width/2, yy, xx+rect_width/2+arrow_width, yy)
gs.EchoArrowLine(NEXT, x-rect_width/2, yy, xx+rect_width/2+arrow_width, yy, NEXT)
}
g.EchoText(TEXT, (x+xx)/2, yy, kit.Format(v[mdb.TEXT]))
gs.EchoText(TEXT, (x+xx)/2, yy-text_size/2, kit.Format(v[mdb.TEXT]))
}
yy += rect_height / 2
if kit.Format(v[PREV]) != "" {
if kit.Format(v[PREV]) != "" { // 响应
xx := line_pos[kit.Int(v[PREV])]
if x < xx {
g.EchoArrowLine(PREV, x+rect_width/2, yy, xx-rect_width/2-arrow_width, yy)
gs.EchoArrowLine(PREV, x+rect_width/2, yy, xx-rect_width/2-arrow_width, yy, PREV)
} else {
g.EchoArrowLine(PREV, x-rect_width/2, yy, xx+rect_width/2+arrow_width, yy)
gs.EchoArrowLine(PREV, x-rect_width/2, yy, xx+rect_width/2+arrow_width, yy, PREV)
}
g.EchoText(ECHO, (x+xx)/2, yy, kit.Format(v[ECHO]))
gs.EchoText(ECHO, (x+xx)/2, yy-echo_size/2, kit.Format(v[ECHO]))
}
}
}
g.Dump(m, HEAD).Dump(m, LINE)
g.Dump(m, RECT).Dump(m, NEXT).Dump(m, PREV)
g.Dump(m, TEXT).Dump(m, ECHO)
return s
}
@ -127,34 +145,41 @@ const (
ORDER = "order"
)
const (
ARROW = "arrow"
HEAD = "head"
TITLE = "title"
LINE = "line"
RECT = "rect"
NEXT = "next"
PREV = "prev"
TEXT = "text"
ECHO = "echo"
ARROW = "arrow"
)
const SEQUENCE = "sequence"
func init() {
wiki.AddChart(SEQUENCE, func(m *ice.Message) wiki.Chart {
m.Option(wiki.MARGINX, "60")
m.Option(wiki.MARGINY, "20")
m.Option(wiki.MARGINX, "40")
m.Option(wiki.MARGINY, "40")
m.Option(wiki.STROKE_WIDTH, "1")
m.Option(wiki.STROKE, cli.WHITE)
switch m.Option("topic") {
case cli.WHITE:
m.Option(wiki.STROKE, cli.BLACK)
m.Option(wiki.FILL, cli.WHITE)
wiki.AddGroupOption(m, ARROW, wiki.HEIGHT, "8", wiki.WIDTH, "18", wiki.FILL, cli.GLASS)
wiki.AddGroupOption(m, HEAD, wiki.FILL, cli.GLASS)
case cli.BLACK:
m.Option(wiki.STROKE, cli.WHITE)
m.Option(wiki.FILL, cli.BLACK)
default:
m.Option(wiki.STROKE, cli.BLACK)
m.Option(wiki.FILL, cli.WHITE)
}
wiki.AddGroupOption(m, LINE, wiki.STROKE_DASHARRAY, "20 4 4 4")
wiki.AddGroupOption(m, RECT, wiki.HEIGHT, "40", wiki.WIDTH, "14")
wiki.AddGroupOption(m, NEXT, wiki.FILL, cli.GLASS)
wiki.AddGroupOption(m, PREV, wiki.STROKE_DASHARRAY, "10 2")
wiki.AddGroupOption(m, TEXT, wiki.FONT_SIZE, "16")
wiki.AddGroupOption(m, ECHO, wiki.FONT_SIZE, "12")
wiki.AddGroupOption(m, ARROW, wiki.HEIGHT, "8", wiki.WIDTH, "18", wiki.FILL, cli.GLASS)
return &Sequence{}
})
}

View File

@ -1,6 +1,8 @@
package wiki
import (
"path"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/ctx"
@ -33,12 +35,13 @@ func init() {
ENDMENU, kit.List(TITLE, ENDMENU),
LABEL, kit.List(CHART, LABEL),
CHAIN, kit.List(CHART, CHAIN),
SEQUENCE, kit.List(CHART, SEQUENCE),
),
mdb.SHORT, "type,name,text",
mdb.FIELD, "time,hash,type,name,text",
)},
}, Commands: map[string]*ice.Command{
WORD: {Name: "word path=src/main.shy@key list play", Help: "语言文字", Meta: kit.Dict(ice.DisplayLocal("")), Action: ice.MergeAction(map[string]*ice.Action{
WORD: {Name: "word path=src/main.shy@key list play", Help: "语言文字", Action: ice.MergeAction(map[string]*ice.Action{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, m.PrefixKey("src/main.shy"))
}},
@ -80,6 +83,10 @@ func init() {
}, ctx.CmdAction(), mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option(nfs.DIR_REG, m.Config(lex.REGEXP))
if m.Option(nfs.DIR_DEEP, ice.TRUE); !_wiki_list(m, cmd, arg...) {
if !kit.FileExists(arg[0]) && kit.FileExists(path.Join("src", arg[0])) {
arg[0] = path.Join("src/", arg[0])
}
m.DisplayLocal("")
_word_show(m, arg[0])
}
}},

View File

@ -80,6 +80,9 @@ func FileURI(dir string) string {
if strings.HasPrefix(dir, USR) {
return path.Join("/require", dir)
}
if kit.FileExists(path.Join("src", dir)) {
return path.Join("/require/src/", dir)
}
return dir
}
func FileCmd(dir string) string {
@ -95,7 +98,7 @@ func GetFileCmd(dir string) string {
if strings.HasPrefix(dir, "require/") {
dir = "/" + dir
}
for _, dir := range []string{dir, "/require/"+Info.Make.Module+"/"+dir}{
for _, dir := range []string{dir, "/require/" + Info.Make.Module + "/" + dir, "/require/" + Info.Make.Module + "/src/" + dir} {
if cmd, ok := Info.File[FileCmd(dir)]; ok {
return cmd
}

View File

@ -112,7 +112,7 @@ func init() {
} else {
m.Option(nfs.DIR_ROOT, path.Join(ice.USR, arg[0])+ice.PS)
}
m.Display("/plugin/story/spide.js?field=path", "root", arg[0])
m.DisplayStory("spide.js?field=path", "root", arg[0])
if len(arg) == 1 { // 目录列表
m.Option(nfs.DIR_DEEP, ice.TRUE)

View File

@ -199,11 +199,11 @@ const STATUS = "status"
func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
STATUS: {Name: "status repos auto", Help: "状态机", Action: map[string]*ice.Action{
STATUS: {Name: "status repos@key auto", Help: "状态机", Action: map[string]*ice.Action{
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
switch arg[0] {
case mdb.NAME:
m.Cmdy(REPOS, ice.OptionFields("name,time"))
case mdb.NAME, REPOS:
m.Cmdy(REPOS).Cut("repos")
case TAGS, VERSION:
if m.Option(TAGS) == ice.ErrWarn {

View File

@ -13,7 +13,7 @@ const TREND = "trend"
func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
TREND: {Name: "trend repos@key begin_time@date auto", Help: "趋势图", Meta: kit.Dict(
ice.Display("/plugin/story/trend.js"),
ice.DisplayStory("trend.js"),
), Action: ice.MergeAction(map[string]*ice.Action{
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(REPOS, ice.OptionFields("name,time"))