添加c、c#、wsl支持

This commit is contained in:
fofolee 2020-06-22 00:54:54 +08:00
parent 528c60825f
commit 21d2f52ee9
4 changed files with 58 additions and 39 deletions

View File

@ -133,6 +133,18 @@ let programs = {
argv: '',
ext: 'php'
},
c: {
bin: 'gcc',
argv: '-o',
ext: 'c',
codec: utools.isWindows() ? 'gbk' : ''
},
csharp: {
bin: 'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe',
argv: '/Nologo',
ext: 'cs',
codec: 'gbk'
},
lua: {
bin: 'lua',
argv: '',
@ -289,7 +301,7 @@ let showCustomize = () => {
<option value="ignore">隐藏并忽略输出</option>
<option value="text">显示纯文本输出</option>
<option value="html">显示html格式的输出</option>
<option value="terminal" id="showInTerm">在终端显示输出</option>
<option value="terminal" id="showInTerm" disabled>在终端显示输出</option>
<option value="clip">复制到剪贴板</option>
<option value="send">发送到活动窗口</option>
<option value="notice">发送系统通知</option>
@ -485,18 +497,19 @@ let programCheck = () => {
case 'custom':
$('.customscript').show();
$('.simulation').hide();
$('#showInTerm').show()
$('#showInTerm').prop("disabled", false);
break;
case 'simulation':
$('.simulation').show();
$('.customscript').hide();
$('#showInTerm').hide()
$('#showInTerm').prop("disabled", true);
mode = 'javascript';
break;
default:
$('.customscript').hide();
$('.simulation').hide();
$('#showInTerm').show()
$('#showInTerm').prop("disabled", false);
(mode == 'csharp' || mode == 'c') && (mode = 'text/x-' + mode)
break;
}
window.editor.setOption("mode", mode);

BIN
src/logo/c.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
src/logo/csharp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -448,17 +448,31 @@ runCodeFile = (cmd, option, terminal, callback) => {
// 批处理和 powershell 默认编码为 GBK, 解决批处理的换行问题
if (ext == 'bat' || ext == 'ps1') cmd = iconv.encode(cmd.replace(/\n/g, '\r\n'), 'GBK');
fs.writeFileSync(script, cmd);
var argvs = [script]
if (argv) {
argvs = argv.split(' ')
argvs.push(script);
// var argvs = [script]
// if (argv) {
// argvs = argv.split(' ')
// argvs.push(script);
// }
var child, cmdline
if (bin.slice(-7) == 'csc.exe') {
cmdline = `pushd "${path.dirname(script)}" && ${bin} ${argv} "${script}" && "${script.slice(0, -2) + 'exe'}"`
} else if (bin == 'gcc') {
var suffix = utools.isWindows() ? '.exe' : ''
cmdline = `pushd "${path.dirname(script)}" && ${bin} ${argv} ${script.slice(0, -2)} "${script}" && "${script.slice(0, -2) + suffix}"`
} else if (utools.isWindows() && bin == 'bash') {
cmdline = `${bin} ${argv} "${script.replace(/\\/g, '/').replace(/C:/i, '/mnt/c')}"`
} else {
cmdline = `${bin} ${argv} "${script}"`
}
var child;
if (bin) {
// 在终端中输出
if (terminal) {
if (utools.isWindows()) {
child = child_process.spawn(`start cmd /k ${bin} ${argv} "${script}"`, { encoding: 'buffer', shell: true })
if (bin.slice(-7) == 'csc.exe' || bin == 'gcc') {
cmdline = cmdline.split("&&")
cmdline = cmdline[0] + "&&" + cmdline[1] + "&& start cmd /k " + cmdline[2]
} else {
cmdline = `start cmd /k ${cmdline}`
}
} else if(utools.isMacOs()){
var appleScript = `if application "Terminal" is running then
tell application "Terminal"
@ -473,20 +487,12 @@ runCodeFile = (cmd, option, terminal, callback) => {
activate
end tell
end if`;
child = child_process.spawn('osascript', ['-e', appleScript], { encoding: 'buffer' })
cmdline = `osascript -e '${appleScript}'`
} else {
return message('Linux 不支持在终端输出')
}
} else {
child = child_process.spawn(bin, argvs, { encoding: 'buffer' })
}
} else {
if (terminal) {
child = child_process.spawn(`start cmd /k "${script}"`, { encoding: 'buffer', shell: true })
} else {
child = child_process.spawn(script, { encoding: 'buffer' })
}
}
child = child_process.spawn(cmdline, { encoding: 'buffer', shell: true })
// var chunks = [],
// err_chunks = [];
child.stdout.on('data', chunk => {