]> git.cworth.org Git - sup/commitdiff
don't require log-mode to auto-respawn
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 9 Sep 2009 14:05:11 +0000 (10:05 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 9 Sep 2009 14:05:11 +0000 (10:05 -0400)
Don't require log-mode (and more importantly, subclasses thereof) to respawn.
If a buffer name is provided during initialization, respawning will be on;
otherwise, it will be off. Now e.g. console mode can use log-mode without
requiring a buffer name, or incurring potentially weird auto-respawn behavior.

lib/sup/modes/log-mode.rb

index 07fa9dd6cda8d4780676119839ee053baee41560..de320ce1c4749f56b8d5502db6e61868b463a206 100644 (file)
@@ -9,9 +9,12 @@ class LogMode < TextMode
     k.add :toggle_follow, "Toggle follow mode", 'f'
   end
 
-  def initialize buffer_name
+  ## if buffer_name is supplied, this mode will spawn a buffer
+  ## upon receiving the << message. otherwise, it will act like
+  ## a regular buffer.
+  def initialize autospawn_buffer_name=nil
     @follow = true
-    @buffer_name = buffer_name
+    @autospawn_buffer_name = autospawn_buffer_name
     @on_kill = []
     super()
   end
@@ -28,8 +31,8 @@ class LogMode < TextMode
   end
 
   def << s
-    unless buffer
-      BufferManager.spawn @buffer_name, self, :hidden => true, :system => true
+    if buffer.nil? && @autospawn_buffer_name
+      BufferManager.spawn @autospawn_buffer_name, self, :hidden => true, :system => true
     end
 
     s.split("\n").each { |l| super(l + "\n") } # insane. different << semantics.