Class: Kward::PromptInterface::Banner

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/prompt_interface/banner.rb

Overview

Startup banner rendering data and helpers for the prompt interface.

Constant Summary collapse

LOGO_WIDTH =
32
LOGO_PIXEL_HEIGHT =
32
MIN_LOGO_HEIGHT =
4
LOGO_PIXELS =
Kward::Resources::AvatarKwardLogo::PIXELS
MESSAGE =
"State your business.".freeze

Instance Method Summary collapse

Constructor Details

#initialize(message:, pixels:, screen_height:, minimum_composer_rows: 3) ⇒ Banner

Returns a new instance of Banner.



17
18
19
20
21
22
23
# File 'lib/kward/prompt_interface/banner.rb', line 17

def initialize(message:, pixels:, screen_height:, minimum_composer_rows: 3)
  @message = message.to_s
  @pixels = pixels
  @screen_height = screen_height
  @minimum_composer_rows = minimum_composer_rows
  @logo_cache = {}
end

Instance Method Details

#logo_rows(width) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/kward/prompt_interface/banner.rb', line 35

def logo_rows(width)
  logo_width, logo_height = logo_dimensions(width)
  return [] unless @pixels && max_logo_height >= MIN_LOGO_HEIGHT

  key = [logo_width, logo_height]
  @logo_cache[key] ||= Kward::PixelLogo.half_block_rows_from_pixels(@pixels, width: logo_width, pixel_height: logo_height)
end

#rows(width) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/kward/prompt_interface/banner.rb', line 25

def rows(width)
  return [] unless visible?(width)

  rows = []
  rows.concat(centered_image_rows(width)) if image_visible?(width)
  rows << align_plain_row(@message, width) unless @message.empty?
  rows << ""
  rows
end