重构 runCode 方法:将参数由 program 改为 options,支持更多配置选项,包括编程语言、脚本参数和编码设置,同时更新 API 文档

This commit is contained in:
fofolee
2025-01-24 23:53:57 +08:00
parent e574471689
commit dcd392ba47
2 changed files with 94 additions and 26 deletions

View File

@@ -652,38 +652,63 @@ interface quickcommandApi {
/**
* 运行代码
* @param code 代码
* @param program 编程语言
* @param runInTerminal 终端运行参数,不传则不在终端运行
* @param runInTerminal.dir 运行目录
* @param runInTerminal.windows windows使用的终端默认wt
* @param runInTerminal.macos macos使用的终端默认warp
* @param options 选项
* @param options.language 编程语言不传时则根据操作系统选择cmd或是shell
* @param options.args 脚本参数
* @param options.charset 编码不传时则根据操作系统及语言选择utf-8或是gbk
* @param options.charset.scriptCode 脚本编码
* @param options.charset.outputCode 输出编码
* @param options.runInTerminal 终端运行参数,不传则不在终端运行
* @param options.runInTerminal.dir 运行目录
* @param options.runInTerminal.windows windows使用的终端默认wt
* @param options.runInTerminal.macos macos使用的终端默认warp
*
* 支持的编程语言:
* shell, applescript, cmd, python, powershell, javascript, ruby, php, lua, perl, csharp, c
*
* ```js
* quickcommand.runCode("print('Hello, World!');", "python");
* const script = `
* import sys
* print(sys.argv[1])
* `
* const options = {
* language: "python",
* args: ["hello world"]
* }
* quickcommand.runCode(script, options).then(result => {
* console.log(result)
* }).catch(e => {
* console.log(e)
* })
* ```
*/
runCode(
code: string,
program:
| "shell"
| "applescript"
| "cmd"
| "python"
| "powershell"
| "javascript"
| "ruby"
| "php"
| "lua"
| "perl"
| "csharp"
| "c",
runInTerminal?: {
dir?: string;
windows?: "wt" | "cmd";
macos?: "warp" | "iterm" | "terminal";
options: {
language:
| "shell"
| "applescript"
| "cmd"
| "python"
| "powershell"
| "javascript"
| "ruby"
| "php"
| "lua"
| "perl"
| "csharp"
| "c";
args?: string[];
charset?: {
scriptCode?: string;
outputCode?: string;
};
runInTerminal?: {
dir?: string;
windows?: "wt" | "cmd";
macos?: "warp" | "iterm" | "terminal";
};
}
): Promise<string>;
}