mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
opt code
Change-Id: I0f25ccc3f8e5b3aca96aae8f7c2585a29276b40c
This commit is contained in:
parent
108155dd31
commit
ec31b37c33
@ -347,6 +347,11 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
}
|
||||
detail = append(detail, arg...)
|
||||
|
||||
if m.Options("current_ctx") && detail[0] != "context" {
|
||||
detail = append([]string{"context", m.Option("current_ctx")}, detail...)
|
||||
m.Option("current_ctx", "")
|
||||
}
|
||||
|
||||
// 目标切换
|
||||
target := m.Optionv("ps_target")
|
||||
if detail[0] != "context" {
|
||||
|
@ -482,6 +482,15 @@ var CGI = template.FuncMap{
|
||||
}
|
||||
return nil
|
||||
},
|
||||
"parse": func(m *Message, arg ...string) interface{} {
|
||||
switch len(arg) {
|
||||
case 1:
|
||||
if len(arg[0]) > 0 {
|
||||
return m.Parse(arg[0])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
"unescape": func(str string) interface{} {
|
||||
return template.HTML(str)
|
||||
|
@ -17,6 +17,45 @@ import (
|
||||
type CTX struct {
|
||||
}
|
||||
|
||||
func (ctx *CTX) Spawn(m *Message, c *Context, arg ...string) Server {
|
||||
s := new(CTX)
|
||||
return s
|
||||
}
|
||||
func (ctx *CTX) Begin(m *Message, arg ...string) Server {
|
||||
m.Sess(m.target.Name, m)
|
||||
m.target.root = m.target
|
||||
m.root = m
|
||||
m.Cap("begin_time", m.Time())
|
||||
m.Cap("goos", runtime.GOOS)
|
||||
for _, msg := range m.Search("") {
|
||||
msg.target.root = m.target
|
||||
if msg.target == m.target {
|
||||
continue
|
||||
}
|
||||
msg.target.Begin(msg, arg...)
|
||||
m.Sess(msg.target.Name, msg)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
func (ctx *CTX) Start(m *Message, arg ...string) bool {
|
||||
m.Optionv("ps_target", Index)
|
||||
|
||||
m.Cmd("log.init")
|
||||
m.Cmd("gdb.init")
|
||||
if m.Cmd("yac.init", "lex"); len(arg) == 0 {
|
||||
m.Cap("stream", "shy")
|
||||
m.Cmd("cli.source", "init.shy").Cmd("cli.source", "stdio").Cmd("cli.source", "exit.shy")
|
||||
return true
|
||||
}
|
||||
|
||||
m.Cmd("cli.source", arg)
|
||||
return true
|
||||
}
|
||||
func (ctx *CTX) Close(m *Message, arg ...string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
var Pulse = &Message{code: 0, time: time.Now(), source: Index, target: Index, Meta: map[string][]string{}}
|
||||
var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
||||
Caches: map[string]*Cache{
|
||||
"begin_time": &Cache{Name: "begin_time", Value: "", Help: "启动时间"},
|
||||
@ -528,15 +567,11 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
||||
|
||||
switch action {
|
||||
case "cmd":
|
||||
|
||||
m.Log("fuck", "what %v", m.Option("bench"))
|
||||
m.Log("fuck", "what %v", m.Option("username"))
|
||||
|
||||
componet := "source"
|
||||
if m.Options("bench") && m.Options("username") &&
|
||||
!m.Cmds("aaa.work", m.Option("bench"), "right", m.Option("username"), "source", arg[0]) {
|
||||
|
||||
m.Log("info", "check %v: %v failure", m.Option("componet"), arg[0])
|
||||
m.Echo("error: ").Echo("no right [%s: %s]", m.Option("componet"), arg[0])
|
||||
!m.Cmds("aaa.work", m.Option("bench"), "right", m.Option("username"), componet, arg[0]) {
|
||||
m.Log("info", "check %v: %v failure", componet, arg[0])
|
||||
m.Echo("error: ").Echo("no right [%s: %s]", componet, arg[0])
|
||||
break
|
||||
}
|
||||
|
||||
@ -1273,46 +1308,6 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
||||
},
|
||||
}
|
||||
|
||||
func (ctx *CTX) Spawn(m *Message, c *Context, arg ...string) Server {
|
||||
s := new(CTX)
|
||||
return s
|
||||
}
|
||||
func (ctx *CTX) Begin(m *Message, arg ...string) Server {
|
||||
m.Sess(m.target.Name, m)
|
||||
m.target.root = m.target
|
||||
m.root = m
|
||||
m.Cap("begin_time", m.Time())
|
||||
m.Cap("goos", runtime.GOOS)
|
||||
for _, msg := range m.Search("") {
|
||||
msg.target.root = m.target
|
||||
if msg.target == m.target {
|
||||
continue
|
||||
}
|
||||
msg.target.Begin(msg, arg...)
|
||||
m.Sess(msg.target.Name, msg)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
func (ctx *CTX) Start(m *Message, arg ...string) bool {
|
||||
m.Optionv("ps_target", Index)
|
||||
|
||||
m.Cmd("log.init")
|
||||
m.Cmd("gdb.init")
|
||||
if m.Cmd("yac.init", "lex"); len(arg) == 0 {
|
||||
m.Cap("stream", "shy")
|
||||
m.Cmd("cli.source", "init.shy").Cmd("cli.source", "stdio").Cmd("cli.source", "exit.shy")
|
||||
return true
|
||||
}
|
||||
|
||||
m.Cmd("cli.source", arg)
|
||||
return true
|
||||
}
|
||||
func (ctx *CTX) Close(m *Message, arg ...string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
var Pulse = &Message{code: 0, time: time.Now(), source: Index, target: Index, Meta: map[string][]string{}}
|
||||
|
||||
func Start(args ...string) bool {
|
||||
if len(args) == 0 {
|
||||
args = append(args, os.Args[1:]...)
|
||||
|
@ -584,13 +584,6 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message {
|
||||
if m == msg {
|
||||
return m
|
||||
}
|
||||
if len(arg) == 0 {
|
||||
if msg.Hand {
|
||||
arg = append(arg, "append", "result")
|
||||
} else {
|
||||
arg = append(arg, "option")
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < len(arg); i++ {
|
||||
meta := arg[i]
|
||||
@ -600,16 +593,6 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message {
|
||||
m.target = msg.target
|
||||
case "callback":
|
||||
m.callback = msg.callback
|
||||
// case "session":
|
||||
// if len(arg) == 0 {
|
||||
// for k, v := range msg.Sessions {
|
||||
// m.Sessions[k] = v
|
||||
// }
|
||||
// } else {
|
||||
// for _, k := range arg {
|
||||
// m.Sessions[k] = msg.Sessions[k]
|
||||
// }
|
||||
// }
|
||||
case "detail", "result":
|
||||
if len(msg.Meta[meta]) > 0 {
|
||||
m.Add(meta, msg.Meta[meta][0], msg.Meta[meta][1:])
|
||||
@ -1218,14 +1201,6 @@ func (m *Message) Match(key string, spawn bool, hand func(m *Message, s *Context
|
||||
return m
|
||||
}
|
||||
|
||||
if strings.Contains(key, ".") {
|
||||
arg := strings.Split(key, ".")
|
||||
m, key = m.Sess(arg[0], spawn), arg[1]
|
||||
}
|
||||
if m == nil {
|
||||
return m
|
||||
}
|
||||
|
||||
context := []*Context{m.target}
|
||||
for _, v := range []string{"aaa", "cli"} {
|
||||
if msg := m.Sess(v, false); msg != nil && msg.target != nil {
|
||||
@ -1320,7 +1295,7 @@ func (m *Message) Free(cbs ...func(msg *Message) (done bool)) *Message {
|
||||
}
|
||||
|
||||
func (m *Message) Cmdy(args ...interface{}) *Message {
|
||||
m.Cmd(args...).CopyTo(m, "append").CopyTo(m, "result")
|
||||
m.Cmd(args...).CopyTo(m)
|
||||
return m
|
||||
}
|
||||
func (m *Message) Cmdx(args ...interface{}) string {
|
||||
@ -1337,9 +1312,16 @@ func (m *Message) Cmd(args ...interface{}) *Message {
|
||||
if len(args) > 0 {
|
||||
m.Set("detail", kit.Trans(args...))
|
||||
}
|
||||
|
||||
key, arg := m.Meta["detail"][0], m.Meta["detail"][1:]
|
||||
|
||||
if strings.Contains(key, ".") {
|
||||
arg := strings.Split(key, ".")
|
||||
m, key = m.Sess(arg[0]), arg[1]
|
||||
}
|
||||
if m == nil {
|
||||
return m
|
||||
}
|
||||
|
||||
m = m.Match(key, true, func(m *Message, s *Context, c *Context, key string) bool {
|
||||
m.Hand = false
|
||||
if x, ok := c.Commands[key]; ok && x.Hand != nil {
|
||||
|
@ -82,7 +82,7 @@ func (gdb *GDB) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
||||
func (gdb *GDB) Start(m *ctx.Message, arg ...string) bool {
|
||||
gdb.goon = make(chan os.Signal, 10)
|
||||
gdb.wait = make(chan interface{}, 10)
|
||||
signal.Notify(gdb.goon, syscall.Signal(19))
|
||||
signal.Notify(gdb.goon, syscall.Signal(30))
|
||||
for {
|
||||
select {
|
||||
case sig := <-gdb.goon:
|
||||
|
@ -49,7 +49,7 @@ func dir(m *ctx.Message, name string, level int, deep bool, dir_type string, tri
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(f.Name(), ".") && dir_type != "both" {
|
||||
if strings.HasPrefix(f.Name(), ".") && dir_type != "all" {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -184,6 +184,8 @@ func (nfs *NFS) Read(p []byte) (n int, err error) {
|
||||
|
||||
m.Optionv("auto_target", m.Optionv("ps_target"))
|
||||
m.Option("auto_cmd", "")
|
||||
m.Options("show_shadow", m.Confs("show_shadow"))
|
||||
|
||||
defer func() { m.Option("auto_cmd", "") }()
|
||||
|
||||
frame, table, index, pick := map[string]interface{}{}, []map[string]string{}, 0, 0
|
||||
@ -306,14 +308,16 @@ func (nfs *NFS) Read(p []byte) (n int, err error) {
|
||||
nfs.Term(m, "refresh").Term(m, "flush")
|
||||
nfs.prompt(what).shadow(rest)
|
||||
case termbox.KeyCtrlL:
|
||||
m.Confi("term", "begin_row", m.Capi("noutput"))
|
||||
m.Confi("term", "begin_col", 0)
|
||||
nfs.Term(m, "clear", "all").Term(m, "flush")
|
||||
nfs.prompt(what).shadow(rest)
|
||||
|
||||
case termbox.KeyCtrlO:
|
||||
case termbox.KeyCtrlT:
|
||||
m.Option("scroll", true)
|
||||
nfs.Term(m, "scroll", 1).Term(m, "flush")
|
||||
m.Option("scroll", false)
|
||||
case termbox.KeyCtrlT:
|
||||
case termbox.KeyCtrlO:
|
||||
m.Option("scroll", true)
|
||||
nfs.Term(m, "scroll", -1).Term(m, "flush")
|
||||
m.Option("scroll", false)
|
||||
@ -346,21 +350,25 @@ func (nfs *NFS) Read(p []byte) (n int, err error) {
|
||||
case termbox.KeyCtrlZ:
|
||||
|
||||
case termbox.KeyTab:
|
||||
if index > len(what) {
|
||||
nfs.shadow("", table, frame)
|
||||
} else {
|
||||
if lines := kit.Int(frame["lines"]); lines > 0 {
|
||||
pick = (pick + 1) % lines
|
||||
}
|
||||
nfs.shadow(what[index:], table, frame, pick)
|
||||
rest = append(rest[:0], []rune(kit.Format(frame["pick"]))[len(what)-index:]...)
|
||||
nfs.prompt(what).shadow(rest)
|
||||
nfs.shadow(what[index:], table, frame, pick)
|
||||
}
|
||||
|
||||
m.Options("show_shadow", true)
|
||||
// if index > len(what) {
|
||||
// nfs.shadow("", table, frame)
|
||||
// } else {
|
||||
// if lines := kit.Int(frame["lines"]); lines > 0 {
|
||||
// pick = (pick + 1) % lines
|
||||
// }
|
||||
// nfs.shadow(what[index:], table, frame, pick)
|
||||
// rest = append(rest[:0], []rune(kit.Format(frame["pick"]))[len(what)-index:]...)
|
||||
// nfs.prompt(what).shadow(rest)
|
||||
// nfs.shadow(what[index:], table, frame, pick)
|
||||
// }
|
||||
//
|
||||
case termbox.KeySpace:
|
||||
what = append(what, ' ')
|
||||
nfs.prompt(what).shadow(rest)
|
||||
if !m.Options("show_shadow") {
|
||||
break
|
||||
}
|
||||
|
||||
if index > len(what) {
|
||||
nfs.shadow("", table, frame)
|
||||
@ -380,6 +388,9 @@ func (nfs *NFS) Read(p []byte) (n int, err error) {
|
||||
default:
|
||||
what = append(what, ev.Ch)
|
||||
nfs.prompt(what).shadow(rest)
|
||||
if !m.Options("show_shadow") {
|
||||
break
|
||||
}
|
||||
|
||||
if change, f, t, i := nfs.Auto(what, Format(ev.Ch), len(what)); change {
|
||||
frame, table, index, pick = f, t, i, 0
|
||||
@ -564,6 +575,7 @@ func (nfs *NFS) Term(msg *ctx.Message, action string, args ...interface{}) *NFS
|
||||
if len(args) > 0 {
|
||||
n = kit.Int(args[0])
|
||||
}
|
||||
m.Options("on_scroll", true)
|
||||
|
||||
// 向下滚动
|
||||
for i := begin_row; n > 0 && i < m.Capi("noutput"); i++ {
|
||||
@ -621,40 +633,71 @@ func (nfs *NFS) Term(msg *ctx.Message, action string, args ...interface{}) *NFS
|
||||
}
|
||||
begin_col = 0
|
||||
}
|
||||
nfs.Term(m, "print", m.Conf("prompt"))
|
||||
// nfs.Term(m, "print", "\n")
|
||||
// nfs.Term(m, "print", m.Conf("prompt"))
|
||||
m.Options("on_scroll", false)
|
||||
|
||||
case "print":
|
||||
for _, v := range kit.Format(args...) {
|
||||
if x < right && y < bottom {
|
||||
termbox.SetCell(x, y, v, fg, bg)
|
||||
list := kit.Format(args...)
|
||||
n := strings.Count(list, "\n") + y - bottom
|
||||
|
||||
for _, v := range list {
|
||||
if x < right {
|
||||
if termbox.SetCell(x, y, v, fg, bg); v > 255 {
|
||||
x++
|
||||
}
|
||||
}
|
||||
|
||||
if v > 255 {
|
||||
x++
|
||||
}
|
||||
if x++; v == '\n' || (x >= right && m.Confs("term", "wrap")) {
|
||||
x, y = left, y+1
|
||||
if y >= bottom {
|
||||
if m.Options("on_scroll") {
|
||||
break
|
||||
}
|
||||
if n%bottom > 0 {
|
||||
m.Log("fuck", "-----scroll %v %v %v %v", m.Conf("term", "begin_row"), m.Conf("term", "begin_col"), y, n)
|
||||
|
||||
nfs.Term(m, "scroll", n%bottom+1)
|
||||
n -= n % bottom
|
||||
x = m.Confi("term", "cursor_x")
|
||||
y = m.Confi("term", "cursor_y")
|
||||
|
||||
m.Log("fuck", "-----scroll %v %v %v %v", m.Conf("term", "begin_row"), m.Conf("term", "begin_col"), y, n)
|
||||
} else if n > 0 {
|
||||
m.Log("fuck", "-----scroll %v %v %v %v", m.Conf("term", "begin_row"), m.Conf("term", "begin_col"), y, n)
|
||||
|
||||
nfs.Term(m, "scroll", bottom)
|
||||
n -= bottom
|
||||
x = m.Confi("term", "cursor_x")
|
||||
y = m.Confi("term", "cursor_y")
|
||||
|
||||
m.Log("fuck", "-----scroll %v %v %v %v", m.Conf("term", "begin_row"), m.Conf("term", "begin_col"), y, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if x < right && y < bottom {
|
||||
if x < right {
|
||||
m.Conf("term", "cursor_x", x)
|
||||
m.Conf("term", "cursor_y", y)
|
||||
termbox.SetCursor(x, y)
|
||||
}
|
||||
|
||||
if y >= bottom {
|
||||
if !m.Options("scroll") {
|
||||
nfs.Term(m, "scroll")
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if m.Options("on_scroll") {
|
||||
x = 0
|
||||
y = y + 1
|
||||
m.Conf("term", "cursor_x", x)
|
||||
m.Conf("term", "cursor_y", y)
|
||||
termbox.SetCursor(x, y)
|
||||
}
|
||||
|
||||
case "color":
|
||||
msg.Conf("term", "bgcolor", kit.Int(args[0])+1)
|
||||
msg.Conf("term", "fgcolor", kit.Int(args[1])+1)
|
||||
nfs.Term(m, "print", args[2:]...)
|
||||
msg.Conf("term", "fgcolor", fg)
|
||||
msg.Conf("term", "bgcolor", bg)
|
||||
|
||||
case "shadow":
|
||||
x := m.Confi("term", "cursor_x")
|
||||
y := m.Confi("term", "cursor_y")
|
||||
@ -696,7 +739,7 @@ func (nfs *NFS) shadow(args ...interface{}) *NFS {
|
||||
case []rune:
|
||||
if len(args) == 1 {
|
||||
nfs.Term(m, "color", m.Confi("term", "rest_bg"), m.Confi("term", "rest_fg"), string(arg))
|
||||
} else if m.Options("show_shadow") {
|
||||
} else {
|
||||
cmd := strings.Split(string(arg), " ")
|
||||
switch table := args[1].(type) {
|
||||
case []map[string]string:
|
||||
@ -835,8 +878,8 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool {
|
||||
|
||||
if nfs.in = m.Optionv("in").(*os.File); m.Has("out") {
|
||||
if nfs.out = m.Optionv("out").(*os.File); m.Cap("goos") != "windows" {
|
||||
// nfs.Term(m, "init")
|
||||
// defer nfs.Term(m, "exit")
|
||||
nfs.Term(m, "init")
|
||||
defer nfs.Term(m, "exit")
|
||||
}
|
||||
}
|
||||
|
||||
@ -984,7 +1027,8 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
"scroll_count": "5",
|
||||
"begin_row": 0, "begin_col": 0,
|
||||
|
||||
"shadow": "hello",
|
||||
"shadow": "hello",
|
||||
"show_shadow": "false",
|
||||
|
||||
"rest_fg": "0",
|
||||
"rest_bg": "7",
|
||||
@ -1064,7 +1108,6 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"pwd": &ctx.Command{Name: "pwd [all] | [[index] path] ", Help: "工作目录,all: 查看所有, index path: 设置路径, path: 设置当前路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Log("fuck", "what %v", m.Format("stack", "chain"))
|
||||
if len(arg) > 0 && arg[0] == "all" {
|
||||
m.Cmdy("nfs.config", "paths")
|
||||
return
|
||||
@ -1231,7 +1274,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
if len(arg) == 1 && m.Has("data") {
|
||||
arg = append(arg, m.Option("data"))
|
||||
}
|
||||
if p, f, e := open(m, m.Format(arg[0]), os.O_WRONLY|os.O_CREATE|os.O_TRUNC); m.Assert(e) {
|
||||
if p, f, e := open(m, kit.Format(arg[0]), os.O_WRONLY|os.O_CREATE|os.O_TRUNC); m.Assert(e) {
|
||||
defer f.Close()
|
||||
m.Append("directory", p)
|
||||
m.Echo(p)
|
||||
@ -1292,12 +1335,6 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
|
||||
m.Option("hi", "hello world")
|
||||
m.Option("he", "hello", "world")
|
||||
|
||||
m.Append("he", "hello", "world")
|
||||
m.Append("hi", "nice", "job")
|
||||
|
||||
data := m.Optionv(kit.Select("data", arg, 1))
|
||||
if len(arg) > 0 && arg[0] == "all" {
|
||||
data, arg = m.Meta, arg[1:]
|
||||
|
@ -1130,6 +1130,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
tmpl.ParseGlob(path.Join(m.Conf("template_dir"), m.Conf("template_sub"), "/*.tmpl"))
|
||||
}
|
||||
|
||||
// 权限检查
|
||||
if m.Confs("login_check") {
|
||||
if m.Option("username", m.Cmdx("web.session", "login")) == "" { // 没有登录
|
||||
m.Set("option", "componet_group", "login").Set("option", "componet_name", "").Set("option", "bench", "")
|
||||
@ -1144,6 +1145,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
m.Append("redirect", merge(m, m.Option("index_url"), "bench", bench))
|
||||
return
|
||||
}
|
||||
m.Optionv("bench_data", m.Confv("auth", []string{m.Option("bench"), "data"}))
|
||||
}
|
||||
|
||||
// 响应模板
|
||||
@ -1207,12 +1209,17 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
|
||||
// 执行命令
|
||||
if order != "" || kit.Right(val["pre_run"]) {
|
||||
if list := m.Confv("auth", []string{m.Option("bench"), "data", "action", msg.Option("componet_name"), "cmd"}); list != nil && order == "" {
|
||||
args = kit.Trans(list)
|
||||
}
|
||||
|
||||
if msg.Cmd(args); m.Options("bench") {
|
||||
name_alias := "action." + kit.Select(msg.Option("componet_name"), msg.Option("componet_name_alias"))
|
||||
|
||||
msg.Put("option", name_alias, map[string]interface{}{
|
||||
"cmd": args, "order": m.Option("componet_name_order"), "action_time": msg.Time(),
|
||||
}).Cmd("web.session", "bench", m.Option("bench"), "data", "option", name_alias, "modify_time", msg.Time())
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -1245,7 +1252,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
|
||||
p := path.Join(m.Conf("directory"), m.Option("download_dir"), h.Filename)
|
||||
p := path.Join(m.Conf("directory"), m.Option("current_dir"), h.Filename)
|
||||
o, e := os.Create(p)
|
||||
m.Assert(e)
|
||||
defer o.Close()
|
||||
|
@ -127,7 +127,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
map[string]interface{}{"componet_name": "command", "componet_help": "command", "template": "componet",
|
||||
map[string]interface{}{"componet_name": "cmd", "componet_help": "cmd", "template": "componet",
|
||||
"componet_ctx": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmd"},
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
|
||||
@ -139,7 +139,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"componet_ctx": "cli.shy", "componet_cmd": "context", "arguments": []interface{}{"@ctx", "list"},
|
||||
"display_result": "",
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "ctx", "value": "shy"},
|
||||
map[string]interface{}{"type": "text", "name": "ctx", "value": ""},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
},
|
||||
@ -148,8 +148,8 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
// "display_result": "",
|
||||
// "inputs": []interface{}{
|
||||
// map[string]interface{}{"type": "choice", "name": "ccc",
|
||||
// "label": "ccc", "value": "command", "choice": []interface{}{
|
||||
// map[string]interface{}{"name": "command", "value": "command"},
|
||||
// "label": "ccc", "value": "cmd", "choice": []interface{}{
|
||||
// map[string]interface{}{"name": "cmd", "value": "cmd"},
|
||||
// map[string]interface{}{"name": "config", "value": "config"},
|
||||
// map[string]interface{}{"name": "cache", "value": "cache"},
|
||||
// },
|
||||
@ -158,7 +158,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
// },
|
||||
// },
|
||||
// map[string]interface{}{"componet_name": "cmd", "componet_help": "cmd", "template": "componet",
|
||||
// "componet_ctx": "cli.shy", "componet_cmd": "context", "arguments": []interface{}{"@current_ctx", "command", "list"},
|
||||
// "componet_ctx": "cli.shy", "componet_cmd": "context", "arguments": []interface{}{"@current_ctx", "cmd", "list"},
|
||||
// "pre_run": true, "display_result": "",
|
||||
// "inputs": []interface{}{
|
||||
// map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
|
@ -29,7 +29,7 @@ function save_clipboard(item) {
|
||||
|
||||
context.GET("", {
|
||||
"componet_group": "index",
|
||||
"componet_name": "command",
|
||||
"componet_name": "cmd",
|
||||
"cmd": "aaa.work "+context.Search("bench")+" clipstack '"+JSON.stringify(txt)+"'"
|
||||
}, function(msg) {
|
||||
alert("保存成功")
|
||||
@ -67,7 +67,7 @@ function copy_to_clipboard(text, skip_blur, skip_docker) {
|
||||
}
|
||||
|
||||
if (event.shiftKey) {
|
||||
var cmd = document.querySelector("form.option.command"+code.current_cmd+" input[name=cmd]")
|
||||
var cmd = document.querySelector("form.option.cmd"+code.current_cmd+" input[name=cmd]")
|
||||
cmd && (cmd.value += " "+text)
|
||||
return
|
||||
}
|
||||
@ -138,14 +138,14 @@ function del_command(target) {
|
||||
}
|
||||
|
||||
for (;order < code.ncommand; order++) {
|
||||
var input = document.querySelector("form.option.command"+order+" input[name=cmd]")
|
||||
var input = document.querySelector("form.option.cmd"+order+" input[name=cmd]")
|
||||
if (input) {
|
||||
input.focus()
|
||||
return
|
||||
}
|
||||
}
|
||||
for (;order >= 0; order--) {
|
||||
var input = document.querySelector("form.option.command"+(order? order: "")+" input[name=cmd]")
|
||||
var input = document.querySelector("form.option.cmd"+(order? order: "")+" input[name=cmd]")
|
||||
code.ncommand = order+1
|
||||
if (input) {
|
||||
input.focus()
|
||||
@ -165,7 +165,7 @@ function shrink_command_result() {
|
||||
}
|
||||
function add_command(init) {
|
||||
var order = code.ncommand
|
||||
var name = "command"+code.ncommand++
|
||||
var name = "cmd"+code.ncommand++
|
||||
|
||||
var fieldset = append_child(document.querySelector("body"), "fieldset")
|
||||
append_child(fieldset, "legend", {"innerText": name})
|
||||
@ -174,7 +174,7 @@ function add_command(init) {
|
||||
"className": "option "+name,
|
||||
"dataset": {
|
||||
"componet_group": "index",
|
||||
"componet_name": "command",
|
||||
"componet_name": "cmd",
|
||||
"componet_name_alias": name,
|
||||
"componet_name_order": order,
|
||||
}
|
||||
@ -216,7 +216,7 @@ function send_command(form, cb) {
|
||||
}
|
||||
|
||||
var order = (data["componet_name_order"]||"")
|
||||
var cmd = document.querySelector("div.workflow>ul>li>ul>li.command"+order)
|
||||
var cmd = document.querySelector("div.workflow>ul>li>ul>li.cmd"+order)
|
||||
cmd && (cmd.innerText = format_date(new Date())+" "+order+": "+data["cmd"])
|
||||
|
||||
context.GET("", data, function(msg) {
|
||||
@ -387,7 +387,7 @@ function onaction(event, action, arg) {
|
||||
})
|
||||
break
|
||||
case "0":
|
||||
document.querySelector("form.option.command input[name=cmd]").focus()
|
||||
document.querySelector("form.option.cmd input[name=cmd]").focus()
|
||||
break
|
||||
case "1":
|
||||
case "2":
|
||||
@ -398,7 +398,7 @@ function onaction(event, action, arg) {
|
||||
case "7":
|
||||
case "8":
|
||||
case "9":
|
||||
document.querySelector("form.option.command"+event.key+" input[name=cmd]").focus()
|
||||
document.querySelector("form.option.cmd"+event.key+" input[name=cmd]").focus()
|
||||
break
|
||||
}
|
||||
return
|
||||
@ -443,15 +443,15 @@ function onaction(event, action, arg) {
|
||||
var item = document.querySelectorAll("div.workflow>ul>li>ul.txt>li[data-text]")
|
||||
target.value += item[parseInt(event.key)-1].dataset["text"]
|
||||
} else {
|
||||
var item = document.querySelectorAll("table.append.command"+(parseInt(option.dataset.componet_name_order)-1)+" td")
|
||||
var item = document.querySelectorAll("table.append.cmd"+(parseInt(option.dataset.componet_name_order)-1)+" td")
|
||||
if (event.shiftKey) {
|
||||
var item = document.querySelectorAll("table.append.command1 td")
|
||||
var item = document.querySelectorAll("table.append.cmd td")
|
||||
}
|
||||
target.value += item[parseInt(event.key)-1].innerText
|
||||
}
|
||||
break
|
||||
case "0":
|
||||
var pre_pre = document.querySelector("code.result.command"+(parseInt(option.dataset.componet_name_order)-1)+" pre")
|
||||
var pre_pre = document.querySelector("code.result.cmd"+(parseInt(option.dataset.componet_name_order)-1)+" pre")
|
||||
target.value += pre_pre.innerText
|
||||
break
|
||||
case "a":
|
||||
@ -536,7 +536,7 @@ function onaction(event, action, arg) {
|
||||
break
|
||||
case "i":
|
||||
for (var order = (parseInt(option.dataset["componet_name_order"])||0)+1; order < code.ncommand; order++) {
|
||||
var input = document.querySelector("form.option.command"+order+" input[name=cmd]")
|
||||
var input = document.querySelector("form.option.cmd"+order+" input[name=cmd]")
|
||||
if (input) {
|
||||
input.focus()
|
||||
return
|
||||
@ -545,7 +545,7 @@ function onaction(event, action, arg) {
|
||||
break
|
||||
case "o":
|
||||
for (var order = parseInt(option.dataset["componet_name_order"])-1; order >= 0; order--) {
|
||||
var input = document.querySelector("form.option.command"+(order? order: "")+" input[name=cmd]")
|
||||
var input = document.querySelector("form.option.cmd"+(order? order: "")+" input[name=cmd]")
|
||||
if (input) {
|
||||
input.focus()
|
||||
return
|
||||
@ -575,7 +575,7 @@ function onaction(event, action, arg) {
|
||||
check_option(target.form, target)
|
||||
}
|
||||
break
|
||||
case "command":
|
||||
case "cmd":
|
||||
check_option(target.form, target, function(msg) {
|
||||
if (target["value"] == "login") {
|
||||
location.reload()
|
||||
@ -640,7 +640,7 @@ function init_download(event) {
|
||||
|
||||
function change(dir, show, run) {
|
||||
if ((dir.endsWith(".sh") || dir.endsWith(".shy") || dir.endsWith(".py")) && !show) {
|
||||
var command = document.querySelector("form.option.command")
|
||||
var command = document.querySelector("form.option.cmd")
|
||||
var cmd = command["cmd"]
|
||||
cmd.value = "run "+ dir.split("/").pop()
|
||||
cmd.focus()
|
||||
@ -652,10 +652,10 @@ function init_download(event) {
|
||||
|
||||
option["dir"].value = dir
|
||||
if (dir == "" || dir.endsWith("/")) {
|
||||
context.Cookie("download_dir", option["dir"].value)
|
||||
context.Cookie("current_dir", option["dir"].value)
|
||||
}
|
||||
send_command(option)
|
||||
option["dir"].value = context.Cookie("download_dir")
|
||||
option["dir"].value = context.Cookie("current_dir")
|
||||
|
||||
}
|
||||
insert_button(append, "root", function(event) {
|
||||
@ -695,7 +695,7 @@ function init_download(event) {
|
||||
})
|
||||
}
|
||||
|
||||
(option["dir"].value = context.Search("download_dir")) && send_command(option)
|
||||
(option["dir"].value = context.Search("current_dir")) && send_command(option)
|
||||
|
||||
add_sort(append, "filename", function(event) {
|
||||
var dir = event.target.innerText
|
||||
@ -728,20 +728,23 @@ function init_context() {
|
||||
add_sort(append, "name", function(event) {
|
||||
change(event.target.innerText.trim())
|
||||
})
|
||||
|
||||
option["ctx"].value = context.Cookie("current_ctx")
|
||||
send_command(option)
|
||||
}
|
||||
function init_command() {
|
||||
var option = document.querySelector("form.option.command")
|
||||
var option = document.querySelector("form.option.cmd")
|
||||
if (!option) {
|
||||
return
|
||||
}
|
||||
option.dataset["componet_name_alias"] = "command"
|
||||
option.dataset["componet_name_alias"] = "cmd"
|
||||
option.dataset["componet_name_order"] = 0
|
||||
|
||||
var action = bench_data.action
|
||||
if (action && action["command"]) {
|
||||
var option = document.querySelector("form.option.command")
|
||||
if (action && action["cmd"]) {
|
||||
var option = document.querySelector("form.option.cmd")
|
||||
var cmd = option.querySelector("input[name=cmd]")
|
||||
cmd.value = action["command"].cmd[1]
|
||||
cmd.value = action["cmd"].cmd[1]
|
||||
check_option(option)
|
||||
}
|
||||
|
||||
@ -755,10 +758,10 @@ function init_command() {
|
||||
|
||||
for (var i = 1; i <= max; i++) {
|
||||
var fieldset = add_command(true)
|
||||
if (action["command"+i]) {
|
||||
if (action["cmd"+i]) {
|
||||
var option = fieldset.querySelector("form.option")
|
||||
var cmd = option.querySelector("input[name=cmd]")
|
||||
cmd.value = action["command"+i].cmd[1]
|
||||
cmd.value = action["cmd"+i].cmd[1]
|
||||
check_option(option)
|
||||
}
|
||||
}
|
||||
@ -818,9 +821,9 @@ function init_docker() {
|
||||
|
||||
// 事件
|
||||
docker.querySelectorAll("li>ul>li").forEach(function(item) {
|
||||
if (bench_data.board["key"] == item.dataset["key"]) {
|
||||
// item.className = "stick"
|
||||
}
|
||||
// if (bench_data.board["key"] == item.dataset["key"]) {
|
||||
// // item.className = "stick"
|
||||
// }
|
||||
|
||||
item.onclick = function(event) {
|
||||
var target = event.target
|
||||
@ -836,7 +839,7 @@ function init_docker() {
|
||||
return
|
||||
}
|
||||
if (event.shiftKey) {
|
||||
var cmd = document.querySelector("form.option.command"+code.current_cmd+" input[name=cmd]")
|
||||
var cmd = document.querySelector("form.option.cmd"+code.current_cmd+" input[name=cmd]")
|
||||
cmd && (cmd.value += " "+text)
|
||||
return
|
||||
}
|
||||
@ -866,7 +869,7 @@ function init_docker() {
|
||||
case "rename_fly":
|
||||
context.GET("", {
|
||||
"componet_group": "index",
|
||||
"componet_name": "command",
|
||||
"componet_name": "cmd",
|
||||
"cmd": "aaa.work "+context.Search("bench")+" rename "+prompt("name"),
|
||||
})
|
||||
location.reload()
|
||||
@ -874,7 +877,7 @@ function init_docker() {
|
||||
case "remove_fly":
|
||||
context.GET("", {
|
||||
"componet_group": "index",
|
||||
"componet_name": "command",
|
||||
"componet_name": "cmd",
|
||||
"cmd": "aaa.work "+context.Search("bench")+" delete",
|
||||
})
|
||||
var b = ""
|
||||
@ -894,7 +897,7 @@ function init_docker() {
|
||||
}
|
||||
|
||||
// 切换命令行
|
||||
var cmd = document.querySelector("form.option.command"+data["cmd"]+" input[name=cmd]")
|
||||
var cmd = document.querySelector("form.option.cmd"+data["cmd"]+" input[name=cmd]")
|
||||
cmd && cmd.focus()
|
||||
}
|
||||
})
|
||||
|
@ -192,7 +192,7 @@
|
||||
<li data-action="create_cmd">+ 添加命令行(Ctrl+M)</li>
|
||||
{{if $bench}}
|
||||
{{range $index, $cmd := index $bench "commands"}}
|
||||
<li class="command{{$index}}" data-cmd="{{$index}}">{{index $cmd "now"|option}} {{$index}}: {{index $cmd "cmd"|option}}</li>
|
||||
<li class="cmd{{$index}}" data-cmd="{{$index}}">{{index $cmd "now"|option}} {{$index}}: {{index $cmd "cmd"|option}}</li>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</ul>
|
||||
@ -215,6 +215,7 @@
|
||||
{{define "componet"}}
|
||||
<fieldset><legend title="{{option .Meta "componet_help"}}">{{option .Meta "componet_help"}}({{option .Meta "componet_ctx"}}.{{option .Meta "componet_cmd"}})</legend>
|
||||
{{$form_type := option . "form_type"|meta}}
|
||||
{{$msg := .}}
|
||||
|
||||
{{if eq $form_type "upload"}}
|
||||
{{end}}
|
||||
@ -223,25 +224,26 @@
|
||||
data-componet_name="{{option . "componet_name"|meta}}"
|
||||
{{if eq $form_type "upload"}}
|
||||
method="POST" action="/upload" enctype="multipart/form-data"
|
||||
onsubmit="onaction(event,'upload')"
|
||||
onsubmit="onaction(event,'upload')"
|
||||
{{end}}
|
||||
>
|
||||
<input style="display:none"></input>
|
||||
{{range $index, $input := option . "inputs"}}
|
||||
<div>
|
||||
{{$type := index $input "type"}}
|
||||
{{$value := index $input "value" | parse $msg}}
|
||||
{{if index $input "label"}}
|
||||
<label>{{index $input "label"}} : </label>
|
||||
{{end}}
|
||||
{{if eq $type "button"}}
|
||||
<input type="button" onclick="return onaction(event, 'command')" value="{{index $input "value"}}">
|
||||
<input type="button" onclick="return onaction(event, 'cmd')" value="{{$value}}">
|
||||
{{else if eq $type "submit"}}
|
||||
<input type="submit" value="{{index $input "value"}}">
|
||||
<input type="submit" value="{{$value}}">
|
||||
{{else if eq $type "file"}}
|
||||
<input type="file" name="{{index $input "name"}}">
|
||||
{{else if eq $type "choice"}}
|
||||
{{$default_value := index $input "value"}}
|
||||
<select name="{{index $input "name"}}" onchange="return onaction(event, 'command')">
|
||||
<select name="{{index $input "name"}}" onchange="return onaction(event, 'cmd')">
|
||||
{{range $index, $value := index $input "choice"}}
|
||||
{{$val := index $value "value"}}
|
||||
{{if eq $default_value $val}}
|
||||
@ -255,14 +257,14 @@
|
||||
<input
|
||||
type="password"
|
||||
name="{{index $input "name"}}"
|
||||
value="{{index $input "value"}}"
|
||||
value="{{$value}}"
|
||||
class="{{index $input "class"}}"
|
||||
onclick="return onaction(event, 'click')"
|
||||
onkeyup="return onaction(event, 'input')">
|
||||
{{else}}
|
||||
<input
|
||||
name="{{index $input "name"}}"
|
||||
value="{{index $input "value"}}"
|
||||
value="{{$value}}"
|
||||
class="{{index $input "class"}}"
|
||||
{{if index $input "clipstack"}}
|
||||
list="{{index $input "clipstack"}}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user