Class: SublimeDSL::Tools::Console
- Inherits:
-
Object
- Object
- SublimeDSL::Tools::Console
- Defined in:
- lib/sublime_dsl/tools/console.rb
Overview
Tools for console interaction.
Instance Attribute Summary collapse
-
#in_progress ⇒ Object
readonly
Returns the value of attribute in_progress.
-
#set_ruby_verbosity ⇒ Object
Returns the value of attribute set_ruby_verbosity.
-
#verbosity ⇒ Object
Returns the value of attribute verbosity.
Instance Method Summary collapse
- #error(text) ⇒ Object
- #info(text, force = false) ⇒ Object
-
#initialize ⇒ Console
constructor
A new instance of Console.
- #progress(index, count, file, force = false) ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize ⇒ Console
Returns a new instance of Console.
14 15 16 17 18 |
# File 'lib/sublime_dsl/tools/console.rb', line 14 def initialize @verbosity = 1 @set_ruby_verbosity = true @in_progress = false end |
Instance Attribute Details
#in_progress ⇒ Object (readonly)
Returns the value of attribute in_progress.
12 13 14 |
# File 'lib/sublime_dsl/tools/console.rb', line 12 def in_progress @in_progress end |
#set_ruby_verbosity ⇒ Object
Returns the value of attribute set_ruby_verbosity.
11 12 13 |
# File 'lib/sublime_dsl/tools/console.rb', line 11 def set_ruby_verbosity @set_ruby_verbosity end |
#verbosity ⇒ Object
Returns the value of attribute verbosity.
10 11 12 |
# File 'lib/sublime_dsl/tools/console.rb', line 10 def verbosity @verbosity end |
Instance Method Details
#error(text) ⇒ Object
20 21 22 23 |
# File 'lib/sublime_dsl/tools/console.rb', line 20 def error(text) end_progress $stderr.puts text end |
#info(text, force = false) ⇒ Object
36 37 38 39 40 |
# File 'lib/sublime_dsl/tools/console.rb', line 36 def info(text, force = false) return unless $stdout.tty? && (verbosity > 0 || force) end_progress puts text end |
#progress(index, count, file, force = false) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sublime_dsl/tools/console.rb', line 46 def progress(index, count, file, force = false) return unless $stdout.tty? && (verbosity == 2 || force) @in_progress = true c = count.to_s prefix = "file %#{c.length}d/#{c}: " % index line = "#{prefix}#{file}" padding = width - line.length - 1 if padding < 0 file = file[(-padding) .. -1] file[0..2] = "..." line = "#{prefix}#{file}" else line << ' ' * padding end print "#{line}\r" $stdout.flush end |
#width ⇒ Object
42 43 44 |
# File 'lib/sublime_dsl/tools/console.rb', line 42 def width (ENV['COLUMNS'] || 80).to_i end |