mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-12-20 02:47:30 +08:00
简化RunCode编码参数结构,新增ScriptEditor组件,优化CodeEditor代码提示
This commit is contained in:
@@ -273,9 +273,8 @@ export default {
|
||||
* @param options 选项
|
||||
* @param options.language 编程语言
|
||||
* @param options.args 脚本参数
|
||||
* @param options.charset 编码
|
||||
* @param options.charset.scriptCode 脚本编码
|
||||
* @param options.charset.outputCode 输出编码
|
||||
* @param options.scriptCode 脚本文件编码
|
||||
* @param options.outputCode 命令行输出编码
|
||||
* @param options.runInTerminal 终端运行参数,不传则不在终端运行
|
||||
* @param options.runInTerminal.dir 运行目录
|
||||
* @param options.runInTerminal.windows windows使用的终端,默认wt
|
||||
@@ -286,11 +285,20 @@ export default {
|
||||
const isWin = window.utools.isWindows();
|
||||
const {
|
||||
language = isWin ? "cmd" : "shell",
|
||||
charset = {},
|
||||
args = [],
|
||||
runInTerminal,
|
||||
} = options;
|
||||
|
||||
if (!options.scriptCode) {
|
||||
options.scriptCode = ["cmd", "powershell"].includes(language)
|
||||
? "gbk"
|
||||
: "utf-8";
|
||||
}
|
||||
|
||||
if (!options.outputCode) {
|
||||
options.outputCode = isWin ? "gbk" : "utf-8";
|
||||
}
|
||||
|
||||
// 兼容编排,传入true时,使用默认终端
|
||||
const runInTerminalOptions =
|
||||
runInTerminal === true ? {} : runInTerminal;
|
||||
@@ -306,23 +314,20 @@ export default {
|
||||
}
|
||||
const argsStr = args.map(unescapeAndQuote).join(" ");
|
||||
|
||||
const defaultCharset =
|
||||
isWin && ["cmd", "powershell"].includes(language) ? "gbk" : "utf-8";
|
||||
|
||||
const { scriptCode = defaultCharset, outputCode = defaultCharset } =
|
||||
charset;
|
||||
|
||||
window.runCodeFile(
|
||||
code,
|
||||
{
|
||||
...programs[language],
|
||||
charset: { scriptCode, outputCode },
|
||||
charset: {
|
||||
scriptCode: options.scriptCode,
|
||||
outputCode: options.outputCode,
|
||||
},
|
||||
scptarg: argsStr,
|
||||
},
|
||||
runInTerminalOptions,
|
||||
(result, err) => (err ? reject(err) : reslove(result))
|
||||
(result, err) => (err ? reject(err) : reslove(result)),
|
||||
false
|
||||
);
|
||||
false;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user