Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
* [sup-talk] [PATCH 1/5] console mode
@ 2009-08-17  6:39 Rich Lane
  2009-08-17  6:39 ` [sup-talk] [PATCH 2/5] console: add/remove labels Rich Lane
  2009-08-18 18:37 ` [sup-talk] [PATCH 1/5] console mode William Morgan
  0 siblings, 2 replies; 6+ messages in thread
From: Rich Lane @ 2009-08-17  6:39 UTC (permalink / raw)


---
 bin/sup                       |    4 +++
 lib/sup.rb                    |    1 +
 lib/sup/modes/console-mode.rb |   42 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 0 deletions(-)
 create mode 100644 lib/sup/modes/console-mode.rb

diff --git a/bin/sup b/bin/sup
index a9f0b95..1dc322a 100755
--- a/bin/sup
+++ b/bin/sup
@@ -78,6 +78,7 @@ global_keymap = Keymap.new do |k|
   k.add :compose, "Compose new message", 'm', 'c'
   k.add :nothing, "Do nothing", :ctrl_g
   k.add :recall_draft, "Edit most recent draft message", 'R'
+  k.add :show_console, "Show the Console buffer", '~'
 end
 
 ## the following magic enables wide characters when used with a ruby
@@ -286,6 +287,9 @@ begin
         b, new = BufferManager.spawn_unless_exists("All drafts") { LabelSearchResultsMode.new [:draft] }
         b.mode.load_threads :num => b.content_height if new
       end
+    when :show_console
+      b, new = bm.spawn_unless_exists("Console", :system => true) { ConsoleMode.new }
+      b.mode.run
     when :nothing, InputSequenceAborted
     when :redraw
       bm.completely_redraw_screen
diff --git a/lib/sup.rb b/lib/sup.rb
index cfa93fc..9e0c33a 100644
--- a/lib/sup.rb
+++ b/lib/sup.rb
@@ -295,6 +295,7 @@ require "sup/modes/buffer-list-mode"
 require "sup/modes/poll-mode"
 require "sup/modes/file-browser-mode"
 require "sup/modes/completion-mode"
+require "sup/modes/console-mode"
 require "sup/sent"
 
 $:.each do |base|
diff --git a/lib/sup/modes/console-mode.rb b/lib/sup/modes/console-mode.rb
new file mode 100644
index 0000000..d06d37b
--- /dev/null
+++ b/lib/sup/modes/console-mode.rb
@@ -0,0 +1,42 @@
+require 'pp'
+
+module Redwood
+
+class Console
+  def initialize mode
+    @mode = mode
+  end
+end
+
+class ConsoleMode < LogMode
+  def initialize
+    super
+    @binding = Console.new(self).instance_eval { binding }
+  end
+
+  def execute cmd
+    begin
+      self << ">> #{cmd}\n"
+      ret = eval cmd, @binding
+      self << "=> #{ret.pretty_inspect}\n"
+    rescue Exception
+      self << "#{$!.class}: #{$!.message}\n"
+      clean_backtrace = []
+      $!.backtrace.each { |l| break if l =~ /console-mode/; clean_backtrace << l }
+      clean_backtrace.each { |l| self << "#{l}\n" }
+    end
+  end
+
+  def prompt
+    BufferManager.ask :console, "eval: "
+  end
+
+  def run
+    while true
+      cmd = prompt or return
+      execute cmd
+    end
+  end
+end
+
+end
-- 
1.6.4



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-08-18 18:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-17  6:39 [sup-talk] [PATCH 1/5] console mode Rich Lane
2009-08-17  6:39 ` [sup-talk] [PATCH 2/5] console: add/remove labels Rich Lane
2009-08-17  6:39   ` [sup-talk] [PATCH 3/5] console: index internals accessor Rich Lane
2009-08-17  6:39     ` [sup-talk] [PATCH 4/5] console: reload Rich Lane
2009-08-17  6:39       ` [sup-talk] [PATCH 5/5] console: clear_hooks Rich Lane
2009-08-18 18:37 ` [sup-talk] [PATCH 1/5] console mode William Morgan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox