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 def initialize buffer_name
14 @buffer_name = buffer_name
19 ## register callbacks for when the buffer is killed
20 def on_kill &b; @on_kill << b end
25 jump_to_line(lines - buffer.content_height + 1) # leave an empty line at bottom
32 BufferManager.spawn @buffer_name, self, :hidden => true, :system => true
35 s.split("\n").each { |l| super(l + "\n") } # insane. different << semantics.
38 follow_top = lines - buffer.content_height + 1
39 jump_to_line follow_top if topline < follow_top
44 super + " (follow: #@follow)"
48 @on_kill.each { |cb| cb.call self }