diff --git a/src/assets/index.js b/src/assets/index.js index aeb5e24..a982b9c 100644 --- a/src/assets/index.js +++ b/src/assets/index.js @@ -1,12 +1,20 @@ utools.onPluginEnter(async ({ code, type, payload }) => { utools.onPluginOut(() => { - var program = $('#program').val(); - $("#options").empty() - $("#out").empty() if (code == "code") { var cmd = window.editor.getValue(); - putDB('history', { cmd: cmd, program: program }, 'codeHistory') + var program = $('#program').val(), + scptarg = $('#scptarg').val(), + customoptions; + if (program == 'custom') customoptions = { + custombin: $('#custombin').val(), + customarg: $('#customarg').val(), + customext: $('#customext').val(), + customcodec: $('#customcodec').val() + } + putDB('history', { cmd: cmd, program: program, scptarg: scptarg, customoptions: customoptions }, 'codeHistory') } + $("#options").empty() + $("#out").empty() }) // 配置页面 if (code == 'options') { @@ -31,6 +39,7 @@ utools.onPluginEnter(async ({ code, type, payload }) => { }else{ option = programs[db.program]; } + option.scptarg = db.scptarg cmd = special(cmd); // 正则 if (type == 'regex') cmd = cmd.replace(/\{\{input\}\}/mg, payload); diff --git a/src/assets/options.js b/src/assets/options.js index ed09bbd..e852968 100644 --- a/src/assets/options.js +++ b/src/assets/options.js @@ -309,9 +309,10 @@ let showCustomize = () => {
脚 本 + - - + + @@ -497,14 +498,18 @@ let programCheck = () => { let mode = $('#program').val(); $('.customscript').hide(); $('.simulation').hide(); + $('#scptarg').show(); $('#showInTerm').prop("disabled", false); if (!hasCustomIcon()) $("#icon").attr('src', `logo/${mode}.png`); switch (mode) { case 'custom': $('.customscript').show(); + var customext = $('#customext').val() + customext && (mode = highlightIfKnown(customext)) break; case 'simulation': $('.simulation').show(); + $('#scptarg').hide(); $('#showInTerm').prop("disabled", true); mode = 'javascript'; break; @@ -578,6 +583,7 @@ $("#options").on('click', '.editBtn', function () { $('#program').val(data.program).trigger("change"); $('#output').val(data.output).trigger("change"); $('#desc').val(data.features.explain); + $('#scptarg').val(data.scptarg); $("#icon").attr('src', data.features.icon); let mode = data.program; if (mode == 'custom') { @@ -718,6 +724,7 @@ let SaveCurrentCommand = async () => { var code = `${type}_${uid}`; } var output = $('#output').val(); + var scptarg = $('#scptarg').val(); var cmd = window.editor.getValue(); // 合规性校验 if (type == 'key' @@ -812,7 +819,8 @@ let SaveCurrentCommand = async () => { program: program, cmd: cmd, output: output, - hasSubInput: hasSubInput + hasSubInput: hasSubInput, + scptarg: scptarg } if (tags) pushData.tags = tags if (program == 'custom') { @@ -933,6 +941,7 @@ let runCurrentCommand = async () => { "ext": $('#customext').val(), 'codec': $('#customcodec').val() } + option.scptarg = $('#scptarg').val() runCodeFile(cmd, option, terminal, (stdout, stderr) => { if (terminal) return if (stderr) return showRunResult(stderr, raw, false) @@ -955,30 +964,35 @@ let quitCurrentCommand = () => { } let highlightIfKnown = ext => { - // 未设置后缀时有自动补全bug var lang = Object.keys(programs).filter(p => programs[p].ext == ext) - if (lang.length) window.editor.setOption("mode", lang[0]) + if (lang.length) { + if (lang[0] == 'python') getPythonMods() + window.editor.setOption("mode", lang[0]) + return lang[0] + } } showCodeEditor = file => { let options = `` - var customWindow = `