Class: Rexpl::Output
- Inherits:
-
Object
- Object
- Rexpl::Output
- 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
-
.print_banner ⇒ Object
Prints the welcome banner and a bit of instructions on how to use the interactive console.
-
.print_debug_info(size, value) ⇒ Object
Prints the current size of the stack and the topmost value.
-
.print_instruction(instruction, idx) ⇒ Object
Prints an instruction in a single row.
-
.print_prompt ⇒ Object
Prints the console prompt.
-
.print_rationale ⇒ Object
Prints a little readme to get people started when firing up the interactive console.
-
.print_reset ⇒ Object
Prints a message indicating that the instruction set has been resetted.
-
.print_stack(cells) ⇒ Object
Prints a stack out of an array of stack cells.
Class Method Details
.print_banner ⇒ Object
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 puts puts bold { red { "rexpl" } } + bold { " v#{Rexpl::VERSION}" } + " - interactive bytecode console for Rubinius" puts bold { "--------------------------------------------------------" } puts print_rationale end |
.print_debug_info(size, value) ⇒ Object
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 |
.print_instruction(instruction, idx) ⇒ Object
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 |
.print_prompt ⇒ Object
Prints the console prompt.
21 22 23 |
# File 'lib/rexpl/output.rb', line 21 def print_prompt print bold { '> ' } end |
.print_rationale ⇒ Object
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 |
.print_reset ⇒ Object
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 |
.print_stack(cells) ⇒ Object
Prints a stack out of an array of stack cells.
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 |