Class: XfOOrth::Console

Inherits:
Object show all
Includes:
ReadPoint
Defined in:
lib/fOOrth/compiler/source/console.rb

Overview

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.

Instance Attribute Summary

Attributes included from ReadPoint

#read_buffer

Instance Method Summary collapse

Methods included from ReadPoint

#eoln?, #read, #reset_read_point

Constructor Details

#initializeConsole

Initialize a new console command source.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fOOrth/compiler/source/console.rb', line 13

def initialize
  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

Instance Method Details

#eof?Boolean

Has the scanning of the text reached the end of input?
Returns

  • Always returns false.

Returns:

  • (Boolean)


40
41
42
# File 'lib/fOOrth/compiler/source/console.rb', line 40

def eof?
  false
end

#getObject

Get the next character of command text from the user.
Returns

  • The next character of user input as a string.



31
32
33
34
35
# File 'lib/fOOrth/compiler/source/console.rb', line 31

def get
  read do
    @edit.readline(prompt: prompt).rstrip
  end
end

#promptObject

Build the command prompt for the user based on the state of the virtual machine.
Returns

  • A prompt string.


Endemic Code Smells

  • :reek:FeatureEnvy



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fOOrth/compiler/source/console.rb', line 50

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
end

#source_nameObject Also known as: file_name

What is the source of this text?



63
64
65
# File 'lib/fOOrth/compiler/source/console.rb', line 63

def source_name
  "The console."
end