diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go index 7694e2d6..6307dd27 100644 --- a/src/contexts/cli/version.go +++ b/src/contexts/cli/version.go @@ -7,5 +7,5 @@ var version = struct { self int }{ []string{"2017-11-01 01:02:03", "2019-07-13 18:02:21"}, - `2019-11-07 00:01:51`, `centos`, 657, + `2019-11-29 12:39:40`, `mac`, 658, } diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go index f8ace77e..8f99f610 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -167,10 +167,10 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", if len(arg) == 0 { m.Confm("ssh.node", func(key string, value map[string]interface{}) { m.Push("create_time", value["create_time"]) - m.Push("pod", key) + m.Push("node", key) m.Push("type", value["type"]) }) - m.Sort("pod").Table() + m.Sort("node").Table() return } @@ -358,9 +358,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", }) arg = arg[4:] - if len(prefix) > 0 && prefix[1] == "_" { - prefix[1], arg = arg[0], arg[1:] - } args := []string{} for _, v := range kit.Trans(tool["args"]) { if strings.HasPrefix(v, "__") { @@ -377,6 +374,17 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", args = append(args, msg.Parse(v)) } } + + if len(prefix) > 0 && prefix[1] == "_" { + if len(args) > 0 { + prefix[1], args = args[0], args[1:] + } else if len(arg) > 0 { + prefix[1], arg = arg[0], arg[1:] + } else { + prefix[1] = "" + } + } + msg.Cmd(prefix, tool["cmd"], args, arg) msg.CopyTo(m) diff --git a/src/examples/chat/chat.go b/src/examples/chat/chat.go index 0e3184e8..afcd4951 100644 --- a/src/examples/chat/chat.go +++ b/src/examples/chat/chat.go @@ -336,12 +336,12 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", } return }}, - "storm": &ctx.Command{Name: "storm [rid] [[delete] group [index [arg...]]]", Help: "风雨", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + "storm": &ctx.Command{Name: "storm rid [[delete] group [index [arg...]]]", Help: "风雨", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { // 登录失败 - arg, rid, ok := check(m, arg) - if !ok { - return + if len(arg[0]) != 32 { + arg[0] = m.Cmdx("aaa.short", arg[0]) } + rid, arg := arg[0], arg[1:] m.Option("river", rid) // 命令列表 @@ -373,9 +373,22 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", arg[2] = m.Conf("flow", []string{rid, "tool", arg[2], "status"}) fallthrough case "save": - if m.Confv("flow", []string{rid, "tool", arg[1], "status"}, arg[2]); kit.Select("", arg, 3) != "" { - m.Confv("flow", []string{rid, "tool", arg[1], "list"}, kit.UnMarshal(arg[3])) + if arg[2] != "" { + m.Cmdy("ssh._route", arg[2], "web.chat.storm", rid, arg[:2], "", arg[3:]) + break } + if m.Confv("flow", []string{rid, "tool", arg[1], "status"}, arg[3]); kit.Select("", arg, 4) != "" { + m.Confv("flow", []string{rid, "tool", arg[1], "list"}, kit.UnMarshal(arg[4])) + } + case "load": + if len(arg) > 2 { + m.Cmdy("ssh._route", arg[2], "web.chat.storm", rid, arg[:2]) + break + } + m.Confm("flow", []string{rid, "tool", arg[1]}, func(value map[string]interface{}) { + m.Append("status", kit.Format(value["status"])) + m.Append("list", kit.Format(value["list"])) + }) default: // 命令列表 @@ -383,8 +396,15 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", m.Set("option", "init") m.Set("option", "view") if len(arg) == 1 { + list := m.Confv("flow", []string{rid, "tool", arg[0], "list"}) + if m.Option("you") != "" { + if msg := m.Cmd("ssh._route", m.Option("you"), "web.chat.storm", rid, "load", arg[0]); msg.Appends("list") { + list = kit.UnMarshal(msg.Append("list")) + } + } + short := m.Cmdx("aaa.short", rid) - m.Confm("flow", []string{rid, "tool", arg[0], "list"}, func(index int, tool map[string]interface{}) { + kit.Map(list, "", func(index int, tool map[string]interface{}) { m.Push("river", short) m.Push("storm", arg[0]) m.Push("action", index) diff --git a/src/examples/code/code.go b/src/examples/code/code.go index a32b76d7..61519b9f 100644 --- a/src/examples/code/code.go +++ b/src/examples/code/code.go @@ -64,6 +64,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", "ctx_dev ctx_share", "curl -s $ctx_dev/publish/auto.sh >auto.sh", "source auto.sh", + "ShyLogin", }, }, }}, @@ -139,7 +140,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", "login": {Name: "login", Value: map[string]interface{}{"check": false, "local": true, "expire": "720h", "meta": map[string]interface{}{ "fields": "time sid type status ship.dream ship.stage pwd pid pane hostname username", "script": "usr/script", - }}, Help: "用户登录"}, + }, "hash": map[string]interface{}{}}, Help: "用户登录"}, "dream": {Name: "dream", Help: "使命必达", Value: map[string]interface{}{ "layout": map[string]interface{}{ "three": []interface{}{ @@ -161,19 +162,17 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", }, "topic": map[string]interface{}{ "index": 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{}{}, + // "git": []interface{}{"clone https://github.com/shylinux/context"}, "layout": []interface{}{"three"}, "tmux": []interface{}{ "send-keys -t $dream.1.1 pwd", }, }, }, - "session": map[string]interface{}{"meta": map[string]interface{}{ - "fields": "river dream favor story stage order expire", - }}, "share": map[string]interface{}{"meta": map[string]interface{}{ "fields": "river dream favor story stage order expire", - }}, + }, "hash": map[string]interface{}{}}, "favor": map[string]interface{}{"meta": map[string]interface{}{ "fields": "tab note word file line col", }}, @@ -216,7 +215,6 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", value = strings.Replace(value, "$dream", arg[1], -1) m.Cmd(tmux, strings.Split(value, " "), "cmd_dir", home) }) - m.Conf("dream", "session."+m.Option("dream")+"."+"share", share) m.Echo(share) case "share": @@ -436,7 +434,6 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", return } if value["sid"] = key; len(arg) < 6 || arg[4] == "" || strings.HasPrefix(kit.Format(value[arg[4]]), arg[5]) { - m.Push("sid", key) m.Push(fields, value) } }) @@ -620,25 +617,147 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", } return }}, - "tmux": {Name: "tmux [session [window [pane cmd]]]", Help: "窗口", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + "tmux": {Name: "tmux [session [window [pane cmd]]]", Help: "窗口", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) { prefix := kit.Trans(m.Confv("prefix", "tmux")) - // 修改信息 if len(arg) > 1 { switch arg[1] { + case "cmd": + + case "pane": + prefix = append(prefix, "list-panes") + if arg[0] == "" { + prefix = append(prefix, "-a") + } else { + prefix = append(prefix, "-s", "-t", arg[0]) + } + m.Cmdy(prefix, "cmd_parse", "cut", " ", "8", "pane_name size some lines bytes haha pane_id tag") + + m.Meta["append"] = []string{"pane_id", "pane_name", "size", "lines", "bytes", "tag"} + m.Table(func(index int, value map[string]string) { + m.Meta["pane_name"][index] = strings.TrimSuffix(value["pane_name"], ":") + m.Meta["pane_id"][index] = strings.TrimPrefix(value["pane_id"], "%") + m.Meta["lines"][index] = strings.TrimSuffix(value["lines"], ",") + m.Meta["bytes"][index] = kit.FmtSize(kit.Int64(value["bytes"])) + }) + m.Sort("pane_name") + m.Table() + return + + case "favor": + env := m.Cmdx(prefix, "show-environment", "-g") + m.Cmdx(prefix, "show-environment") + for _, l := range strings.Split(env, "\n") { + if strings.HasPrefix(l, "ctx_") { + v := strings.SplitN(l, "=", 2) + m.Option(v[0], v[1]) + } + } + m.Option("ctx_dev", m.Option("ctx_self")) + + m.Confm("tmux", "favor."+kit.Select("index", arg, 4), func(index int, value string) { + if index == 0 { + keys := strings.Split(value, " ") + value = "export" + for _, k := range keys { + value += " " + k + "=" + m.Option(k) + } + + } + m.Cmdy(prefix, "send-keys", "-t", arg[0], value, "Enter") + time.Sleep(100 * time.Millisecond) + }) + m.Echo(strings.TrimSpace(m.Cmdx(prefix, "capture-pane", "-pt", arg[0]))) + return + + case "buffer": + // 写缓存 + if len(arg) > 5 { + switch arg[3] { + case "modify": + switch arg[4] { + case "text": + m.Cmdy(prefix, "set-buffer", "-b", arg[2], arg[5]) + } + } + } else if len(arg) > 3 { + m.Cmd(prefix, "set-buffer", "-b", arg[2], arg[3]) + } + + // 读缓存 + if len(arg) > 2 { + m.Cmdy(prefix, "show-buffer", "-b", arg[2]) + return + } + + m.Cmdy(prefix, "list-buffers", "cmd_parse", "cut", ": ", "3", "buffer size text") + for i, v := range m.Meta["text"] { + if i < 3 { + m.Meta["text"][i] = m.Cmdx(prefix, "show-buffer", "-b", m.Meta["buffer"][i]) + } else { + m.Meta["text"][i] = v[2 : len(v)-1] + } + } + return + + case "select": + // 切换会话 + if !m.Has("session") { + m.Cmd(prefix, "switch-client", "-t", arg[0]) + arg = arg[:0] + break + } + m.Cmd(prefix, "switch-client", "-t", m.Option("session")) + + // 切换窗口 + if !m.Has("window") { + m.Cmd(prefix, "select-window", "-t", m.Option("session")+":"+arg[0]) + arg = []string{m.Option("session")} + break + } + m.Cmd(prefix, "select-window", "-t", m.Option("session")+":"+m.Option("window")) + + // 切换终端 + m.Cmd(prefix, "select-pane", "-t", m.Option("session")+":"+m.Option("window")+"."+arg[0]) + arg = []string{m.Option("session"), m.Option("window")} + case "modify": switch arg[2] { case "session": + // 重命名会话 m.Cmdy(prefix, "rename-session", "-t", arg[0], arg[3]) + arg = arg[:0] + case "window": - m.Cmdy(prefix, "rename-window", "-t", arg[0], arg[3]) + // 重命名窗口 + m.Cmdy(prefix, "rename-window", "-t", m.Option("session")+":"+arg[0], arg[3]) + arg = []string{m.Option("session")} + + default: + return } - return + case "delete": + // 删除会话 + if !m.Has("session") { + m.Cmdy(prefix, "kill-session", "-t", arg[0]) + arg = arg[:0] + break + } + + // 删除窗口 + if !m.Has("window") { + m.Cmdy(prefix, "kill-window", "-t", m.Option("session")+":"+arg[0]) + arg = []string{m.Option("session")} + break + } + + // 删除终端 + m.Cmd(prefix, "kill-pane", "-t", m.Option("session")+":"+m.Option("window")+"."+arg[3]) + arg = []string{m.Option("session"), m.Option("window")} } } // 查看会话 - if m.Cmdy(prefix, "list-session", "-F", "#{session_id},#{session_name},#{session_windows},#{session_height},#{session_width}", - "cmd_parse", "cut", ",", "5", "id session windows height width"); len(arg) == 0 { + if m.Cmdy(prefix, "list-session", "-F", "#{session_id},#{session_attached},#{session_name},#{session_windows},#{session_height},#{session_width}", + "cmd_parse", "cut", ",", "6", "id tag session windows height width"); len(arg) == 0 { return } @@ -649,8 +768,8 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", m.Set("append").Set("result") // 查看窗口 - if m.Cmdy(prefix, "list-windows", "-t", arg[0], "-F", "#{window_id},#{window_name},#{window_panes},#{window_height},#{window_width}", - "cmd_parse", "cut", ",", "5", "id window panes height width"); len(arg) == 1 { + if m.Cmdy(prefix, "list-windows", "-t", arg[0], "-F", "#{window_id},#{window_active},#{window_name},#{window_panes},#{window_height},#{window_width}", + "cmd_parse", "cut", ",", "6", "id tag window panes height width"); len(arg) == 1 { return } @@ -662,89 +781,16 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", // 查看面板 if len(arg) == 2 { - m.Cmdy(prefix, "list-panes", "-t", arg[0]+":"+arg[1], "-F", "#{pane_id},#{pane_index},#{pane_tty},#{pane_height},#{pane_width}", - "cmd_parse", "cut", ",", "5", "id pane tty height width") + m.Cmdy(prefix, "list-panes", "-t", arg[0]+":"+arg[1], "-F", "#{pane_id},#{pane_active},#{pane_index},#{pane_tty},#{pane_height},#{pane_width}", + "cmd_parse", "cut", ",", "6", "id tag pane tty height width") return } // 执行命令 target := arg[0] + ":" + arg[1] + "." + arg[2] if len(arg) > 3 { - // 修改缓存 - if len(arg) > 5 { - switch arg[5] { - case "modify": - switch arg[6] { - case "text": - m.Cmdy(prefix, "set-buffer", "-b", arg[4], arg[7]) - } - return - } - } - - switch arg[3] { - case "favor": - env := m.Cmdx(prefix, "show-environment", "-g") + m.Cmdx(prefix, "show-environment") - for _, l := range strings.Split(env, "\n") { - if strings.HasPrefix(l, "ctx_") { - v := strings.SplitN(l, "=", 2) - m.Option(v[0], v[1]) - } - } - - m.Confm("tmux", "favor."+kit.Select("index", arg, 4), func(index int, value string) { - if index == 0 { - keys := strings.Split(value, " ") - value = "export" - for _, k := range keys { - value += " " + k + "=" + m.Option(k) - } - - } - m.Cmdy(prefix, "send-keys", "-t", target, value, "Enter") - }) - - case "buffer": - // 操作缓存 - if len(arg) > 5 { - m.Cmd(prefix, "set-buffer", "-b", arg[4], arg[5]) - } - if len(arg) > 4 { - m.Cmdy(prefix, "show-buffer", "-b", arg[4]) - return - } - m.Cmdy(prefix, "list-buffers", "cmd_parse", "cut", ": ", "3", "buffer size text") - for i, v := range m.Meta["text"] { - if i < 3 { - m.Meta["text"][i] = m.Cmdx(prefix, "show-buffer", "-b", m.Meta["buffer"][i]) - } else { - m.Meta["text"][i] = v[2 : len(v)-1] - } - } - return - case "pane": - // 面板列表 - m.Cmdy(prefix, "list-panes", "-a", "cmd_parse", "cut", " ", "8", "pane_name size some lines bytes haha pane_id tag") - m.Meta["append"] = []string{"pane_id", "pane_name", "size", "lines", "bytes", "tag"} - m.Table(func(index int, value map[string]string) { - m.Meta["pane_name"][index] = strings.TrimSuffix(value["pane_name"], ":") - m.Meta["pane_id"][index] = strings.TrimPrefix(value["pane_id"], "%") - m.Meta["lines"][index] = strings.TrimSuffix(value["lines"], ",") - m.Meta["bytes"][index] = kit.FmtSize(kit.Int64(value["bytes"])) - }) - m.Sort("pane_name") - m.Table() - return - case "run": - // 运行命令 - arg = arg[1:] - fallthrough - default: - if len(arg) > 3 { - m.Cmdy(prefix, "send-keys", "-t", target, strings.Join(arg[3:], " "), "Enter") - time.Sleep(1 * time.Second) - } - } + m.Cmdy(prefix, "send-keys", "-t", target, strings.Join(arg[3:], " "), "Enter") + time.Sleep(1 * time.Second) } // 查看终端 @@ -755,54 +801,38 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", prefix := kit.Trans(m.Confv("prefix", "docker")) switch arg[0] { case "image": - prefix = append(prefix, "image") - pos := kit.Select(m.Conf("runtime", "boot.ctx_app"), arg, 1) - tag := kit.Select(m.Conf("runtime", "boot.version"), arg, 2) - - // 查看镜像 - if m.Cmdy(prefix, "ls", "cmd_parse", "cut", "cmd_headers", "IMAGE ID", "IMAGE_ID"); len(arg) == 1 { - return - } else if i := kit.IndexOf(m.Meta["IMAGE_ID"], arg[1]); i > -1 { - arg, pos, tag = arg[2:], strings.TrimSpace(m.Meta["REPOSITORY"][i]), strings.TrimSpace(m.Meta["TAG"][i]) - } else { - arg = arg[3:] + if prefix = append(prefix, "image"); len(arg) < 3 { + m.Cmdy(prefix, "ls", "cmd_parse", "cut", "cmd_headers", "IMAGE ID", "IMAGE_ID") + break } - // 拉取镜像 - if len(arg) == 0 { - m.Cmdy(prefix, "pull", pos+":"+tag) - return - } - - switch arg[0] { - // 启动容器 + switch arg[2] { case "运行": - m.Set("append").Set("result") - m.Cmdy(prefix[:2], "run", "-dt", pos+":"+tag) - return - // 清理镜像 + m.Cmdy(prefix[:2], "run", "-dt", m.Option("REPOSITORY")+":"+m.Option("TAG")) case "清理": - m.Cmd(prefix, "prune", "-f") - - // 删除镜像 + m.Cmdy(prefix, "prune", "-f") case "delete": - m.Cmd(prefix, "rm", pos+":"+tag) - - // 创建镜像 - default: - m.Option("base", pos+":"+tag) - pos = kit.Select(m.Conf("runtime", "boot.ctx_app"), arg, 0) - m.Option("name", pos+":"+m.Time("20060102")) + m.Cmdy(prefix, "rm", m.Option("IMAGE_ID")) + case "创建": + m.Option("base", m.Option("REPOSITORY")+":"+m.Option("TAG")) + app := m.Conf("runtime", "boot.ctx_app") + m.Option("name", app+":"+m.Time("20060102")) m.Option("file", m.Conf("docker", "output")) - m.Option("user", kit.Select(m.Conf("runtime", "boot.username"), arg, 1)) + m.Option("user", m.Conf("runtime", "boot.username")) m.Option("host", "http://"+m.Conf("runtime", "boot.hostname")+".local"+m.Conf("runtime", "boot.web_port")) if f, _, e := kit.Create(m.Option("file")); m.Assert(e) { defer f.Close() - if m.Assert(ctx.ExecuteStr(m, f, m.Conf("docker", "template."+arg[0]))) { + if m.Assert(ctx.ExecuteStr(m, f, m.Conf("docker", "template."+app))) { m.Cmdy(prefix, "build", "-f", m.Option("file"), "-t", m.Option("name"), ".") } } + + default: + if len(arg) == 3 { + m.Cmdy(prefix, "pull", arg[1]+":"+arg[2]) + break + } } case "volume": @@ -830,7 +860,8 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", if prefix = append(prefix, "container"); len(arg) > 1 { switch arg[2] { case "进入": - m.Cmdy(m.Confv("prefix", "tmux"), "new-window", "-dPF", "#{session_name}:#{window_name}.1", "docker exec -it "+arg[1]+" sh") + m.Cmdy(m.Confv("prefix", "tmux"), "new-window", "-t", "", "-n", m.Option("CONTAINER_NAME"), + "-PF", "#{session_name}:#{window_name}.1", "docker exec -it "+arg[1]+" sh") return case "停止": @@ -852,7 +883,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", } case "delete": - m.Cmd(prefix, "rm", arg[1]) + m.Cmdy(prefix, "rm", arg[1]) default: if len(arg) == 2 { diff --git a/src/plugin/context/index.shy b/src/plugin/context/index.shy index cd952cae..cd5a5b81 100644 --- a/src/plugin/context/index.shy +++ b/src/plugin/context/index.shy @@ -1,14 +1,14 @@ kit project "项目" private \ - select "" values plugin values review values submit values trends values trend values stats values stat values init action auto \ + select "" values "plugin review submit trends trend stats stat init" action auto \ text "" name see imports plugin_see action auto \ - button "执行" \ - button "返回" cb Last \ feature detail "加载" "复制" "下载" \ - exports see name see + exports see name see \ + button "执行" action auto \ + button "返回" cb Last kit compile "编译" private \ - select "" values plugin values restart values windows values darwin values linux values self values all action auto \ + select "" values "plugin restart windows darwin linux self all" action auto \ text "" name see imports plugin_see \ button "编译" @@ -16,32 +16,32 @@ kit publish "发布" private \ text "" name see imports plugin_see \ button "发布" -kit upgrade "升级" private "ssh._route" _ "cli.upgrade" \ +kit upgrade "升级" private "_:cli.upgrade" \ text "" name pod imports plugin_pod \ - select "" values script values plugin values restart values package values system values portal values bench action auto \ + select "" values "script plugin restart package system portal bench" action auto \ text "" name see imports plugin_see \ button "升级" -kit missyou "任务" private "ssh._route" _ "cli.missyou" \ +kit missyou "任务" private "_:cli.missyou" \ text "" name pod imports plugin_pod \ text "" name you view long \ text "" name see imports plugin_see \ button "行动" action auto \ exports you "" you -kit pod "设备" private "ssh._route" _ "ssh.remote" __ \ - text "" name pod \ +kit pod "设备" private "_:ssh.remote" \ + text "" name pod imports plugin_pod \ button "查看" action auto \ button "返回" cb Last \ - exports pod pod pod + exports pod node pod -kit ctx "模块" private "ssh._route" _ context _ list __ \ +kit ctx "模块" private "_:context" _ _ list \ text "" name pod imports plugin_pod action auto \ text "cli" name ctx imports plugin_ctx action auto \ button "查看" \ exports ctx names -kit cmd "命令" private "ssh._route" _ context _ command __ \ +kit cmd "命令" private "_:context" _ _ command \ text "" name pod imports plugin_pod \ text "cli" name ctx imports plugin_ctx \ text "date" name cmd imports plugin_cmd \ @@ -49,7 +49,7 @@ kit cmd "命令" private "ssh._route" _ context _ command __ \ button "返回" cb Last \ exports cmd cmd -kit dir "目录" private "ssh._route" _ "nfs.dir" _ time size line path \ +kit dir "目录" private "_:nfs.dir" _ _ time size line path \ text "" name pod imports plugin_pod action auto \ text "usr/script" name dir imports plugin_dir action auto view long \ button "浏览" action auto \ diff --git a/src/plugin/docker/index.shy b/src/plugin/docker/index.shy index 6abe9fd6..1857542d 100644 --- a/src/plugin/docker/index.shy +++ b/src/plugin/docker/index.shy @@ -1,18 +1,17 @@ -kit dir "目录" private "_:web.code.zsh" \ - text "" name pod imports "plugin_pod plugin_you" action auto \ + +kit dir "目录" private "_:web.code.zsh" "@pod" \ text "" name dir imports plugin_path action auto \ - select "" name cmd values list values find values tail values grep values init action auto \ + select "" name cmd values "list find tail grep init" action auto \ text "" name txt \ exports path path \ feature display editor \ button "搜索" action auto \ button "返回" cb Last -kit clip "粘贴板" private "web.code.tmux" "" "" "" "buffer" \ +kit clip "粘贴板" private "web.code.tmux" "" "buffer" \ text "" name tag imports plugin_buffer action auto \ text "" name txt \ exports buffer buffer \ - feature detail "复制" "下载" "修改" \ button "查看" action auto \ button "返回" cb Last @@ -26,16 +25,13 @@ kit tmux "终端" private "web.code.tmux" \ kit tmuxs "终端" private "web.code.tmux" \ text "" name session imports plugin_session \ - text "" name window imports plugin_window \ - text "" name pane imports plugin_pane view char \ - select "" name cmd values "favor buffer pane run"\ + select "" name cmd values "favor pane cmd"\ text "" name arg \ - ueature detail "复制" "下载" "修改" \ button "执行" kit image "镜像" private "web.code.docker" "image" \ - text "" name pos imports plugin_REPOSITORY \ - text "" name tag imports plugin_TAG \ + text "" name pos \ + text "" name tag \ exports IMAGE_ID IMAGE_ID "" REPOSITORY REPOSITORY "" TAG TAG "" \ feature detail "运行" "清理" "删除" "创建" \ button "查看" @@ -52,8 +48,8 @@ kit network "网络" private "web.code.docker" "network" \ kit container "容器" private "web.code.docker" "container" \ text "" name arg imports plugin_CONTAINER_ID \ - exports CONTAINER_ID CONTAINER_ID \ feature detail "进入" "停止" "启动" "重启" "清理" "修改" "删除" \ + exports CONTAINER_ID CONTAINER_ID "" CONTAINER_NAME NAMES "" \ button "查看" action auto kit command "命令" private "web.code.docker" "command" \ @@ -63,8 +59,7 @@ kit command "命令" private "web.code.docker" "command" \ text "" name arg view long \ button "执行" -kit git "记录" private "_:web.code.zsh" \ - text "" name pod imports "plugin_pod plugin_you" action auto \ +kit git "记录" private "_:web.code.zsh" "@pod"\ text "usr/local" name dir imports plugin_git_path action auto \ select "git" name cmd values git \ select "status" name cmd values "diff status commit branch remote pull push sum init" action auto \ diff --git a/src/plugin/story/index.shy b/src/plugin/story/index.shy index 5c84343c..f02071d3 100644 --- a/src/plugin/story/index.shy +++ b/src/plugin/story/index.shy @@ -4,16 +4,14 @@ kit share "共享" public "web.chat.share" \ text "" name dream imports plugin_you \ button "共享" -kit note "记事本" public "ssh._route" _ "web.wiki.note" \ - text "" name dream imports plugin_you action auto \ +kit note "记事本" public "_:web.wiki.note" "@you" \ text "miss.md" name story imports plugin_story view long action auto \ button "查看" action auto \ button "返回" cb Last \ exports story file \ feature display inner -kit favor "收藏夹" public "ssh._route" _ "web.wiki.story" favor \ - text "" name dream imports plugin_you action auto \ +kit favor "收藏夹" public "_:web.wiki.story" "@you" favor \ text "see" name table imports plugin_story_table action auto \ text "" name index imports plugin_story_id view tiny action auto \ feature detail "修改" "复制" "下载" \ @@ -21,8 +19,7 @@ kit favor "收藏夹" public "ssh._route" _ "web.wiki.story" favor \ button "记录" action auto \ button "返回" cb Last -kit commit "记录" public "ssh._route" _ "web.wiki.story" commit \ - text "" name dream imports plugin_you \ +kit commit "记录" public "_:web.wiki.story" "@you" commit \ text "miss.md" name story imports plugin_story \ text "table" name sence \ text "hello" name enjoy \ diff --git a/src/plugin/vim/index.shy b/src/plugin/vim/index.shy index 676b2f2f..7bbab5d5 100644 --- a/src/plugin/vim/index.shy +++ b/src/plugin/vim/index.shy @@ -1,5 +1,5 @@ -kit tips "便签" private "_:web.code.favor" list \ - text "" name dream imports plugin_you action auto \ + +kit tips "便签" private "_:web.code.favor" "@you" list \ text "tip" name favor view tiny \ text "" name index imports plugin_vim_favor view tiny action auto \ text "" name limit view tiny \ @@ -9,8 +9,7 @@ kit tips "便签" private "_:web.code.favor" list \ button "查看" action auto \ button "返回" cb Last -kit favor "收藏" private "_:web.code.favor" post \ - text "" name dream imports plugin_you \ +kit favor "收藏" private "_:web.code.favor" "@you" post \ text "tip" name table view tiny \ text "" name tab \ text "" name note \ diff --git a/src/plugin/zsh/index.shy b/src/plugin/zsh/index.shy index b21851e7..e2b5404f 100644 --- a/src/plugin/zsh/index.shy +++ b/src/plugin/zsh/index.shy @@ -1,6 +1,5 @@ -kit file "文件" private "_:web.code.favor" file \ - text "" name dream imports plugin_you action auto \ +kit file "文件" private "_:web.code.favor" "@you" file \ text "file" name table view tiny \ text "" name index imports plugin_zsh_block action auto view tiny \ text "" name limit view tiny \ @@ -9,8 +8,7 @@ kit file "文件" private "_:web.code.favor" file \ button "查看" action auto \ button "返回" cb Last -kit tips "便签" private "_:web.code.favor" list \ - text "" name dream imports plugin_you action auto \ +kit tips "便签" private "_:web.code.favor" "@you" list \ text "tip" name table view tiny \ text "" name index imports plugin_zsh_favor view tiny action auto \ text "" name limit view tiny \ @@ -20,8 +18,7 @@ kit tips "便签" private "_:web.code.favor" list \ button "查看" action auto \ button "返回" cb Last -kit favor "收藏" private "_:web.code.favor" post \ - text "" name dream imports plugin_you \ +kit favor "收藏" private "_:web.code.favor" "@you" post \ text "tip" name table view tiny \ text "" name tab \ text "" name note \ diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js index 1b26e832..aec69eac 100644 --- a/usr/librarys/chat.js +++ b/usr/librarys/chat.js @@ -323,15 +323,25 @@ var page = Page({ initAction: function(page, field, option, output) { var river = "", storm = 0, input = "", share = "" var temp = "" + var you = "" output.DisplayRaw = true page.Sync("plugin_you").change(function(value) { page.title(value) + kit.Selector(field, "div.action>input.you", function(item) { + item.value = value + }) + }) + page.Sync("plugin_pod").change(function(value) { + kit.Selector(field, "div.action>input.pod", function(item) { + item.value = value + }) }) return { Show: function() {var pane = field.Pane if (river && storm && field.Pane.Load(river+"."+storm, output)) {return} - pane.Event(event, {}, {name: pane.Zone("show", river, storm)}) + var msg = pane.Event(event, {}, {name: pane.Zone("show", river, storm)}) + msg.Option("you", you) output.innerHTML = "", pane.Appends([river, storm], "plugin", ["name", "help"], "name", true, null, function() { }) }, @@ -341,6 +351,7 @@ var page = Page({ return layout.value }, Listen: { + plugin_you: function(value, old) {you = value}, river: function(value, old) {temp = value}, storm: function(value, old) { river && storm && field.Pane.Save(river+"."+storm, output) @@ -349,6 +360,8 @@ var page = Page({ source: function(value, old) {input = value}, target: function(value, old) {share = value}, }, + Option: { + }, Action: { "刷新": function(event, value) { output.innerHTML = "", field.Pane.Show() @@ -412,12 +425,20 @@ var page = Page({ "调试": function(event, value) { page.debug.Pane.Show() }, + option: function(event, value) { + console.log(event, value) + }, + refresh: function(event, value) { + console.log(event, value) + }, }, Button: [["layout", "工作", "办公", "聊天", "最高", "最宽", "最大"], "", "刷新", "清屏", "并行", "串行", "", ["display", "表格", "编辑", "绘图"], "", "复制", "删除", "加参", "减参", "", "执行", "下载", "清空", "返回", + "", kit.CreateMeta("input", "pod"), + "", kit.CreateMeta("input", "you"), ], Choice: [ ["layout", "工作", "聊天", "最高"], @@ -426,6 +447,7 @@ var page = Page({ } }, initStorm: function(page, field, option, output) {var river = "" + var you = "" return { Show: function(which) {var pane = field.Pane var data = river && field.Pane.Load(river, output) @@ -435,6 +457,7 @@ var page = Page({ output.innerHTML = "", pane.Appends([river], "text", ["key", "count"], "key", which||ctx.Search("storm")||true, null) }, Listen: { + plugin_you: function(value, old) {you = value}, river: function(value, old) {var pane = field.Pane river && pane.Save(river, output, {which: pane.which.get()}) river = value, pane.which.set(""), pane.Show() @@ -467,22 +490,24 @@ var page = Page({ field.Pane.Show(name) }) }, - "恢复": function(event, value, meta, line) { - var status = JSON.parse(line.status) - kit.Selector(page.action, "fieldset.item", function(field, index) { - var args = status[index].args - args = args.slice(kit.Selector(field, ".args", function(input, index) { - return input.value = args[index]||"" - }).length) - - kit.List(args, function(arg) { - field.Plugin.Append({type: "text"}, "", arg) + "恢复": function(event, value, meta, line) {var pane = field.Pane + field.Pane.Run(event, [river, "load", pane.which.get(), you], function(msg) { + if (!msg.status || msg.status.length == 0) {return} + var status = JSON.parse(msg.status[0]) + kit.Selector(page.action, "fieldset.item", function(field, index) { + var args = status[index].args + args = args.slice(kit.Selector(field, ".args", function(input, index) { + return input.value = args[index]||"" + }).length) + kit.List(args, function(arg) { + field.Plugin.Append({type: "text"}, "", arg) + }) }) }) }, "保存": function(event, value, meta, line) {var pane = field.Pane - field.Pane.Run(event, [river, "save", pane.which.get(), + field.Pane.Run(event, [river, "save", pane.which.get(), you, line.status=JSON.stringify(kit.Selector(page.action, "fieldset.item", function(field) { return {name: field.Meta.name, args: kit.Selector(field, ".args", function(input) { return input.value @@ -490,7 +515,7 @@ var page = Page({ })), JSON.stringify(kit.Selector(page.action, "fieldset.item", function(field) { return {group: field.Meta.group, index: field.Meta.index, name: field.Meta.name, node: field.Meta.node} }))], function(msg) { - page.toast.Pane.Show("保存成功") + page.toast.Pane.Show("保存成功", you) }) }, "创建": function(event) { diff --git a/usr/librarys/context.js b/usr/librarys/context.js index 2cfe4e6b..bff686a0 100644 --- a/usr/librarys/context.js +++ b/usr/librarys/context.js @@ -49,6 +49,7 @@ ctx = context = (function(kit) {var ctx = {__proto__: kit, return msg.append && msg.append[0]? ["table", JSON.stringify(msg.Table())]: ["code", msg.result? msg.result.join(""): ""] }, Option: function(key, val) { + if (val == undefined) {return msg[key]} msg.option = msg.option || [] kit.List(msg.option, function(k) { if (k == key) {return k} diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 6ed18b3f..678c493e 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -811,7 +811,7 @@ function Pane(page, field) { pane.Event(event, {}, {name: pane.Zone("click", value)}) page.script("record", [name, value]) - var cb = function() {} + var cb = pane.Action.option || function() {} if (pane.Action && pane.Action.meta && typeof pane.Action.meta[value] == "function") { cb = pane.Action.meta[value] } else if (pane.Action && typeof pane.Action[value] == "function") { @@ -1001,7 +1001,10 @@ function Pane(page, field) { })}) }), Run: shy("执行命令", function(event, cmds, cb) { - pane.Event(event, null, {name: pane.Zone(cmds[0])}) + var msg = pane.Event(event, null, {name: pane.Zone(cmds[0])}) + kit.Selector(action, "input", function(item, index) { + msg.Option(item.name, item.value) + }) ctx.Run(event, option.dataset, cmds, cb||pane.ondaemon) }), @@ -1236,7 +1239,7 @@ function Plugin(page, pane, field, inits, runs) { return name == "status" || line.status == "stop" ? undefined: line.you }, pod: function(value, name, line, list) { - return (option[list[0]].value? option[list[0]].value+".": "")+line.pod + return (option[list[0]].value? option[list[0]].value+".": "")+value }, dir: function(value, name, line) { name != "path" && (value = line.path) @@ -1480,51 +1483,66 @@ function Output(plugin, type, msg, cb, target, option) { onimport: shy("导入数据", { _table: function(msg, list) { return list && list.length > 0 && kit.OrderTable(kit.AppendTable(kit.AppendChild(target, "table"), msg.Table(), list), "", output.onexport, function(event, value, name, line, index) { - var td = event.target; + var td = event.target plugin.oncarte(event, shy("菜单列表", { + "选择": "select", "修改": "modify", - "删除": "delete", - "下载": "Download", "复制": function(event, text) {kit.CopyText(text), plugin.ontoast(text, "Copy to ClipBoard!")}, - }, feature.detail||["复制", "下载"], function(event, item, meta) { + "下载": "Download", + "删除": "delete", + }, feature.detail||["选择", "修改", "复制", "下载", "删除"], function(event, item, meta) { var text = td.innerText.trim() if (typeof meta[item] == "function") {meta[item](event, text); return} + // 选项 var msg = plugin.Event(event) kit.Selector(option, ".args", function(item) { - msg.Option(item.name, item.value) + msg.Option(item.name, item.value||"") }) - var cmd = [] + + // 参数 + var cmd = [], id = "" option.dream && cmd.push(option.dream.value) option.table && cmd.push(option.table.value) - if (item == "修改") { - text = kit.AppendChilds(td, [{type: "input", value: text, style: {width: td.clientWidth+"px"}, data: {onkeydown: function(event) { - if (event.key == "Enter") { - var id = "" - for (var i = 0; i < exports.length-1; i += 3) { - id = (id || line[exports[i+1]] || "").trim() - } - - var msg = plugin.Event(event) - kit.Selector(option, ".args", function(item) { - msg.Option(item.name, item.value) - }) - if (name == "value") { - name = line.key - id = option.index.value - } - cmd.push(id, meta[item], name, event.target.value) - plugin.Run(event, cmd, function(msg) { - td.innerHTML = event.target.value - plugin.ontoast("修改成功") - }, true) - return - } - }}}]).input, text.focus(), text.setSelectionRange(0, -1) - } else if (output[meta[item]]) { - output[meta[item]](event) + if (td.dataset && td.dataset.id) { + id = td.dataset.id + } else if (name == "value") { + id = option.index.value, name = line.key } else { - cmd.push(td.dataset.id||(line[exports[1]]||"").trim(), meta[item]||item) + for (var i = 0; i < exports.length-1; i += 3) { + line[exports[i+1]] && msg.Option(exports[i], line[exports[i+1]].trim()) + id = (id || line[exports[i+1]] || "").trim() + } + } + cmd.push(id, meta[item]||item) + + // 命令 + if (item == "修改") { + // 交互命令 + text = kit.AppendChilds(td, [{type: "input", value: text, style: {width: td.clientWidth+"px"}, data: {onkeydown: function(event) { + if (event.key != "Enter") {return} + + // 选项 + var msg = plugin.Event(event) + kit.Selector(option, ".args", function(item) { + msg.Option(item.name, item.value) + }) + + // 后端命令 + cmd.push(name, event.target.value) + plugin.Run(event, cmd, function(msg) { + td.innerHTML = event.target.value + plugin.ontoast("修改成功") + }, true) + }}}]).input, text.focus(), text.setSelectionRange(0, -1) + + } else if (output[meta[item]]) { + // 前端命令 + output[meta[item]](event) + + } else { + // 后端命令 + cmd.push(name, text) plugin.Run(event, cmd, function(msg) { console.log(msg) }) diff --git a/usr/librarys/toolkit.js b/usr/librarys/toolkit.js index 31055118..92482b8e 100644 --- a/usr/librarys/toolkit.js +++ b/usr/librarys/toolkit.js @@ -274,6 +274,20 @@ kit = toolkit = (function() {var kit = {__proto__: document, kit.AppendChild(elm, children) return parent.insertBefore(elm, position || parent.firstElementChild) }, + CreateMeta: function(type, name, meta) { + meta = meta || {} + meta.data = meta.data || {} + switch (type) { + case "input": + meta.type = type + meta.name = name + kit.classList.add(meta, name) + kit.SetDefault(meta.data, "title", name) + kit.SetDefault(meta.data, "placeholder", name) + } + return meta + }, + // HTML控件操作 AppendActions: function(parent, list, cb, diy) { parent.innerHTML = "", kit.AppendAction(parent, list, cb, diy) @@ -532,6 +546,12 @@ kit = toolkit = (function() {var kit = {__proto__: document, } return list }, + SetDefault: function(obj, key, value) { + if (obj[key] == undefined) { + obj[key] = value + } + return + }, // 数据类型转换 Trans: function(c) { return typeof c == "string"? c.split(" "): c