Module: CLI::UI::Frame::FrameStack

Extended by:
T::Sig
Defined in:
lib/cli/ui/frame/frame_stack.rb

Defined Under Namespace

Classes: StackItem

Constant Summary collapse

COLOR_ENVVAR =
'CLI_FRAME_STACK'
STYLE_ENVVAR =
'CLI_STYLE_STACK'

Class Method Summary collapse

Methods included from T::Sig

sig

Class Method Details

.itemsObject


33
34
35
36
37
38
39
40
# File 'lib/cli/ui/frame/frame_stack.rb', line 33

def items
  colors = ENV.fetch(COLOR_ENVVAR, '').split(':').map(&:to_sym)
  styles = ENV.fetch(STYLE_ENVVAR, '').split(':').map(&:to_sym)

  colors.each_with_index.map do |color, i|
    StackItem.new(color, styles[i] || Frame.frame_style)
  end
end

.popObject


83
84
85
86
87
88
89
90
# File 'lib/cli/ui/frame/frame_stack.rb', line 83

def pop
  curr = items
  ret = curr.pop

  serialize(curr)

  ret.nil? ? nil : ret
end

.push(item = nil, color: nil, style: nil) ⇒ Object


68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/cli/ui/frame/frame_stack.rb', line 68

def push(item = nil, color: nil, style: nil)
  if color.nil? != style.nil? || item.nil? == color.nil?
    raise ArgumentError, 'Must give one of item or color: and style:'
  end

  item ||= StackItem.new(T.must(color), T.must(style))

  curr = items
  curr << item

  serialize(curr)
end