Class: Fir::ReplState
- Inherits:
-
Object
- Object
- Fir::ReplState
- Defined in:
- lib/fir/repl_state.rb
Instance Attribute Summary collapse
-
#cursor ⇒ Object
Returns the value of attribute cursor.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#indent ⇒ Object
readonly
Returns the value of attribute indent.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#repl_binding ⇒ Object
readonly
Returns the value of attribute repl_binding.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #blank ⇒ Object
- #blank? ⇒ Boolean
- #clone ⇒ Object
- #commit_current_line_to_history ⇒ Object
- #current_line ⇒ Object
- #current_line=(new_line) ⇒ Object
- #executable? ⇒ Boolean
- #indents ⇒ Object
-
#initialize(lines, cursor, repl_binding = TOPLEVEL_BINDING, history = Fir::History.new) ⇒ ReplState
constructor
A new instance of ReplState.
- #suggestion ⇒ Object
- #transition(command) {|new_state| ... } ⇒ Object
Constructor Details
#initialize(lines, cursor, repl_binding = TOPLEVEL_BINDING, history = Fir::History.new) ⇒ ReplState
Returns a new instance of ReplState.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fir/repl_state.rb', line 19 def initialize( lines, cursor, repl_binding = TOPLEVEL_BINDING, history = Fir::History.new ) @lines = lines @cursor = cursor @repl_binding = repl_binding @history = history set_indent end |
Instance Attribute Details
#cursor ⇒ Object
Returns the value of attribute cursor.
12 13 14 |
# File 'lib/fir/repl_state.rb', line 12 def cursor @cursor end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
13 14 15 |
# File 'lib/fir/repl_state.rb', line 13 def history @history end |
#indent ⇒ Object (readonly)
Returns the value of attribute indent.
13 14 15 |
# File 'lib/fir/repl_state.rb', line 13 def indent @indent end |
#lines ⇒ Object
Returns the value of attribute lines.
12 13 14 |
# File 'lib/fir/repl_state.rb', line 12 def lines @lines end |
#repl_binding ⇒ Object (readonly)
Returns the value of attribute repl_binding.
13 14 15 |
# File 'lib/fir/repl_state.rb', line 13 def repl_binding @repl_binding end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object
62 63 64 |
# File 'lib/fir/repl_state.rb', line 62 def ==(other) lines == other.lines && cursor == other.cursor end |
#blank ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/fir/repl_state.rb', line 49 def blank self.class.new( Lines.blank, Cursor.blank, repl_binding, history ) end |
#blank? ⇒ Boolean
58 59 60 |
# File 'lib/fir/repl_state.rb', line 58 def blank? lines.blank? && cursor.blank? end |
#clone ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/fir/repl_state.rb', line 40 def clone self.class.new( lines.clone, cursor.clone, repl_binding, history ) end |
#commit_current_line_to_history ⇒ Object
86 87 88 89 90 |
# File 'lib/fir/repl_state.rb', line 86 def commit_current_line_to_history Fir::History.add_line_to_history_file( current_line.join ) end |
#current_line ⇒ Object
70 71 72 |
# File 'lib/fir/repl_state.rb', line 70 def current_line lines[cursor.y] end |
#current_line=(new_line) ⇒ Object
66 67 68 |
# File 'lib/fir/repl_state.rb', line 66 def current_line=(new_line) lines[cursor.y] = new_line end |
#executable? ⇒ Boolean
78 79 80 |
# File 'lib/fir/repl_state.rb', line 78 def executable? indent.executable? end |
#indents ⇒ Object
74 75 76 |
# File 'lib/fir/repl_state.rb', line 74 def indents indent.indents end |
#suggestion ⇒ Object
82 83 84 |
# File 'lib/fir/repl_state.rb', line 82 def suggestion history.suggestion(current_line.join) end |
#transition(command) {|new_state| ... } ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/fir/repl_state.rb', line 32 def transition(command) new_state = command.execute new_state.set_indent yield new_state if block_given? return blank if new_state.executable? new_state end |