class RatatuiRuby::DSL

A wrapper class that provides a concise DSL for creating widgets and interacting with the terminal within the main_loop.

This class is yielded to the block provided to {RatatuiRuby.main_loop}. It uses metaprogramming to delegate method calls to {RatatuiRuby} module functions and to act as a factory for {RatatuiRuby} widget classes.

Features

  1. **Widget Shorthand**: Provides factory methods for every widget class. Converts snake_case method calls (e.g., paragraph) into CamelCase class instantiations (e.g., RatatuiRuby::Paragraph.new).

  2. **Method Shorthand**: Aliases module functions of {RatatuiRuby}, allowing you to call methods like draw and poll_event directly on the DSL object.

Example

RatatuiRuby.main_loop do |tui|
  # Create UI using shorthand methods
  view = tui.paragraph(
    text: "Hello World",
    block: tui.block(borders: [:all])
  )

  # Use module aliases to draw and handle events
  tui.draw(view)
  event = tui.poll_event

  break if event && event[:code] == "q"
end