-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache_display.rb
More file actions
63 lines (49 loc) · 1.16 KB
/
cache_display.rb
File metadata and controls
63 lines (49 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
54
55
56
57
58
59
60
61
62
63
require 'io/console'
require 'colorize'
class CacheDisplay
def initialize(width = IO.console.winsize[1])
@width = width
@result = ""
end
def add_separator_top
@result << "┌" << line << "┐\n"
end
def add_separator_down
@result << "└" << line << "┘\n"
end
def add_separator
@result << pipe << line << pipe << "\n"
end
def persentage(pers, color = :default)
width = (pers * @width / 100)
percentage = " #{pers} % ".center(width, "█")
@result << percentage.colorize(color) << "\n" if pers != 0
end
def add_content(arr, font_color = :default)
size = (@width - 2 - (arr.size - 1)) / arr.size
@result << pipe
arr.each_with_index do |word, index|
@result << (word.to_s.center(size, " ")).white
if (2 + arr.size - 1 + size * arr.size != @width) && index == arr.size - 1
@result << " " * (@width - (2 + arr.size - 1 + size * arr.size))
end
@result << pipe
end
@result += "\n"
end
def build
temp = @result
@result = ""
temp
end
private
def pipe
"│".blue
end
def dash
"─".blue
end
def line
(dash * (@width - 2))
end
end