Parent

Class/Module Index [+]

Quicksearch

Redwood::ScrollMode

Constants

COL_JUMP

Attributes

botline[R]

we left leftcol and rightcol as the left and right columns of any content in the current view. but since we're operating in a line-centric fashion, rightcol is always leftcol + the buffer width. (whereas botline is topline + at most the buffer height, and can be == to topline in the case that there's no content.)

leftcol[R]

we left leftcol and rightcol as the left and right columns of any content in the current view. but since we're operating in a line-centric fashion, rightcol is always leftcol + the buffer width. (whereas botline is topline + at most the buffer height, and can be == to topline in the case that there's no content.)

status[R]

we left leftcol and rightcol as the left and right columns of any content in the current view. but since we're operating in a line-centric fashion, rightcol is always leftcol + the buffer width. (whereas botline is topline + at most the buffer height, and can be == to topline in the case that there's no content.)

topline[R]

we left leftcol and rightcol as the left and right columns of any content in the current view. but since we're operating in a line-centric fashion, rightcol is always leftcol + the buffer width. (whereas botline is topline + at most the buffer height, and can be == to topline in the case that there's no content.)

Public Class Methods

new(opts={}) click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 33
def initialize opts={}
  @topline, @botline, @leftcol = 0, 0, 0
  @slip_rows = opts[:slip_rows] || 0 # when we pgup/pgdown,
                                     # how many lines do we keep?
  @twiddles = opts.member?(:twiddles) ? opts[:twiddles] : true
  @search_query = nil
  @search_line = nil
  @status = ""
  super()
end

Public Instance Methods

at_bottom?() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 130
def at_bottom?; @botline == lines end
at_top?() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 129
def at_top?; @topline == 0 end
cancel_search!() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 60
def cancel_search!; @search_line = nil end
col_left() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 101
def col_left
  return unless @leftcol > 0
  @leftcol -= COL_JUMP
  buffer.mark_dirty
end
col_right() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 107
def col_right
  @leftcol += COL_JUMP
  buffer.mark_dirty
end
continue_search_in_buffer() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 62
def continue_search_in_buffer
  unless @search_query
    BufferManager.flash "No current search!"
    return
  end

  start = @search_line || search_start_line
  line, col = find_text @search_query, start
  if line.nil? && (start > 0)
    line, col = find_text @search_query, 0
    BufferManager.flash "Search wrapped to top!" if line
  end
  if line
    @search_line = line + 1
    search_goto_pos line, col, col + @search_query.display_length
    buffer.mark_dirty
  else
    BufferManager.flash "Not found!"
  end
end
draw() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 46
def draw
  ensure_mode_validity
  (@topline ... @botline).each { |ln| draw_line ln }
  ((@botline - @topline) ... buffer.content_height).each do |ln|
    if @twiddles
      buffer.write ln, 0, "~", :color => :twiddle_color
    else
      buffer.write ln, 0, ""
    end
  end
  @status = "lines #{@topline + 1}:#{@botline}/#{lines}"
end
ensure_mode_validity() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 141
def ensure_mode_validity
  @topline = @topline.clamp 0, [lines - 1, 0].max
  @botline = [@topline + buffer.content_height, lines].min
end
half_page_down() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 136
def half_page_down; jump_to_line @topline + buffer.content_height / 2; end
half_page_up() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 137
def half_page_up; jump_to_line @topline - buffer.content_height / 2; end
in_search?() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 59
def in_search?; @search_line end
jump_to_col(col) click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 112
def jump_to_col col
  col = col - (col % COL_JUMP)
  buffer.mark_dirty unless @leftcol == col
  @leftcol = col
end
jump_to_end() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 139
def jump_to_end; jump_to_line lines - buffer.content_height; end
jump_to_left() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 118
def jump_to_left; jump_to_col 0; end
jump_to_line(l) click to toggle source

set top line to l

# File lib/sup/modes/scroll-mode.rb, line 121
def jump_to_line l
  l = l.clamp 0, lines - 1
  return if @topline == l
  @topline = l
  @botline = [l + buffer.content_height, lines].min
  buffer.mark_dirty
end
jump_to_start() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 138
def jump_to_start; jump_to_line 0; end
line_down() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 132
def line_down; jump_to_line @topline + 1; end
line_up() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 133
def line_up;  jump_to_line @topline - 1; end
page_down() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 134
def page_down; jump_to_line @topline + buffer.content_height - @slip_rows; end
page_up() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 135
def page_up; jump_to_line @topline - buffer.content_height + @slip_rows; end
resize(*a) click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 146
def resize *a
  super(*a)
  ensure_mode_validity
end
rightcol() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 44
def rightcol; @leftcol + buffer.content_width; end
search_goto_line(line;) click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 99
def search_goto_line line; jump_to_line line end
search_goto_pos(line, leftcol, rightcol) click to toggle source

subclasses can override these three!

# File lib/sup/modes/scroll-mode.rb, line 91
def search_goto_pos line, leftcol, rightcol
  search_goto_line line

  if rightcol > self.rightcol # if it's occluded...
    jump_to_col [rightcol - buffer.content_width + 1, 0].max # move right
  end
end
search_in_buffer() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 83
def search_in_buffer
  query = BufferManager.ask :search, "search in buffer: "
  return if query.nil? || query.empty?
  @search_query = Regexp.escape query
  continue_search_in_buffer
end
search_start_line() click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 98
def search_start_line; @topline end

Protected Instance Methods

draw_line(ln, opts={}) click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 175
def draw_line ln, opts={}
  regex = /(#{@search_query})/
  case(s = self[ln])
  when String
    if in_search?
      draw_line_from_array ln, matching_text_array(s, regex), opts
    else
      draw_line_from_string ln, s, opts
    end
  when Array
    if in_search?
      ## seems like there ought to be a better way of doing this
      array = []
      s.each do |color, text| 
        if text =~ regex
          array += matching_text_array text, regex, color
        else
          array << [color, text]
        end
      end
      draw_line_from_array ln, array, opts
    else
      draw_line_from_array ln, s, opts
    end
  else
    raise "unknown drawable object: #{s.inspect} in #{self} for line #{ln}" # good for debugging
  end

    ## speed test
    # str = s.map { |color, text| text }.join
    # buffer.write ln - @topline, 0, str, :color => :none, :highlight => opts[:highlight]
    # return
end
draw_line_from_array(ln, a, opts) click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 220
def draw_line_from_array ln, a, opts
  xpos = 0
  a.each_with_index do |(color, text), i|
    raise "nil text for color '#{color}'" if text.nil? # good for debugging
    l = text.display_length
    no_fill = i != a.size - 1

    if xpos + l < @leftcol
      buffer.write ln - @topline, 0, "", :color => color,
                   :highlight => opts[:highlight]
    elsif xpos < @leftcol
      ## partial
      buffer.write ln - @topline, 0, text[(@leftcol - xpos) .. -1],
                   :color => color,
                   :highlight => opts[:highlight], :no_fill => no_fill
    else
      buffer.write ln - @topline, xpos - @leftcol, text,
                   :color => color, :highlight => opts[:highlight],
                   :no_fill => no_fill
    end
    xpos += l
  end
end
draw_line_from_string(ln, s, opts) click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 244
def draw_line_from_string ln, s, opts
  buffer.write ln - @topline, 0, s[@leftcol .. -1], :highlight => opts[:highlight]
end
find_text(query, start_line) click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 153
def find_text query, start_line
  regex = /#{query}/
  (start_line ... lines).each do |i|
    case(s = self[i])
    when String
      match = s =~ regex
      return [i, match] if match
    when Array
      offset = 0
      s.each do |color, string|
        match = string =~ regex
        if match
          return [i, offset + match]
        else
          offset += string.display_length
        end
      end
    end
  end
  nil
end
matching_text_array(s, regex, oldcolor=:none) click to toggle source
# File lib/sup/modes/scroll-mode.rb, line 209
def matching_text_array s, regex, oldcolor=:none
  s.split(regex).map do |text|
    next if text.empty?
    if text =~ regex
      [:search_highlight_color, text]
    else
      [oldcolor, text]
    end
  end.compact + [[oldcolor, ""]]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.