The CLI::UI::Frame module allows you to create visual boundaries in the terminal to organize content. Frames can be nested, creating a hierarchical visual structure where each nested frame inherits or overrides the styling of its parent.
There are two ways to use frames:
- Block Form (Recommended): You pass a block to
CLI::UI::Frame.open. The frame automatically closes when the block finishes. The return value of the block determines if the frame is marked as a success or failure. If the block raises an error, the frame is automatically closed with a failure state. - Blockless Form: You call
CLI::UI::Frame.open without a block. In this mode, you must manually call CLI::UI::Frame.close to terminate the frame. This mode is strongly discouraged.
When nesting frames, CLI::UI::Frame.divider can be used to add horizontal separators within a frame, and it correctly respects the nesting level to maintain visual alignment.
# Block form with automatic success/failure handling
CLI::UI::Frame.open('Task Name', success_text: 'Done!', failure_text: 'Failed') do
# Perform work here
puts 'Working...'
end
# Nested framing
CLI::UI::Frame.open('Parent') do
puts 'Parent content'
CLI::UI::Frame.open('Child') do
puts 'Child content'
CLI::UI::Frame.divider('Separator')
end
end