summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--css/codeq/console.css17
-rw-r--r--js/codeq/console.js42
-rw-r--r--prolog.html2
3 files changed, 50 insertions, 11 deletions
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 = $('<div></div>'), // the rendering of the console
- jqInput = $('<textarea style="left: 0; bottom: 0; width: 2px; position: absolute;"></textarea>'), // for receiving keypresses, clipboard content
+ jqContent = $('<div class="cq-con"></div>'), // the rendering of the console
+ jqInput = $('<textarea style="left: -9999px; bottom: 0; width: 2px; position: absolute;"></textarea>'), // 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 @@
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
<!-- App -->
<link rel="stylesheet" href="css/codeq.css" type="text/css">
+ <link rel="stylesheet" href="css/codeq/console.css" type="text/css">
</head>
<body>
@@ -96,6 +97,7 @@
<!-- codeq app -->
<script src="js/codeq.js"></script>
<script src="js/codeq/comms.js"></script>
+ <script src="js/codeq/console.js"></script>
<script src="js/def_parser.js"></script>
<script src="js/prolog.js"></script>
</body>