Inline Viewports
Standard TUIs erase themselves on exit. Your carefully formatted CLI output disappears. Users lose their scrollback.
Inline viewports solve this. They occupy a fixed number of lines, render rich UI, then leave the output in place when done.
Perfect for spinners, menus, progress indicators—any brief moment of richness.
class Spinner
def main
RatatuiRuby.(viewport: :inline, height: 1) do |tui|
until
status = tui.(text: "#{} Connecting...")
tui. { |frame| frame.(status, frame.) }
return (tui, "Canceled!", :red) if tui..
end
(tui, "Connected!", :green)
end
end
def ending(tui, message, color) = tui. do |frame|
frame.(tui.(text: message, fg: color), frame.)
end
def initialize = (@frame, @finish = 0, Time. + 2)
def connected? = Time. >= @finish
def spin = SPINNER[(@frame += 1) % SPINNER.]
SPINNER = %w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏]
end
Spinner..;