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

* [sup-talk] [PATCH 2/5] console: add/remove labels
  2009-08-17  6:39 [sup-talk] [PATCH 1/5] console mode Rich Lane
@ 2009-08-17  6:39 ` Rich Lane
  2009-08-17  6:39   ` [sup-talk] [PATCH 3/5] console: index internals accessor Rich Lane
  2009-08-18 18:37 ` [sup-talk] [PATCH 1/5] console mode William Morgan
  1 sibling, 1 reply; 6+ messages in thread
From: Rich Lane @ 2009-08-17  6:39 UTC (permalink / raw)


---
 lib/sup/modes/console-mode.rb |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/lib/sup/modes/console-mode.rb b/lib/sup/modes/console-mode.rb
index d06d37b..a91bbbf 100644
--- a/lib/sup/modes/console-mode.rb
+++ b/lib/sup/modes/console-mode.rb
@@ -6,6 +6,18 @@ class Console
   def initialize mode
     @mode = mode
   end
+
+  def query(query)
+    Enumerable::Enumerator.new(Index, :each_message, Index.parse_query(query))
+  end
+
+  def add_labels(query, *labels)
+    query(query).each { |m| m.labels += labels; m.save Index }
+  end
+
+  def remove_labels(query, *labels)
+    query(query).each { |m| m.labels -= labels; m.save Index }
+  end
 end
 
 class ConsoleMode < LogMode
-- 
1.6.4



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

* [sup-talk] [PATCH 3/5] console: index internals accessor
  2009-08-17  6:39 ` [sup-talk] [PATCH 2/5] console: add/remove labels Rich Lane
@ 2009-08-17  6:39   ` Rich Lane
  2009-08-17  6:39     ` [sup-talk] [PATCH 4/5] console: reload Rich Lane
  0 siblings, 1 reply; 6+ messages in thread
From: Rich Lane @ 2009-08-17  6:39 UTC (permalink / raw)


---
 lib/sup/modes/console-mode.rb |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/lib/sup/modes/console-mode.rb b/lib/sup/modes/console-mode.rb
index a91bbbf..c794a4c 100644
--- a/lib/sup/modes/console-mode.rb
+++ b/lib/sup/modes/console-mode.rb
@@ -18,6 +18,9 @@ class Console
   def remove_labels(query, *labels)
     query(query).each { |m| m.labels -= labels; m.save Index }
   end
+
+  def xapian; Index.instance.instance_variable_get :@xapian; end
+  def ferret; Index.instance.instance_variable_get :@index; end
 end
 
 class ConsoleMode < LogMode
-- 
1.6.4



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

* [sup-talk] [PATCH 4/5] console: reload
  2009-08-17  6:39   ` [sup-talk] [PATCH 3/5] console: index internals accessor Rich Lane
@ 2009-08-17  6:39     ` Rich Lane
  2009-08-17  6:39       ` [sup-talk] [PATCH 5/5] console: clear_hooks Rich Lane
  0 siblings, 1 reply; 6+ messages in thread
From: Rich Lane @ 2009-08-17  6:39 UTC (permalink / raw)


---
 lib/sup/modes/console-mode.rb |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/lib/sup/modes/console-mode.rb b/lib/sup/modes/console-mode.rb
index c794a4c..c344fa6 100644
--- a/lib/sup/modes/console-mode.rb
+++ b/lib/sup/modes/console-mode.rb
@@ -21,6 +21,36 @@ class Console
 
   def xapian; Index.instance.instance_variable_get :@xapian; end
   def ferret; Index.instance.instance_variable_get :@index; end
+
+  ## files that won't cause problems when reloaded
+  ## TODO expand this list / convert to blacklist
+  RELOAD_WHITELIST = %w(sup/xapian_index.rb sup/modes/console-mode.rb)
+
+  def reload
+    old_verbose = $VERBOSE
+    $VERBOSE = nil
+    old_features = $".dup
+    begin
+      fs = $".grep(/^sup\//)
+      fs.reject! { |f| not RELOAD_WHITELIST.member? f }
+      fs.each { |f| $".delete f }
+      fs.each do |f|
+        @mode << "reloading #{f}\n"
+        begin
+          require f
+        rescue LoadError => e
+          raise unless e.message =~ /no such file to load/
+        end
+      end
+    rescue Exception
+      $".clear
+      $".concat old_features
+      raise
+    ensure
+      $VERBOSE = old_verbose
+    end
+    true
+  end
 end
 
 class ConsoleMode < LogMode
-- 
1.6.4



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

* [sup-talk] [PATCH 5/5] console: clear_hooks
  2009-08-17  6:39     ` [sup-talk] [PATCH 4/5] console: reload Rich Lane
@ 2009-08-17  6:39       ` Rich Lane
  0 siblings, 0 replies; 6+ messages in thread
From: Rich Lane @ 2009-08-17  6:39 UTC (permalink / raw)


---
 lib/sup/hook.rb               |    2 ++
 lib/sup/modes/console-mode.rb |    5 +++++
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/lib/sup/hook.rb b/lib/sup/hook.rb
index 33a97b2..099158d 100644
--- a/lib/sup/hook.rb
+++ b/lib/sup/hook.rb
@@ -130,6 +130,8 @@ EOS
 
   def enabled? name; !hook_for(name).nil? end
 
+  def clear; @hooks.clear; end
+
 private
 
   def hook_for name
diff --git a/lib/sup/modes/console-mode.rb b/lib/sup/modes/console-mode.rb
index c344fa6..372a466 100644
--- a/lib/sup/modes/console-mode.rb
+++ b/lib/sup/modes/console-mode.rb
@@ -51,6 +51,11 @@ class Console
     end
     true
   end
+
+  def clear_hooks
+    HookManager.clear
+    nil
+  end
 end
 
 class ConsoleMode < LogMode
-- 
1.6.4



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

* [sup-talk] [PATCH 1/5] console mode
  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-18 18:37 ` William Morgan
  1 sibling, 0 replies; 6+ messages in thread
From: William Morgan @ 2009-08-18 18:37 UTC (permalink / raw)


Cool idea. Branch console-mode, merged into next.
-- 
William <wmorgan-sup at masanjin.net>


^ 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