Class: Zgomot::UI::ErrorWindow

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/zgomot/ui/windows.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#set_color, #write

Constructor Details

#initialize(top) ⇒ ErrorWindow

Returns a new instance of ErrorWindow.



305
306
307
308
# File 'lib/zgomot/ui/windows.rb', line 305

def initialize(top)
  @top = top
  display
end

Instance Attribute Details

#topObject (readonly)

Returns the value of attribute top.



304
305
306
# File 'lib/zgomot/ui/windows.rb', line 304

def top
  @top
end

Instance Method Details

#displayObject



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/zgomot/ui/windows.rb', line 309

def display
  error_message = Zgomot.last_error
  text, text_color = if error_message.nil?
                       [["it's cool"], COLOR_BORDER]
                     else
                       [error_message.scan(/.{1,#{WIDTH-4}}/), COLOR_ERROR]
                     end
  set_color(COLOR_BORDER) {
    write(top, 0, '-' * WIDTH)
    write(top + 1, 0, '|')
    write(top + 1, WIDTH-1, '|')
    write(top + 2, 0, '|')
    write(top + 2, WIDTH-1, '|')
    write(top + 3, 0, '-' * WIDTH)
  }
  set_color(text_color) {
    lines = text.length > 1 ? 2 : 1
    lines.times{|i| write(top + 1 + i, 2, "%-#{WIDTH-4}s" % text[i])}
    blank_width = WIDTH - 4
    (2 - lines).times{|i| write(top + 2 - i, 2, ' ' * blank_width)}
  }
end