This commit is contained in:
fofolee 2020-06-22 23:00:23 +08:00
parent 21d2f52ee9
commit de580d8668
3 changed files with 56 additions and 36 deletions

View File

@ -337,12 +337,14 @@ let showCustomize = () => {
createEditor() createEditor()
$('#program, #type, #output').select2({ $('#program, #type, #output').select2({
width: '40%', width: '40%',
minimumResultsForSearch: Infinity minimumResultsForSearch: Infinity,
dropdownParent: $("#customize")
}); });
$('#vars').select2({ $('#vars').select2({
width: '40%', width: '40%',
placeholder: "插入特殊变量", placeholder: "插入特殊变量",
minimumResultsForSearch: Infinity minimumResultsForSearch: Infinity,
dropdownParent: $("#customize")
}); });
$('#tags').select2({ $('#tags').select2({
width: '40%', width: '40%',
@ -350,7 +352,8 @@ let showCustomize = () => {
tags: true, tags: true,
allowClear: true, allowClear: true,
tokenSeparators: [',', ' '], tokenSeparators: [',', ' '],
maximumSelectionLength: 3 maximumSelectionLength: 3,
dropdownParent: $("#customize")
}); });
$("#customize").animate({ top: '0px' }); $("#customize").animate({ top: '0px' });
} }
@ -972,7 +975,8 @@ showCodeEditor = () => {
` `
$("#options").html(customWindow) $("#options").html(customWindow)
createEditor() createEditor()
$(".CodeMirror").css({ height: '41rem' }) $(".CodeMirror").css({ height: '580px' })
$(".robot").css({ "margin-bottom": "5px" });
$("#customize").css({ top: '0px', padding: '0px' }); $("#customize").css({ top: '0px', padding: '0px' });
$("span.customscript > input").css({"height": "30px"}) $("span.customscript > input").css({"height": "30px"})
var db = getDB('codeHistory') var db = getDB('codeHistory')
@ -984,7 +988,8 @@ showCodeEditor = () => {
programCheck() programCheck()
$('#program').select2({ $('#program').select2({
width: 100, width: 100,
minimumResultsForSearch: Infinity minimumResultsForSearch: Infinity,
dropdownParent: $("#customize")
}); });
$("#options").show() $("#options").show()
} }

View File

@ -523,9 +523,9 @@ input::-webkit-input-placeholder {
transition: 0.5s; transition: 0.5s;
} }
::-webkit-scrollbar { /* ::-webkit-scrollbar {
height: 0; height: 0;
} } */
li.CodeMirror-hint { li.CodeMirror-hint {
min-width: 200px; min-width: 200px;

View File

@ -81,7 +81,7 @@ const quickcommand = {
showInputBox: function (callback, placeHolders) { showInputBox: function (callback, placeHolders) {
let helps = `正确用法: let helps = `正确用法:
showInputBox(yourinput => { quickcommand.showInputBox(yourinput => {
do something... do something...
}, [placeholder of input1, placeholder of input2...])` }, [placeholder of input1, placeholder of input2...])`
if (!(callback instanceof Function)) throw helps if (!(callback instanceof Function)) throw helps
@ -109,8 +109,10 @@ const quickcommand = {
showSelectBox: function (callback, selects) { showSelectBox: function (callback, selects) {
let helps = `正确用法: let helps = `正确用法:
showSelectBox(yourchoise => { quickcommand.showSelectBox(choise => {
do something... var index = choise.index
var text = choise.text
//do something...
}, [option1, option2...])` }, [option1, option2...])`
if (!(callback instanceof Function)) throw helps if (!(callback instanceof Function)) throw helps
if (!(selects instanceof Array) || (selects && !selects.length)) throw helps if (!(selects instanceof Array) || (selects && !selects.length)) throw helps
@ -122,7 +124,7 @@ const quickcommand = {
var selectBoxNumbers = selects.length var selectBoxNumbers = selects.length
modWindowHeight(selectBoxNumbers) modWindowHeight(selectBoxNumbers)
for (let i = 0; i < selectBoxNumbers; i++) { for (let i = 0; i < selectBoxNumbers; i++) {
html += `<option value="${selects[i]}">${selects[i]}</option>` html += `<option value="${i}">${selects[i]}</option>`
} }
html += `</select></div>` html += `</select></div>`
$("body").append(html) $("body").append(html)
@ -135,7 +137,7 @@ const quickcommand = {
$('#quickselect .select2').hide() $('#quickselect .select2').hide()
$('#selectBox').on('select2:select', function (e) { $('#selectBox').on('select2:select', function (e) {
$('#selectBox').off('select2:select'); $('#selectBox').off('select2:select');
callback($(this).val()) callback({ index: $(this).val(), text: selects[$(this).val()] })
$("#quickselect").remove() $("#quickselect").remove()
}) })
$('#quickselect .select2-search__field').bind("input propertychange change",function(event){ $('#quickselect .select2-search__field').bind("input propertychange change",function(event){
@ -145,8 +147,10 @@ const quickcommand = {
showButtonBox: function (callback, buttons) { showButtonBox: function (callback, buttons) {
let helps = `正确用法: let helps = `正确用法:
showButtonBox(yourchoise => { quickcommand.showButtonBox(yourchoise => {
do something... var index = choise.index
var text = choise.text
//do something...
}, [button1, button2...])` }, [button1, button2...])`
if (!(callback instanceof Function)) throw helps if (!(callback instanceof Function)) throw helps
if (!(buttons instanceof Array) || (buttons && !buttons.length)) throw helps if (!(buttons instanceof Array) || (buttons && !buttons.length)) throw helps
@ -258,20 +262,30 @@ runCodeInVm = (cmd, cb) => {
// shell 以环境变量下命令作为代码提示 // shell 以环境变量下命令作为代码提示
getShellCommand = () => { getShellCommand = () => {
var bin = [] var bin = localStorage['shellcommand']
if (bin) {
bin = JSON.parse(bin)
} else {
bin = []
if (!utools.isWindows()) { if (!utools.isWindows()) {
process.env.PATH.split(':').forEach(d => { process.env.PATH.split(':').forEach(d => {
try { try {
bin = bin.concat(fs.readdirSync(d).filter(x => x[0] != ".")) bin = bin.concat(fs.readdirSync(d).filter(x => x[0] != "."))
} catch (e) { } } catch (e) { }
}) })
localStorage['shellcommand'] = JSON.stringify(bin)
}
} }
return bin return bin
} }
// cmd 以环境变量下命令作为代码提示 // cmd 以环境变量下命令作为代码提示
getCmdCommand = () => { getCmdCommand = () => {
var bin = [] var bin = localStorage['cmdcommand']
if (bin) {
bin = JSON.parse(bin)
} else {
bin = []
if (utools.isWindows()) { if (utools.isWindows()) {
process.env.Path.split(';').forEach(d => { process.env.Path.split(';').forEach(d => {
try { try {
@ -279,6 +293,8 @@ getCmdCommand = () => {
} catch (e) { } } catch (e) { }
}) })
bin = bin.concat(bin).join("|").replace(/\.exe/g, '').split("|") bin = bin.concat(bin).join("|").replace(/\.exe/g, '').split("|")
localStorage['cmdcommand'] = JSON.stringify(bin)
}
} }
return bin return bin
} }
@ -455,10 +471,10 @@ runCodeFile = (cmd, option, terminal, callback) => {
// } // }
var child, cmdline var child, cmdline
if (bin.slice(-7) == 'csc.exe') { if (bin.slice(-7) == 'csc.exe') {
cmdline = `pushd "${path.dirname(script)}" && ${bin} ${argv} "${script}" && "${script.slice(0, -2) + 'exe'}"` cmdline = `${bin} ${argv} /out:"${script.slice(0, -2) + 'exe'}" "${script}" && "${script.slice(0, -2) + 'exe'}"`
} else if (bin == 'gcc') { } else if (bin == 'gcc') {
var suffix = utools.isWindows() ? '.exe' : '' var suffix = utools.isWindows() ? '.exe' : ''
cmdline = `pushd "${path.dirname(script)}" && ${bin} ${argv} ${script.slice(0, -2)} "${script}" && "${script.slice(0, -2) + suffix}"` cmdline = `${bin} ${argv} "${script.slice(0, -2)}" "${script}" && "${script.slice(0, -2) + suffix}"`
} else if (utools.isWindows() && bin == 'bash') { } else if (utools.isWindows() && bin == 'bash') {
cmdline = `${bin} ${argv} "${script.replace(/\\/g, '/').replace(/C:/i, '/mnt/c')}"` cmdline = `${bin} ${argv} "${script.replace(/\\/g, '/').replace(/C:/i, '/mnt/c')}"`
} else { } else {
@ -469,21 +485,19 @@ runCodeFile = (cmd, option, terminal, callback) => {
if (utools.isWindows()) { if (utools.isWindows()) {
if (bin.slice(-7) == 'csc.exe' || bin == 'gcc') { if (bin.slice(-7) == 'csc.exe' || bin == 'gcc') {
cmdline = cmdline.split("&&") cmdline = cmdline.split("&&")
cmdline = cmdline[0] + "&&" + cmdline[1] + "&& start cmd /k " + cmdline[2] cmdline = cmdline[0] + "&& start cmd /k " + cmdline[1]
} else { } else {
cmdline = `start cmd /k ${cmdline}` cmdline = `start cmd /k ${cmdline}`
} }
} else if(utools.isMacOs()){ } else if(utools.isMacOs()){
var appleScript = `if application "Terminal" is running then var appleScript = `if application "Terminal" is running then
tell application "Terminal" tell application "Terminal"
# do script without "in window" will open a new window do script "clear;${cmdline.replace(/"/g, `\\"`)}"
do script "clear;${bin} ${argv} ${script}"
activate activate
end tell end tell
else else
tell application "Terminal" tell application "Terminal"
# window 1 is guaranteed to be recently opened window do script "clear;${cmdline.replace(/"/g, `\\"`)}" in window 1
do script "clear;${bin} ${argv} ${script}" in window 1
activate activate
end tell end tell
end if`; end if`;
@ -495,6 +509,7 @@ runCodeFile = (cmd, option, terminal, callback) => {
child = child_process.spawn(cmdline, { encoding: 'buffer', shell: true }) child = child_process.spawn(cmdline, { encoding: 'buffer', shell: true })
// var chunks = [], // var chunks = [],
// err_chunks = []; // err_chunks = [];
console.log('running: ' + cmdline);
child.stdout.on('data', chunk => { child.stdout.on('data', chunk => {
if (option.codec) chunk = iconv.decode(chunk, option.codec) if (option.codec) chunk = iconv.decode(chunk, option.codec)
callback(chunk, null) callback(chunk, null)