mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 14:34:13 +08:00
新增runcode功能
This commit is contained in:
parent
85009b5de4
commit
d26ae3223b
@ -1,13 +1,25 @@
|
|||||||
utools.onPluginEnter(async ({ code, type, payload }) => {
|
utools.onPluginEnter(async ({ code, type, payload }) => {
|
||||||
|
utools.onPluginOut(() => {
|
||||||
|
var program = $('#program').val();
|
||||||
|
$("#options").empty().show()
|
||||||
|
$("#out").empty()
|
||||||
|
if (code == "code") {
|
||||||
|
var cmd = window.editor.getValue();
|
||||||
|
putDB('history', { cmd: cmd, program: program }, 'codeHistory')
|
||||||
|
}
|
||||||
|
})
|
||||||
// 配置页面
|
// 配置页面
|
||||||
if (code == 'options') {
|
if (code == 'options') {
|
||||||
utools.setExpendHeight(600);
|
utools.setExpendHeight(600);
|
||||||
// $("#options").show();
|
// $("#options").show();
|
||||||
showOptions();
|
showOptions();
|
||||||
|
} else if (code == 'code') {
|
||||||
|
utools.setExpendHeight(600);
|
||||||
|
showCodeEditor()
|
||||||
} else {
|
} else {
|
||||||
// console.log(new Date().getTime() - window.startTime);
|
// console.log(new Date().getTime() - window.startTime);
|
||||||
utools.setExpendHeight(0);
|
utools.setExpendHeight(0);
|
||||||
// $("#options").hide();
|
$("#options").hide();
|
||||||
var db = utools.db.get('customFts').data[code],
|
var db = utools.db.get('customFts').data[code],
|
||||||
cmd = db.cmd;
|
cmd = db.cmd;
|
||||||
if (db.program == "custom") {
|
if (db.program == "custom") {
|
||||||
@ -78,21 +90,23 @@ let runQuickCommand = (cmd, option, output) => {
|
|||||||
utools.outPlugin();
|
utools.outPlugin();
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
var maxheight = true
|
||||||
if (option == "simulation") {
|
if (option == "simulation") {
|
||||||
// 内置环境
|
// 内置环境
|
||||||
runCodeInVm(cmd, (stdout, stderr) => {
|
runCodeInVm(cmd, (stdout, stderr) => {
|
||||||
switchQuickCommandResult(stdout, stderr, output)
|
if (cmd.includes("utools.setExpendHeight")) maxheight = false
|
||||||
|
switchQuickCommandResult(stdout, stderr, output, maxheight)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
var terminal = output == 'terminal' ? true : false
|
var terminal = output == 'terminal' ? true : false
|
||||||
// 执行脚本
|
// 执行脚本
|
||||||
runCodeFile(cmd, option, terminal, (stdout, stderr) => {
|
runCodeFile(cmd, option, terminal, (stdout, stderr) => {
|
||||||
switchQuickCommandResult(stdout, stderr, output)
|
switchQuickCommandResult(stdout, stderr, output, maxheight)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switchQuickCommandResult = (stdout, stderr, output) => {
|
switchQuickCommandResult = (stdout, stderr, output, maxheight) => {
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
$("#out").addClass('error')
|
$("#out").addClass('error')
|
||||||
// 报错
|
// 报错
|
||||||
@ -119,11 +133,11 @@ switchQuickCommandResult = (stdout, stderr, output) => {
|
|||||||
// 有输出
|
// 有输出
|
||||||
switch (output) {
|
switch (output) {
|
||||||
case "text":
|
case "text":
|
||||||
utools.setExpendHeight(600);
|
if(maxheight) utools.setExpendHeight(600);
|
||||||
$("#out").append(htmlEncode(stdout, true))
|
$("#out").append(htmlEncode(stdout, true))
|
||||||
break;
|
break;
|
||||||
case "html":
|
case "html":
|
||||||
utools.setExpendHeight(600);
|
if(maxheight) utools.setExpendHeight(600);
|
||||||
$("#out").append(stdout)
|
$("#out").append(stdout)
|
||||||
break;
|
break;
|
||||||
case "clip":
|
case "clip":
|
||||||
@ -146,8 +160,3 @@ switchQuickCommandResult = (stdout, stderr, output) => {
|
|||||||
utools.outPlugin()
|
utools.outPlugin()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
utools.outPlugin(() => {
|
|
||||||
$("#options").empty()
|
|
||||||
$("#out").empty()
|
|
||||||
})
|
|
Loading…
x
Reference in New Issue
Block a user