forked from x/ContextOS
tce add code.scroll
This commit is contained in:
parent
0c8debc6f9
commit
5302004d03
@ -107,7 +107,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
"nuser": &ctx.Cache{Name: "nuser", Value: "0", Help: "用户数量"},
|
"nuser": &ctx.Cache{Name: "nuser", Value: "0", Help: "用户数量"},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ctx.Config{
|
Configs: map[string]*ctx.Config{
|
||||||
"expire": &ctx.Config{Name: "expire(s)", Value: "7200", Help: "会话超时"},
|
"expire": &ctx.Config{Name: "expire(s)", Value: "72000", Help: "会话超时"},
|
||||||
"cert": &ctx.Config{Name: "cert", Value: "etc/pem/cert.pem", Help: "证书文件"},
|
"cert": &ctx.Config{Name: "cert", Value: "etc/pem/cert.pem", Help: "证书文件"},
|
||||||
"pub": &ctx.Config{Name: "pub", Value: "etc/pem/pub.pem", Help: "公钥文件"},
|
"pub": &ctx.Config{Name: "pub", Value: "etc/pem/pub.pem", Help: "公钥文件"},
|
||||||
"key": &ctx.Config{Name: "key", Value: "etc/pem/key.pem", Help: "私钥文件"},
|
"key": &ctx.Config{Name: "key", Value: "etc/pem/key.pem", Help: "私钥文件"},
|
||||||
|
@ -341,7 +341,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.Target().Message().Set("result").Set("append").Copy(msg, "result").Copy(msg, "append")
|
m.Target().Message().Set("result").Set("append").Copy(msg, "result").Copy(msg, "append")
|
||||||
m.Set("append").Set("result").Copy(msg, "append").Copy(msg, "result")
|
m.Set("append").Copy(msg, "append")
|
||||||
|
m.Set("result").Copy(msg, "result")
|
||||||
|
|
||||||
// m.Capi("last_msg", 0, msg.Code())
|
// m.Capi("last_msg", 0, msg.Code())
|
||||||
// m.Capi("ps_count", 1)
|
// m.Capi("ps_count", 1)
|
||||||
}
|
}
|
||||||
@ -580,7 +582,8 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}
|
}
|
||||||
m.Add("append", "return", arg[1:])
|
m.Add("append", "return", arg[1:])
|
||||||
}},
|
}},
|
||||||
"source": &ctx.Command{Name: "source [stdio [init.shy [exit.shy]]]|[filename [async]]|string", Help: "解析脚本, filename: 文件名, async: 异步执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"source": &ctx.Command{Name: "source [stdio [init.shy [exit.shy]]]|[filename [async]]|string", Help: "解析脚本, filename: 文件名, async: 异步执行",
|
||||||
|
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if _, ok := m.Source().Server.(*CLI); ok {
|
if _, ok := m.Source().Server.(*CLI); ok {
|
||||||
msg := m.Spawn(c)
|
msg := m.Spawn(c)
|
||||||
m.Copy(msg, "target")
|
m.Copy(msg, "target")
|
||||||
@ -624,7 +627,8 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
m.Sess("yac").Call(func(msg *ctx.Message) *ctx.Message {
|
m.Sess("yac").Call(func(msg *ctx.Message) *ctx.Message {
|
||||||
switch msg.Cmd().Detail(0) {
|
switch msg.Cmd().Detail(0) {
|
||||||
case "cmd":
|
case "cmd":
|
||||||
m.Set("append").Copy(msg, "append").Set("result").Copy(msg, "result")
|
m.Set("append").Copy(msg, "append")
|
||||||
|
m.Set("result").Copy(msg, "result")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}, "parse", "line", "void", strings.Join(arg, " "))
|
}, "parse", "line", "void", strings.Join(arg, " "))
|
||||||
|
@ -7,6 +7,8 @@ var code = {
|
|||||||
ncommand: 1,
|
ncommand: 1,
|
||||||
show_result: true,
|
show_result: true,
|
||||||
show_height: "30px",
|
show_height: "30px",
|
||||||
|
scroll_x: 50,
|
||||||
|
scroll_y: 50,
|
||||||
}
|
}
|
||||||
|
|
||||||
function copy_to_clipboard(text) {
|
function copy_to_clipboard(text) {
|
||||||
@ -225,6 +227,53 @@ function onaction(event, action) {
|
|||||||
var dataset = target.dataset
|
var dataset = target.dataset
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case "scroll":
|
||||||
|
var body = document.getElementsByTagName("body")[0]
|
||||||
|
if (target.tagName == "BODY") {
|
||||||
|
switch (event.key) {
|
||||||
|
case "h":
|
||||||
|
if (event.ctrlKey) {
|
||||||
|
window.scrollBy(-code.scroll_x*10, 0)
|
||||||
|
} else {
|
||||||
|
window.scrollBy(-code.scroll_x, 0)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "H":
|
||||||
|
window.scrollBy(-body.scrollWidth, 0)
|
||||||
|
break
|
||||||
|
case "l":
|
||||||
|
if (event.ctrlKey) {
|
||||||
|
window.scrollBy(code.scroll_x*10, 0)
|
||||||
|
} else {
|
||||||
|
window.scrollBy(code.scroll_x, 0)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "L":
|
||||||
|
window.scrollBy(body.scrollWidth, 0)
|
||||||
|
break
|
||||||
|
case "j":
|
||||||
|
if (event.ctrlKey) {
|
||||||
|
window.scrollBy(0, code.scroll_y*10)
|
||||||
|
} else {
|
||||||
|
window.scrollBy(0, code.scroll_y)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "J":
|
||||||
|
window.scrollBy(0, body.scrollHeight)
|
||||||
|
break
|
||||||
|
case "k":
|
||||||
|
if (event.ctrlKey) {
|
||||||
|
window.scrollBy(0, -code.scroll_y*10)
|
||||||
|
} else {
|
||||||
|
window.scrollBy(0, -code.scroll_y)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "K":
|
||||||
|
window.scrollBy(0, -body.scrollHeight)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
case "keymap":
|
case "keymap":
|
||||||
if (target.tagName == "INPUT" && target.type == "text") {
|
if (target.tagName == "INPUT" && target.type == "text") {
|
||||||
return
|
return
|
||||||
@ -236,12 +285,6 @@ function onaction(event, action) {
|
|||||||
item.className = code.showmap? "keymap show": "keymap hide"
|
item.className = code.showmap? "keymap show": "keymap hide"
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case "j":
|
|
||||||
window.scrollBy(0, context.scroll_by)
|
|
||||||
break
|
|
||||||
case "k":
|
|
||||||
window.scrollBy(0, -context.scroll_by)
|
|
||||||
break
|
|
||||||
case "m":
|
case "m":
|
||||||
add_command()
|
add_command()
|
||||||
break
|
break
|
||||||
@ -249,10 +292,10 @@ function onaction(event, action) {
|
|||||||
code.show_result = !code.show_result
|
code.show_result = !code.show_result
|
||||||
document.querySelectorAll("form.option input[name=cmd]").forEach(function(input) {
|
document.querySelectorAll("form.option input[name=cmd]").forEach(function(input) {
|
||||||
for (var command = input; command.tagName != "FIELDSET"; command = command.parentElement) {}
|
for (var command = input; command.tagName != "FIELDSET"; command = command.parentElement) {}
|
||||||
var result = command.querySelector("code.result pre")
|
|
||||||
var append = command.querySelector("table.append")
|
var append = command.querySelector("table.append")
|
||||||
|
var result = command.querySelector("code.result pre")
|
||||||
|
// append.style.display = (code.show_result||!append.querySelector("tr"))? "": "none"
|
||||||
result.style.height = (code.show_result||result.innerText=="")? "": code.show_height
|
result.style.height = (code.show_result||result.innerText=="")? "": code.show_height
|
||||||
append.style.display = (code.show_result||!append.querySelector("tr"))? "": "none"
|
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case "0":
|
case "0":
|
||||||
@ -367,13 +410,11 @@ function onaction(event, action) {
|
|||||||
result.innerHTML = ""
|
result.innerHTML = ""
|
||||||
break
|
break
|
||||||
case "z":
|
case "z":
|
||||||
append.style.display = (result.style.height||!append.querySelector("tr"))? "": "none"
|
// append.style.display = (result.style.height||!append.querySelector("tr"))? "": "none"
|
||||||
result.style.height = result.style.height? "": code.show_height
|
result.style.height = result.style.height? "": code.show_height
|
||||||
break
|
break
|
||||||
case "x":
|
case "x":
|
||||||
target.value = ""
|
result.style.height = result.style.height? "": "1px"
|
||||||
append.innerHTML = ""
|
|
||||||
result.innerHTML = ""
|
|
||||||
break
|
break
|
||||||
case "s":
|
case "s":
|
||||||
copy_to_clipboard(result.innerText)
|
copy_to_clipboard(result.innerText)
|
||||||
@ -457,6 +498,8 @@ function init_option() {
|
|||||||
case "g".charCodeAt(0):
|
case "g".charCodeAt(0):
|
||||||
case "j".charCodeAt(0):
|
case "j".charCodeAt(0):
|
||||||
case "k".charCodeAt(0):
|
case "k".charCodeAt(0):
|
||||||
|
case "h".charCodeAt(0):
|
||||||
|
case "l".charCodeAt(0):
|
||||||
case "z".charCodeAt(0):
|
case "z".charCodeAt(0):
|
||||||
case "m".charCodeAt(0):
|
case "m".charCodeAt(0):
|
||||||
continue
|
continue
|
||||||
|
@ -99,7 +99,7 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body onkeyup="return onaction(event, 'keymap')">
|
<body onkeyup="return onaction(event, 'keymap')" onkeydown="return onaction(event, 'scroll')">
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "void"}}{{end}}
|
{{define "void"}}{{end}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user