]> andersk Git - test.git/commitdiff
Don't blink the cursor while the user is typing.
authorJay Weisskopf <jay@jayschwa.net>
Sun, 1 Jan 2012 05:19:42 +0000 (23:19 -0600)
committerJay Weisskopf <jay@jayschwa.net>
Sun, 1 Jan 2012 12:08:24 +0000 (06:08 -0600)
demo/vt100.js
shellinabox/vt100.js
shellinabox/vt100.jspp

index 317ce0c5a97714dcafb843121563ce8daa5fe5be..5c93b83135f07daf6cd76d984728f46705444245 100644 (file)
@@ -2399,6 +2399,7 @@ VT100.prototype.hideSoftKeyboard = function() {
 
 VT100.prototype.toggleCursorBlinking = function() {
   this.blinkingCursor = !this.blinkingCursor;
+  this.animateCursor('bright');
 };
 
 VT100.prototype.about = function() {
@@ -2879,6 +2880,10 @@ VT100.prototype.keyDown = function(event) {
   //             (event.shiftKey ? 'S' : '') + (event.ctrlKey ? 'C' : '') +
   //             (event.altKey ? 'A' : '') + (event.metaKey ? 'M' : '') : '') +
   //            '\r\n');
+
+  // Keep the cursor lit when there is user activity.
+  this.animateCursor('bright');
+
   this.checkComposedKeys(event);
   this.lastKeyPressedEvent      = undefined;
   this.lastKeyDownEvent         = undefined;
@@ -2971,6 +2976,10 @@ VT100.prototype.keyPressed = function(event) {
   //             (event.shiftKey ? 'S' : '') + (event.ctrlKey ? 'C' : '') +
   //             (event.altKey ? 'A' : '') + (event.metaKey ? 'M' : '') : '') +
   //            '\r\n');
+
+  // Keep the cursor lit when there is user activity.
+  this.animateCursor('bright');
+
   if (this.lastKeyDownEvent) {
     // If we already processed the key on keydown, do not process it
     // again here. Ideally, the browser should not even have generated a
@@ -3007,6 +3016,10 @@ VT100.prototype.keyUp = function(event) {
   //             (event.shiftKey ? 'S' : '') + (event.ctrlKey ? 'C' : '') +
   //             (event.altKey ? 'A' : '') + (event.metaKey ? 'M' : '') : '') +
   //            '\r\n');
+
+  // Keep the cursor lit when there is user activity.
+  this.animateCursor('bright');
+
   if (this.lastKeyPressedEvent) {
     // The compose key on Linux occasionally confuses the browser and keeps
     // inserting bogus characters into the input field, even if just a regular
@@ -3072,7 +3085,25 @@ VT100.prototype.keyUp = function(event) {
   return false;
 };
 
-VT100.prototype.animateCursor = function(inactive) {
+VT100.prototype.animateCursor = function(state) {
+  if (state != undefined) {
+    this.cursor.className = state;
+
+    // Reset the blink timer when a state is explicitly defined.
+    if (this.cursorInterval) {
+      clearInterval(this.cursorInterval);
+      this.cursorInterval = undefined;
+    }
+  } else {
+    if (this.cursor.className != 'inactive') {
+      if (this.blinkingCursor && this.cursor.className == 'bright') {
+        this.cursor.className = 'dim';
+      } else {
+        this.cursor.className = 'bright';
+      }
+    }
+  }
+
   if (!this.cursorInterval) {
     this.cursorInterval       = setInterval(
       function(vt100) {
@@ -3085,26 +3116,14 @@ VT100.prototype.animateCursor = function(inactive) {
         }
       }(this), 500);
   }
-  if (inactive != undefined || this.cursor.className != 'inactive') {
-    if (inactive) {
-      this.cursor.className   = 'inactive';
-    } else {
-      if (this.blinkingCursor) {
-        this.cursor.className = this.cursor.className == 'bright'
-                                ? 'dim' : 'bright';
-      } else {
-        this.cursor.className = 'bright';
-      }
-    }
-  }
 };
 
 VT100.prototype.blurCursor = function() {
-  this.animateCursor(true);
+  this.animateCursor('inactive');
 };
 
 VT100.prototype.focusCursor = function() {
-  this.animateCursor(false);
+  this.animateCursor('bright');
 };
 
 VT100.prototype.flashScreen = function() {
index 317ce0c5a97714dcafb843121563ce8daa5fe5be..5c93b83135f07daf6cd76d984728f46705444245 100644 (file)
@@ -2399,6 +2399,7 @@ VT100.prototype.hideSoftKeyboard = function() {
 
 VT100.prototype.toggleCursorBlinking = function() {
   this.blinkingCursor = !this.blinkingCursor;
+  this.animateCursor('bright');
 };
 
 VT100.prototype.about = function() {
@@ -2879,6 +2880,10 @@ VT100.prototype.keyDown = function(event) {
   //             (event.shiftKey ? 'S' : '') + (event.ctrlKey ? 'C' : '') +
   //             (event.altKey ? 'A' : '') + (event.metaKey ? 'M' : '') : '') +
   //            '\r\n');
+
+  // Keep the cursor lit when there is user activity.
+  this.animateCursor('bright');
+
   this.checkComposedKeys(event);
   this.lastKeyPressedEvent      = undefined;
   this.lastKeyDownEvent         = undefined;
@@ -2971,6 +2976,10 @@ VT100.prototype.keyPressed = function(event) {
   //             (event.shiftKey ? 'S' : '') + (event.ctrlKey ? 'C' : '') +
   //             (event.altKey ? 'A' : '') + (event.metaKey ? 'M' : '') : '') +
   //            '\r\n');
+
+  // Keep the cursor lit when there is user activity.
+  this.animateCursor('bright');
+
   if (this.lastKeyDownEvent) {
     // If we already processed the key on keydown, do not process it
     // again here. Ideally, the browser should not even have generated a
@@ -3007,6 +3016,10 @@ VT100.prototype.keyUp = function(event) {
   //             (event.shiftKey ? 'S' : '') + (event.ctrlKey ? 'C' : '') +
   //             (event.altKey ? 'A' : '') + (event.metaKey ? 'M' : '') : '') +
   //            '\r\n');
+
+  // Keep the cursor lit when there is user activity.
+  this.animateCursor('bright');
+
   if (this.lastKeyPressedEvent) {
     // The compose key on Linux occasionally confuses the browser and keeps
     // inserting bogus characters into the input field, even if just a regular
@@ -3072,7 +3085,25 @@ VT100.prototype.keyUp = function(event) {
   return false;
 };
 
-VT100.prototype.animateCursor = function(inactive) {
+VT100.prototype.animateCursor = function(state) {
+  if (state != undefined) {
+    this.cursor.className = state;
+
+    // Reset the blink timer when a state is explicitly defined.
+    if (this.cursorInterval) {
+      clearInterval(this.cursorInterval);
+      this.cursorInterval = undefined;
+    }
+  } else {
+    if (this.cursor.className != 'inactive') {
+      if (this.blinkingCursor && this.cursor.className == 'bright') {
+        this.cursor.className = 'dim';
+      } else {
+        this.cursor.className = 'bright';
+      }
+    }
+  }
+
   if (!this.cursorInterval) {
     this.cursorInterval       = setInterval(
       function(vt100) {
@@ -3085,26 +3116,14 @@ VT100.prototype.animateCursor = function(inactive) {
         }
       }(this), 500);
   }
-  if (inactive != undefined || this.cursor.className != 'inactive') {
-    if (inactive) {
-      this.cursor.className   = 'inactive';
-    } else {
-      if (this.blinkingCursor) {
-        this.cursor.className = this.cursor.className == 'bright'
-                                ? 'dim' : 'bright';
-      } else {
-        this.cursor.className = 'bright';
-      }
-    }
-  }
 };
 
 VT100.prototype.blurCursor = function() {
-  this.animateCursor(true);
+  this.animateCursor('inactive');
 };
 
 VT100.prototype.focusCursor = function() {
-  this.animateCursor(false);
+  this.animateCursor('bright');
 };
 
 VT100.prototype.flashScreen = function() {
index 77bb89d7b4a475bd7fba4988527480fbbe764ee5..eecf04833de157e1a1fd60716ebedfc9d2b0ca1c 100755 (executable)
@@ -2399,6 +2399,7 @@ VT100.prototype.hideSoftKeyboard = function() {
 
 VT100.prototype.toggleCursorBlinking = function() {
   this.blinkingCursor = !this.blinkingCursor;
+  this.animateCursor('bright');
 };
 
 VT100.prototype.about = function() {
@@ -2879,6 +2880,10 @@ VT100.prototype.keyDown = function(event) {
   //             (event.shiftKey ? 'S' : '') + (event.ctrlKey ? 'C' : '') +
   //             (event.altKey ? 'A' : '') + (event.metaKey ? 'M' : '') : '') +
   //            '\r\n');
+
+  // Keep the cursor lit when there is user activity.
+  this.animateCursor('bright');
+
   this.checkComposedKeys(event);
   this.lastKeyPressedEvent      = undefined;
   this.lastKeyDownEvent         = undefined;
@@ -2971,6 +2976,10 @@ VT100.prototype.keyPressed = function(event) {
   //             (event.shiftKey ? 'S' : '') + (event.ctrlKey ? 'C' : '') +
   //             (event.altKey ? 'A' : '') + (event.metaKey ? 'M' : '') : '') +
   //            '\r\n');
+
+  // Keep the cursor lit when there is user activity.
+  this.animateCursor('bright');
+
   if (this.lastKeyDownEvent) {
     // If we already processed the key on keydown, do not process it
     // again here. Ideally, the browser should not even have generated a
@@ -3007,6 +3016,10 @@ VT100.prototype.keyUp = function(event) {
   //             (event.shiftKey ? 'S' : '') + (event.ctrlKey ? 'C' : '') +
   //             (event.altKey ? 'A' : '') + (event.metaKey ? 'M' : '') : '') +
   //            '\r\n');
+
+  // Keep the cursor lit when there is user activity.
+  this.animateCursor('bright');
+
   if (this.lastKeyPressedEvent) {
     // The compose key on Linux occasionally confuses the browser and keeps
     // inserting bogus characters into the input field, even if just a regular
@@ -3072,7 +3085,25 @@ VT100.prototype.keyUp = function(event) {
   return false;
 };
 
-VT100.prototype.animateCursor = function(inactive) {
+VT100.prototype.animateCursor = function(state) {
+  if (state != undefined) {
+    this.cursor.className = state;
+
+    // Reset the blink timer when a state is explicitly defined.
+    if (this.cursorInterval) {
+      clearInterval(this.cursorInterval);
+      this.cursorInterval = undefined;
+    }
+  } else {
+    if (this.cursor.className != 'inactive') {
+      if (this.blinkingCursor && this.cursor.className == 'bright') {
+        this.cursor.className = 'dim';
+      } else {
+        this.cursor.className = 'bright';
+      }
+    }
+  }
+
   if (!this.cursorInterval) {
     this.cursorInterval       = setInterval(
       function(vt100) {
@@ -3085,26 +3116,14 @@ VT100.prototype.animateCursor = function(inactive) {
         }
       }(this), 500);
   }
-  if (inactive != undefined || this.cursor.className != 'inactive') {
-    if (inactive) {
-      this.cursor.className   = 'inactive';
-    } else {
-      if (this.blinkingCursor) {
-        this.cursor.className = this.cursor.className == 'bright'
-                                ? 'dim' : 'bright';
-      } else {
-        this.cursor.className = 'bright';
-      }
-    }
-  }
 };
 
 VT100.prototype.blurCursor = function() {
-  this.animateCursor(true);
+  this.animateCursor('inactive');
 };
 
 VT100.prototype.focusCursor = function() {
-  this.animateCursor(false);
+  this.animateCursor('bright');
 };
 
 VT100.prototype.flashScreen = function() {
This page took 0.052441 seconds and 5 git commands to generate.