1
0
mirror of https://shylinux.com/x/volcanos synced 2025-07-01 20:11:19 +08:00

opt xterm.js

This commit is contained in:
harveyshao 2022-07-25 08:11:09 +08:00
parent 9834321291
commit 7b2b1447ab
8 changed files with 80 additions and 57 deletions

View File

@ -68,7 +68,7 @@ Volcanos(chat.ONENGINE, {help: "搜索引擎", _init: function(can, meta, list,
can.onengine.signal(can, chat.ONREMOTE, can.request({}, {_follow: panel._follow, _msg: msg, _cmds: cmds}))
var names = msg.Option(chat._NAMES)||panel._names||((can.Conf("iceberg")||Volcanos.meta.iceberg)+panel._name)
can.misc.Run(event, can, {names: names, daemon: can.core.Keys(can.ondaemon._list[0], msg._daemon)}, cmds, function(msg) {
can.misc.Run(event, can, {names: names, daemon: msg._daemon}, cmds, function(msg) {
Volcanos.meta.pack[keys] = msg, toast && toast.close(), toast = true, can.base.isFunc(cb) && cb(msg)
})
},
@ -516,6 +516,7 @@ Volcanos(chat.ONLAYOUT, {help: "页面布局", _init: function(can, target) { ta
},
profile_auto: function(can, target) {
can.onlayout.profile(can, target)
can.page.style(can, can.ui.project, html.MAX_HEIGHT, can.ConfHeight())
can.page.ClassList.add(can, can.ui.project, ice.AUTO)
can.page.ClassList.add(can, can.ui.profile, ice.AUTO)
can.page.ClassList.add(can, can.ui.display, ice.AUTO)
@ -558,8 +559,8 @@ Volcanos(chat.ONMOTION, {help: "动态特效", _init: function(can, target) {
},
float: {_hash: {},
del: function(can, key) {
key == chat.CARTE && can.page.Select(can, can._root._target, can.core.Keys(html.DIV, chat.CARTE), function(item) {
can.page.Remove(can, item)
key == chat.CARTE && can.page.Select(can, can._root._target, can.core.Keys(html.DIV, chat.CARTE), function(target) {
can.page.Remove(can, target)
})
var last = this._hash[key]; if (!last) { return }
last.close? last.close(): can.page.Remove(can, last._target)

View File

@ -134,7 +134,8 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg
})
can.misc.POST(can, msg, can.base.MergeURL(dataset.names.toLowerCase(),
"_", (msg._can.sup||msg._can)._name, ice.MSG_DAEMON, msg.__daemon||dataset.daemon||""
"_name", (msg._can.sup||msg._can)._name, "_index", (msg._can.sup||msg._can)._index,
ice.MSG_DAEMON, msg.__daemon||dataset.daemon||""
), form, cb)
},
WSS: function(can, args, cb, onopen, onclose, onerror) { if (can.user.isIE) { return }

View File

@ -464,7 +464,7 @@ Volcanos("page", {help: "用户界面", ClassList: {
},
insertBefore: function(can, list, before, parent) { parent = parent||before.parentNode
var item = can.page.Append(can, parent, list).first
return parent.insertBefore(item, before), item
var item = can.base.isArray(list)? can.page.Append(can, parent, list).first: list
return before && parent.insertBefore(item, before), item
},
})

7
package.json Normal file
View File

@ -0,0 +1,7 @@
{
"dependencies": {
"xterm": "^4.19.0",
"xterm-addon-fit": "^0.5.0",
"xterm-addon-web-links": "^0.6.0"
}
}

View File

@ -7,7 +7,7 @@ Volcanos(chat.ONFIGURE, {help: "控件详情", key: {
_show: function(can, msg, cbs, target, name) {
if (!can.onmotion.toggle(can, can._target, msg.Length() != 0)) { return }
can.onmotion.clear(can), can.onappend.table(can, msg, function(value) {
return {text: [value, html.TD], style: msg.Length() > 1? {"min-width": target.offsetWidth-16}: {}, onclick: function(event) { can.base.isFunc(cbs) && cbs(can, value, target.value)
return {text: [value, html.TD], style: msg.append && msg.append.length == 1? {"min-width": target.offsetWidth-16}: {}, onclick: function(event) { can.base.isFunc(cbs) && cbs(can, value, target.value)
msg.Option(ice.MSG_PROCESS) == ice.PROCESS_AGAIN && can.onmotion.delay(can, function() {
can.onfigure.key._init(event, can, cbs, target, name, value)
})

View File

@ -2,103 +2,112 @@ Volcanos(chat.ONIMPORT, {help: "导入数据", _init: function(can, msg, cb, tar
can.onmotion.clear(can), can.onlayout.profile_auto(can), can.base.isFunc(cb) && cb(msg)
can.onimport.layout(can), can.onappend._status(can), can.term = {}
can.requireModules(["xterm/css/xterm.css", "xterm", "xterm-addon-fit", "xterm-addon-web-links"], function() {
can.requireModules(["xterm/css/xterm.css", "xterm", "xterm-addon-fit", "xterm-addon-web-links"], function() { can.onmotion.delay(can, function() {
if (can.Option(mdb.HASH) != "") {
var item = {hash: can.Option(mdb.HASH)}; msg.Table(function(value) { can.core.Value(item, value.key, value.value) })
return can.onmotion.delay(can, function() { can.onimport._connect(can, item).writeln() }, 1000)
return can.onimport._connect(can, item)
}
var hash = can.sup._hash||(location.hash||"#").slice(1)||true, list = msg.Table(function(value) {
var item = can.onimport._item(can, value); value.hash == hash && (item.click(), hash = false)
});
hash && can.runAction({}, mdb.CREATE, [mdb.TYPE, "", mdb.NAME, "term"], function(msg) {
can.onimport._item(can, {hash: msg.Result(), name: msg.Option(mdb.NAME)}).click()
})
})
hash && can.onimport._create(can, [mdb.TYPE, "", mdb.NAME, "term"])
}, 500) })
},
layout: function(can) {
can.page.style(can, can.ui.content, html.HEIGHT, can.ConfHeight(), html.WIDTH, can.ConfWidth())
var term = can.ui.content._term; if (!term) { return }
term._fit.fit(), can.onexport.term(can, term._item, term)
},
_size: function(can, item, size) {
can.runAction(can.request({}, size, item), "resize", [], function() {})
},
_input: function(can, item, val) {
can.runAction(can.request({}, item), "input", [val], function() {})
_create: function(can, args, data) {
can.runAction({}, mdb.CREATE, args, function(msg) {
var current = can.onimport._item(can, {hash: msg.Result(), name: msg.Option(mdb.NAME), extra: data})
can.page.insertBefore(can, current, can.ui.project.firstChild).click()
})
},
_item: function(can, item) { item.extra = can.base.Obj(item.extra, {})
return can.onimport.item(can, item, function(event) { can.runAction(can.request(event, item), "select")
item._menu = shy(can.ondetail, can.ondetail.list, function(event, button, meta) { can.request(event, item), meta[button](event, can, button, item) })
_input: function(can, item, val) {
can.runAction(can.request({}, item), "input", [btoa(val)], function() {})
},
_item: function(can, item) {
item._menu = shy(can.ondetail, can.ondetail.list, function(event, button, meta) {
can.request(event, item, item.extra), meta[button](event, can, button, item)
})
return item._item = can.onimport.item(can, item, function(event) {
item._plugin && can.onmotion.toggle(can, item._plugin._target, true)
item._tabs? item._tabs.click(): item._tabs = can.onimport.tabs(can, [item], function(event) {
can.onimport._connect(can, item)
})
}, function(event) {
can.user.carteRight(event, can, can.ondetail, can.ondetail.list, function(event, button) {
can.request(event, item, item.extra)
can.ondetail[button](event, can, button, item)
})
can.user.carteRight(event, can, can.ondetail, can.ondetail.list, item._menu)
})
},
_plug: function(can, item) {
can.onmotion.clear(can, can.ui.profile)
can.onimport.plug(can, item.extra, can.ui.profile, function() {
_plug: function(can, item) { can.onmotion.clear(can, can.ui.profile)
can.onimport.plug(can, item.extra, can.ui.profile, function(sub) { item._plugin = sub
can.page.style(can, sub._output, html.MAX_WIDTH, can.ConfWidth()*3/4)
})
},
_connect: function(can, item, target) { target = target||can.ui.content
can.sup._hash = item.hash, can.isCmdMode() && (location.hash = item.hash)
if (can.onmotion.cache(can, function() { return item.hash }, target, can.ui.profile)) {
return can.onexport.term(can, item, can.term[item.hash])
return item._term.focus(), can.onexport.term(can, item, item._term)
}
item.extra = can.base.Obj(item.extra, {})
var term = new Terminal({theme: item.extra, cursorBlink: true, tabStopWidth: 4})
var fitAddon = new FitAddon.FitAddon(); term.loadAddon(fitAddon)
var fitAddon = new FitAddon.FitAddon(); term.loadAddon(fitAddon), term._fit = fitAddon
term.loadAddon(new WebLinksAddon.WebLinksAddon())
term.open(target||can.ui.content)
term.onData(function(val) { can.onimport._input(can, item, val) })
term.onCursorMove(function(e) { can.onexport.term(can, item, term) })
term.onResize(function(size) { can.onimport._size(can, item, size) })
fitAddon.fit()
var submode = false
term.onCursorMove(function(e) {
can.misc.Debug(e)
})
var submode = false, keyskip = false
term.onKey(function(e) { var event = e.domEvent
if (submode) { switch (event.key) {
case "l": target.nextSibling && target.nextSibling._term && target.nextSibling._term.focus(); break
case "h": target.previousSibling && target.previousSibling._term && target.previousSibling._term.focus(); break
if (submode) { keyskip = true; switch (event.key) {
case "l": target.nextSibling && target.nextSibling._term? target.nextSibling._term.focus():
item._tabs && item._tabs.nextSibling && item._tabs.nextSibling.click();
break
case "h": target.previousSibling && target.previousSibling._term? target.previousSibling._term.focus():
item._tabs && item._tabs.previousSibling && item._tabs.previousSibling.click();
break
case "n": can.onaction.create(event, can); break
break
default: keyskip = false
} }
submode = event.ctrlKey && event.key == "g"
can.onexport.term(can, item, term)
})
term.onData(function(val) {
if (submode || keyskip) { keyskip = false; return }
can.onimport._input(can, item, val)
})
term.onTitleChange(function(title) { can.isCmdMode() && can.user.title(title) })
can.term[item.hash] = target._term = term, term._target = target
can.runAction(can.request(event, item), "select")
can.onexport.term(can, item, term)
can.onimport._plug(can, item)
item._term = term
return term
can.term[item.hash] = item._term = target._term = term, term._target = target, term._item = item
can.runAction(can.request(event, item), "select"), can.onimport._plug(can, item)
return item._term.focus(), can.onexport.term(can, item, term)
},
grow: function(can, msg, str) { var data = can.base.Obj(str), term = can.term[msg.Option(mdb.HASH)]
switch (data.type) {
case "data": term.write(atob(data.text)); break
grow: function(can, msg, type) { var term = can.term[msg.Option(mdb.HASH)]
switch (type) {
case "data": term.write(atob(msg.Option(mdb.TEXT))); break
case "exit": can.onmotion.clear(can, term._target); break
}
},
})
Volcanos(chat.ONACTION, {help: "操作数据", list: ["create", "split", "prunes"],
Volcanos(chat.ONACTION, {help: "操作数据", list: [mdb.CREATE, lex.SPLIT, mdb.PRUNES],
_trans: {split: "分屏", theme: "主题"},
create: function(event, can) {
can.user.input(event, can, [mdb.TYPE, mdb.NAME, "background", "index", "args"], function(args, data) {
can.runAction({}, mdb.CREATE, args, function(msg) { data.hash = msg.Result()
can.onimport._item(can, {hash: msg.Result(), name: msg.Option(mdb.NAME)}).click()
})
can.user.input(event, can, [mdb.TYPE, mdb.NAME, "background", ctx.INDEX, ctx.ARGS], function(args, data) {
can.onimport._create(can, args, data)
})
},
split: function(event, can) { can.request(event, {name: "term", nrow: 2, ncol: 2})
can.user.input(event, can, [mdb.TYPE, mdb.NAME, "nrow", "ncol"], function(data) {
can.onimport.tabs(can, [data], function(event) {
if (can.onmotion.cache(can, function() { return data.name }, can.ui.content)) { return }
can.onimport.tabs(can, [data], function(event) { if (can.onmotion.cache(can, function() { return data.name }, can.ui.content)) { return }
can.core.List(parseInt(data.nrow), function(nrow) { var row = can.page.Append(can, can.ui.content, [{view: "row", style: {height: can.ConfHeight()/data.nrow}}]).first
can.core.List(parseInt(data.ncol), function(ncol) { var col = can.page.Append(can, row, [{view: "col", style: {height: can.ConfHeight()/data.nrow, width: can.ConfWidth()/data.ncol-2}}]).first
can.runAction({}, mdb.CREATE, [mdb.TYPE, data.type, mdb.NAME, can.core.Keys(data.name, nrow, ncol)], function(msg) { can.onimport._connect(can, {hash: msg.Result()}, col) })
@ -121,23 +130,25 @@ Volcanos(chat.ONDETAIL, {help: "操作数据", list: ["share", "plugin", "theme"
},
theme: function(event, can, button, item) {
can.user.input(event, can, ["background", "selection", "cursor", "foreground"], function(args, data) {
item._term && item._term.setOption("theme", data), can.runAction(event, mdb.MODIFY, args)
can.runAction(event, mdb.MODIFY, args), item._term.setOption("theme", data), can.base.Copy(item.extra, data)
})
},
rename: function(event, can, button, item) {
can.user.input(event, can, [mdb.NAME], function(args) {
can.runAction(event, button, args)
can.runAction(event, button, args), item.name = item._item.innerText = item._tabs.innerText = args[1]
})
},
remove: function(event, can, button, item) {
can.runAction(event, button)
},
})
Volcanos(chat.ONEXPORT, {help: "导出数据", list: ["type", "background", "rows", "cols", "cursorY", "cursorX", "index"],
Volcanos(chat.ONEXPORT, {help: "导出数据", list: ["total", "type", "background", "rows", "cols", "cursorY", "cursorX", ctx.INDEX],
term: function(can, item, term) {
can.core.List(can.onexport.list, function(key) {
can.Status(key, can.base.getValid(item[key], item.extra[key], term[key], term.buffer.active[key], ""))
})
can.Status("total", can.page.Select(can, can.ui.project, html.DIV_ITEM).length)
can.Status("type", item["type"]||"")
return term
},
})

View File

@ -124,9 +124,10 @@ Volcanos(chat.ONIMPORT, {help: "导入数据", _init: function(can, msg, cb, tar
}))
},
plug: function(can, meta, target, cb) { if (!meta || !meta.index) { return }
meta.type = "plug", can.onappend.plugin(can, meta, function(sub) {
meta.type = "plug", can.onappend.plugin(can, meta, function(sub) { sub.sup = can
sub.run = function(event, cmds, cb) { can.runActionCommand(can.request(event, can.Option()), meta.index, cmds, cb) }
sub.onaction.close = function() { can.onmotion.hidden(sub, sub._target) }
sub.onaction.close = function() { can.ui && target == can.ui.profile? can.onmotion.hidden(sub, target): can.onmotion.hidden(sub, sub._target) }
can.page.style(can, sub._output, html.MAX_HEIGHT, can.ConfHeight()-2*html.ACTION_HEIGHT, html.MAX_WIDTH, can.ConfWidth())
can.base.isFunc(cb) && cb(sub)
}, target)
},

View File

@ -347,7 +347,9 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", pack:
},
request: function(event) { event = event||{}, event = event._event||event
var msg = event._msg||can.misc.Message(event, can); event._msg = msg
function set(key, value) { msg.Option(key) || value == "" || msg.Option(key, value) }
function set(key, value) {
typeof value == lang.FUNCTION || typeof value == lang.OBJECT || value == "" || msg.Option(key) || msg.Option(key, value)
}
// 添加参数
can.core.List(arguments, function(option, index) { if (!option || index == 0) { return }