lib/textbringer/window.rb in textbringer-0.1.4 vs lib/textbringer/window.rb in textbringer-0.1.5
- old
+ new
@@ -189,11 +189,12 @@
def self.beep
Curses.beep
end
- attr_reader :buffer, :lines, :columns, :y, :x
+ attr_reader :buffer, :lines, :columns, :y, :x, :window, :mode_line
+ attr_reader :top_of_window, :bottom_of_window
def initialize(lines, columns, y, x)
@lines = lines
@columns = columns
@y = y
@@ -334,12 +335,13 @@
if current? && @buffer.visible_mark &&
@buffer.point_after_mark?(@buffer.visible_mark)
@window.attron(Curses::A_REVERSE)
end
while !@buffer.end_of_buffer?
+ cury, curx = @window.cury, @window.curx
if @buffer.point_at_mark?(point)
- y, x = @window.cury, @window.curx
+ y, x = cury, curx
if current? && @buffer.visible_mark
if @buffer.point_after_mark?(@buffer.visible_mark)
@window.attroff(Curses::A_REVERSE)
elsif @buffer.point_before_mark?(@buffer.visible_mark)
@window.attron(Curses::A_REVERSE)
@@ -355,20 +357,35 @@
end
end
c = @buffer.char_after
if c == "\n"
@window.clrtoeol
- break if @window.cury == lines - 2 # lines include mode line
+ break if cury == lines - 2 # lines include mode line
+ @window.setpos(cury + 1, 0)
+ @buffer.forward_char
+ next
elsif c == "\t"
- n = calc_tab_width(@window.curx)
+ n = calc_tab_width(curx)
c = " " * n
else
c = escape(c)
end
+ if curx < columns - 4
+ newx = nil
+ else
+ newx = curx + Buffer.display_width(c)
+ if newx > columns
+ if cury == lines - 2
+ break
+ else
+ @window.clrtoeol
+ @window.setpos(cury + 1, 0)
+ end
+ end
+ end
@window.addstr(c)
- break if @window.cury == lines - 2 && # lines include mode line
- @window.curx == columns
+ break if newx == columns && cury == lines - 2
@buffer.forward_char
end
if current? && @buffer.visible_mark
@window.attroff(Curses::A_REVERSE)
end
@@ -502,11 +519,11 @@
line, column = @buffer.get_line_and_column(@point_mark.location)
end
@mode_line.addstr(unicode_codepoint(c))
@mode_line.addstr(" #{line},#{column}")
@mode_line.addstr(" (#{@buffer.mode&.name || 'None'})")
- @mode_line.addstr(" " * (@mode_line.maxx - @mode_line.curx))
+ @mode_line.addstr(" " * (columns - @mode_line.curx))
@mode_line.attroff(Curses::A_REVERSE)
@mode_line.noutrefresh
end
def unicode_codepoint(c)
@@ -517,17 +534,17 @@
end
end
def escape(s)
if @buffer.binary?
- s.gsub(/[\0-\b\v-\x1f]/) { |c|
+ s.gsub(/[\0-\b\v-\x1f\x7f]/) { |c|
"^" + (c.ord ^ 0x40).chr
}.gsub(/[\x80-\xff]/n) { |c|
"<%02X>" % c.ord
}
else
- s.gsub(/[\0-\b\v-\x1f]/) { |c|
+ s.gsub(/[\0-\b\v-\x1f\x7f]/) { |c|
"^" + (c.ord ^ 0x40).chr
}
end
end
@@ -618,9 +635,10 @@
end
end
end
class EchoArea < Window
+ attr_reader :message
attr_accessor :prompt
attr_writer :active
def initialize(*args)
super