Sha256: c9824f6a9cd745b5d67c7a2c5b5768800e1138f4b9ed613567328d9458309739

Contents?: true

Size: 1.23 KB

Versions: 32

Compression:

Stored size: 1.23 KB

Contents

class RubyText::Window

  def coords(r, c)
    r = case
          when r == :center
            self.rows / 2 
          when r == :top
            0
          when r == :bottom
            self.rows - 1
          else
            r
          end
    c = case
          when c == :center
            self.cols / 2 
          when c == :left
            0
          when c == :right
            self.cols - 1
          else
            c
          end
    [r, c]
  end

  def goto(r, c)  # only accepts numbers!
    @cwin.setpos(r, c)
  end

  def go(r0, c0)
    r, c = coords(r0, c0)
    save = self.rc
    goto r, c 
    if block_given?
      yield 
      goto *save
    end
  end

  def up(n=1)
    r, c = rc
    go r-n, c
  end

  def down(n=1)
    r, c = rc
    go r+n, c
  end

  def left(n=1)
    r, c = rc
    go r, c-n
  end

  def right(n=1)
    r, c = rc
    go r, c+n
  end

  def top
    r, c = rc
    go 0, c
  end

  def bottom 
    r, c = rc
    rmax = self.rows - 1
    go rmax, c
  end

  def up!
    top
  end

  def down!
    bottom
  end

  def left!
    r, c = rc
    go r, 0
  end

  def right!
    r, c = rc
    cmax = self.cols - 1
    go r, cmax
  end

  def home
    go 0, 0
  end

  def rc
    [@cwin.cury, @cwin.curx]
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
rubytext-0.1.22 lib/navigation.rb
rubytext-0.1.21 lib/navigation.rb
rubytext-0.1.20 lib/navigation.rb
rubytext-0.1.19 lib/navigation.rb
rubytext-0.1.18 lib/navigation.rb
rubytext-0.1.17 lib/navigation.rb
rubytext-0.1.16 lib/navigation.rb
rubytext-0.1.15 lib/navigation.rb
rubytext-0.1.14 lib/navigation.rb
rubytext-0.1.13 lib/navigation.rb
rubytext-0.1.12 lib/navigation.rb
rubytext-0.1.11 lib/navigation.rb
rubytext-0.1.10 lib/navigation.rb
rubytext-0.1.8 lib/navigation.rb
rubytext-0.1.7 lib/navigation.rb
rubytext-0.1.6 lib/navigation.rb
rubytext-0.1.5 lib/navigation.rb
rubytext-0.1.4 lib/navigation.rb
rubytext-0.1.3 lib/navigation.rb
rubytext-0.1.2 lib/navigation.rb