4 ## a variant of text mode that allows the user to automatically follow text,
5 ## and respawns when << is called if necessary.
7 class LogMode < TextMode
9 k.add :toggle_follow, "Toggle follow mode", 'f'
12 ## if buffer_name is supplied, this mode will spawn a buffer
13 ## upon receiving the << message. otherwise, it will act like
15 def initialize autospawn_buffer_name=nil
17 @autospawn_buffer_name = autospawn_buffer_name
22 ## register callbacks for when the buffer is killed
23 def on_kill &b; @on_kill << b end
28 jump_to_line(lines - buffer.content_height + 1) # leave an empty line at bottom
34 if buffer.nil? && @autospawn_buffer_name
35 BufferManager.spawn @autospawn_buffer_name, self, :hidden => true, :system => true
38 s.split("\n").each { |l| super(l + "\n") } # insane. different << semantics.
41 follow_top = lines - buffer.content_height + 1
42 jump_to_line follow_top if topline < follow_top
47 super + " (follow: #@follow)"
51 @on_kill.each { |cb| cb.call self }