mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
opt nfs
This commit is contained in:
parent
4753646ff0
commit
002b42b68e
@ -29,7 +29,7 @@ type CLI struct {
|
|||||||
|
|
||||||
func (cli *CLI) schedule(m *ctx.Message) string {
|
func (cli *CLI) schedule(m *ctx.Message) string {
|
||||||
first, timer := "", int64(1<<50)
|
first, timer := "", int64(1<<50)
|
||||||
for k, v := range m.Confv("timer").(map[string]interface{}) {
|
for k, v := range m.Confv("timer", "list").(map[string]interface{}) {
|
||||||
val := v.(map[string]interface{})
|
val := v.(map[string]interface{})
|
||||||
if val["action_time"].(int64) < timer && !val["done"].(bool) {
|
if val["action_time"].(int64) < timer && !val["done"].(bool) {
|
||||||
first, timer = k, val["action_time"].(int64)
|
first, timer = k, val["action_time"].(int64)
|
||||||
@ -331,6 +331,9 @@ func main() {
|
|||||||
for i := 0; i < len(m.Meta["cmd_env"])-1; i += 2 {
|
for i := 0; i < len(m.Meta["cmd_env"])-1; i += 2 {
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", m.Meta["cmd_env"][i], m.Parse(m.Meta["cmd_env"][i+1])))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", m.Meta["cmd_env"][i], m.Parse(m.Meta["cmd_env"][i+1])))
|
||||||
}
|
}
|
||||||
|
for _, k := range []string{"PATH", "HOME"} {
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, os.Getenv(k)))
|
||||||
|
}
|
||||||
if len(cmd.Env) > 0 {
|
if len(cmd.Env) > 0 {
|
||||||
m.Log("info", "env %v", cmd.Env)
|
m.Log("info", "env %v", cmd.Env)
|
||||||
}
|
}
|
||||||
@ -617,10 +620,10 @@ func main() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if timer := m.Confm("timer", "list", m.Conf("timer", "next")); timer != nil && !kit.Right(timer["stop"]) {
|
if timer := m.Confm("timer", []string{"list", m.Conf("timer", "next")}); timer != nil && !kit.Right(timer["stop"]) {
|
||||||
m.Log("info", "timer %s %v", m.Conf("timer", "next"), timer["cmd"])
|
m.Log("info", "timer %s %v", m.Conf("timer", "next"), timer["cmd"])
|
||||||
|
|
||||||
msg := m.Sess("cli").Cmd("source", timer["cmd"])
|
msg := m.Cmd("nfs.source", timer["cmd"])
|
||||||
timer["result"] = msg.Meta["result"]
|
timer["result"] = msg.Meta["result"]
|
||||||
timer["msg"] = msg.Code()
|
timer["msg"] = msg.Code()
|
||||||
|
|
||||||
@ -834,16 +837,23 @@ func main() {
|
|||||||
m.Cmdy("nfs.dir", m.Conf("publish", "path"), "dir_reg", "bench")
|
m.Cmdy("nfs.dir", m.Conf("publish", "path"), "dir_reg", "bench")
|
||||||
|
|
||||||
case "self":
|
case "self":
|
||||||
env := []string{}
|
env := []string{
|
||||||
|
"cmd_env", "GOTMPDIR", path.Join(wd, m.Conf("compile", "tmp")),
|
||||||
|
"cmd_env", "GOCACHE", path.Join(wd, m.Conf("compile", "tmp")),
|
||||||
|
}
|
||||||
m.Confm("compile", "env", func(index int, key string) {
|
m.Confm("compile", "env", func(index int, key string) {
|
||||||
env = append(env, "cmd_env", key, kit.Select(os.Getenv(key), m.Option(key)))
|
env = append(env, "cmd_env", key, kit.Select(os.Getenv(key), m.Option(key)))
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Cmd("cli.version", "create")
|
m.Cmd("cli.version", "create")
|
||||||
if m.Cmdy("cli.system", env, "go", "install", path.Join(m.Conf("runtime", "boot.ctx_home"), m.Conf("compile", "bench"))); m.Result(0) == "" {
|
os.MkdirAll(m.Conf("compile", "tmp"), 0777)
|
||||||
|
|
||||||
|
p, q := path.Join(m.Conf("runtime", "boot.ctx_home"), m.Conf("compile", "bench")), path.Join(kit.Select(os.Getenv("GOBIN"), ""), "bench")
|
||||||
|
if m.Cmdy("cli.system", env, "go", "build", "-o", q, p); m.Result(0) == "" {
|
||||||
m.Cmdy("cli.quit", 1)
|
m.Cmdy("cli.quit", 1)
|
||||||
m.Append("host", version.host)
|
m.Append("time", m.Time())
|
||||||
m.Append("self", version.self)
|
m.Append("hash", kit.Hashs(q)[:8])
|
||||||
|
m.Append("bin", q)
|
||||||
m.Table()
|
m.Table()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1008,7 +1018,7 @@ func main() {
|
|||||||
|
|
||||||
m.Add("append", "time", m.Time())
|
m.Add("append", "time", m.Time())
|
||||||
m.Add("append", "file", file)
|
m.Add("append", "file", file)
|
||||||
m.Add("append", "hash", kit.Hashs(file))
|
m.Add("append", "hash", kit.Hashs(file)[:8])
|
||||||
|
|
||||||
if strings.HasSuffix(link, ".tar.gz") {
|
if strings.HasSuffix(link, ".tar.gz") {
|
||||||
m.Cmd("cli.system", "tar", "-xvf", file, "-C", path.Dir(file))
|
m.Cmd("cli.system", "tar", "-xvf", file, "-C", path.Dir(file))
|
||||||
|
@ -4,5 +4,5 @@ var version = struct {
|
|||||||
host string
|
host string
|
||||||
self int
|
self int
|
||||||
}{
|
}{
|
||||||
"2019-07-23 08:08:38", "com.mac_1", 209,
|
"2019-07-23 21:26:44", "ZYB-20190522USI", 232,
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ func (m *Message) Format(arg ...interface{}) string {
|
|||||||
}
|
}
|
||||||
case "stack":
|
case "stack":
|
||||||
pc := make([]uintptr, 100)
|
pc := make([]uintptr, 100)
|
||||||
pc = pc[:runtime.Callers(6, pc)]
|
pc = pc[:runtime.Callers(0, pc)]
|
||||||
frames := runtime.CallersFrames(pc)
|
frames := runtime.CallersFrames(pc)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
File diff suppressed because it is too large
Load Diff
640
src/contexts/nfs/term.go
Normal file
640
src/contexts/nfs/term.go
Normal file
@ -0,0 +1,640 @@
|
|||||||
|
package nfs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"contexts/ctx"
|
||||||
|
"toolkit"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/nsf/termbox-go"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (nfs *NFS) Read(p []byte) (n int, err error) {
|
||||||
|
m := nfs.Context.Message()
|
||||||
|
if !m.Caps("termbox") {
|
||||||
|
return nfs.in.Read(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
m.TryCatch(m, true, func(m *ctx.Message) {
|
||||||
|
scroll_count := 0
|
||||||
|
scroll_lines := m.Confi("term", "scroll_lines")
|
||||||
|
which := m.Capi("ninput")
|
||||||
|
what := make([]rune, 0, 1024)
|
||||||
|
rest := make([]rune, 0, 1024)
|
||||||
|
back := make([]rune, 0, 1024)
|
||||||
|
|
||||||
|
m.Option("bio.cmd", "")
|
||||||
|
m.Options("bio.shadow", m.Confs("show_shadow"))
|
||||||
|
|
||||||
|
defer func() { m.Option("bio.cmd", "") }()
|
||||||
|
|
||||||
|
frame, table, index, pick := map[string]interface{}{}, []map[string]string{}, 0, 0
|
||||||
|
if change, f, t, i := nfs.Auto(what, ":", 0); change {
|
||||||
|
frame, table, index, pick = f, t, i, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
switch ev := termbox.PollEvent(); ev.Type {
|
||||||
|
case termbox.EventInterrupt:
|
||||||
|
case termbox.EventResize:
|
||||||
|
nfs.Term(m, "resize")
|
||||||
|
case termbox.EventMouse:
|
||||||
|
switch ev.Key {
|
||||||
|
case termbox.MouseLeft:
|
||||||
|
if m.Confs("term", "mouse.resize") {
|
||||||
|
nfs.Term(m, "window", ev.MouseX, ev.MouseY)
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
}
|
||||||
|
|
||||||
|
case termbox.MouseMiddle:
|
||||||
|
case termbox.MouseRight:
|
||||||
|
if m.Confs("term", "mouse.resize") {
|
||||||
|
nfs.Term(m, "resize", ev.MouseX, ev.MouseY)
|
||||||
|
}
|
||||||
|
case termbox.MouseRelease:
|
||||||
|
case termbox.MouseWheelUp:
|
||||||
|
if scroll_count++; scroll_count > m.Confi("term", "scroll_count") {
|
||||||
|
nfs.Term(m, "scroll", -1).Term(m, "flush")
|
||||||
|
scroll_count = 0
|
||||||
|
}
|
||||||
|
case termbox.MouseWheelDown:
|
||||||
|
if scroll_count++; scroll_count > m.Confi("term", "scroll_count") {
|
||||||
|
nfs.Term(m, "scroll", 1).Term(m, "flush")
|
||||||
|
scroll_count = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case termbox.EventError:
|
||||||
|
case termbox.EventNone:
|
||||||
|
case termbox.EventRaw:
|
||||||
|
case termbox.EventKey:
|
||||||
|
|
||||||
|
switch ev.Key {
|
||||||
|
case termbox.KeyCtrlP:
|
||||||
|
if which--; which < 0 {
|
||||||
|
which = m.Capi("ninput") - 1
|
||||||
|
}
|
||||||
|
if v := m.Conf("input", []interface{}{which, "line"}); v != "" {
|
||||||
|
what, rest = append(what[:0], []rune(v)...), rest[:0]
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
}
|
||||||
|
case termbox.KeyCtrlN:
|
||||||
|
if which++; which >= m.Capi("ninput") {
|
||||||
|
which = 0
|
||||||
|
}
|
||||||
|
if v := m.Conf("input", []interface{}{which, "line"}); v != "" {
|
||||||
|
what, rest = append(what[:0], []rune(v)...), rest[:0]
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
}
|
||||||
|
|
||||||
|
case termbox.KeyCtrlA:
|
||||||
|
if len(what) > 0 {
|
||||||
|
what, rest = append(what, rest...), rest[:0]
|
||||||
|
rest, what = append(rest, what...), what[:0]
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
}
|
||||||
|
case termbox.KeyCtrlF:
|
||||||
|
if len(rest) > 0 {
|
||||||
|
pos := len(what) + 1
|
||||||
|
what, rest = append(what, rest...), rest[:0]
|
||||||
|
rest, what = append(rest, what[pos:]...), what[:pos]
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
}
|
||||||
|
case termbox.KeyCtrlB:
|
||||||
|
if len(what) > 0 {
|
||||||
|
pos := len(what) - 1
|
||||||
|
what, rest = append(what, rest...), rest[:0]
|
||||||
|
rest, what = append(rest, what[pos:]...), what[:pos]
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
}
|
||||||
|
case termbox.KeyCtrlE:
|
||||||
|
if len(rest) > 0 {
|
||||||
|
what, rest = append(what, rest...), rest[:0]
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
}
|
||||||
|
|
||||||
|
case termbox.KeyCtrlU:
|
||||||
|
back = back[:0]
|
||||||
|
back, what = append(back, what...), what[:0]
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
case termbox.KeyCtrlD: // termbox.KeyBackspace
|
||||||
|
if len(rest) > 0 {
|
||||||
|
pos := len(what)
|
||||||
|
what, rest = append(what, rest[1:]...), rest[:0]
|
||||||
|
rest, what = append(rest, what[pos:]...), what[:pos]
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
}
|
||||||
|
case termbox.KeyCtrlH: // termbox.KeyBackspace
|
||||||
|
if len(what) > 0 {
|
||||||
|
what = what[:len(what)-1]
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
}
|
||||||
|
case termbox.KeyCtrlK:
|
||||||
|
back = back[:0]
|
||||||
|
back, rest = append(back, rest...), rest[:0]
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
|
||||||
|
case termbox.KeyCtrlW:
|
||||||
|
if len(what) > 0 {
|
||||||
|
pos := len(what) - 1
|
||||||
|
for space := what[pos] == ' '; pos >= 0; pos-- {
|
||||||
|
if (space && what[pos] != ' ') || (!space && what[pos] == ' ') {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
back = back[:0]
|
||||||
|
back, what = append(back, what[pos+1:]...), what[:pos+1]
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
}
|
||||||
|
case termbox.KeyCtrlY:
|
||||||
|
what = append(what, back...)
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
|
||||||
|
case termbox.KeyCtrlR:
|
||||||
|
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.KeyCtrlT:
|
||||||
|
m.Option("scroll", true)
|
||||||
|
nfs.Term(m, "scroll", scroll_lines).Term(m, "flush")
|
||||||
|
m.Option("scroll", false)
|
||||||
|
case termbox.KeyCtrlO:
|
||||||
|
m.Option("scroll", true)
|
||||||
|
nfs.Term(m, "scroll", -scroll_lines).Term(m, "flush")
|
||||||
|
m.Option("scroll", false)
|
||||||
|
|
||||||
|
case termbox.KeyCtrlJ, termbox.KeyEnter:
|
||||||
|
what = append(what, '\n')
|
||||||
|
n = copy(p, []byte(string(what)))
|
||||||
|
return
|
||||||
|
case termbox.KeyCtrlQ, termbox.KeyCtrlC:
|
||||||
|
nfs.Term(m, "exit")
|
||||||
|
n = copy(p, []byte("return\n"))
|
||||||
|
return
|
||||||
|
|
||||||
|
case termbox.KeyCtrlV:
|
||||||
|
|
||||||
|
for i := -1; i < 8; i++ {
|
||||||
|
nfs.Term(m, "color", i, m.Confi("term", "rest_fg"), fmt.Sprintf("\nhello bg %d", i))
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := -1; i < 8; i++ {
|
||||||
|
nfs.Term(m, "color", m.Confi("term", "rest_bg"), i, fmt.Sprintf("\nhello fg %d", i))
|
||||||
|
}
|
||||||
|
nfs.Term(m, "flush")
|
||||||
|
|
||||||
|
case termbox.KeyCtrlG:
|
||||||
|
case termbox.KeyCtrlX:
|
||||||
|
m.Options("bio.shadow", !m.Options("bio.shadow"))
|
||||||
|
case termbox.KeyCtrlS:
|
||||||
|
|
||||||
|
case termbox.KeyCtrlZ:
|
||||||
|
|
||||||
|
case termbox.KeyTab:
|
||||||
|
m.Options("bio.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("bio.shadow") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if index > len(what) {
|
||||||
|
nfs.shadow("", table, frame)
|
||||||
|
} else {
|
||||||
|
m.Option("auto_key", strings.TrimSpace(string(what[index:])))
|
||||||
|
if change, f, t, i := nfs.Auto(what, " ", len(what)); change {
|
||||||
|
frame, table, index, pick = f, t, i, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if nfs.shadow(what[index:], table, frame); len(table) > 0 {
|
||||||
|
rest = append(rest[:0], []rune(table[0][kit.Format(frame["field"])])...)
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
nfs.shadow(what[index:], table, frame)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
what = append(what, ev.Ch)
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
if !m.Options("bio.shadow") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if change, f, t, i := nfs.Auto(what, kit.Format(ev.Ch), len(what)); change {
|
||||||
|
frame, table, index, pick = f, t, i, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if index > len(what) {
|
||||||
|
nfs.shadow("", table, frame)
|
||||||
|
} else {
|
||||||
|
nfs.shadow(what[index:], table, frame, pick)
|
||||||
|
if pos, word := len(what)-index, kit.Format(frame["pick"]); len(table) > 0 && pos < len(word) {
|
||||||
|
rest = append(rest[:0], []rune(word)[pos:]...)
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
nfs.shadow(what[index:], table, frame, pick)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (nfs *NFS) Auto(what []rune, trigger string, index int) (change bool, frame map[string]interface{}, table []map[string]string, nindex int) {
|
||||||
|
return
|
||||||
|
m := nfs.Context.Message()
|
||||||
|
|
||||||
|
auto_target := m.Optionv("bio.ctx").(*ctx.Context)
|
||||||
|
auto_cmd := ""
|
||||||
|
auto_arg := []string{}
|
||||||
|
|
||||||
|
switch trigger {
|
||||||
|
case " ":
|
||||||
|
switch m.Conf("term", "help_state") {
|
||||||
|
case "context":
|
||||||
|
auto_target = auto_target.Sub(m.Option("auto_key"))
|
||||||
|
m.Optionv("bio.ctx", auto_target)
|
||||||
|
trigger = ":"
|
||||||
|
case "command":
|
||||||
|
m.Option("arg_index", index)
|
||||||
|
auto_cmd = m.Option("bio.cmd", m.Option("auto_key"))
|
||||||
|
trigger = "="
|
||||||
|
case "argument":
|
||||||
|
auto_cmd = m.Option("bio.cmd")
|
||||||
|
auto_arg = strings.Split(strings.TrimSpace(string(what[m.Optioni("arg_index"):])), " ")
|
||||||
|
trigger = "="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto := m.Confm("auto", trigger)
|
||||||
|
if auto == nil {
|
||||||
|
return false, nil, nil, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := []interface{}{kit.Select(kit.Format(auto["cmd"]), auto_cmd)}
|
||||||
|
if len(auto_arg) == 0 {
|
||||||
|
auto_arg = kit.Trans(auto["arg"])
|
||||||
|
}
|
||||||
|
for _, v := range auto_arg {
|
||||||
|
cmd = append(cmd, m.Parse(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
table = []map[string]string{}
|
||||||
|
m.Spawn(auto_target).Cmd(cmd...).Table(func(line int, maps map[string]string) {
|
||||||
|
fields := []interface{}{}
|
||||||
|
for _, v := range auto["fields"].([]interface{}) {
|
||||||
|
fields = append(fields, maps[kit.Format(v)])
|
||||||
|
}
|
||||||
|
maps["format"] = fmt.Sprintf(kit.Format(auto["format"]), fields...)
|
||||||
|
table = append(table, maps)
|
||||||
|
})
|
||||||
|
m.Conf("term", []interface{}{"help_table", auto["table"]}, table)
|
||||||
|
|
||||||
|
frame = map[string]interface{}{
|
||||||
|
"color": auto["color"],
|
||||||
|
"table": auto["table"],
|
||||||
|
"field": auto["field"],
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.Conf("term", []interface{}{"help_index"}, index); index == 0 {
|
||||||
|
m.Conf("term", "help_stack", []interface{}{frame})
|
||||||
|
} else {
|
||||||
|
m.Conf("term", []interface{}{"help_stack", -2}, frame)
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Conf("term", "help_next_auto", auto["next_auto"])
|
||||||
|
m.Conf("term", "help_state", auto["state"])
|
||||||
|
return true, frame, table, index
|
||||||
|
}
|
||||||
|
func (nfs *NFS) Term(msg *ctx.Message, action string, args ...interface{}) *NFS {
|
||||||
|
m := nfs.Context.Message()
|
||||||
|
// m.Log("debug", "%s %v", action, args)
|
||||||
|
|
||||||
|
switch action {
|
||||||
|
case "init":
|
||||||
|
defer func() {
|
||||||
|
if e := recover(); e != nil {
|
||||||
|
m.Log("warn", "term init %s", e)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
termbox.Init()
|
||||||
|
termbox.SetInputMode(termbox.InputEsc)
|
||||||
|
termbox.SetInputMode(termbox.InputMouse)
|
||||||
|
m.Cap("termbox", "true")
|
||||||
|
}
|
||||||
|
|
||||||
|
width, height := termbox.Size()
|
||||||
|
msg.Conf("term", "width", width)
|
||||||
|
msg.Conf("term", "height", height)
|
||||||
|
|
||||||
|
left := msg.Confi("term", "left")
|
||||||
|
top := msg.Confi("term", "top")
|
||||||
|
right := msg.Confi("term", "right")
|
||||||
|
bottom := msg.Confi("term", "bottom")
|
||||||
|
|
||||||
|
x := m.Confi("term", "cursor_x")
|
||||||
|
y := m.Confi("term", "cursor_y")
|
||||||
|
bg := termbox.Attribute(msg.Confi("term", "bgcolor"))
|
||||||
|
fg := termbox.Attribute(msg.Confi("term", "fgcolor"))
|
||||||
|
|
||||||
|
begin_row := m.Confi("term", "begin_row")
|
||||||
|
begin_col := m.Confi("term", "begin_col")
|
||||||
|
|
||||||
|
switch action {
|
||||||
|
case "init":
|
||||||
|
m.Conf("term", "left", 0)
|
||||||
|
m.Conf("term", "top", 0)
|
||||||
|
m.Conf("term", "right", width)
|
||||||
|
m.Conf("term", "bottom", height)
|
||||||
|
|
||||||
|
case "exit":
|
||||||
|
m.Cap("termbox", "false")
|
||||||
|
termbox.Close()
|
||||||
|
|
||||||
|
case "window":
|
||||||
|
if len(args) > 1 {
|
||||||
|
msg.Conf("term", "left", args[0])
|
||||||
|
msg.Conf("term", "top", args[1])
|
||||||
|
}
|
||||||
|
if len(args) > 3 {
|
||||||
|
msg.Conf("term", "right", args[2])
|
||||||
|
msg.Conf("term", "bottom", args[3])
|
||||||
|
} else {
|
||||||
|
msg.Conf("term", "right", width)
|
||||||
|
msg.Conf("term", "bottom", height)
|
||||||
|
}
|
||||||
|
|
||||||
|
case "resize":
|
||||||
|
if len(args) > 1 {
|
||||||
|
msg.Conf("term", "right", args[0])
|
||||||
|
msg.Conf("term", "bottom", args[1])
|
||||||
|
right = msg.Confi("term", "right")
|
||||||
|
bottom = msg.Confi("term", "bottom")
|
||||||
|
} else {
|
||||||
|
msg.Conf("term", "right", right)
|
||||||
|
msg.Conf("term", "bottom", bottom)
|
||||||
|
}
|
||||||
|
|
||||||
|
fallthrough
|
||||||
|
case "clear":
|
||||||
|
if len(args) == 0 {
|
||||||
|
top = m.Confi("term", "prompt_y")
|
||||||
|
} else if kit.Format(args[0]) == "all" {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
for x := left; x < right; x++ {
|
||||||
|
for y := top; y < bottom; y++ {
|
||||||
|
termbox.SetCell(x, y, ' ', fg, bg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.Conf("term", "cursor_x", left)
|
||||||
|
m.Conf("term", "cursor_y", top)
|
||||||
|
termbox.SetCursor(left, top)
|
||||||
|
|
||||||
|
case "cursor":
|
||||||
|
m.Conf("term", "cursor_x", kit.Format(args[0]))
|
||||||
|
m.Conf("term", "cursor_y", kit.Format(args[1]))
|
||||||
|
termbox.SetCursor(m.Confi("term", "cursor_x"), m.Confi("term", "cursor_y"))
|
||||||
|
|
||||||
|
case "flush":
|
||||||
|
termbox.Flush()
|
||||||
|
|
||||||
|
case "scroll":
|
||||||
|
n := 1
|
||||||
|
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++ {
|
||||||
|
line := []rune(m.Conf("output", []interface{}{i, "line"}))
|
||||||
|
|
||||||
|
for j, l := begin_col, left; n > 0; j, l = j+1, l+1 {
|
||||||
|
if j >= len(line)-1 {
|
||||||
|
begin_row, begin_col = i+1, 0
|
||||||
|
n--
|
||||||
|
break
|
||||||
|
} else if line[j] == '\n' {
|
||||||
|
begin_row, begin_col = i, j+1
|
||||||
|
n--
|
||||||
|
} else if l >= right-1 && m.Confs("term", "wrap") {
|
||||||
|
begin_row, begin_col = i, j
|
||||||
|
n--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 向上滚动
|
||||||
|
for i := begin_row; n < 0 && i >= 0; i-- {
|
||||||
|
line := []rune(m.Conf("output", []interface{}{i, "line"}))
|
||||||
|
if begin_col == 0 {
|
||||||
|
i--
|
||||||
|
line = []rune(m.Conf("output", []interface{}{i, "line"}))
|
||||||
|
begin_col = len(line)
|
||||||
|
}
|
||||||
|
|
||||||
|
for j, l := begin_col-1, right-1; n < 0; j, l = j-1, l-1 {
|
||||||
|
if j <= 0 {
|
||||||
|
begin_row, begin_col = i, 0
|
||||||
|
n++
|
||||||
|
break
|
||||||
|
} else if line[j-1] == '\n' {
|
||||||
|
begin_row, begin_col = i, j
|
||||||
|
n++
|
||||||
|
} else if l < left && m.Confs("term", "wrap") {
|
||||||
|
begin_row, begin_col = i, j
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Conf("term", "begin_row", begin_row)
|
||||||
|
m.Conf("term", "begin_col", begin_col)
|
||||||
|
|
||||||
|
fallthrough
|
||||||
|
case "refresh":
|
||||||
|
|
||||||
|
nfs.Term(m, "clear", "all")
|
||||||
|
for i := begin_row; i < m.Capi("noutput"); i++ {
|
||||||
|
if line := m.Conf("output", []interface{}{i, "line"}); begin_col < len(line) {
|
||||||
|
nfs.Term(m, "print", line[begin_col:])
|
||||||
|
}
|
||||||
|
begin_col = 0
|
||||||
|
}
|
||||||
|
// nfs.Term(m, "print", "\n")
|
||||||
|
// nfs.Term(m, "print", m.Conf("prompt"))
|
||||||
|
m.Options("on_scroll", false)
|
||||||
|
|
||||||
|
case "print":
|
||||||
|
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 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 {
|
||||||
|
|
||||||
|
nfs.Term(m, "scroll", n%bottom+1)
|
||||||
|
n -= n % bottom
|
||||||
|
x = m.Confi("term", "cursor_x")
|
||||||
|
y = m.Confi("term", "cursor_y")
|
||||||
|
|
||||||
|
} else if n > 0 {
|
||||||
|
|
||||||
|
nfs.Term(m, "scroll", bottom)
|
||||||
|
n -= bottom
|
||||||
|
x = m.Confi("term", "cursor_x")
|
||||||
|
y = m.Confi("term", "cursor_y")
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if x < right {
|
||||||
|
m.Conf("term", "cursor_x", x)
|
||||||
|
m.Conf("term", "cursor_y", y)
|
||||||
|
termbox.SetCursor(x, y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
nfs.Term(m, "color", args...)
|
||||||
|
nfs.Term(m, "cursor", x, y).Term(m, "flush")
|
||||||
|
}
|
||||||
|
return nfs
|
||||||
|
}
|
||||||
|
func (nfs *NFS) prompt(arg ...interface{}) *NFS {
|
||||||
|
m := nfs.Context.Message()
|
||||||
|
target, _ := m.Optionv("bio.ctx").(*ctx.Context)
|
||||||
|
if target == nil {
|
||||||
|
target = nfs.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
line := fmt.Sprintf("%d[%s]%s> ", m.Capi("ninput"), time.Now().Format("15:04:05"), target.Name)
|
||||||
|
m.Conf("prompt", line)
|
||||||
|
|
||||||
|
line += kit.Format(arg...)
|
||||||
|
if m.Caps("termbox") {
|
||||||
|
m.Conf("term", "prompt_y", m.Conf("term", "cursor_y"))
|
||||||
|
nfs.Term(m, "clear").Term(m, "print", line).Term(m, "flush")
|
||||||
|
} else if nfs.out != nil {
|
||||||
|
nfs.out.WriteString(line)
|
||||||
|
}
|
||||||
|
return nfs
|
||||||
|
}
|
||||||
|
func (nfs *NFS) shadow(args ...interface{}) *NFS {
|
||||||
|
if len(args) == 0 {
|
||||||
|
return nfs
|
||||||
|
}
|
||||||
|
|
||||||
|
m := nfs.Context.Message()
|
||||||
|
x := m.Confi("term", "cursor_x")
|
||||||
|
y := m.Confi("term", "cursor_y")
|
||||||
|
defer func() { nfs.Term(m, "cursor", x, y).Term(m, "flush") }()
|
||||||
|
|
||||||
|
switch arg := args[0].(type) {
|
||||||
|
case []rune:
|
||||||
|
if len(args) == 1 {
|
||||||
|
nfs.Term(m, "color", m.Confi("term", "rest_bg"), m.Confi("term", "rest_fg"), string(arg))
|
||||||
|
} else {
|
||||||
|
cmd := strings.Split(string(arg), " ")
|
||||||
|
switch table := args[1].(type) {
|
||||||
|
case []map[string]string:
|
||||||
|
frame := args[2].(map[string]interface{})
|
||||||
|
field := kit.Format(frame["field"])
|
||||||
|
fg := kit.Int(frame["color"])
|
||||||
|
pick := kit.Int(kit.Select("0", args, 3))
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
for _, line := range table {
|
||||||
|
if strings.Contains(kit.Format(line[field]), cmd[0]) {
|
||||||
|
if i == pick {
|
||||||
|
frame["pick"] = line[field]
|
||||||
|
nfs.Term(m, "color", m.Confi("term", "pick_bg"), m.Confi("term", "pick_fg"), "\n", kit.Format(line["format"]))
|
||||||
|
} else {
|
||||||
|
nfs.Term(m, "color", 0, fg, "\n", kit.Format(line["format"]))
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
if i > 10 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
frame["lines"] = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return nfs
|
||||||
|
}
|
||||||
|
func (nfs *NFS) print(arg ...string) *NFS {
|
||||||
|
m := nfs.Context.Message()
|
||||||
|
|
||||||
|
line := strings.TrimRight(strings.Join(arg, ""), "\n")
|
||||||
|
m.Log("debug", "noutput %s", m.Cap("noutput", m.Capi("noutput")+1))
|
||||||
|
m.Confv("output", -2, map[string]interface{}{"time": time.Now().Unix(), "line": line})
|
||||||
|
|
||||||
|
if m.Caps("termbox") {
|
||||||
|
nfs.Term(m, "clear").Term(m, "print", line).Term(m, "flush")
|
||||||
|
m.Conf("term", "prompt_y", m.Confi("term", "cursor_y")+1)
|
||||||
|
m.Conf("term", "cursor_y", m.Confi("term", "cursor_y")+1)
|
||||||
|
} else {
|
||||||
|
nfs.out.WriteString(line)
|
||||||
|
nfs.out.WriteString("\n")
|
||||||
|
}
|
||||||
|
return nfs
|
||||||
|
}
|
||||||
|
func (nfs *NFS) Show(arg ...interface{}) bool {
|
||||||
|
nfs.prompt(arg...)
|
||||||
|
return true
|
||||||
|
}
|
@ -608,7 +608,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
|
|
||||||
case "_redial": // 断线重连
|
case "_redial": // 断线重连
|
||||||
if !m.Caps("stream") {
|
if !m.Caps("stream") {
|
||||||
m.Cmdx("remote", "dial", arg[1:])
|
m.Cmdx("ssh.remote", "dial", arg[1:])
|
||||||
}
|
}
|
||||||
|
|
||||||
case "dial": // 连接主机
|
case "dial": // 连接主机
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -14,6 +15,10 @@ import (
|
|||||||
|
|
||||||
var DisableLog = false
|
var DisableLog = false
|
||||||
|
|
||||||
|
func Pwd() string {
|
||||||
|
wd, _ := os.Getwd()
|
||||||
|
return wd
|
||||||
|
}
|
||||||
func Env(key string) {
|
func Env(key string) {
|
||||||
os.Getenv(key)
|
os.Getenv(key)
|
||||||
}
|
}
|
||||||
@ -296,3 +301,13 @@ func View(args []string, conf map[string]interface{}) []string {
|
|||||||
}
|
}
|
||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Create(p string) (*os.File, string, error) {
|
||||||
|
if dir, _ := path.Split(p); dir != "" {
|
||||||
|
if e := os.MkdirAll(dir, 0777); e != nil {
|
||||||
|
return nil, p, e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f, e := os.Create(p)
|
||||||
|
return f, p, e
|
||||||
|
}
|
||||||
|
@ -24,7 +24,7 @@ fieldset>form.option div.hide {
|
|||||||
display:none;
|
display:none;
|
||||||
}
|
}
|
||||||
fieldset>form.option div input.args {
|
fieldset>form.option div input.args {
|
||||||
width:100px;
|
width:80px;
|
||||||
}
|
}
|
||||||
fieldset>form.option div.cmd input.args {
|
fieldset>form.option div.cmd input.args {
|
||||||
color:white;
|
color:white;
|
||||||
@ -35,7 +35,7 @@ fieldset>form.option div.clear {
|
|||||||
clear:both;
|
clear:both;
|
||||||
}
|
}
|
||||||
fieldset>form.option div.long input.args {
|
fieldset>form.option div.long input.args {
|
||||||
width:320px;
|
width:240px;
|
||||||
}
|
}
|
||||||
fieldset>form.option label {
|
fieldset>form.option label {
|
||||||
margin-right:6px;
|
margin-right:6px;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user