mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 17:24:05 +08:00
mac add cli.for
This commit is contained in:
parent
dfe3d76e69
commit
a3885ec58d
@ -1,5 +1,6 @@
|
|||||||
source etc/local.shy
|
source etc/demo.shy
|
||||||
return
|
return
|
||||||
|
source etc/local.shy
|
||||||
|
|
||||||
return "hello" "world"
|
return "hello" "world"
|
||||||
source etc/demo.shy
|
source etc/demo.shy
|
||||||
|
@ -293,14 +293,15 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
Name: "source filename [async [cli_name [cli_help]]",
|
Name: "source filename [async [cli_name [cli_help]]",
|
||||||
Help: "解析脚本, filename: 文件名, cli_name: 模块名, cli_help: 模块帮助",
|
Help: "解析脚本, filename: 文件名, cli_name: 模块名, cli_help: 模块帮助",
|
||||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if cli, ok := m.Target().Server.(*CLI); m.Assert(ok) { // {{{
|
if _, ok := m.Target().Server.(*CLI); m.Assert(ok) { // {{{
|
||||||
m.Start(m.Confx("cli_name", arg, 2), m.Confx("cli_help", arg, 3), key, arg[0])
|
m.Start(m.Confx("cli_name", arg, 2), m.Confx("cli_help", arg, 3), key, arg[0])
|
||||||
if len(arg) > 1 && arg[1] == "async" {
|
if len(arg) > 1 && arg[1] == "async" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
<-m.Target().Exit
|
<-m.Target().Exit
|
||||||
sub := m.Target().Server.(*CLI)
|
m.Target(m.Source())
|
||||||
cli.target = sub.target
|
// sub := m.Target().Server.(*CLI)
|
||||||
|
// cli.target = sub.target
|
||||||
} // }}}
|
} // }}}
|
||||||
}},
|
}},
|
||||||
"return": &ctx.Command{Name: "return result...", Help: "结束脚本, rusult: 返回值", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"return": &ctx.Command{Name: "return result...", Help: "结束脚本, rusult: 返回值", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
@ -605,7 +606,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}},
|
}},
|
||||||
"if": &ctx.Command{Name: "if exp", Help: "条件语句, exp: 表达式", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"if": &ctx.Command{Name: "if exp", Help: "条件语句, exp: 表达式", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if cli, ok := m.Target().Server.(*CLI); m.Assert(ok) { // {{{
|
if cli, ok := m.Target().Server.(*CLI); m.Assert(ok) { // {{{
|
||||||
cli.stack = append(cli.stack, Frame{pos: m.Optioni("nline") - 1, key: key, run: arg[1]})
|
cli.stack = append(cli.stack, Frame{pos: m.Optioni("file_pos"), key: key, run: arg[1]})
|
||||||
m.Capi("level", 1)
|
m.Capi("level", 1)
|
||||||
m.Caps("skip", !ctx.Right(arg[1]))
|
m.Caps("skip", !ctx.Right(arg[1]))
|
||||||
} // }}}
|
} // }}}
|
||||||
@ -628,6 +629,14 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}},
|
}},
|
||||||
"end": &ctx.Command{Name: "end", Help: "结束语句", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"end": &ctx.Command{Name: "end", Help: "结束语句", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if cli, ok := m.Target().Server.(*CLI); m.Assert(ok) { // {{{
|
if cli, ok := m.Target().Server.(*CLI); m.Assert(ok) { // {{{
|
||||||
|
frame := cli.stack[len(cli.stack)-1]
|
||||||
|
if frame.key == "for" {
|
||||||
|
if ctx.Right(frame.run) {
|
||||||
|
m.Append("file_pos0", frame.pos)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if cli.stack = cli.stack[:len(cli.stack)-1]; m.Capi("level", -1) > 0 {
|
if cli.stack = cli.stack[:len(cli.stack)-1]; m.Capi("level", -1) > 0 {
|
||||||
frame := cli.stack[len(cli.stack)-1]
|
frame := cli.stack[len(cli.stack)-1]
|
||||||
m.Caps("skip", !ctx.Right(frame.run))
|
m.Caps("skip", !ctx.Right(frame.run))
|
||||||
@ -638,7 +647,14 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}},
|
}},
|
||||||
"for": &ctx.Command{Name: "for exp", Help: "循环语句, exp: 表达式", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"for": &ctx.Command{Name: "for exp", Help: "循环语句, exp: 表达式", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if cli, ok := m.Target().Server.(*CLI); m.Assert(ok) { // {{{
|
if cli, ok := m.Target().Server.(*CLI); m.Assert(ok) { // {{{
|
||||||
cli.stack = append(cli.stack, Frame{pos: m.Optioni("nline") - 1, key: key, run: arg[1]})
|
if len(cli.stack) > 0 {
|
||||||
|
// frame := cli.stack[len(cli.stack)-1]
|
||||||
|
// if frame.pos == m.Optioni("pos") {
|
||||||
|
// m.Caps("skip", !ctx.Right(arg[1]))
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
cli.stack = append(cli.stack, Frame{pos: m.Optioni("file_pos"), key: key, run: arg[1]})
|
||||||
m.Capi("level", 1)
|
m.Capi("level", 1)
|
||||||
m.Caps("skip", !ctx.Right(arg[1]))
|
m.Caps("skip", !ctx.Right(arg[1]))
|
||||||
} // }}}
|
} // }}}
|
||||||
|
@ -133,7 +133,7 @@ func (nfs *NFS) escape(form string, args ...interface{}) *NFS { // {{{
|
|||||||
// }}}
|
// }}}
|
||||||
func (nfs *NFS) color(str string, attr ...int) *NFS { // {{{
|
func (nfs *NFS) color(str string, attr ...int) *NFS { // {{{
|
||||||
if !nfs.Confs("color") {
|
if !nfs.Confs("color") {
|
||||||
fmt.Fprintf(nfs.out, "%s", str)
|
fmt.Fprint(nfs.out, str)
|
||||||
return nfs
|
return nfs
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,14 +152,13 @@ func (nfs *NFS) color(str string, attr ...int) *NFS { // {{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
nfs.escape("4%dm", bg).escape("3%dm", fg)
|
nfs.escape("4%dm", bg).escape("3%dm", fg)
|
||||||
fmt.Fprintf(nfs.out, "%s", str)
|
fmt.Fprint(nfs.out, str)
|
||||||
nfs.escape("0m")
|
nfs.escape("0m")
|
||||||
return nfs
|
return nfs
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
func (nfs *NFS) print(str string, arg ...interface{}) bool { // {{{
|
func (nfs *NFS) print(str string) bool { // {{{
|
||||||
str = fmt.Sprintf(str, arg...)
|
|
||||||
ls := strings.Split(str, "\n")
|
ls := strings.Split(str, "\n")
|
||||||
for i, l := range ls {
|
for i, l := range ls {
|
||||||
rest := ""
|
rest := ""
|
||||||
@ -585,14 +584,23 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
nfs.history = append(nfs.history, line)
|
nfs.history = append(nfs.history, line)
|
||||||
|
m.Capi("nline", 1)
|
||||||
|
|
||||||
msg := m.Spawn(m.Source()).Set("detail", line)
|
for i := len(nfs.history) - 1; i < len(nfs.history); i++ {
|
||||||
msg.Option("nline", m.Capi("nline", 1))
|
line = nfs.history[i]
|
||||||
m.Back(msg)
|
|
||||||
|
|
||||||
for _, v := range msg.Meta["result"] {
|
msg := m.Spawn(m.Source()).Set("detail", line)
|
||||||
m.Capi("nwrite", len(v))
|
msg.Option("file_pos", i)
|
||||||
nfs.print(v)
|
m.Back(msg)
|
||||||
|
|
||||||
|
for _, v := range msg.Meta["result"] {
|
||||||
|
m.Capi("nwrite", len(v))
|
||||||
|
nfs.print(v)
|
||||||
|
}
|
||||||
|
if msg.Append("file_pos0") != "" {
|
||||||
|
i = msg.Appendi("file_pos0")
|
||||||
|
i--
|
||||||
|
}
|
||||||
}
|
}
|
||||||
line = ""
|
line = ""
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user