Class: Term::ANSIColor::PPMReader
- Inherits:
-
Object
- Object
- Term::ANSIColor::PPMReader
- Includes:
- Term::ANSIColor
- Defined in:
- lib/term/ansicolor/ppm_reader.rb
Constant Summary
Constants included from Term::ANSIColor
COLORED_REGEXP, VERSION, VERSION_ARRAY, VERSION_BUILD, VERSION_MAJOR, VERSION_MINOR
Instance Method Summary collapse
-
#initialize(io, options = {}) ⇒ PPMReader
constructor
A new instance of PPMReader.
- #reset_io ⇒ Object
- #rows ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Methods included from Term::ANSIColor
#apply_attribute, #apply_code, attributes, #color, coloring=, coloring?, #on_color, #term_ansicolor_attributes, term_ansicolor_attributes, true_coloring=, true_coloring?, #uncolor
Methods included from Attribute::Underline
Methods included from Hyperlink
Methods included from Movement
#clear_screen, #erase_in_display, #erase_in_line, #hide_cursor, #move_backward, #move_down, #move_forward, #move_home, #move_to, #move_to_column, #move_to_line, #move_to_next_line, #move_to_previous_line, #move_up, #restore_position, #return_to_position, #save_position, #scroll_down, #scroll_up, #show_cursor, #terminal_columns, #terminal_lines
Constructor Details
#initialize(io, options = {}) ⇒ PPMReader
Returns a new instance of PPMReader.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/term/ansicolor/ppm_reader.rb', line 6 def initialize(io, = {}) @io = io @options = @buffer = ''.dup if [:true_coloring] @color = -> pixel { on_color Attribute.true_color(pixel, @options) } else @color = -> pixel { on_color Attribute.nearest_rgb_color(pixel, @options) } end end |
Instance Method Details
#reset_io ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/term/ansicolor/ppm_reader.rb', line 17 def reset_io begin @io.rewind rescue Errno::ESPIPE end parse_header end |
#rows ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/term/ansicolor/ppm_reader.rb', line 25 def rows reset_io Enumerator.new do |yielder| @height.times do yielder.yield parse_row end end end |
#to_a ⇒ Object
35 36 37 |
# File 'lib/term/ansicolor/ppm_reader.rb', line 35 def to_a rows.to_a end |
#to_s ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/term/ansicolor/ppm_reader.rb', line 39 def to_s rows.map do |row| last_pixel = nil row.map do |pixel| if pixel != last_pixel last_pixel = pixel @color.(pixel) << ' ' else ' ' end end.join << reset << ?\n end.join end |