Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
From: rlane@club.cc.cmu.edu (Rich Lane)
Subject: [sup-talk] [PATCH 1/5] console mode
Date: Sun, 16 Aug 2009 23:39:11 -0700	[thread overview]
Message-ID: <1250491155-19281-1-git-send-email-rlane@club.cc.cmu.edu> (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



             reply	other threads:[~2009-08-17  6:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-17  6:39 Rich Lane [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1250491155-19281-1-git-send-email-rlane@club.cc.cmu.edu \
    --to=rlane@club.cc.cmu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox