lib/sup/modes/line-cursor-mode.rb in sup-0.8.1 vs lib/sup/modes/line-cursor-mode.rb in sup-0.9
- old
+ new
@@ -13,15 +13,28 @@
attr_reader :curpos
def initialize opts={}
@cursor_top = @curpos = opts.delete(:skip_top_rows) || 0
@load_more_callbacks = []
- @load_more_callbacks_m = Mutex.new
- @load_more_callbacks_active = false
+ @load_more_q = Queue.new
+ @load_more_thread = ::Thread.new do
+ while true
+ e = @load_more_q.pop
+ @load_more_callbacks.each { |c| c.call e }
+ sleep 0.5
+ @load_more_q.pop until @load_more_q.empty?
+ end
+ end
+
super opts
end
+ def cleanup
+ @load_more_thread.kill
+ super
+ end
+
def draw
super
set_status
end
@@ -75,11 +88,11 @@
super
set_cursor_pos botline - 1 if @curpos > botline - 1
end
def cursor_down
- call_load_more_callbacks buffer.content_height if @curpos == lines - 1
+ call_load_more_callbacks buffer.content_height if @curpos >= lines - [buffer.content_height/2,1].max
return false unless @curpos < lines - 1
if @curpos >= botline - 1
page_down
set_cursor_pos topline
@@ -161,23 +174,10 @@
l = lines
@status = l > 0 ? "line #{@curpos + 1} of #{l}" : ""
end
def call_load_more_callbacks size
- go =
- @load_more_callbacks_m.synchronize do
- if @load_more_callbacks_active
- false
- else
- @load_more_callbacks_active = true
- end
- end
-
- return unless go
-
- @load_more_callbacks.each { |c| c.call size }
- @load_more_callbacks_active = false
- end
-
+ @load_more_q.push size
+ end
end
end