Class: Git::Trac::Pager
- Inherits:
-
Object
- Object
- Git::Trac::Pager
- Defined in:
- lib/git/trac/pager.rb
Constant Summary collapse
- DIFF_COLORS =
{ :reset => "\033[m", :plain => "", :meta => "\033[1m", :frag => "\033[36m", :old => "\033[31m", :new => "\033[32m", :commit => "\033[33m", :whitespace => "\033[41m" }
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Instance Method Summary collapse
-
#initialize(command = nil) ⇒ Pager
constructor
A new instance of Pager.
- #page(body, diff = false) ⇒ Object
Constructor Details
#initialize(command = nil) ⇒ Pager
Returns a new instance of Pager.
31 32 33 34 |
# File 'lib/git/trac/pager.rb', line 31 def initialize(command = nil) @command = command || ENV["PAGER"] || "less" @command = nil if @command.empty? end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
29 30 31 |
# File 'lib/git/trac/pager.rb', line 29 def command @command end |
Instance Method Details
#page(body, diff = false) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/git/trac/pager.rb', line 36 def page(body, diff = false) less = ENV["LESS"] ENV["LESS"] ||= "FRSX" return $stdout.puts(body) unless $stdout.tty? if command.nil? output_to_io($stdout, body, diff) else IO.popen(command, "w") do |io| output_to_io(io, body, diff) end end rescue Errno::EPIPE # Pager was terminated ensure ENV["LESS"] = less end |