Method: TermColor::RuleSet#printf
- Defined in:
- lib/term_color/rule_set.rb
#printf(format_string, *args, **opts) ⇒ Object
Wraps STDOUT printf method, passing output of ‘apply` to `print` Doesn’t actually use ‘printf`, instead passes result of `format_string % args` to `print`.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/term_color/rule_set.rb', line 184 def printf(format_string,*args,**opts) stdout = opts.fetch(:out, $stdout) # Sanitize rule symbols sanitized = format_string.dup @rules.keys.each { |k| sanitized.gsub!("#{@symbols.rule}#{k.to_s}","#{255.chr}#{k.to_s}") } sanitized.gsub!(@symbols.reset, 255.chr*2) t = sanitized % args # Reinstate rule symbols @rules.keys.each { |k| t.gsub!("#{255.chr}#{k.to_s}","#{@symbols.rule}#{k.to_s}") } t.gsub!(255.chr*2,@symbols.reset) stdout.print apply(t) end |