Class: NattyUI::Wrapper::Section

Inherits:
Element
  • Object
show all
Defined in:
lib/natty-ui/wrapper/section.rb

Overview

Visual Element to keep text lines together.

A section can contain other elements and sections.

See Also:

Direct Known Subclasses

Framed, Message, Quote

Instance Method Summary collapse

Instance Method Details

#available_widthInteger

Returns available columns count within the section.

Returns:

  • (Integer)

    available columns count within the section



31
32
33
34
# File 'lib/natty-ui/wrapper/section.rb', line 31

def available_width
  @available_width ||=
    @parent.available_width - @prefix_width - @suffix_width
end

Print given arguments into the section.

Parameters:

  • args (#to_s)

    objects to print

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :align (:left, :right, :center)

    text alignment

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/natty-ui/wrapper/section.rb', line 60

def print(*args, **options)
  return self if @status
  @parent.print(
    *args,
    **options.merge!(
      prefix: "#{@prefix}#{options[:prefix]}",
      prefix_width: @prefix_width + options[:prefix_width].to_i,
      suffix: "#{options[:suffix]}#{@suffix}",
      suffix_width: @suffix_width + options[:suffix_width].to_i
    )
  )
  self
end

#puts(*args, **options) ⇒ Section

Print given arguments line-wise into the section.

Parameters:

  • args (#to_s)

    objects to print

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :align (:left, :right, :center)

    text alignment

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/natty-ui/wrapper/section.rb', line 41

def puts(*args, **options)
  return self if @status
  @parent.puts(
    *args,
    **options.merge!(
      prefix: "#{@prefix}#{options[:prefix]}",
      prefix_width: @prefix_width + options[:prefix_width].to_i,
      suffix: "#{options[:suffix]}#{@suffix}",
      suffix_width: @suffix_width + options[:suffix_width].to_i
    )
  )
  self
end

#space(lines = 1) ⇒ Section

Add at least one empty line

Parameters:

  • lines (#to_i) (defaults to: 1)

    count of lines

Returns:



78
# File 'lib/natty-ui/wrapper/section.rb', line 78

def space(lines = 1) = puts("\n" * [1, lines.to_i].max)

#temporary {|Section| ... } ⇒ Object

Note:

The screen manipulation is only available in ANSI mode see NattyUI::Wrapper#ansi?

Resets the part of the screen written below the current output line when the given block ended.

Examples:

section.temporary do |temp|
  temp.info('This message will disappear in 5 seconds!')
  sleep 5
end

Yields:

Returns:

  • (Object)

    block result



93
# File 'lib/natty-ui/wrapper/section.rb', line 93

def temporary = block_given? ? yield(self) : self