Class: RMTools::TempPrinter
Overview
transparent print: print text (or object details) and erase it
Instance Method Summary collapse
- #clear ⇒ Object
- #end ⇒ Object
- #end! ⇒ Object
- #format_str(params_hash = nil) ⇒ Object
-
#initialize(object = nil, format = nil) ⇒ TempPrinter
constructor
A new instance of TempPrinter.
- #p(str = format_str) ⇒ Object
Constructor Details
#initialize(object = nil, format = nil) ⇒ TempPrinter
Returns a new instance of TempPrinter.
8 9 10 11 12 13 14 |
# File 'lib/rmtools/console/printing.rb', line 8 def initialize object=nil, format=nil if @object = object @format = '"' + format.gsub(/:([a-z_]\w*)/, '#{@\1.inspect}') + '"' else @format = format end end |
Instance Method Details
#clear ⇒ Object
38 39 40 |
# File 'lib/rmtools/console/printing.rb', line 38 def clear p "" end |
#end ⇒ Object
34 35 36 |
# File 'lib/rmtools/console/printing.rb', line 34 def end @eraser = nil end |
#end! ⇒ Object
42 43 44 45 |
# File 'lib/rmtools/console/printing.rb', line 42 def end! clear self.end end |
#format_str(params_hash = nil) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/rmtools/console/printing.rb', line 16 def format_str params_hash=nil if params_hash params_hash.each {|k, v| @format.sub! ":#{k}", v.inspect} else @object.instance_eval @format end end |
#p(str = format_str) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/rmtools/console/printing.rb', line 24 def p(str=format_str) STDOUT << @eraser if @eraser cols = ENV['COLUMNS'].to_i astr = RUBY_VERSION < '1.9' ? UTF2ANSI[str] : str rows = astr.split("\n").sum {|line| 1 + line.size/cols} eraser = "\b" + "\r\b"*rows + " " @eraser = eraser + " "*cols*rows + eraser puts str end |