mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 14:34:13 +08:00
实现输出自动滚动和自动调整高度
This commit is contained in:
parent
621e7bbc0e
commit
3fa62f9f29
@ -1,4 +1,5 @@
|
|||||||
utools.onPluginEnter(async ({ code, type, payload }) => {
|
utools.onPluginEnter(async ({ code, type, payload }) => {
|
||||||
|
var handleEnter
|
||||||
utools.onPluginOut(() => {
|
utools.onPluginOut(() => {
|
||||||
if (code == "code") {
|
if (code == "code") {
|
||||||
var cmd = window.editor.getValue();
|
var cmd = window.editor.getValue();
|
||||||
@ -13,8 +14,12 @@ utools.onPluginEnter(async ({ code, type, payload }) => {
|
|||||||
}
|
}
|
||||||
putDB('history', { cmd: cmd, program: program, scptarg: scptarg, customoptions: customoptions }, 'codeHistory')
|
putDB('history', { cmd: cmd, program: program, scptarg: scptarg, customoptions: customoptions }, 'codeHistory')
|
||||||
}
|
}
|
||||||
|
// 初始化
|
||||||
$("#options").empty()
|
$("#options").empty()
|
||||||
$("#out").empty()
|
$("#out").empty()
|
||||||
|
$("#quickselect").remove()
|
||||||
|
swal.close()
|
||||||
|
if(handleEnter) document.removeEventListener('keydown', handleEnter)
|
||||||
})
|
})
|
||||||
// 配置页面
|
// 配置页面
|
||||||
if (code == 'options') {
|
if (code == 'options') {
|
||||||
@ -23,7 +28,7 @@ utools.onPluginEnter(async ({ code, type, payload }) => {
|
|||||||
showOptions();
|
showOptions();
|
||||||
} else if (code == 'code') {
|
} else if (code == 'code') {
|
||||||
var file = ""
|
var file = ""
|
||||||
utools.setExpendHeight(600);
|
// utools.setExpendHeight(600);
|
||||||
if (type == 'files') file = payload[0].path
|
if (type == 'files') file = payload[0].path
|
||||||
showCodeEditor(file)
|
showCodeEditor(file)
|
||||||
} else {
|
} else {
|
||||||
@ -75,58 +80,57 @@ utools.onPluginEnter(async ({ code, type, payload }) => {
|
|||||||
subinput = text;
|
subinput = text;
|
||||||
}, '');
|
}, '');
|
||||||
}
|
}
|
||||||
var handleEnter = (event) => {
|
handleEnter = (event) => {
|
||||||
if (event.keyCode == 13) {
|
if (event.keyCode == 13) {
|
||||||
$("#out").empty();
|
$("#out").append('\n-------------------------------------\n\n');
|
||||||
var execmd = cmd.replace(/\{\{subinput\}\}/mg, subinput);
|
var execmd = cmd.replace(/\{\{subinput\}\}/mg, subinput);
|
||||||
runQuickCommand(execmd, option, db.output);
|
runQuickCommand(execmd, option, db.output, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
setSubInput();
|
setSubInput();
|
||||||
document.addEventListener('keydown', handleEnter);
|
document.addEventListener('keydown', handleEnter);
|
||||||
// 移除监听
|
|
||||||
utools.onPluginOut(() => {
|
|
||||||
document.removeEventListener('keydown', handleEnter);
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
runQuickCommand(cmd, option, db.output);
|
runQuickCommand(cmd, option, db.output, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
let runQuickCommand = (cmd, option, output) => {
|
let runQuickCommand = (cmd, option, output, autoScroll = false, autoHeight = true) => {
|
||||||
// 不需要输出的,提前关闭窗口
|
// 不需要输出的,提前关闭窗口
|
||||||
if (['ignore', 'clip', 'send', 'notice', 'terminal'].indexOf(output) !== -1) {
|
if (['ignore', 'clip', 'send', 'notice', 'terminal'].indexOf(output) !== -1) {
|
||||||
utools.hideMainWindow();
|
utools.hideMainWindow();
|
||||||
setTimeout(() => {
|
setTimeout(() => { utools.outPlugin(); }, 500);
|
||||||
utools.outPlugin();
|
|
||||||
}, 500);
|
|
||||||
}
|
}
|
||||||
var maxheight = true
|
|
||||||
if (option == "simulation") {
|
if (option == "simulation") {
|
||||||
// 内置环境
|
// 内置环境
|
||||||
runCodeInVm(cmd, (stdout, stderr) => {
|
runCodeInVm(cmd, (stdout, stderr) => {
|
||||||
if (cmd.includes("utools.setExpendHeight")) maxheight = false
|
if (cmd.includes("utools.setExpendHeight")) autoHeight = false
|
||||||
switchQuickCommandResult(stdout, stderr, output, maxheight)
|
switchQuickCommandResult(stdout, stderr, output, autoScroll, autoHeight)
|
||||||
})
|
})
|
||||||
} 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, maxheight)
|
switchQuickCommandResult(stdout, stderr, output, autoScroll, autoHeight)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switchQuickCommandResult = (stdout, stderr, output, maxheight) => {
|
switchQuickCommandResult = (stdout, stderr, output, autoScroll, autoHeight) => {
|
||||||
|
var outputAutoFix = (autoScroll, autoHeight) => {
|
||||||
|
var outputHeight = $("#out").height() + 26
|
||||||
|
if (outputHeight > 600) outputHeight = 600
|
||||||
|
if (autoHeight) utools.setExpendHeight(outputHeight);
|
||||||
|
if (outputHeight == 600 && autoScroll) $(document).scrollTop($(document).height());
|
||||||
|
}
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
$("#out").addClass('error')
|
$("#out").addClass('error')
|
||||||
// 报错
|
// 报错
|
||||||
if (output == 'text' || output == 'html')
|
if (output == 'text' || output == 'html')
|
||||||
{
|
{
|
||||||
utools.setExpendHeight(600);
|
|
||||||
$("#out").append(stderr)
|
$("#out").append(stderr)
|
||||||
|
outputAutoFix(autoScroll, autoHeight)
|
||||||
} else {
|
} else {
|
||||||
var index = utools.showMessageBox({
|
var index = utools.showMessageBox({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
@ -146,12 +150,12 @@ switchQuickCommandResult = (stdout, stderr, output, maxheight) => {
|
|||||||
// 有输出
|
// 有输出
|
||||||
switch (output) {
|
switch (output) {
|
||||||
case "text":
|
case "text":
|
||||||
if(maxheight) utools.setExpendHeight(600);
|
|
||||||
$("#out").append(htmlEncode(stdout, true))
|
$("#out").append(htmlEncode(stdout, true))
|
||||||
|
outputAutoFix(autoScroll, autoHeight)
|
||||||
break;
|
break;
|
||||||
case "html":
|
case "html":
|
||||||
if(maxheight) utools.setExpendHeight(600);
|
|
||||||
$("#out").append(stdout)
|
$("#out").append(stdout)
|
||||||
|
outputAutoFix(autoScroll, autoHeight)
|
||||||
break;
|
break;
|
||||||
case "clip":
|
case "clip":
|
||||||
copyTo(stdout)
|
copyTo(stdout)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user