Sha256: 96fd83930cb66744d65d68058dddbd2140cc0d64d04a45fdc6e45f118ef1fc48
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
# frozen_string_literal: false module Prompts class Content attr_reader :slots def initialize(width: MAX_WIDTH) @slots = [] @frame_stack = [] @width = width end def paragraph(text) paragraph = Paragraph.new(text, width: @width) @slots.concat paragraph.lines self end def gap @slots << SPACE self end def box(padded: false, border_color: nil, &block) box = Box.new(width: @width, padded: padded, border_color: border_color) yield(box) @slots.concat box.lines self end def render clear_screen render_frame end def reset! @slots = @frame_stack.first.dup end def prepend(*lines) @slots.unshift(*lines) end private def clear_screen jump_cursor_to_top erase_down end def render_frame @frame_stack << @slots.dup OUTPUT.puts SPACE return if @slots.empty? OUTPUT.puts @slots.join("\n") OUTPUT.puts SPACE @slots.clear end def jump_cursor_to_top OUTPUT.print "\033[H" end def erase_down OUTPUT.print "\e[J" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
prompts-0.2.0 | lib/prompts/content.rb |