1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00

opt table.go

This commit is contained in:
shaoying 2021-09-02 01:20:08 +08:00
parent 1a1a53db00
commit 44d2dfbfd5
2 changed files with 33 additions and 6 deletions

View File

@ -4,9 +4,29 @@ import (
"strings"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/cli"
kit "shylinux.com/x/toolkits"
)
func _table_run(m *ice.Message, arg ...string) {
msg := m.Cmd(arg)
list := [][]string{}
msg.Table(func(index int, value map[string]string, head []string) {
if index == 0 {
m.Optionv("head", head)
}
line := []string{}
for _, h := range head {
line = append(line, value[h])
}
list = append(list, line)
})
m.Optionv("list", list)
_wiki_template(m, TABLE, "", "")
}
func _table_show(m *ice.Message, text string, arg ...string) {
head, list := []string{}, [][]string{}
for i, v := range kit.Split(strings.TrimSpace(text), ice.NL) {
@ -35,7 +55,7 @@ func _table_show(m *ice.Message, text string, arg ...string) {
m.Optionv("head", head)
m.Optionv("list", list)
_wiki_template(m, ORDER, "", text, arg...)
_wiki_template(m, TABLE, "", text, arg...)
}
const TABLE = "table"
@ -43,7 +63,11 @@ const TABLE = "table"
func init() {
Index.Merge(&ice.Context{
Commands: map[string]*ice.Command{
TABLE: {Name: "table `[item item\n]...`", Help: "表格", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
TABLE: {Name: "table `[item item\n]...`", Help: "表格", Action: map[string]*ice.Action{
cli.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
_table_run(m, arg...)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_table_show(m, arg[0], arg[1:]...)
}},
},

View File

@ -1,6 +1,7 @@
package wiki
import (
"path"
"strings"
ice "shylinux.com/x/icebergs"
@ -15,14 +16,14 @@ func _title_deep(str string) int {
}
return 0
}
func _title_parse(m *ice.Message, root map[string]interface{}, list []string) int {
func _title_parse(m *ice.Message, dir string, root map[string]interface{}, list []string) int {
var last map[string]interface{}
deep := _title_deep(list[0])
for i := 0; i < len(list); i++ {
if d := _title_deep(list[i]); d < deep {
return i
} else if d > deep {
i += _title_parse(m, last, list[i:]) - 1
i += _title_parse(m, dir, last, list[i:]) - 1
continue
}
@ -31,9 +32,11 @@ func _title_parse(m *ice.Message, root map[string]interface{}, list []string) in
case 0:
continue
case 1:
case 2:
default:
m.Debug("what %v %v", dir, ls)
ls[1] = path.Join(dir, ls[1])
}
meta := kit.Dict(
"name", kit.Select("", ls, 0),
"link", kit.Select("", ls, 1),
@ -52,7 +55,7 @@ func _title_show(m *ice.Message, kind, text string, arg ...string) {
case NAVMENU: // 导航目录
_option(m, kind, "", text, arg...)
data := kit.Dict("meta", kit.Dict(), "list", kit.List())
_title_parse(m, data, strings.Split(text, ice.NL))
_title_parse(m, path.Dir(m.Option(ice.MSG_SCRIPT)), data, strings.Split(text, ice.NL))
m.RenderTemplate(kit.Format("<div {{.OptionTemplate}} data-data='%s'></div>", kit.Format(data)))
return