Class: Swarm::Console::PopUp

Inherits:
Window
  • Object
show all
Defined in:
lib/swarm/console.rb

Instance Method Summary collapse

Constructor Details

#initialize(message, indent: 2) ⇒ PopUp

Returns a new instance of PopUp.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/swarm/console.rb', line 42

def initialize(message, indent: 2)
  lines = message.split(?\n)
  height = 2 + lines.count
  max = lines.map(&:length).max
  width = max + (indent*2)

  super height,
        width,
        (Console.height/2) - (height/2),
        (Console.width/2) - (max/2) - indent

  box ?|, ?-, ?+

  lines.each.with_index do |line, index|
    setpos (index + 1), 2
    addstr line.center(max)
  end
end