Class: Bash_Visual::HorizontalScroll

Inherits:
Scroll
  • Object
show all
Defined in:
lib/bash-visual/horizontal_scroll.rb

Constant Summary collapse

DEFAULT_SEPARATOR =
"\u2502"

Constants inherited from Scroll

Scroll::BACKWARD, Scroll::BEGINNING, Scroll::ENDING, Scroll::FORWARD

Instance Attribute Summary

Attributes inherited from Scroll

#console

Attributes included from FixedObject

#height, #width, #x, #y

Instance Method Summary collapse

Methods inherited from Scroll

#add, form_block, #prefix, #prefix=, #scroll

Methods included from FixedObject

#position, #size

Constructor Details

#initialize(options) ⇒ HorizontalScroll

Returns a new instance of HorizontalScroll.



6
7
8
9
10
11
12
13
14
# File 'lib/bash-visual/horizontal_scroll.rb', line 6

def initialize options
  super

  @separator =
    if @separator == true;                  DEFAULT_SEPARATOR
    elsif @s.instance_of? String;   @separator[0]
    else                                    nil
  end
end

Instance Method Details

#get_x_position(available_area_width, message_width = 0) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/bash-visual/horizontal_scroll.rb', line 16

def get_x_position available_area_width, message_width = 0
  if (@start == BEGINNING)
    @x + (@width - available_area_width)
  else
    @x + available_area_width - message_width
  end
end


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bash-visual/horizontal_scroll.rb', line 24

def print_message message, font, available_area

  available_area_width, available_area_height = available_area

  block_width = msg_block_width =
      case
        when @fixed_message_block_size
          @fixed_message_block_size
        when @max_message_block_size
          @max_message_block_size
        else
          available_area_width
      end

  msg_block_width -= @separator.size if @separator
  msg_block_width = available_area_width if msg_block_width > available_area_width

  msg_block_height = @adapt ? available_area_height : 1

  message = Scroll.form_block message, [msg_block_width, msg_block_height], @fixed_message_block_size
  if @separator
    message.map! do |row|
      row + @separator
    end
  end

  write(get_x_position(available_area_width, block_width), @y, message, font)

  [available_area_width - block_width, available_area_height]
end