From 4f4b1a97d3a2c6962fb9c1c230ab054deed82926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Wed, 2 Sep 2015 22:02:29 +0200 Subject: Bugfixed CodeQ Console, loaded it from prolog.html, added CSS and cursor blinking. --- css/codeq/console.css | 17 +++++++++++++++++ js/codeq/console.js | 42 +++++++++++++++++++++++++++++++----------- prolog.html | 2 ++ 3 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 css/codeq/console.css diff --git a/css/codeq/console.css b/css/codeq/console.css new file mode 100644 index 0000000..3e00913 --- /dev/null +++ b/css/codeq/console.css @@ -0,0 +1,17 @@ +.cq-con { + background: black; + color: greenyellow; + font-family: "Courier Menlo", Monaco, Consolas, "Courier New", monospace; + font-size: medium; +} +.cq-con-text { + +} +.cq-con-cursor { + color: black; + background: greenyellow; +} +.cq-con-cursor.inverted { + color: greenyellow; + background: black; +} diff --git a/js/codeq/console.js b/js/codeq/console.js index bc7f3c6..023fcc1 100644 --- a/js/codeq/console.js +++ b/js/codeq/console.js @@ -161,11 +161,11 @@ codeq.makeConsole = function (jqElt, options) { var lines = [], // console content - maxLines = options.maxLines || 10000, // how many lines to display at most + maxLines = (options && options.maxLines) || 10000, // how many lines to display at most currentRow = 0, // cursor position currentCol = 0, - jqContent = $('
'), // the rendering of the console - jqInput = $(''), // for receiving keypresses, clipboard content + jqContent = $('
'), // the rendering of the console + jqInput = $(''), // for receiving keypresses, clipboard content inputDisabled = false, // whether to ignore input lineBuffered = true, // whether we are line-buffered or not buffered @@ -217,7 +217,7 @@ jqLine.append(jq1); jqLine.append(jqCursor); jqLine.append(jq2); - jq1.text(content.substr(0, currentCol - 1)); + jq1.text(content.substr(0, currentCol)); jqCursor.text(content.charAt(currentCol)); jq2.text(content.substr(currentCol + 1)); } @@ -516,6 +516,10 @@ 'destroy': function () { var n = lines.length, i, lineDescriptor; + if (blinkTimer !== null) { + clearInterval(blinkTimer); + blinkTimer = null; + } // detach all jQuery objects from internal structures for (i = 0; i < n; i++) { lineDescriptor = lines[i]; @@ -601,6 +605,8 @@ clipboardPasteInProgress = false, // whether the previous keydown was a CTRL+V or shift+insert aKeyIsDown = false, // whether a key is currently pressed: if it's not and there is input, then we got a paste via mouse + cursorBlinkRate = (options && options.cursorBlinkRate) || 750, // default: 750 ms + blinkTimer = null, i, j, a, b, c; // copy default key handlers @@ -668,23 +674,37 @@ // the element supports input events, use them in preference to keypress events jqInput.on('input', function (evt) { // this event cannot be prevented/cancelled in the DOM scheme of things, but we can simulate prevention, because we have a "detached" display - handleInput(evt.input); + var t = jqInput.val(); + jqInput.val(''); + handleInput(t); }); } else { // the element does not support the "modern" input events, so it ought to support the old keypress events jqInput.on('keypress', function (evt) { // this event cannot be prevented/cancelled in the DOM scheme of things, but we can simulate prevention, because we have a "detached" display - var keyChar = false; - if ('char' in evt) keyChar = evt.char; - else if ('charCode' in evt) keyChar = String.fromCharCode(evt.charCode); - else return; // ignore input - handleInput(keyChar); + var keyChar; + try { + if ('char' in evt) keyChar = evt.char; + else if ('charCode' in evt) keyChar = String.fromCharCode(evt.charCode); + else return; // ignore input + handleInput(keyChar); + } + finally { + jqInput.val(''); + } }); } + // start the cursor blinking if so instructed + if ((typeof cursorBlinkRate === 'number') && (cursorBlinkRate >= 50)) { // have some sense of sanity + blinkTimer = setInterval(function () { + jqContent.find('.cq-con-cursor').toggleClass('inverted'); + }, cursorBlinkRate); + } + // emit greeting if provided - if (options.greeting) { + if (options && options.greeting) { lines.push({content: options.greeting, className: 'greeting'}); currentRow++; } diff --git a/prolog.html b/prolog.html index 5dbfde9..c3e80b2 100644 --- a/prolog.html +++ b/prolog.html @@ -15,6 +15,7 @@ + @@ -96,6 +97,7 @@ + -- cgit v1.2.1