$LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
require "ratatui_ruby"
class WidgetPopup
def initialize
@clear_enabled = false
end
def run
RatatuiRuby.run do |tui|
loop do
tui.draw do |frame|
render(tui, frame)
end
break if handle_input(tui) == :quit
sleep 0.05
end
end
end
private def render(tui, frame)
area = frame.area
background = tui.paragraph(
text: "BACKGROUND RED " * 100,
style: tui.style(bg: :red, fg: :white),
wrap: true
)
frame.render_widget(background, area)
vertical_layout = tui.layout_split(
area,
direction: :vertical,
constraints: [
tui.constraint_percentage(25),
tui.constraint_percentage(50),
tui.constraint_percentage(25),
]
)
popup_area_vertical = vertical_layout[1]
horizontal_layout = tui.layout_split(
popup_area_vertical,
direction: :horizontal,
constraints: [
tui.constraint_percentage(20),
tui.constraint_percentage(60),
tui.constraint_percentage(20),
]
)
popup_area = horizontal_layout[1]
popup_text = if @clear_enabled
"✓ Clear is ENABLED\n\nResets background to default\n(Usually Black/Transparent)\n\nPress Space to toggle"
else
"✗ Clear is DISABLED\n\nStyle Bleed: Popup is RED!\n(Inherits background style)\n\nPress Space to toggle"
end
popup_content = tui.paragraph(
text: popup_text,
alignment: :center,
block: tui.block(
title: "Popup (q to quit, space to toggle)",
borders: [:all]
)
)
if @clear_enabled
frame.render_widget(tui.clear, popup_area)
end
frame.render_widget(popup_content, popup_area)
end
private def handle_input(tui)
case tui.poll_event
in { type: :key, code: "q" } | { type: :key, code: "c", modifiers: ["ctrl"] }
:quit
in type: :key, code: " "
@clear_enabled = !@clear_enabled
else
nil
end
end
end
WidgetPopup.new.run if __FILE__ == $0