Class: TUITD::Screenshot
- Inherits:
-
Object
- Object
- TUITD::Screenshot
- Includes:
- ANSIUtils
- Defined in:
- lib/tui_td/screenshot.rb
Constant Summary collapse
- CELL_W =
8- CELL_H =
16
Constants included from ANSIUtils
ANSIUtils::ANSI_INDEX, ANSIUtils::ANSI_RGB, ANSIUtils::CUBE, ANSIUtils::DEFAULT_BG, ANSIUtils::DEFAULT_FG
Instance Method Summary collapse
-
#initialize(state) ⇒ Screenshot
constructor
A new instance of Screenshot.
- #render(output_path) ⇒ Object
Methods included from ANSIUtils
#_dig, #resolve_color, #xterm_256
Constructor Details
#initialize(state) ⇒ Screenshot
Returns a new instance of Screenshot.
112 113 114 115 116 117 |
# File 'lib/tui_td/screenshot.rb', line 112 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
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/tui_td/screenshot.rb', line 119 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 |