class Textbringer::EchoArea

Attributes

active[W]
message[R]
prompt[RW]

Public Class Methods

new(*args) click to toggle source
Calls superclass method Textbringer::Window::new
# File lib/textbringer/window.rb, line 806
def initialize(*args)
  super
  @message = nil
  @prompt = ""
  @active = false
end

Public Instance Methods

active?() click to toggle source
# File lib/textbringer/window.rb, line 817
def active?
  @active
end
clear() click to toggle source
# File lib/textbringer/window.rb, line 821
def clear
  @buffer.clear
  @top_of_window.location = @buffer.point_min
  @message = nil
  @prompt = ""
end
clear_message() click to toggle source
# File lib/textbringer/window.rb, line 828
def clear_message
  @message = nil
end
echo_area?() click to toggle source
# File lib/textbringer/window.rb, line 813
def echo_area?
  true
end
move(y, x) click to toggle source
# File lib/textbringer/window.rb, line 880
def move(y, x)
  @y = y
  @x = x
  @window.move(y, x)
end
redisplay() click to toggle source
# File lib/textbringer/window.rb, line 836
def redisplay
  return if @buffer.nil?
  @buffer.save_point do |saved|
    @window.erase
    @window.setpos(0, 0)
    if @message
      @window.addstr(escape(@message))
    else
      prompt = escape(@prompt)
      @window.addstr(prompt)
      framer
      @buffer.point_to_mark(@top_of_window)
      y = x = 0
      while !@buffer.end_of_buffer?
        cury, curx = @window.cury, @window.curx
        if @buffer.point_at_mark?(saved)
          y, x = cury, curx
        end
        c = @buffer.char_after
        if c == "\n"
          break
        end
        s = escape(c)
        newx = curx + Buffer.display_width(s)
        if newx > @columns
          break
        end
        @window.addstr(s)
        break if newx >= @columns
        @buffer.forward_char
      end
      if @buffer.point_at_mark?(saved)
        y, x = @window.cury, @window.curx
      end
      @window.setpos(y, x)
    end
    @window.noutrefresh
  end
end
redraw() click to toggle source
# File lib/textbringer/window.rb, line 876
def redraw
  @window.redraw
end
resize(lines, columns) click to toggle source
# File lib/textbringer/window.rb, line 886
def resize(lines, columns)
  @lines = lines
  @columns = columns
  @window.resize(lines, columns)
end
show(message) click to toggle source
# File lib/textbringer/window.rb, line 832
def show(message)
  @message = message
end

Private Instance Methods

escape(s) click to toggle source
Calls superclass method Textbringer::Window#escape
# File lib/textbringer/window.rb, line 898
def escape(s)
  super(s).gsub(/\t/, "^I")
end
framer() click to toggle source
# File lib/textbringer/window.rb, line 902
def framer
  @buffer.save_point do |saved|
    max_width = @columns - @window.curx
    width = 0
    loop do
      c = @buffer.char_after
      if c.nil?
        width += 1
      else
        width += Buffer.display_width(escape(c))
      end
      if width > max_width
        @buffer.forward_char
        break
      elsif width == max_width || @buffer.beginning_of_line? ||
          @buffer.point_at_mark?(@top_of_window)
        break
      end
      @buffer.backward_char
    end
    @top_of_window.location = @buffer.point
  end
end
initialize_window(num_lines, num_columns, y, x) click to toggle source
# File lib/textbringer/window.rb, line 894
def initialize_window(num_lines, num_columns, y, x)
  @window = Curses::Window.new(num_lines, num_columns, y, x)
end