unison-watch/lib/unison/ui/fileview.rb

37 lines
725 B
Ruby

module Unison
module UI
class FileView < Qt::TextEdit
INITIAL = "Watching for changes..."
def initialize(file, *args)
super(*args)
@file = file
@current_log_size = File.exist?(@file) ? File.size(@file) : 0
self.plainText = INITIAL
self.readOnly = true
self.resize 800, 600
self.connect(SIGNAL(:textChanged), &method(:on_text_change))
end
def show
super
self.raise
end
def on_text_change
self.moveCursor Qt::TextCursor::End
end
def read!
File.open(@file, 'r') { |fh|
fh.seek(@current_log_size)
self.plainText = fh.read
}
end
end
end
end