class XfOOrth::Console
The console class enables the use of the command line console as a source for fOOrth commands and source code. The readline facility is used to enable editing and command history and retrieval.
Public Class Methods
Initialize a new console command source.
# File lib/fOOrth/compiler/source/console.rb, line 13 def initialize @peek_buffer = nil reset_read_point auto_src = lambda { SymbolMap.forward_map.keys.sort } @edit = MiniReadline::Readline.new(history: true, auto_complete: true, auto_source: MiniReadline::ArraySource, array_src: auto_src, eoi_detect: true) end
Public Instance Methods
Close the console source.
# File lib/fOOrth/compiler/source/console.rb, line 28 def close @peek_buffer = nil reset_read_point end
Has the scanning of the text reached the end of input?
Returns
-
Always returns false.
# File lib/fOOrth/compiler/source/console.rb, line 56 def eof? false end
The console has no file name to return.
# File lib/fOOrth/compiler/source/console.rb, line 84 def fine_name nil end
Get the next character of command text from the user.
Returns
-
The next character of user input as a string.
# File lib/fOOrth/compiler/source/console.rb, line 38 def get @peek_buffer || read do @edit.readline(prompt: prompt).rstrip end ensure @peek_buffer = nil end
Peek ahead by one character.
Returns:
-
A peek at next character or nil if none are available.
# File lib/fOOrth/compiler/source/console.rb, line 49 def peek @peek_buffer ||= get unless eoln? end
Build the command prompt for the user based on the state of the virtual machine.
Returns
-
A prompt string.
Endemic Code Smells
-
:reek:FeatureEnvy
# File lib/fOOrth/compiler/source/console.rb, line 66 def prompt vm = Thread.current[:vm] puts if vm.show_stack vm.data_stack.to_foorth_s(vm) puts vm.pop end '>' * vm.context.depth + '"' * vm.quotes + '(' * vm.parens end
What is the source of this text?
# File lib/fOOrth/compiler/source/console.rb, line 79 def source_name "The console." end