From 148e8a38468837974fde5c64465062aac1e2c084 Mon Sep 17 00:00:00 2001 From: shaoying Date: Thu, 21 Nov 2019 22:36:49 +0800 Subject: [PATCH] add dream.layout --- etc/conf/auto.sh | 1 + src/contexts/ctx/core.go | 7 ++----- src/contexts/ctx/ctx.go | 4 ++-- src/contexts/ctx/misc.go | 6 +++--- src/examples/code/code.go | 37 +++++++++++++++++++++++++++++++------ src/examples/wiki/wiki.go | 1 + 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/etc/conf/auto.sh b/etc/conf/auto.sh index d6d6dd68..70dda522 100644 --- a/etc/conf/auto.sh +++ b/etc/conf/auto.sh @@ -192,6 +192,7 @@ ShyInit() { echo "pid: $$" echo "pane: $TMUX_PANE" echo "begin: ${ctx_begin}" + echo "share: ${ctx_share}" } ShyInit && trap ShyLogout EXIT diff --git a/src/contexts/ctx/core.go b/src/contexts/ctx/core.go index d1d2a719..672e941c 100644 --- a/src/contexts/ctx/core.go +++ b/src/contexts/ctx/core.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "io" - "runtime" "strings" "time" "toolkit" @@ -36,13 +35,11 @@ func (c *Context) Register(s *Context, x Server, args ...interface{}) *Context { return s } func (c *Context) Plugin(s *Context, args []string) string { - runtime.GOMAXPROCS(8) - c.Register(s, nil) m := Pulse.Spawn(s) // m := &Message{code: 0, time: time.Now(), source: s, target: s, Meta: map[string][]string{}} // kit.DisableLog = true - // m.Option("log.disable", true) + m.Option("log.disable", false) m.Option("bio.modal", "action") if len(args) == 0 { @@ -50,7 +47,7 @@ func (c *Context) Plugin(s *Context, args []string) string { m.Echo("命令列表:\n") for k, v := range s.Commands { if !strings.HasPrefix(k, "_") { - m.Echo(" %s: %s\n %v\n\n", k, v.Name, v.Help) + m.Echo("--%s: %s\n %v\n\n", k, v.Name, v.Help) } } m.Echo("配置列表:\n") diff --git a/src/contexts/ctx/ctx.go b/src/contexts/ctx/ctx.go index 51016ec5..d422cf9d 100644 --- a/src/contexts/ctx/ctx.go +++ b/src/contexts/ctx/ctx.go @@ -339,10 +339,10 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, } value = m.Confv(arg[0], arg[1]) } else if len(arg) > 2 && arg[2] == "list" { - for i := 3; i < len(arg)-1; i += 1 { + for i := 3; i < len(arg); i += 1 { m.Confv(arg[0], []interface{}{arg[1], -2}, arg[i]) } - value = m.Confv(arg[0], arg[1]) + return } else if len(arg) > 1 && arg[1] == "list" { for i := 2; i < len(arg)-1; i += 1 { m.Confv(arg[0], -2, arg[i]) diff --git a/src/contexts/ctx/misc.go b/src/contexts/ctx/misc.go index 324908b8..a67f1efa 100644 --- a/src/contexts/ctx/misc.go +++ b/src/contexts/ctx/misc.go @@ -19,9 +19,9 @@ func (m *Message) Log(action string, str string, arg ...interface{}) *Message { kit.Log("error", fmt.Sprintf("stack: %s", m.Format("stack"))) } - if m.Options("log.disable") { - return m - } + // if m.Options("log.disable") { + // return m + // } if l := m.Sess("log", false); l != nil { if log, ok := l.target.Server.(LOGGER); ok { diff --git a/src/examples/code/code.go b/src/examples/code/code.go index 3e856095..82556d57 100644 --- a/src/examples/code/code.go +++ b/src/examples/code/code.go @@ -118,10 +118,29 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", "least": 3, }}, "dream": {Name: "dream", Help: "使命必达", Value: map[string]interface{}{ + "layout": map[string]interface{}{ + "three": []interface{}{ + "split-window -t $dream:1.1", + "split-window -v -t $dream:1.2", + "rename-window -t $dream:1 source", + "select-layout -t $dream:1 main-horizontal", + + "new-window -t $dream:2 -n docker", + "split-window -t $dream:2.1", + "split-window -v -t $dream:2.2", + "select-layout -t $dream:2 main-horizontal", + + "new-window -t $dream:3 -n online", + "split-window -t $dream:3.1", + "split-window -v -t $dream:3.2", + "select-layout -t $dream:3 main-horizontal", + }, + }, "topic": map[string]interface{}{ "hello": map[string]interface{}{ - "ship": []interface{}{"tip", "miss.md", "task", "feed"}, - "git": []interface{}{"clone https://github.com/shylinux/context"}, + "ship": []interface{}{"tip", "miss.md", "task", "feed"}, + "git": []interface{}{"clone https://github.com/shylinux/context"}, + "layout": []interface{}{}, "tmux": []interface{}{ "split-window -t $dream:1.1", "new-window -t $dream:2", @@ -143,11 +162,12 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", if !m.Cmds(tmux, "has-session", "-t", arg[1]) { break } + topic := kit.Select("hello", kit.Select(m.Option("topic"), arg, 2)) // 下载代码 home := path.Join(m.Conf("missyou", "path"), arg[1], m.Conf("missyou", "local")) git := kit.Trans(m.Confv("prefix", "git"), "cmd_dir", home) - m.Confm("dream", []string{"topic", m.Option("topic"), "git"}, func(index int, value string) { + m.Confm("dream", []string{"topic", topic, "git"}, func(index int, value string) { value = strings.Replace(value, "$dream", arg[1], -1) m.Cmdx(git, strings.Split(value, " ")) }) @@ -156,16 +176,21 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", m.Cmds(tmux, "set-environment", "-g", "ctx_share", m.Cmdx("dream", "share")) m.Cmds(tmux, "new-session", "-ds", arg[1], "cmd_dir", home, "cmd_env", "TMUX", "") m.Cmds(tmux, "set-environment", "-t", arg[1], "ctx_share", m.Cmdx("dream", "share")) - m.Confm("dream", []string{"topic", m.Option("topic"), "tmux"}, func(index int, value string) { + m.Confm("dream", []string{"layout", m.Conf("dream", []string{"topic", m.Option("topic"), "layout", "0"})}, func(index int, value string) { + value = strings.Replace(value, "$dream", arg[1], -1) + m.Cmdx(tmux, strings.Split(value, " "), "cmd_dir", home) + }) + m.Confm("dream", []string{"topic", topic, "tmux"}, func(index int, value string) { value = strings.Replace(value, "$dream", arg[1], -1) m.Cmdx(tmux, strings.Split(value, " "), "cmd_dir", home) }) - arg = []string{"share"} + arg = []string{"share", topic} fallthrough case "share": + topic := kit.Select("hello", kit.Select(m.Option("topic"), arg, 1)) if len(arg) == 1 { - m.Confm("dream", []string{"topic", kit.Select("hello", m.Option("topic")), "ship"}, func(index int, value string) { + m.Confm("dream", []string{"topic", kit.Select("hello", topic), "ship"}, func(index int, value string) { arg = append(arg, value) }) } diff --git a/src/examples/wiki/wiki.go b/src/examples/wiki/wiki.go index c77dce9b..879e5b00 100644 --- a/src/examples/wiki/wiki.go +++ b/src/examples/wiki/wiki.go @@ -273,6 +273,7 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心", return }}, "run": {Name: "run", Help: "便签", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + m.Option("render", "raw") m.Cmdy(arg) return }},