Class: Fir

Inherits:
Object
  • Object
show all
Defined in:
lib/fir.rb,
lib/fir/key.rb,
lib/fir/lines.rb,
lib/fir/cursor.rb,
lib/fir/eraser.rb,
lib/fir/indent.rb,
lib/fir/screen.rb,
lib/fir/history.rb,
lib/fir/version.rb,
lib/fir/renderer.rb,
lib/fir/evaluater.rb,
lib/fir/repl_state.rb,
lib/fir/suggestion.rb,
lib/fir/screen_helper.rb,
lib/fir/key_command/key_command.rb,
lib/fir/key_command/tab_command.rb,
lib/fir/key_command/enter_command.rb,
lib/fir/key_command/ctrl_a_command.rb,
lib/fir/key_command/ctrl_c_command.rb,
lib/fir/key_command/ctrl_d_command.rb,
lib/fir/key_command/ctrl_e_command.rb,
lib/fir/key_command/ctrl_v_command.rb,
lib/fir/key_command/ctrl_z_command.rb,
lib/fir/key_command/up_arrow_command.rb,
lib/fir/key_command/backspace_command.rb,
lib/fir/key_command/down_arrow_command.rb,
lib/fir/key_command/left_arrow_command.rb,
lib/fir/key_command/single_key_command.rb,
lib/fir/key_command/right_arrow_command.rb

Defined Under Namespace

Modules: ScreenHelper Classes: BackspaceCommand, CtrlACommand, CtrlCCommand, CtrlDCommand, CtrlECommand, CtrlVCommand, CtrlZCommand, Cursor, DownArrowCommand, EnterCommand, Eraser, Evaluater, History, Indent, Key, KeyCommand, LeftArrowCommand, Lines, Renderer, ReplState, RightArrowCommand, Screen, SingleKeyCommand, Suggestion, TabCommand, UpArrowCommand

Constant Summary collapse

VERSION =
'0.1.1'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, screen) ⇒ Fir

Returns a new instance of Fir.



46
47
48
49
# File 'lib/fir.rb', line 46

def initialize(key, screen)
  @key = key
  @screen = screen
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



13
14
15
# File 'lib/fir.rb', line 13

def key
  @key
end

#screenObject (readonly)

Returns the value of attribute screen.



14
15
16
# File 'lib/fir.rb', line 14

def screen
  @screen
end

Class Method Details

.configObject



34
35
36
37
38
# File 'lib/fir.rb', line 34

def self.config
  @config ||= {
    history: '~/.irb_history'
  }
end

.parse_opts(output) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/fir.rb', line 24

def self.parse_opts(output)
  OptionParser.new do |cl_opts|
    cl_opts.banner = 'Usage: fir [options]'
    cl_opts.on('-v', '--version', 'Show version') do |v|
      config[:version] = v
    end
  end.parse!
  process_immediate_opts(config, output)
end

.process_immediate_opts(opts, output) ⇒ Object



40
41
42
43
44
# File 'lib/fir.rb', line 40

def self.process_immediate_opts(opts, output)
  return unless opts[:version]
  output.syswrite(Fir::VERSION)
  exit(0)
end

.start(input, output, error) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/fir.rb', line 16

def self.start(input, output, error)
  parse_opts(output)
  new(
    Key.new(input),
    Screen.new(output, error)
  ).perform(ReplState.blank)
end

Instance Method Details

#perform(state) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/fir.rb', line 51

def perform(state)
  state = yield(state) if block_given?
  perform(state) do
    state.transition(KeyCommand.for(key.get, state)) do |new_state|
      screen.update(state, new_state)
    end
  end
end