class Vice::Vice
Attributes
buffers[RW]
config[R]
current_buffer[RW]
cursor[RW]
mode[RW]
msg[R]
prompt[RW]
Public Class Methods
new(filenames)
click to toggle source
# File lib/vice.rb, line 15 def initialize(filenames) init_config @mode = :command @buffers = [] @parser = Parser.new @prompt = '' @current_buffer = 0 if filenames.nil? || filenames.empty? @buffers.push Buffer.new(self, nil) else filenames.each do |f| @buffers.push Buffer.new(self, f) next_buffer end end end
Public Instance Methods
alert(msg)
click to toggle source
# File lib/vice.rb, line 82 def alert(msg) @msg = msg end
error(msg)
click to toggle source
# File lib/vice.rb, line 86 def error(msg) @msg = 'error: ' + msg end
init_config()
click to toggle source
# File lib/vice.rb, line 34 def init_config defaults = DEFAULTS.clone configfile = "#{Dir.home}/.vicerc" unless File.file? configfile @config = defaults return end user_defined = File.open(configfile) { |f| YAML.safe_load(f.read) } if File.file? configfile # merge the hashes, to up to two levels of depth. # positive side-effect: our keys are symbols now @config = {} defaults.each do |dk, dv| uv = user_defined[dk.to_s] @config[dk] = if uv.nil? dv elsif uv.is_a? Hash uv = Hash[uv.map { |k, v| [k, v.to_sym] }] dv.merge(uv) else uv end end end
next_buffer()
click to toggle source
# File lib/vice.rb, line 94 def next_buffer @current_buffer += 1 @current_buffer = 0 if @current_buffer >= @buffers.length end
prev_buffer()
click to toggle source
# File lib/vice.rb, line 99 def prev_buffer @current_buffer -= 1 @current_buffer = @buffers.length - 1 if @current_buffer.negative? end
reset_alert()
click to toggle source
# File lib/vice.rb, line 90 def reset_alert @msg = nil end
start()
click to toggle source
# File lib/vice.rb, line 62 def start Curses.init_screen Curses.noecho Curses.start_color Curses.use_default_colors window = Curses.stdscr blitter = Blitter.new window alert "welcome to vice #{VERSION} - https://github.com/knarka/vice" loop do blitter.drawbuffer self, window key = window.getch @parser.parsekeypress self, @current_buffer, key end Curses.close_screen end