From 25628004a4051d78318a13c5ee95792fc5527d13 Mon Sep 17 00:00:00 2001 From: bergyu Date: Sun, 23 Jan 2022 14:16:05 +0800 Subject: [PATCH] opt some --- base/cli/system.go | 21 +++++++++++---------- base/web/dream.go | 11 +++++++---- core/code/go.go | 42 ++++++++++++++++++++++++++++++++++++++++++ misc/tmux/session.go | 5 +++-- 4 files changed, 63 insertions(+), 16 deletions(-) diff --git a/base/cli/system.go b/base/cli/system.go index eb115552..45a93722 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -3,7 +3,6 @@ package cli import ( "bytes" "io" - "io/ioutil" "os" "os/exec" "path" @@ -34,21 +33,23 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd { for _, p := range strings.Split(env[i+1], ice.DF) { if _, err := os.Stat(path.Join(p, arg[0])); err == nil { cmd.Path = path.Join(p, arg[0]) + m.Debug("what %v", cmd.Path) break } } } } - // 定制目录 - if buf, err := ioutil.ReadFile(ice.ETC_PATH); err == nil && len(buf) > 0 { - for _, p := range strings.Split(string(buf), ice.NL) { - if _, e := os.Stat(path.Join(p, arg[0])); e == nil { - cmd.Path = kit.Path(path.Join(p, arg[0])) - break - } - } - } + // // 定制目录 + // if buf, err := ioutil.ReadFile(ice.ETC_PATH); err == nil && len(buf) > 0 { + // for _, p := range strings.Split(string(buf), ice.NL) { + // if _, e := os.Stat(path.Join(p, arg[0])); e == nil { + // cmd.Path = kit.Path(path.Join(p, arg[0])) + // m.Debug("what %v", cmd.Path) + // break + // } + // } + // } m.Debug("cmd: %v", cmd.Path) if len(cmd.Env) > 0 { diff --git a/base/web/dream.go b/base/web/dream.go index e217c4f8..0c3b8f05 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -26,6 +26,7 @@ func _dream_list(m *ice.Message) *ice.Message { m.Push(cli.STATUS, cli.STOP) m.PushButton(cli.START) } + m.Push(mdb.LINK, kit.MergePOD(m.Option(ice.MSG_USERWEB), value[mdb.NAME])) }) } func _dream_show(m *ice.Message, name string) { @@ -82,7 +83,7 @@ func _dream_show(m *ice.Message, name string) { m.Optionv(cli.CMD_OUTPUT, path.Join(p, m.Config(kit.Keys(cli.ENV, cli.CTX_LOG)))) // 启动任务 - m.Cmd(cli.DAEMON, "ice.bin", SPACE, tcp.DIAL, ice.DEV, ice.DEV, mdb.NAME, name, m.OptionSimple(RIVER)) + m.Cmd(cli.DAEMON, "ice.bin", SPACE, tcp.DIAL, ice.DEV, ice.OPS, mdb.NAME, name, m.OptionSimple(RIVER)) defer m.Event(DREAM_CREATE, kit.SimpleKV("", m.Option(mdb.TYPE), name)...) m.Sleep3s() } @@ -101,12 +102,14 @@ func init() { _dream_show(m, m.Option(mdb.NAME, kit.Select(path.Base(m.Option(nfs.REPOS)), m.Option(mdb.NAME)))) }}, DREAM_STOP: {Name: "dream.stop type name", Help: "停止", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(SPACE, mdb.REMOVE, m.OptionSimple(mdb.NAME)) - m.Cmd(DREAM, cli.START, m.OptionSimple(mdb.NAME)) + if m.Cmd(DREAM, m.Option(mdb.NAME)).Length() > 0 { + m.Cmdy(SPACE, mdb.REMOVE, m.OptionSimple(mdb.NAME)) + m.Cmd(DREAM, cli.START, m.OptionSimple(mdb.NAME)) + } }}, cli.STOP: {Name: "stop", Help: "停止", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(SPACE, mdb.REMOVE, m.OptionSimple(mdb.NAME)) m.Cmdy(SPACE, m.Option(mdb.NAME), "exit", "0") + m.Cmdy(SPACE, mdb.REMOVE, m.OptionSimple(mdb.NAME)) }}, mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { _dream_list(m).Cut("name,status,time") diff --git a/core/code/go.go b/core/code/go.go index f32af265..6e4916e3 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -72,6 +72,48 @@ func _go_exec(m *ice.Message, arg ...string) { m.SetAppend() } func _go_show(m *ice.Message, arg ...string) { + if arg[1] == "main.go" { + const ( + PACKAGE = "package" + IMPORT = "import" + ) + block := "" + index := 0 + push := func(repos string) { + index++ + m.Push("index", index) + m.Push("repos", repos) + } + m.Cmd(nfs.CAT, path.Join(arg[2], arg[1]), func(line string) { + ls := kit.Split(line) + switch { + case strings.HasPrefix(line, IMPORT+" ("): + block = IMPORT + return + case strings.HasPrefix(line, ")"): + block = "" + return + case strings.HasPrefix(line, IMPORT): + if len(ls) == 2 { + push(ls[1]) + } else if len(ls) == 3 { + push(ls[2]) + } + return + } + switch block { + case IMPORT: + if len(ls) == 0 { + push("") + } else if len(ls) == 1 { + push(ls[0]) + } else if len(ls) == 2 { + push(ls[1]) + } + } + }) + return + } if key, ok := ice.Info.File[path.Join(arg[2], arg[1])]; ok && key != "" { m.ProcessCommand(key, kit.Simple()) } else { diff --git a/misc/tmux/session.go b/misc/tmux/session.go index 4d41eec4..6c72084d 100644 --- a/misc/tmux/session.go +++ b/misc/tmux/session.go @@ -53,7 +53,7 @@ func init() { }, Commands: map[string]*ice.Command{ SESSION: {Name: "session session window pane cmd auto", Help: "会话管理", Action: map[string]*ice.Action{ web.DREAM_CREATE: {Name: "dream.create type name", Help: "梦想", Hand: func(m *ice.Message, arg ...string) { - if kit.IndexOf(m.Cmd(m.PrefixKey()).Appendv(SESSION), m.Option(mdb.NAME)) == -1 { + if m.Cmd(m.PrefixKey(), m.Option(mdb.NAME)).Length() > 0 { m.Cmd(m.PrefixKey(), mdb.CREATE) } }}, @@ -90,7 +90,8 @@ func init() { m.Cmdy(cli.SYSTEM, TMUX, "split-window", "-t", kit.Keys(name, "2"), "-h") m.Cmd(cli.SYSTEM, TMUX, "send-keys", "-t", kit.Keys(name, "3"), "ish_miss_log", "Enter") - m.Cmd(cli.SYSTEM, TMUX, "send-keys", "-t", kit.Keys(name, "2"), "ish_miss_space", "Enter") + // m.Cmd(cli.SYSTEM, TMUX, "send-keys", "-t", kit.Keys(name, "2"), "ish_miss_space", "Enter") + m.Cmd(cli.SYSTEM, TMUX, "send-keys", "-t", kit.Keys(name, "2"), "ish_miss_space") m.Cmd(cli.SYSTEM, TMUX, "send-keys", "-t", kit.Keys(name, "1"), "vi etc/miss.sh", "Enter") m.Cmdy(cli.SYSTEM, TMUX, "link-window", "-s", name, "-t", "miss:")