Class: Bash_Visual::Scroll
- Inherits:
-
Object
- Object
- Bash_Visual::Scroll
show all
- Includes:
- FixedObject
- Defined in:
- lib/bash-visual/scroll.rb
Constant Summary
collapse
- FORWARD =
1
- BACKWARD =
-1
- BEGINNING =
false
- ENDING =
true
Instance Attribute Summary collapse
Attributes included from FixedObject
#height, #width, #x, #y
Class Method Summary
collapse
Instance Method Summary
collapse
#position, #size
Constructor Details
#initialize(options) ⇒ Scroll
options = {
position: [x, y],
size: [width, height],
font: Font.new (:bold)
start: Scroll::ENDING,
adapt_size_message: true,
prefix: -> { '>' }
separator: '-'
}
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
|
# File 'lib/bash-visual/scroll.rb', line 28
def initialize(options)
unless options[:position] && options[:size]
raise "Minimum needs: :size and :position"
end
@width, @height = options[:size]
@x, @y = options[:position]
@prefix = options[:prefix]
@adapt = options[:adapt].nil? ? true : options[:adapt]
@separator = options[:separator]
@max_message_block_size = options[:max_message_block_size]
@fixed_message_block_size = options[:fixed_message_block_size]
@start = options[:start] ? ENDING : BEGINNING
@font = options[:font] ? options[:font] : Font.new
@stack = []
@stateless = false
@console = Console.new @font, Console::OUTPUT_STRING
@mutex = Mutex.new
end
|
Instance Attribute Details
#console ⇒ Object
Returns the value of attribute console.
12
13
14
|
# File 'lib/bash-visual/scroll.rb', line 12
def console
@console
end
|
Class Method Details
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/bash-visual/scroll.rb', line 86
def form_block(text, size, fixate = false)
width, height = size
result = []
height.times do |i|
line = text[i * width, width]
unless line
break unless fixate
result.fill(' ' * width, i, height - i)
break
end
result << line.ljust(width)
end
result
end
|
Instance Method Details
#add(message, font = @font) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/bash-visual/scroll.rb', line 60
def add(message, font = @font)
unless font.background
font = Font.new font.types, font.foreground, @font.background
end
@stack << {message: prefix() + message.to_s, font: font}
clear
redraw
nil
end
|
#prefix ⇒ Object
80
81
82
83
|
# File 'lib/bash-visual/scroll.rb', line 80
def prefix
return @prefix[].to_s if (defined? @prefix.call)
''
end
|
#prefix=(prefix) ⇒ Object
76
77
78
|
# File 'lib/bash-visual/scroll.rb', line 76
def prefix= (prefix)
@prefix = prefix
end
|
54
55
56
|
# File 'lib/bash-visual/scroll.rb', line 54
def scroll(positions = 1, direction = @direction * positions)
end
|