mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 14:34:13 +08:00
内置环境模式输出处理
This commit is contained in:
parent
5b4ae6763f
commit
2254f5642e
@ -2,13 +2,12 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
|||||||
// 配置页面
|
// 配置页面
|
||||||
if (code == 'options') {
|
if (code == 'options') {
|
||||||
utools.setExpendHeight(600);
|
utools.setExpendHeight(600);
|
||||||
$("#out").hide().html('');
|
// $("#options").show();
|
||||||
$("#options").show();
|
|
||||||
showOptions();
|
showOptions();
|
||||||
} else {
|
} else {
|
||||||
|
// console.log(new Date().getTime() - window.startTime);
|
||||||
utools.setExpendHeight(0);
|
utools.setExpendHeight(0);
|
||||||
$("#options").hide();
|
// $("#options").hide();
|
||||||
$("#out").show().text('');
|
|
||||||
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") {
|
||||||
@ -18,7 +17,7 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
|||||||
}else{
|
}else{
|
||||||
option = programs[db.program];
|
option = programs[db.program];
|
||||||
}
|
}
|
||||||
cmd = await special(cmd);
|
cmd = special(cmd);
|
||||||
// 正则
|
// 正则
|
||||||
if (type == 'regex') cmd = cmd.replace(/\{\{input\}\}/mg, payload);
|
if (type == 'regex') cmd = cmd.replace(/\{\{input\}\}/mg, payload);
|
||||||
// 窗口
|
// 窗口
|
||||||
@ -44,7 +43,7 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
|||||||
if (db.hasSubInput) {
|
if (db.hasSubInput) {
|
||||||
// 启动子命令输入
|
// 启动子命令输入
|
||||||
// 清空输出
|
// 清空输出
|
||||||
$("#out").text('');
|
$("#out").empty();
|
||||||
var subinput = '';
|
var subinput = '';
|
||||||
var setSubInput = () => {
|
var setSubInput = () => {
|
||||||
utools.setSubInput(({text}) => {
|
utools.setSubInput(({text}) => {
|
||||||
@ -53,9 +52,9 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
|||||||
}
|
}
|
||||||
var handleEnter = (event) => {
|
var handleEnter = (event) => {
|
||||||
if (event.keyCode == 13) {
|
if (event.keyCode == 13) {
|
||||||
$("#out").text('');
|
$("#out").empty();
|
||||||
var execmd = cmd.replace(/\{\{subinput\}\}/mg, subinput);
|
var execmd = cmd.replace(/\{\{subinput\}\}/mg, subinput);
|
||||||
runCmd(execmd, option, db.output);
|
runQuickCommand(execmd, option, db.output);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
setSubInput();
|
setSubInput();
|
||||||
@ -65,35 +64,43 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
|||||||
document.removeEventListener('keydown', handleEnter);
|
document.removeEventListener('keydown', handleEnter);
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
runCmd(cmd, option, db.output);
|
runQuickCommand(cmd, option, db.output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function runCmd(cmd, option, output) {
|
|
||||||
if (option == "simulation") {
|
let runQuickCommand = (cmd, option, output) => {
|
||||||
utools.setExpendHeight(0);
|
|
||||||
utools.hideMainWindow();
|
|
||||||
eval(`(async () => {
|
|
||||||
${cmd}
|
|
||||||
})()`);
|
|
||||||
utools.outPlugin();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 不需要输出的,提前关闭窗口
|
// 不需要输出的,提前关闭窗口
|
||||||
if (['ignore', 'clip', 'send', 'notice', 'terminal'].indexOf(output) !== -1) {
|
if (['ignore', 'clip', 'send', 'notice', 'terminal'].indexOf(output) !== -1) {
|
||||||
utools.setExpendHeight(0);
|
|
||||||
utools.hideMainWindow();
|
utools.hideMainWindow();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
utools.outPlugin();
|
utools.outPlugin();
|
||||||
}, 10);
|
}, 500);
|
||||||
}
|
}
|
||||||
var terminal = false;
|
if (option == "simulation") {
|
||||||
if(output == 'terminal') terminal = true;
|
// 内置环境
|
||||||
// 运行脚本
|
runCodeInVm(cmd, (stdout, stderr) => {
|
||||||
window.run(cmd, option, terminal, (stdout, stderr) => {
|
switchQuickCommandResult(stdout, stderr, output)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
var terminal = output == 'terminal' ? true : false
|
||||||
|
// 执行脚本
|
||||||
|
runCodeFile(cmd, option, terminal, (stdout, stderr) => {
|
||||||
|
switchQuickCommandResult(stdout, stderr, output)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switchQuickCommandResult = (stdout, stderr, output) => {
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
|
$("#out").addClass('error')
|
||||||
// 报错
|
// 报错
|
||||||
|
if (output == 'text' || output == 'html')
|
||||||
|
{
|
||||||
|
utools.setExpendHeight(600);
|
||||||
|
$("#out").append(stderr)
|
||||||
|
} else {
|
||||||
var index = utools.showMessageBox({
|
var index = utools.showMessageBox({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
title: '啊嘞?!',
|
title: '啊嘞?!',
|
||||||
@ -101,31 +108,33 @@ function runCmd(cmd, option, output) {
|
|||||||
buttons: ['转至脚本目录', '退出']
|
buttons: ['转至脚本目录', '退出']
|
||||||
})
|
})
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
locate(resolve(tmpdir, `QuickCommandTempScript.${option.ext}`));
|
locate(getQuickCommandScriptFile(option.ext));
|
||||||
}
|
}
|
||||||
copyTo(stderr);
|
copyTo(stderr);
|
||||||
message("已复制报错信息");
|
message("已复制报错信息");
|
||||||
utools.outPlugin();
|
utools.outPlugin();
|
||||||
|
}
|
||||||
} else if (stdout) {
|
} else if (stdout) {
|
||||||
|
$("#out").removeClass("error")
|
||||||
// 有输出
|
// 有输出
|
||||||
switch (output) {
|
switch (output) {
|
||||||
case "text":
|
case "text":
|
||||||
utools.setExpendHeight(600);
|
utools.setExpendHeight(600);
|
||||||
$("#out").text(stdout);
|
$("#out").append(htmlEncode(stdout, true))
|
||||||
break;
|
break;
|
||||||
case "html":
|
case "html":
|
||||||
utools.setExpendHeight(600);
|
utools.setExpendHeight(600);
|
||||||
$("#out").html(stdout);
|
$("#out").append(stdout)
|
||||||
break;
|
break;
|
||||||
case "clip":
|
case "clip":
|
||||||
copyTo(stdout);
|
copyTo(stdout)
|
||||||
break;
|
break;
|
||||||
case "send":
|
case "send":
|
||||||
send(stdout)
|
send(stdout)
|
||||||
break;
|
break;
|
||||||
case "notice":
|
case "notice":
|
||||||
// 发送系统通知
|
// 发送系统通知
|
||||||
message(stdout);
|
message(stdout)
|
||||||
break;
|
break;
|
||||||
case "ignore":
|
case "ignore":
|
||||||
break;
|
break;
|
||||||
@ -136,5 +145,9 @@ function runCmd(cmd, option, output) {
|
|||||||
// 无输出
|
// 无输出
|
||||||
utools.outPlugin()
|
utools.outPlugin()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utools.outPlugin(() => {
|
||||||
|
$("#options").empty()
|
||||||
|
$("#out").empty()
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user