Module: RatatuiRuby::Labs::A11y
- Defined in:
- lib/ratatui_ruby/labs/a11y.rb
Overview
A11Y lab: exports widget tree as XML.
Writes an XML representation of the widget tree to a temporary file every frame when enabled.
Constant Summary collapse
- OUTPUT_PATH =
Path to the XML output file in the system temp directory.
File.join(Dir.tmpdir, "ratatui_ruby_a11y.xml").freeze
Class Method Summary collapse
-
.dump_widget_tree(widget, _area = nil) ⇒ Object
Dumps the widget tree to XML (single widget for tree mode).
-
.dump_widgets(widgets_with_areas) ⇒ Object
Dumps multiple widgets captured from Frame API mode.
-
.startup_message ⇒ Object
Returns startup message for users to see before TUI launches.
Class Method Details
.dump_widget_tree(widget, _area = nil) ⇒ Object
Dumps the widget tree to XML (single widget for tree mode).
22 23 24 25 26 27 28 |
# File 'lib/ratatui_ruby/labs/a11y.rb', line 22 def (, _area = nil) ensure_rexml_loaded doc = REXML::Document.new doc.add(REXML::XMLDecl.new("1.0", "UTF-8")) doc.add(build_element()) write_document(doc) end |
.dump_widgets(widgets_with_areas) ⇒ Object
Dumps multiple widgets captured from Frame API mode.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ratatui_ruby/labs/a11y.rb', line 44 def () ensure_rexml_loaded Labs.warn_once!("Labs::A11y (RR_LABS=A11Y)") # Reset counter each frame for stable IDs @widget_id_counter = 0 doc = REXML::Document.new doc.add(REXML::XMLDecl.new("1.0", "UTF-8")) frame = REXML::Element.new("RatatuiFrame") .each do |, area| frame.add(build_element_with_area(, area)) end doc.add(frame) write_document(doc) end |
.startup_message ⇒ Object
Returns startup message for users to see before TUI launches.
Since stdout is captured during TUI rendering, users need to know where the XML file will be written before the app starts.
34 35 36 37 38 39 40 41 |
# File 'lib/ratatui_ruby/labs/a11y.rb', line 34 def <<~MSG A11Y Lab enabled! Widget tree will be written to: #{OUTPUT_PATH} Press Enter to launch the TUI... MSG end |