lib/sup/buffer.rb in sup-0.0.4 vs lib/sup/buffer.rb in sup-0.0.5
- old
+ new
@@ -215,11 +215,10 @@
## quick hack
if true
buf = @buffers.last
buf.resize Ncurses.rows - minibuf_lines, Ncurses.cols
- File.open("asdf.txt", "a") { |f| f.puts "dirty #@dirty, (re)drawing #{buf.mode.name}" }
@dirty ? buf.draw : buf.redraw
end
draw_minibuf :sync => false unless opts[:skip_minibuf]
@dirty = false
@@ -231,11 +230,10 @@
## gets the mode from the block, which is only called if the buffer
## doesn't already exist. this is useful in the case that generating
## the mode is expensive, as it often is.
def spawn_unless_exists title, opts={}
if @name_map.member? title
- Redwood::log "buffer '#{title}' already exists, raising to front"
raise_to_front @name_map[title] unless opts[:hidden]
else
mode = yield
spawn title, mode, opts
end
@@ -290,11 +288,14 @@
else
raise_to_front @buffers.last
end
end
+ ## not really thread safe.
def ask domain, question, default=nil
+ raise "impossible!" if @asking
+
@textfields[domain] ||= TextField.new Ncurses.stdscr, Ncurses.rows - 1, 0, Ncurses.cols
tf = @textfields[domain]
## this goddamn ncurses form shit is a fucking 1970's
## nightmare. jesus christ. the exact sequence of ncurses events
@@ -308,11 +309,14 @@
end
ret = nil
tf.position_cursor
Ncurses.sync { Ncurses.refresh }
+
+ @asking = true
while tf.handle_input(Ncurses.nonblocking_getch); end
+ @asking = false
ret = tf.value
Ncurses.sync { tf.deactivate }
@dirty = true
@@ -367,11 +371,13 @@
end
end
def minibuf_lines
@minibuf_mutex.synchronize do
- [(@flash ? 1 : 0) + @minibuf_stack.compact.size, 1].max
+ [(@flash ? 1 : 0) +
+ (@asking ? 1 : 0) +
+ @minibuf_stack.compact.size, 1].max
end
end
def draw_minibuf opts={}
m = nil
@@ -381,12 +387,13 @@
m << "" if m.empty?
end
Ncurses.mutex.lock unless opts[:sync] == false
Ncurses.attrset Colormap.color_for(:none)
+ adj = @asking ? 2 : 1
m.each_with_index do |s, i|
- Ncurses.mvaddstr Ncurses.rows - i - 1, 0, s + (" " * [Ncurses.cols - s.length, 0].max)
+ Ncurses.mvaddstr Ncurses.rows - i - adj, 0, s + (" " * [Ncurses.cols - s.length, 0].max)
end
Ncurses.refresh if opts[:refresh]
Ncurses.mutex.unlock unless opts[:sync] == false
end
@@ -404,10 +411,10 @@
draw_minibuf :refresh => true
end
if block_given?
begin
- yield
+ yield id
ensure
clear id
end
end
id