From 7a6d28dac29c00e8f1947f4f730ea7bd40c80fce Mon Sep 17 00:00:00 2001 From: shaoying Date: Wed, 14 Nov 2018 00:34:36 +0800 Subject: [PATCH] mac add what? --- Makefile | 32 +++++-------- etc/bootstrap.sh | 5 ++- etc/exit.shy | 1 - etc/init.shy | 10 +++++ src/contexts/cli/cli.go | 1 - src/contexts/nfs/nfs.go | 7 ++- src/contexts/web/web.go | 6 +-- usr/librarys/code.js | 89 +++++++++++++++++++++++++++---------- usr/librarys/context.js | 15 +++++-- usr/template/code/code.tmpl | 5 +-- 10 files changed, 107 insertions(+), 64 deletions(-) diff --git a/Makefile b/Makefile index b2ae136a..12b27061 100644 --- a/Makefile +++ b/Makefile @@ -18,11 +18,8 @@ install_all: install touch etc/login.txt touch etc/history.txt -build: - go build $(BENCH) - run: - etc/run.sh 2>var/error.log + etc/bootstrap.sh tar: [ -e tar ] || mkdir tar @@ -45,26 +42,19 @@ tar_all: tar darwin linux64 mv bench.linux64 tar/bin/ tar zcvf tar.tgz tar +linux64: + GOARCH=amd64 GOOS=linux go build $(BENCH) -o bench.linux64 +linux32: + GOARCH=386 GOOS=linux go build $(BENCH) -o bench.linux32 +linux_arm: + GOARCH=arm GOOS=linux go build $(BENCH) -o bench.linux.arm darwin: - GOARCH=amd64 GOOS=darwin go build $(BENCH) - mv bench bench.darwin + GOARCH=amd64 GOOS=darwin go build $(BENCH) -o bench.darwin win64: - GOARCH=amd64 GOOS=windows go build $(BENCH) - mv bench.exe bench_1.0_win64.exe + GOARCH=amd64 GOOS=windows go build $(BENCH) -o bench.win64.exe win32: - GOARCH=386 GOOS=windows go build $(BENCH) - mv bench.exe bench_1.0_win32.exe - -linux64: - GOARCH=amd64 GOOS=linux go build $(BENCH) - mv bench bench.linux64 -linux32: - GOARCH=386 GOOS=linux go build $(BENCH) - mv bench bench_1.0_linux32 -linux_arm: - GOARCH=arm GOOS=linux go build $(BENCH) - mv bench bench_1.0_linux_arm + GOARCH=386 GOOS=windows go build $(BENCH) -o bench.win32.exe DOTS=etc/dotsfile @@ -93,5 +83,5 @@ load_dotsfile:\ ~/.vim/syntax/shy.vim: $(DOTS)/shy.vim cp $< $@ -.PHONY: tar +.PHONY: tar run diff --git a/etc/bootstrap.sh b/etc/bootstrap.sh index 05831eb4..405c3e45 100755 --- a/etc/bootstrap.sh +++ b/etc/bootstrap.sh @@ -1,12 +1,13 @@ #!/usr/bin/env bash -bench=bench [ `uname` = "Darwin" ] && bench=bin/bench.darwin [ `uname` = "Linux" ] && bench=bin/bench.linux64 [ -e "$bench" ] || bench=bench +echo "bench: $bench"> var/boot.log + while true; do - $bench stdio && break + $bench stdio 2>var/error.log && break echo "bench run error" echo "restarting..." sleep 3 diff --git a/etc/exit.shy b/etc/exit.shy index db87fae1..fda4dfba 100644 --- a/etc/exit.shy +++ b/etc/exit.shy @@ -4,5 +4,4 @@ source etc/exit_local.shy config save counter.json counter ~stdio config save history.json history -return hello diff --git a/etc/init.shy b/etc/init.shy index 02125050..5efc36cc 100644 --- a/etc/init.shy +++ b/etc/init.shy @@ -3,5 +3,15 @@ ~code config load counter.json counter +~aaa + login root root +~find aaa.root + config right right.role root +~aaa + login void void + right void owner login add from root + right void owner login add from root + source etc/local.shy + ~shy diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index 01ee4283..498c32c3 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -316,7 +316,6 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", } for _, v := range exports { - m.Log("info", "export %v", v) if v["file"] != "" { m.Sess("nfs").Copy(msg, "option").Copy(msg, "append").Copy(msg, "result").Cmd("export", v["file"]) } diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index d42b5f5f..e67c7f92 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -69,7 +69,7 @@ func open(m *ctx.Message, name string, arg ...int) (string, *os.File, error) { } m.Log("info", "open %s", name) - f, e := os.OpenFile(name, flag, os.ModePerm) + f, e := os.OpenFile(name, flag, 0660) return name, f, e } func dir(m *ctx.Message, name string, level int, deep bool, trip int, fields []string) { @@ -1075,13 +1075,11 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", } w.Flush() default: - m.Log("fuck", "what ---%v", m.Meta) for _, v := range m.Meta["result"] { f.WriteString(v) } } - m.Log("fuck", "what ---%v", m.Meta) - m.Set("append").Set("result").Echo(name) + m.Set("append").Set("result").Add("append", "directory", name).Echo(name) }}, "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) { @@ -1167,6 +1165,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", p := path.Join(m.Confv("paths", 0).(string), arg[0]) qrcode.WriteFile(strings.Join(arg[1:], ""), qrcode.Medium, size, p) m.Log("info", "genqr %s", p) + m.Append("directory", p) } }}, diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 133cc92c..10f127ea 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -230,10 +230,6 @@ func (web *WEB) Start(m *ctx.Message, arg ...string) bool { return true }) - if len(arg) == 0 { - return false - } - web.Caches["protocol"] = &ctx.Cache{Name: "protocol", Value: m.Confx("protocol", arg, 2), Help: "服务协议"} web.Caches["address"] = &ctx.Cache{Name: "address", Value: m.Confx("address", arg, 1), Help: "服务地址"} m.Log("info", "%d %s://%s", m.Capi("nserve", 1), m.Cap("protocol"), m.Cap("stream", m.Cap("address"))) @@ -825,7 +821,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", } if msg.Appends("directory") { - m.Append("page_redirect", fmt.Sprintf("/download/%s", msg.Append("directory"))) + m.Append("download_file", fmt.Sprintf("/download/%s", msg.Append("directory"))) return } diff --git a/usr/librarys/code.js b/usr/librarys/code.js index 044aeb29..5ce353d2 100644 --- a/usr/librarys/code.js +++ b/usr/librarys/code.js @@ -9,6 +9,7 @@ function copy_to_clipboard(text) { insert_child(clipstack, "option").value = text clipstack.childElementCount > 3 && clipstack.removeChild(clipstack.lastElementChild) } + function send_command(form, cb) { var data = {} for (var key in form.dataset) { @@ -49,6 +50,7 @@ function send_command(form, cb) { typeof(cb) == "function" && cb(msg) }) } + function check_argument(form, target) { for (var i = 0; i < form.length-1; i++) { if (form[i] == target) { @@ -62,6 +64,36 @@ function check_argument(form, target) { } send_command(form) } + +var ncommand = 3 +function add_fieldset() { + var name = "command"+ncommand++ + + var fieldset = append_child(document.querySelector("body"), "fieldset") + append_child(fieldset, "legend", {"innerText": name}) + + var option = append_child(fieldset, "form", { + "className": "option "+name, + "dataset": { + "componet_group": "index", + "componet_name": "command", + "componet_name_alias": name, + "componet_name_order": ncommand-1, + } + }) + + append_child(option, "input", {"style": {"display": "none"}}) + + append_child(option, "input", { + "name": "cmd", + "className": "cmd", + "onkeyup": function(event){onaction(event, "input")} + }).focus() + + var append = append_child(fieldset, "table", {"className": "append "+name}) + append_child(append_child(fieldset, "code", {"className": "result "+name}), "pre") +} + function onaction(event, action) { switch (action) { case "submit": @@ -162,10 +194,40 @@ function onaction(event, action) { event.target.dataset["history_last"] = history.length-1 break } - case "b": - if (event.ctrlKey && event.key == "b") { + case "v": + if (event.ctrlKey && event.key == "v") { add_fieldset() } + case "q": + if (event.ctrlKey && event.key == "q") { + var can_remove = false + var order = -1 + for (var p = event.target; p.parentElement && p.tagName != "FIELDSET"; p = p.parentElement) { + if (p.tagName == "FORM" && p.dataset["componet_name_alias"]) { + can_remove = true + order = p.dataset["componet_name_order"] + } + } + if (p && can_remove) { + p.parentElement.removeChild(p) + } + + for (;order < ncommand; order++) { + var input = document.querySelector("form.option.command"+order+" input[name=cmd]") + if (input) { + input.focus() + return + } + } + for (;order > 0; order--) { + var input = document.querySelector("form.option.command"+order+" input[name=cmd]") + if (input) { + input.focus() + ncommand = order+1 + return + } + } + } default: console.log(event) if (event.target.dataset["last_char"] == "j" && event.key == "k") { @@ -204,6 +266,7 @@ function onaction(event, action) { break } } + var inputs = {} var ninput = 0 var keymap = ['a', 'b', 'c'] @@ -352,7 +415,6 @@ function init_download(event) { }) } } - function init_context() { var append = document.querySelector("table.append.ctx") if (!append) { @@ -459,7 +521,6 @@ function init_command() { } }) } - function init_userinfo() { var append = document.querySelector("table.append.userinfo") if (!append) { @@ -478,26 +539,6 @@ function init_userinfo() { }) } -var ncommand = 3 -function add_fieldset() { - var name = "command"+ncommand++ - - var fieldset = append_child(document.querySelector("body"), "fieldset") - append_child(fieldset, "legend", {"innerText": name}) - - var option = append_child(fieldset, "form", {"className": "option "+name}) - option.dataset["componet_group"] = "index" - option.dataset["componet_name"] = "command" - option.dataset["componet_name_alias"] = name - append_child(option, "input").style["display"] = "none" - append_child(option, "input", {"name": "cmd", "className": "cmd", "onkeyup": function(event){ - onaction(event, "input") - }}).focus() - - var append = append_child(fieldset, "table", {"className": "append "+name}) - append_child(append_child(fieldset, "code", {"className": "result "+name}), "pre") -} - window.onload = function() { init_option() init_append() diff --git a/usr/librarys/context.js b/usr/librarys/context.js index f4e94d14..870e578f 100644 --- a/usr/librarys/context.js +++ b/usr/librarys/context.js @@ -109,14 +109,16 @@ context = { } try { - var msg = JSON.parse(xhr.responseText||'{"result":[]}'); + var msg = JSON.parse(xhr.responseText||'{"result":[]}') } catch (e) { var msg = {"result": [xhr.responseText]} } console.log(msg) - msg.result && console.log(msg.result.join("")); - if (msg.page_redirect) { + msg.result && console.log(msg.result.join("")) + if (msg.download_file) { + window.open(msg.download_file.join("")) + } else if (msg.page_redirect) { location.href = msg.page_redirect.join("") } else if (msg.page_refresh) { location.reload() @@ -139,6 +141,13 @@ function append_child(parent, element, html) { html && typeof html == "string" && (elm.innerHTML = html) if (typeof html == "object") { for (var k in html) { + if (typeof html[k] == "object") { + for (var d in html[k]) { + elm[k][d] = html[k][d] + } + continue + } + elm[k] = html[k] } } diff --git a/usr/template/code/code.tmpl b/usr/template/code/code.tmpl index 3b1d24dd..dd29e583 100644 --- a/usr/template/code/code.tmpl +++ b/usr/template/code/code.tmpl @@ -97,7 +97,8 @@ height:2em; } - + + {{end}} @@ -205,7 +206,5 @@ {{end}} {{define "tail"}} - - {{end}}