]> git.notmuchmail.org Git - sup/blobdiff - lib/sup/modes/console-mode.rb
bugfix: console mode can't start a message in #initialize
[sup] / lib / sup / modes / console-mode.rb
index c344fa6c96de3769f914fd16f79528cfbf0f629a..f0c626e60e1024cdeee957e1dc5d0309f7f3973b 100644 (file)
@@ -21,6 +21,7 @@ class Console
 
   def xapian; Index.instance.instance_variable_get :@xapian; end
   def ferret; Index.instance.instance_variable_get :@index; end
+  def special_methods; methods - Object.methods end
 
   ## files that won't cause problems when reloaded
   ## TODO expand this list / convert to blacklist
@@ -51,12 +52,22 @@ class Console
     end
     true
   end
+
+  def clear_hooks
+    HookManager.clear
+    nil
+  end
 end
 
 class ConsoleMode < LogMode
+  register_keymap do |k|
+    k.add :run, "Restart evaluation", 'e'
+  end
+
   def initialize
     super
-    @binding = Console.new(self).instance_eval { binding }
+    @console = Console.new self
+    @binding = @console.instance_eval { binding }
   end
 
   def execute cmd
@@ -73,13 +84,23 @@ class ConsoleMode < LogMode
   end
 
   def prompt
-    BufferManager.ask :console, "eval: "
+    BufferManager.ask :console, ">> "
   end
 
   def run
+    self << <<EOS
+Sup v#{VERSION} console session started.
+Available extra commands: #{(@console.special_methods) * ", "}
+Ctrl-G stops evaluation; 'e' restarts it.
+
+EOS
     while true
-      cmd = prompt or return
-      execute cmd
+      if(cmd = prompt)
+        execute cmd
+      else
+        self << "Console session ended."
+        break
+      end
     end
   end
 end