Class: Machinery::Ui
- Inherits:
-
Object
- Object
- Machinery::Ui
- Defined in:
- lib/ui.rb
Class Attribute Summary collapse
-
.use_pager ⇒ Object
Returns the value of attribute use_pager.
Class Method Summary collapse
- .close_pager ⇒ Object
- .error(s) ⇒ Object
- .internal_scope_list_to_string(scopes) ⇒ Object
- .puts(output) ⇒ Object
- .warn(s) ⇒ Object
- .write_output_to_pager(output) ⇒ Object
Class Attribute Details
.use_pager ⇒ Object
Returns the value of attribute use_pager.
21 22 23 |
# File 'lib/ui.rb', line 21 def use_pager @use_pager end |
Class Method Details
.close_pager ⇒ Object
38 39 40 |
# File 'lib/ui.rb', line 38 def close_pager @pager.close if @pager end |
.error(s) ⇒ Object
77 78 79 |
# File 'lib/ui.rb', line 77 def error(s) STDERR.puts s end |
.internal_scope_list_to_string(scopes) ⇒ Object
23 24 25 26 |
# File 'lib/ui.rb', line 23 def internal_scope_list_to_string(scopes) list = Array(scopes) list.map { |e| e.tr("_", "-") }.join(", ") end |
.puts(output) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ui.rb', line 42 def puts(output) if !use_pager || !$stdout.tty? begin STDOUT.puts output rescue Errno::EPIPE # We just ignore broken pipes. end else if !ENV['PAGER'] || ENV['PAGER'] == '' ENV['PAGER'] = 'less' ENV['LESS'] = 'FSRX' begin LocalSystem.validate_existence_of_package("less") write_output_to_pager(output) rescue Machinery::Errors::MissingRequirement STDOUT.puts output end else IO.popen("$PAGER &>/dev/null", "w") { |f| f.close } if $?.success? write_output_to_pager(output) else raise(Machinery::Errors::InvalidPager.new("'#{ENV['PAGER']}' could not " \ "be executed. Use the --no-pager option or modify your $PAGER " \ "bash environment variable to display output.") ) end end end end |
.warn(s) ⇒ Object
73 74 75 |
# File 'lib/ui.rb', line 73 def warn(s) STDERR.puts s end |
.write_output_to_pager(output) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/ui.rb', line 28 def write_output_to_pager(output) @pager ||= IO.popen("$PAGER", "w") begin @pager.puts output rescue Errno::EPIPE # We just ignore broken pipes. end end |