---
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
_______________________________________________
sup-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/sup-talk