Class: TUITD::HtmlRenderer
- Inherits:
-
Object
- Object
- TUITD::HtmlRenderer
- Includes:
- ANSIUtils
- Defined in:
- lib/tui_td/html_renderer.rb
Overview
Renders terminal state as a self-contained HTML document. Faithfully reproduces what a TUI application shows — colors, styles, cursor position — so an LLM or human can “see” the terminal.
Constant Summary
Constants included from ANSIUtils
ANSIUtils::ANSI_INDEX, ANSIUtils::ANSI_RGB, ANSIUtils::CUBE, ANSIUtils::DEFAULT_BG, ANSIUtils::DEFAULT_FG
Instance Method Summary collapse
-
#initialize(state) ⇒ HtmlRenderer
constructor
A new instance of HtmlRenderer.
-
#render(output_path) ⇒ Object
Write HTML to a file.
-
#to_html ⇒ Object
Return HTML string.
Methods included from ANSIUtils
#_dig, #resolve_color, #xterm_256
Constructor Details
#initialize(state) ⇒ HtmlRenderer
Returns a new instance of HtmlRenderer.
12 13 14 15 16 17 18 |
# File 'lib/tui_td/html_renderer.rb', line 12 def initialize(state) @state = state @rows = _dig(state, :size, :rows) || 40 @cols = _dig(state, :size, :cols) || 120 @grid = state[:rows] || state["rows"] || [] @cursor = state[:cursor] || state["cursor"] || { row: 0, col: 0 } end |
Instance Method Details
#render(output_path) ⇒ Object
Write HTML to a file
39 40 41 42 |
# File 'lib/tui_td/html_renderer.rb', line 39 def render(output_path) File.write(output_path, to_html) output_path end |
#to_html ⇒ Object
Return HTML string
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tui_td/html_renderer.rb', line 21 def to_html css = render_css body = render_body <<~HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>TUI Terminal</title> <style>#{css}</style> </head> <body>#{body}</body> </html> HTML end |