Class: TUITD::Screenshot
- Inherits:
-
Object
- Object
- TUITD::Screenshot
- Defined in:
- lib/tui_td/screenshot.rb
Constant Summary collapse
- CELL_W =
8- CELL_H =
16- DEFAULT_FG =
[0xC0, 0xC0, 0xC0].freeze
- DEFAULT_BG =
[0x00, 0x00, 0x00].freeze
Instance Method Summary collapse
-
#initialize(state) ⇒ Screenshot
constructor
A new instance of Screenshot.
- #render(output_path) ⇒ Object
Constructor Details
#initialize(state) ⇒ Screenshot
Returns a new instance of Screenshot.
142 143 144 145 146 147 |
# File 'lib/tui_td/screenshot.rb', line 142 def initialize(state) @state = state @rows = _dig(state, :size, :rows) || 40 @cols = _dig(state, :size, :cols) || 120 @grid = state[:rows] || state["rows"] || [] end |
Instance Method Details
#render(output_path) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/tui_td/screenshot.rb', line 149 def render(output_path) width = @cols * CELL_W height = @rows * CELL_H image = ChunkyPNG::Image.new(width, height, ChunkyPNG::Color::BLACK) @grid.each_with_index do |row, ri| next unless row row.each_with_index do |cell, ci| next unless cell render_cell(image, ri, ci, cell) end end image.save(output_path) output_path end |