Class: Rexpl::Output

Inherits:
Object
  • Object
show all
Extended by:
ANSI::Code
Defined in:
lib/rexpl/output.rb

Overview

Utility module to abstract output-related stuff, like printing banners or graphically representing stacks.

Class Method Summary collapse

Class Method Details

Prints the welcome banner and a bit of instructions on how to use the interactive console.



12
13
14
15
16
17
18
# File 'lib/rexpl/output.rb', line 12

def print_banner
  puts
  puts bold { red { "rexpl" } } + bold { " v#{Rexpl::VERSION}" } + " - interactive bytecode console for Rubinius"
  puts bold { "--------------------------------------------------------" }
  puts
  print_rationale
end

Prints the current size of the stack and the topmost value.



31
32
33
# File 'lib/rexpl/output.rb', line 31

def print_debug_info(size, value)
  puts "=> [" + bold { "Stack size: #{size}"} + "] " + "[" + bold { "Topmost value: #{value}" } + "]"
end

Prints an instruction in a single row.



36
37
38
# File 'lib/rexpl/output.rb', line 36

def print_instruction(instruction, idx)
  puts bold { "[" } + blue { idx.to_s } + bold { "]" } + ": " + green { instruction.first } + " " + bold { instruction[1..-1].map(&:inspect) }
end

Prints the console prompt.



21
22
23
# File 'lib/rexpl/output.rb', line 21

def print_prompt
  print bold { '> ' }
end

Prints a little readme to get people started when firing up the interactive console.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rexpl/output.rb', line 56

def print_rationale
  puts "To start playing, just start typing some Rubinius VM instructions."
  puts "You can find a complete list with documentation here:"
  puts
  puts "\thttp://rubini.us/doc/en/virtual-machine/instructions/"
  puts
  puts "To introspect the program you are writing, use the following commands,"
  puts "or type " + bold { "exit" } + " to exit:"
  puts
  puts "  " + bold { "list" } + " lists the instruction set of the current program."
  puts "  " + bold { "reset" } + " empties the instruction set and starts a new program."
  puts "  " + bold { "draw" } + " prints a visual representation of the stack after each instruction."
  puts
end

Prints a message indicating that the instruction set has been resetted.



26
27
28
# File 'lib/rexpl/output.rb', line 26

def print_reset
  puts "Reseted!"
end

Prints a stack out of an array of stack cells.

Parameters:

  • cells (Array)

    the cells of the stack containing its values.



43
44
45
46
47
48
49
50
51
52
# File 'lib/rexpl/output.rb', line 43

def print_stack(cells)
  puts
  puts "\t#{bold { 'Current stack' }.center(33, ' ')}"
  puts "\t" + blue { "-------------------------" }
  cells.reverse.each do |element|
    puts "\t#{blue {"|"} }#{bold { element.inspect.center(23, ' ') }}#{blue {"|"}}"
    puts "\t" + blue { "-------------------------" }
  end
  puts
end