diff --git a/css/style.css b/css/style.css index 8114aba1f1..c7c36fd53c 100644 --- a/css/style.css +++ b/css/style.css @@ -718,32 +718,33 @@ div.runCode { margin: 1em 0 1em 3em; } -div.d_code_output, textarea.d_code_stdin, textarea.d_code_args +textarea.d_code_output, textarea.d_code_stdin, textarea.d_code_args { text-align: left; border: none; width: 98%; - font-size: 12px; + font-size: 1.09em; font-family: monospace; padding: 5px; margin: 1px; - max-height: 150px; - overflow: auto; word-wrap: break-word; - height: 150px; + height: auto; background: white; + margin-left: 2px; + outline: none; } -div.d_code_output_div, div.d_code_stdin, div.d_code_args +div.d_code_output, div.d_code_stdin, div.d_code_args { border: 1px solid #CCC; background: white; display: none; + height: auto; + width: 100%; } .CodeMirror-lines {background: white;} -.CodeMirror {line-height: 1.2em; font-size: 1.2em; - border: 1px solid #CCC;} +.CodeMirror {line-height: 1.2em; font-size: 1.2em;border: 1px solid #CCC;} .cm-s-eclipse span.cm-word {color: #006;} .cm-s-eclipse span.cm-meta {color: #FF1717;} .cm-s-eclipse span.cm-keyword { color: blue; } diff --git a/doc.ddoc b/doc.ddoc index 8f3bf09c33..919ac2c2b6 100644 --- a/doc.ddoc +++ b/doc.ddoc @@ -15,7 +15,7 @@ DDOC= $(TITLE) - D Programming Language - + @@ -386,10 +386,11 @@ D_PSYMBOL = $0 D_PARAM = $0 D_RUN_CODE =
+
Standard input
Command line arguments
-
Application output
Running...
+
Application output
diff --git a/index.dd b/index.dd index 28f3a18173..094616f606 100644 --- a/index.dd +++ b/index.dd @@ -5,23 +5,11 @@ $(D_S D Programming Language, $(SECTION3 The D programming language. Modern convenience. Modeling power. Native efficiency., - -
[your code here] - Got a brief example illustrating D? Submit your code to the digitalmars.D forum specifying "[your code here]" in the title. Upon approval it will be showcased on a random schedule on D‘s homepage. + Got a brief example illustrating D? Submit your code to the digitalmars.D forum specifying "[your code here]" in the title. Upon approval it will be showcased on a random schedule on D's homepage.
@@ -62,11 +50,6 @@ void main() { $(ARGS Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tristique rutrum sem, nec convallis enim bibendum ut. Donec ac dolor tortor, sit amet consequat turpis. In hac habitasse platea dictumst. Fusce lacus dolor, sodales ac consequat eu, ultricies et leo. In commodo scelerisque urna non posuere. Sed justo ipsum, consectetur nec sodales in, faucibus ut nunc. Phasellus nunc metus, mollis eu malesuada at, scelerisque eget nulla. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus ac velit vel massa faucibus sagittis ut quis lectus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam convallis dolor quis nunc viverra suscipit. Nam egestas pretium enim, sit amet tincidunt orci condimentum sit amet. Duis accumsan elit vehicula nisl tincidunt hendrerit. Nunc nec augue velit, ac lacinia nunc.), $(ARGS)) -$(TAG2 div, id="your-code-info" style="display:block; position:relative; width: 50%; margin-left:auto; top:-2.5em; bottom:0em; background:white; border:1px solid #ccc; font-size:80%; padding:0px 5px 0px 5px; line-height:1.4em;", - -) - - D is a language with C-like syntax and static typing. It pragmatically combines efficiency, control, and modeling power, with safety and programmer productivity. diff --git a/js/d.js b/js/d.js index cf491f0453..de0a5ca33e 100644 --- a/js/d.js +++ b/js/d.js @@ -154,62 +154,8 @@ CodeMirror.defineMode("clike", function(config, parserConfig) { for (var i = 0; i < words.length; ++i) obj[words[i]] = true; return obj; } - var cKeywords = "auto if break int case long char register continue return default short do sizeof " + - "double static else struct entry switch extern typedef float union for unsigned " + - "goto while enum void const signed volatile"; - function cppHook(stream, state) { - if (!state.startOfLine) return false; - stream.skipToEnd(); - return "meta"; - } - - // C#-style strings where "" escapes a quote. - function tokenAtString(stream, state) { - var next; - while ((next = stream.next()) != null) { - if (next == '"' && !stream.eat('"')) { - state.tokenize = null; - break; - } - } - return "string"; - } - - CodeMirror.defineMIME("text/x-csrc", { - name: "clike", - keywords: words(cKeywords), - blockKeywords: words("case do else for if switch while struct"), - atoms: words("null"), - hooks: {"#": cppHook} - }); - CodeMirror.defineMIME("text/x-c++src", { - name: "clike", - keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " + - "static_cast typeid catch operator template typename class friend private " + - "this using const_cast inline public throw virtual delete mutable protected " + - "wchar_t"), - blockKeywords: words("catch class do else finally for if struct switch try while"), - atoms: words("true false null"), - hooks: {"#": cppHook} - }); - CodeMirror.defineMIME("text/x-java", { - name: "clike", - keywords: words("abstract assert boolean break byte case catch char class const continue default " + - "do double else enum extends final finally float for goto if implements import " + - "instanceof int interface long native new package private protected public " + - "return short static strictfp super switch synchronized this throw throws transient " + - "try void volatile while"), - blockKeywords: words("catch class do else finally for if switch try while"), - atoms: words("true false null"), - hooks: { - "@": function(stream, state) { - stream.eatWhile(/[\w\$_]/); - return "meta"; - } - } - }); - CodeMirror.defineMIME("text/x-csharp", { + CodeMirror.defineMIME("text/x-d", { name: "clike", keywords: words("abstract alias align assert auto body bool break byte case cast catch cdouble cent cfloat" + " char class const continue creal dchar debug default delegate delete deprecated double dstring" + @@ -222,14 +168,6 @@ CodeMirror.defineMode("clike", function(config, parserConfig) { atoms: words("asm catch class debug do else exit failure finally for foreach foreach_reverse if struct switch synchronized unittest version try while with "), hooks: { - "@": function(stream, state) { - if (stream.eat('"')) { - state.tokenize = tokenAtString; - return tokenAtString(stream, state); - } - stream.eatWhile(/[\w\$_]/); - return "meta"; - } } }); }()); diff --git a/js/run.js b/js/run.js index 9d663281df..4865578b42 100644 --- a/js/run.js +++ b/js/run.js @@ -1,6 +1,15 @@ +/** +Runnable examples functionality + +Copyright: Damian Ziemba 2012 + +License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 + +Authors: Andrei Alexandrescu, Damian Ziemba +*/ String.prototype.nl2br = function() -{ - return this.replace(/\n/g, "
"); +{ + return this.replace(/\n/g, "
"); } function showHideAnswer(zis) @@ -20,46 +29,55 @@ function showHideAnswer(zis) } } -function parseOutput(data) +function parseOutput(data, o, oTitle) { - output = ""; - var json = jQuery.parseJSON(data); - if (json == null) + var xml = $(data); + if (xml == null || xml.find("response") == null) { - output = "
Temporarily unavaible
"; - return output; + o.text("Temporarily unavaible"); + return; } - /* - * Escape html/script/etc - */ - var cout = $('
').text(json["compilation"]["stdout"]).html(); - var stdout = $('
').text(json["runtime"]["stdout"]).html(); - var stderr = $('
').text(json["runtime"]["stderr"]).html(); - - if (json["compilation"]["status"] != 0) + var output = ""; + var cout = xml.find("response").find("compilation").find("stdout").text(); + var stdout = xml.find("response").find("runtime").find("stdout").text(); + var stderr = xml.find("response").find("runtime").find("stderr").text(); + var ctime = parseInt(xml.find("response").find("compilation").find("time").text()); + var rtime = parseInt(xml.find("response").find("runtime").find("time").text()); + var cstatus = parseInt(xml.find("response").find("compilation").find("status").text()); + var rstatus = parseInt(xml.find("response").find("runtime").find("status").text()); + var cerr = xml.find("response").find("compilation").find("err").text(); + var rerr = xml.find("response").find("runtime").find("err").text(); + + if (cstatus != 0) { - output = 'Compilation failure:
'+ cout + "
"; + oTitle.text("Compilation output ("+cstatus+": "+cerr+")"); + if ($.browser.msie) + o.html(cout.nl2br()); + else + o.text(cout); + + return; } else { + oTitle.text("Application output");// (compile "+ctime+"ms, run "+rtime+"ms)"); if ( cout != "") - { - output = 'Compilation output:
' - + '
' + cout + "

"; - } - output += (stdout == "" && stderr == "" ? - '
-- No output --
' : '
'+stdout); + output = 'Compilation output: \n' + cout + "\n"; + + output += (stdout == "" && stderr == "" ? '-- No output --' : stdout); if (stderr != "") - { output += stderr; - } - output += "
"; + if (rstatus != 0) + oTitle.text("Application output ("+rstatus+": "+rerr+")"); } - return output.nl2br(); + if ($.browser.msie) + o.html(output.nl2br()); + else + o.text(output); } $(document).ready(function() @@ -67,37 +85,38 @@ $(document).ready(function() $('textarea[class=d_code]').each(function(index) { var thisObj = $(this); - var p = thisObj.parent(); - var codeStr = thisObj.val(); - p.css("display", "block"); - var originalSource = thisObj.val(); + var parent = thisObj.parent(); + parent.css("display", "block"); - var editor = CodeMirror.fromTextArea(thisObj[0], { - lineNumbers: false, - tabSize: 4, - indentUnit: 4, - indentWithTabs: true, - mode: "text/x-csharp", - lineWrapping: true, - theme: "eclipse", - readOnly: false, - onChange: function (editor, event) { - codeStr = editor.getValue(); - }, + lineNumbers: false, + tabSize: 4, + indentUnit: 4, + indentWithTabs: true, + mode: "text/x-d", + lineWrapping: true, + theme: "eclipse", + readOnly: false, + matchBrackets: true }); - - var runBtn = p.children("input.runButton"); - var editBtn = p.children("input.editButton"); - var inputBtn = p.children("input.inputButton"); - var resetBtn = p.children("input.resetButton"); - var argsBtn = p.children("input.argsButton"); - var stdinDiv = p.children("div.d_code_stdin"); - var argsDiv = p.children("div.d_code_args"); - var outputDiv = p.children("div.d_code_output_div"); + var height = function(diff) { + return (parseInt(code.css('height')) - diff) + 'px'; + }; + if ($.browser.webkit) + editor.setValue(parent.children("div.d_code_src").text()); + + var runBtn = parent.children("input.runButton"); + var editBtn = parent.children("input.editButton"); + var inputBtn = parent.children("input.inputButton"); + var resetBtn = parent.children("input.resetButton"); + var argsBtn = parent.children("input.argsButton"); + var stdinDiv = parent.children("div.d_code_stdin"); + var argsDiv = parent.children("div.d_code_args"); + var outputDiv = parent.children("div.d_code_output"); var code = $(editor.getWrapperElement()); - var output = outputDiv.children("div.d_code_output"); + var output = outputDiv.children("textarea.d_code_output"); + var outputTitle = outputDiv.children("span.d_code_title"); var stdin = stdinDiv.children("textarea.d_code_stdin"); var args = argsDiv.children("textarea.d_code_args"); @@ -107,42 +126,40 @@ $(document).ready(function() argsDiv.css('display', 'none'); outputDiv.css('display', 'none'); code.css('display', 'none'); - - inputBtn.removeClass('test'); - argsBtn.removeClass('test'); - runBtn.removeClass('test'); - editBtn.removeClass('test'); }; - var originalStdin = stdin.val(); - var originalArgs = args.val(); - argsBtn.click(function(){ + args.css('height', height(37)); hideAllWindows(); argsDiv.css('display', 'block'); - $(this).addClass('test'); + args.focus(); }); inputBtn.click(function(){ + stdin.css('height', height(37)); hideAllWindows(); stdinDiv.css('display', 'block'); - $(this).addClass('test'); + stdin.focus(); }); editBtn.click(function(){ hideAllWindows(); code.css('display', 'block'); - $(this).addClass('test'); + editor.focus(); }); runBtn.click(function(){ $(this).attr("disabled", true); hideAllWindows(); + output.css('height', height(37)); outputDiv.css('display', 'block'); + outputTitle.text("Application output"); output.html("Running..."); - + output.focus(); + $.ajax({ type: 'POST', url: "/process.php", + dataType: "xml", data: { 'code' : encodeURIComponent(editor.getValue()), @@ -151,12 +168,12 @@ $(document).ready(function() }, success: function(data) { - output.html(parseOutput(data)); + parseOutput(data, output, outputTitle); runBtn.attr("disabled", false); }, error: function() { - output.html("
Temporarily unavaible
"); + output.html("Temporarily unavaible"); runBtn.attr("disabled", false); } }); diff --git a/process.php b/process.php index c84fdde04b..627b34b402 100644 --- a/process.php +++ b/process.php @@ -1,4 +1,13 @@