module Keyboard

Module to control keyboard input and control console

Author

Steven Davidovitz (steviedizzle@gmail.com)

Copyright

Copyright © 2006, The Nebular Gauntlet DEV team

License

GPL

Public Instance Methods

cursor_begin() click to toggle source

Moves cursor to then beginning of the buffer

# File lib/keyboard.rb, line 66
def cursor_begin
  @cursor_pos = 0
end
cursor_end() click to toggle source

Moves cursor to then end of the buffer

# File lib/keyboard.rb, line 61
def cursor_end
  @cursor_pos = @buffer.length
end
cursor_left() click to toggle source

Moves cursor left one character

# File lib/keyboard.rb, line 56
def cursor_left
  @cursor_pos -= 1 if @cursor_pos > 0
end
cursor_right() click to toggle source

Moves cursor right one character

# File lib/keyboard.rb, line 51
def cursor_right
  @cursor_pos += 1 if @cursor_pos < @buffer.length
end
history_down() click to toggle source

Scrolls history down one line

# File lib/keyboard.rb, line 37
def history_down      
  if @command_archive.length != 0
    if @hpos < -1
      @hpos += 1
      @buffer = @command_archive[@hpos]
      @cursor_pos = @buffer.length
    else
      @buffer = ""
      @cursor_pos = @buffer.length
    end
  end
end
history_up() click to toggle source

Scrolls history up one line

# File lib/keyboard.rb, line 28
def history_up
  if @command_archive.length != 0
    @buffer = @command_archive[@hpos]
    @cursor_pos = @buffer.length
    @hpos -= 1 if @hpos.abs < @command_archive.length
  end
end
scroll_down() click to toggle source

Scrolls input buffer down one command

# File lib/keyboard.rb, line 20
def scroll_down
  if @console_view[-1][1] != @console_archive[-1][1]
    @console_view.insert(-1, @console_archive.at(@console_archive.index(@console_view[-1]) + 1))
    @console_view.shift
  end
end
scroll_up() click to toggle source

Scrolls input buffer up one command

# File lib/keyboard.rb, line 12
def scroll_up
  if @console_view[0][1] != @console_archive[0][1]
    @console_view.insert(0, @console_archive.at(@console_archive.index(@console_view[0]) - 1))
    @console_view.pop
  end
end