From 44d2dfbfd50edacc8abe9d9bd6e32dcbc7e3f942 Mon Sep 17 00:00:00 2001 From: shaoying Date: Thu, 2 Sep 2021 01:20:08 +0800 Subject: [PATCH] opt table.go --- core/wiki/table.go | 28 ++++++++++++++++++++++++++-- core/wiki/title.go | 11 +++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/core/wiki/table.go b/core/wiki/table.go index da95ab35..01481b02 100644 --- a/core/wiki/table.go +++ b/core/wiki/table.go @@ -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:]...) }}, }, diff --git a/core/wiki/title.go b/core/wiki/title.go index 0281731c..16203197 100644 --- a/core/wiki/title.go +++ b/core/wiki/title.go @@ -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("
", kit.Format(data))) return