tab completion for commands in debugger
authorRyan Dahl <ry@tinyclouds.org>
Wed, 12 Jan 2011 18:32:48 +0000 (10:32 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Wed, 12 Jan 2011 18:32:48 +0000 (10:32 -0800)
lib/_debugger.js

index 3fd61238f025c2946a6333e005612156fcf3aefb..422858ee43ee0e86da8eaf2632933ebc7a77d4ed 100644 (file)
@@ -351,7 +351,10 @@ function SourceInfo(body) {
 // "node debug"
 function Interface() {
   var self = this;
-  var term = this.term = readline.createInterface(process.stdout);
+  var term = this.term =
+    readline.createInterface(process.stdout, function (line) {
+      return self.complete(line);
+    });
   var child;
   var client;
   var term;
@@ -396,6 +399,39 @@ function Interface() {
 }
 
 
+var commands = [
+  'backtrace',
+  'continue',
+  'help',
+  'info breakpoints',
+  'kill',
+  'list',
+  'next',
+  'print',
+  'quit',
+  'run',
+  'scripts',
+  'step',
+  'version',
+];
+
+
+Interface.prototype.complete = function(line) {
+  // Match me with a command.
+  var matches = [];
+  // Remove leading whitespace
+  line = line.replace(/^\s*/, '');
+
+  for (var i = 0; i < commands.length; i++) {
+    if (commands[i].indexOf(line) >= 0) {
+      matches.push(commands[i]);
+    }
+  }
+
+  return [matches, line];
+};
+
+
 Interface.prototype.handleSIGINT = function() {
   if (this.paused) {
     this.child.kill('SIGINT');