From 831ead99e0e3a83c8fc084f01ae7cfbeac5064d4 Mon Sep 17 00:00:00 2001 From: shaoying Date: Thu, 1 Aug 2019 09:53:13 +0800 Subject: [PATCH] add plugin/favor --- bin/boot.sh | 4 ++ src/contexts/cli/version.go | 2 +- src/contexts/ctx/ctx.go | 20 +++++----- src/contexts/yac/yac.go | 19 +++++++++ src/plugin/favor/index.go | 36 +++++++++++++++++ src/plugin/favor/index.js | 4 ++ src/plugin/favor/index.shy | 79 +++++++++++++++++++++++++++++++++++++ src/plugin/favor/local.shy | 1 + 8 files changed, 154 insertions(+), 11 deletions(-) create mode 100644 src/plugin/favor/index.go create mode 100644 src/plugin/favor/index.js create mode 100644 src/plugin/favor/index.shy create mode 100644 src/plugin/favor/local.shy diff --git a/bin/boot.sh b/bin/boot.sh index 98976215..bdf9af43 100755 --- a/bin/boot.sh +++ b/bin/boot.sh @@ -1,5 +1,9 @@ #! /bin/bash +# ctx_log_debug=false +# ctx_log_disable=false +# ctx_gdb_enable=false + ctx_log=${ctx_log:="var/log"} ctx_app=${ctx_app:="bench"} ctx_bin=${ctx_app} && [ -f bin/${ctx_app} ] && ctx_bin=$(pwd)/bin/${ctx_app} diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go index 37458822..888f553d 100644 --- a/src/contexts/cli/version.go +++ b/src/contexts/cli/version.go @@ -4,5 +4,5 @@ var version = struct { host string self int }{ - "2019-07-31 21:50:19", "ZYB-20190522USI", 329, + "2019-08-01 09:34:16", "com.mac", 245, } diff --git a/src/contexts/ctx/ctx.go b/src/contexts/ctx/ctx.go index bbff5a06..25a0cea3 100644 --- a/src/contexts/ctx/ctx.go +++ b/src/contexts/ctx/ctx.go @@ -46,24 +46,24 @@ func (ctx *CTX) Begin(m *Message, arg ...string) Server { func (ctx *CTX) Start(m *Message, arg ...string) bool { if m.Optionv("bio.ctx", Index); len(arg) == 0 { kit.DisableLog = false - m.Optionv("bio.msg", m) - m.Optionv("bio.ctx", m.Target()) - m.Option("bio.modal", "active") - m.Option("log.debug", false) - m.Option("log.disable", false) - m.Option("gdb.enable", false) - m.Cap("stream", "stdio") + m.Option("log.debug", kit.Right(os.Getenv("ctx_log_debug"))) + m.Option("log.disable", kit.Right(os.Getenv("ctx_log_disable"))) + m.Option("gdb.enable", kit.Right(os.Getenv("ctx_gdb_enable"))) m.Cmd("log._init") m.Cmd("gdb._init") - m.Cmd("ctx._init") + m.Option("bio.modal", "active") + + m.Optionv("bio.ctx", m.Target()) + m.Optionv("bio.msg", m) + m.Cap("stream", "stdio") m.Cmd("aaa.role", "root", "user", m.Option("username", m.Conf("runtime", "boot.username"))) m.Option("sessid", m.Cmdx("aaa.user", "session", "select")) + m.Cmd("nfs.source", m.Conf("cli.system", "script.init")).Cmd("nfs.source", "stdio").Cmd("nfs.source", m.Conf("cli.system", "script.exit")) } else { - m.Option("bio.modal", "action") - m.Cmd("ctx._init") + m.Option("bio.modal", "action") for _, v := range m.Sess("cli").Cmd(arg).Meta["result"] { fmt.Printf("%s", v) } diff --git a/src/contexts/yac/yac.go b/src/contexts/yac/yac.go index b742ad14..13cd468e 100644 --- a/src/contexts/yac/yac.go +++ b/src/contexts/yac/yac.go @@ -328,6 +328,9 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", map[string]interface{}{"page": "line", "hash": "line", "word": []interface{}{"opt{", "mul{", "stm", "cmd", "}", "}", "com"}}, // 复合语句 + map[string]interface{}{"page": "op1", "hash": "op1", "word": []interface{}{"mul{", "!", "}"}}, + map[string]interface{}{"page": "op2", "hash": "op2", "word": []interface{}{"mul{", "&&", "||", "}"}}, + map[string]interface{}{"page": "exe", "hash": "exe", "word": []interface{}{"(", "exp", ")"}}, map[string]interface{}{"page": "exe", "hash": "exe", "word": []interface{}{"$", "(", "cmd", ")"}}, map[string]interface{}{"page": "stm", "hash": "var", "word": []interface{}{"var", "key", "opt{", "=", "exp", "}"}}, map[string]interface{}{"page": "stm", "hash": "let", "word": []interface{}{"let", "key", "opt{", "=", "exp", "}"}}, @@ -595,6 +598,8 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", switch arg[0] { case "$", "@": m.Result(0, arg[2:len(arg)-1]) + case "(": + m.Echo(arg[1]) } } return @@ -629,6 +634,8 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", if info, e := os.Stat(arg[1]); e == nil && info.IsDir() { result = "true" } + case "!": + result = kit.Format(!kit.Right(arg[1])) case "+": result = arg[1] case "-": @@ -713,6 +720,18 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", } else { result = fmt.Sprintf("%t", arg[0] != arg[2]) } + case "&&": + if kit.Right(arg[0]) { + result = arg[2] + } else { + result = arg[0] + } + case "||": + if kit.Right(arg[0]) { + result = arg[0] + } else { + result = arg[2] + } case "~": if m, e := regexp.MatchString(arg[2], arg[0]); m && e == nil { diff --git a/src/plugin/favor/index.go b/src/plugin/favor/index.go new file mode 100644 index 00000000..82ab5752 --- /dev/null +++ b/src/plugin/favor/index.go @@ -0,0 +1,36 @@ +package main + +import ( + "contexts/cli" + "contexts/ctx" + "toolkit" + + "fmt" + "os" +) + +var Index = &ctx.Context{Name: "test", Help: "测试工具", + Caches: map[string]*ctx.Cache{}, + Configs: map[string]*ctx.Config{ + "_index": &ctx.Config{Name: "index", Value: []interface{}{ + map[string]interface{}{"name": "demo", "help": "demo", + "tmpl": "componet", "view": "componet", "init": "", + "type": "public", "ctx": "demo", "cmd": "demo", + "args": []interface{}{}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "pod", "value": "hello world"}, + map[string]interface{}{"type": "button", "value": "执行"}, + }, + }, + }}, + }, + Commands: map[string]*ctx.Command{ + "demo": {Name: "demo", Help: "demo", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + m.Echo(kit.Select("hello world", arg, 0)) + return + }}, + }, +} + +func main() { + fmt.Print(cli.Index.Plugin(Index, os.Args[1:])) +} diff --git a/src/plugin/favor/index.js b/src/plugin/favor/index.js new file mode 100644 index 00000000..8c8f3659 --- /dev/null +++ b/src/plugin/favor/index.js @@ -0,0 +1,4 @@ + +{init: function(page, pane, field, option, output) { + kit.Log("hello world") +}} diff --git a/src/plugin/favor/index.shy b/src/plugin/favor/index.shy new file mode 100644 index 00000000..ba29d856 --- /dev/null +++ b/src/plugin/favor/index.shy @@ -0,0 +1,79 @@ + +fun clip "粘贴板" "" "" \ + public \ + text "" name you imports plugin_you action auto \ + text "" view long \ + button "存储" + + copy ssh._route $1 aaa.clip $2 +end + +fun qrcode "二维码" "" "" \ + public \ + text "" view long \ + button "生成" + + table qrcode $1 +end + +fun salary "工资单" "" "" \ + public \ + text "9000" label total \ + text "9000" label base \ + button "计算" + + let total = $1 || $2 + let base = $2 || $1 + + let house = $base * 120 / 1000 + let old = $base * 80 / 1000 + let tread = $base * 20 / 1000 + let job = $base * 2 / 1000 + let get = $total - $house - $old - $tread - $job + + let tax = 0 + let rest = $get + if $rest > 85000 + let tax = $tax + ($rest - 85000) * 45 / 100 + let rest = 85000 + end + if $rest > 60000 + let tax = $tax + ($rest - 60000) * 35 / 100 + let rest = 60000 + end + if $rest > 40000 + let tax = $tax + ($rest - 40000) * 30 / 100 + let rest = 40000 + end + if $rest > 30000 + let tax = $tax + ($rest - 30000) * 25 / 100 + let rest = 30000 + end + if $rest > 17000 + let tax = $tax + ($rest - 17000) * 20 / 100 + let rest = 17000 + end + if $rest > 8000 + let tax = $tax + ($rest - 8000) * 10 / 100 + let rest = 8000 + end + if $rest > 5000 + let tax = $tax + ($rest - 5000) * 3 / 100 + end + let rest = $get - $tax + + + append "公积金" $house + append "养老保险" $old + append "医疗保险" $tread + append "失业保险" $job + append "个税" $tax + append "结余" $rest +end + +fun hello world "" "" \ + public \ + text "" \ + button "执行" + copy pwd +end diff --git a/src/plugin/favor/local.shy b/src/plugin/favor/local.shy new file mode 100644 index 00000000..0519ecba --- /dev/null +++ b/src/plugin/favor/local.shy @@ -0,0 +1 @@ + \ No newline at end of file