Class: ChefCLI::Pager
- Inherits:
-
Object
- Object
- ChefCLI::Pager
- Defined in:
- lib/chef-cli/pager.rb
Instance Attribute Summary collapse
-
#pager_pid ⇒ Object
readonly
Returns the value of attribute pager_pid.
Instance Method Summary collapse
-
#env ⇒ Object
private
This is just public so we can stub it for testing.
-
#have_tty? ⇒ Boolean
private
This is just public so we can stub it for testing.
-
#initialize(enable_pager: true) ⇒ Pager
constructor
A new instance of Pager.
- #pager_enabled? ⇒ Boolean
- #start ⇒ Object
- #ui ⇒ Object
- #wait ⇒ Object
- #with_pager ⇒ Object
Constructor Details
#initialize(enable_pager: true) ⇒ Pager
Returns a new instance of Pager.
25 26 27 28 |
# File 'lib/chef-cli/pager.rb', line 25 def initialize(enable_pager: true) @enable_pager = enable_pager @pipe = nil end |
Instance Attribute Details
#pager_pid ⇒ Object (readonly)
Returns the value of attribute pager_pid.
23 24 25 |
# File 'lib/chef-cli/pager.rb', line 23 def pager_pid @pager_pid end |
Instance Method Details
#env ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This is just public so we can stub it for testing
75 76 77 |
# File 'lib/chef-cli/pager.rb', line 75 def env ENV end |
#have_tty? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This is just public so we can stub it for testing
81 82 83 |
# File 'lib/chef-cli/pager.rb', line 81 def have_tty? $stdout.tty? end |
#pager_enabled? ⇒ Boolean
30 31 32 |
# File 'lib/chef-cli/pager.rb', line 30 def pager_enabled? !!(@enable_pager && have_tty? && env["PAGER"]) end |
#start ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/chef-cli/pager.rb', line 52 def start return false unless pager_enabled? # Ignore CTRL-C because it can cause the parent to die before the # pager which causes wonky behavior in the terminal Kernel.trap(:INT, "IGNORE") @pager_pid = Process.spawn(pager_env, env["PAGER"], in: child_stdin) child_stdin.close end |
#ui ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/chef-cli/pager.rb', line 34 def ui @ui ||= if pager_enabled? UI.new(out: parent_stdout) else UI.new end end |
#wait ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/chef-cli/pager.rb', line 64 def wait return false unless pager_enabled? # Sends EOF to the PAGER parent_stdout.close # wait or else we'd kill the pager when we exit Process.waitpid(pager_pid) end |
#with_pager ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/chef-cli/pager.rb', line 43 def with_pager start begin yield self ensure wait end end |