bash-visual 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +3 -6
- data/example/hello_world.rb +1 -1
- data/example/painter.rb +1 -1
- data/example/scroll.rb +3 -3
- data/lib/bash-visual/console.rb +9 -7
- data/lib/bash-visual/horizontal_scroll.rb +7 -8
- data/lib/bash-visual/painter.rb +52 -18
- data/lib/bash-visual/version.rb +1 -1
- data/test/console_test.rb +0 -4
- data/test/painter_test.rb +34 -8
- metadata +2 -3
- data/bash-visual-1.0.6.gem +0 -0
data/README.md
CHANGED
@@ -32,14 +32,11 @@ Or install it yourself as:
|
|
32
32
|
require 'bash-visual'
|
33
33
|
include Bash_Visual
|
34
34
|
|
35
|
-
|
36
|
-
main_color = Font.new(:bold, :green)
|
37
|
-
|
38
|
-
console = Console.new(main_color)
|
35
|
+
console = Console.new
|
39
36
|
console.clear
|
40
37
|
|
41
|
-
console.draw_window(
|
42
|
-
console.write_to_position
|
38
|
+
console.draw_window([3, 3], [18, 5], 'Example') {{font: Font.new(:std, :red)}}
|
39
|
+
console.write_to_position 5, 4, 'Hello World!', Font.new(:bold)
|
43
40
|
console.position = [0, 8]
|
44
41
|
```
|
45
42
|
|
data/example/hello_world.rb
CHANGED
@@ -6,6 +6,6 @@ include Bash_Visual
|
|
6
6
|
console = Console.new
|
7
7
|
console.clear
|
8
8
|
|
9
|
-
console.draw_window
|
9
|
+
console.draw_window([3, 3], [18, 5], 'Example') {{font: Font.new(:std, :red)}}
|
10
10
|
console.write_to_position 5, 4, 'Hello World!', Font.new(:bold)
|
11
11
|
console.position = [0, 8]
|
data/example/painter.rb
CHANGED
data/example/scroll.rb
CHANGED
@@ -6,9 +6,6 @@ include Bash_Visual
|
|
6
6
|
console = Console.new
|
7
7
|
console.clear
|
8
8
|
|
9
|
-
console.draw_window([32, 0] ,[42, 11], 'Vertical scroll')
|
10
|
-
console.draw_window([0, 12] ,[73, 6], 'Horizontal scroll')
|
11
|
-
|
12
9
|
v_scroll = VerticalScroll.new(
|
13
10
|
position: [33, 1],
|
14
11
|
size: [39, 9],
|
@@ -22,6 +19,9 @@ h_scroll = HorizontalScroll.new(
|
|
22
19
|
separator: true
|
23
20
|
)
|
24
21
|
|
22
|
+
console.draw_window(v_scroll, 'Vertical scroll')
|
23
|
+
console.draw_window(h_scroll, 'Horizontal scroll')
|
24
|
+
|
25
25
|
phrases =[
|
26
26
|
"Bash is a Unix shell",
|
27
27
|
"GNU’s Not UNIX",
|
data/lib/bash-visual/console.rb
CHANGED
@@ -61,13 +61,6 @@ module Bash_Visual
|
|
61
61
|
@font = font
|
62
62
|
end
|
63
63
|
|
64
|
-
def lines
|
65
|
-
`tput lines`
|
66
|
-
end
|
67
|
-
|
68
|
-
def cols
|
69
|
-
`tput cols`
|
70
|
-
end
|
71
64
|
|
72
65
|
private
|
73
66
|
def print string
|
@@ -81,5 +74,14 @@ module Bash_Visual
|
|
81
74
|
end
|
82
75
|
end
|
83
76
|
|
77
|
+
class << self
|
78
|
+
def lines
|
79
|
+
`tput lines`
|
80
|
+
end
|
81
|
+
|
82
|
+
def cols
|
83
|
+
`tput cols`
|
84
|
+
end
|
85
|
+
end
|
84
86
|
end
|
85
87
|
end
|
@@ -25,7 +25,7 @@ module Bash_Visual
|
|
25
25
|
|
26
26
|
available_area_width, available_area_height = available_area
|
27
27
|
|
28
|
-
msg_block_width =
|
28
|
+
block_width = msg_block_width =
|
29
29
|
case
|
30
30
|
when @fixed_message_block_size
|
31
31
|
@fixed_message_block_size
|
@@ -35,22 +35,21 @@ module Bash_Visual
|
|
35
35
|
available_area_width
|
36
36
|
end
|
37
37
|
|
38
|
-
msg_block_width -=
|
38
|
+
msg_block_width -= @separator.size if @separator
|
39
39
|
msg_block_width = available_area_width if msg_block_width > available_area_width
|
40
40
|
|
41
|
-
|
41
|
+
msg_block_height = @adapt ? available_area_height : 1
|
42
42
|
|
43
|
-
message = Scroll.form_block message, [msg_block_width,
|
43
|
+
message = Scroll.form_block message, [msg_block_width, msg_block_height], @fixed_message_block_size
|
44
44
|
if @separator
|
45
45
|
message.map! do |row|
|
46
|
-
row
|
46
|
+
row + @separator
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
write(get_x_position(available_area_width, msg_block_width), @y, message, font)
|
50
|
+
write(get_x_position(available_area_width, block_width), @y, message, font)
|
52
51
|
|
53
|
-
[available_area_width -
|
52
|
+
[available_area_width - block_width, available_area_height]
|
54
53
|
end
|
55
54
|
end
|
56
55
|
end
|
data/lib/bash-visual/painter.rb
CHANGED
@@ -19,11 +19,12 @@ module Bash_Visual
|
|
19
19
|
"\u2551", "\u2551",
|
20
20
|
"\u255A", "\u2550", "\u255D"]
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
|
23
|
+
|
24
|
+
# @param [Array] positioning
|
25
|
+
# @param [Integer] color
|
26
|
+
def draw_filled_rectangle(*positioning, color)
|
27
|
+
x, y, width, height = prepare_positioning positioning
|
27
28
|
raise 'width,height must be great than 1' if (width < 1 or height < 1)
|
28
29
|
|
29
30
|
color = color.background if color.is_a? Font
|
@@ -40,13 +41,15 @@ module Bash_Visual
|
|
40
41
|
print @builder.write(bash, font)
|
41
42
|
end
|
42
43
|
|
43
|
-
# @param [Array]
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
# @param [Array] positioning
|
45
|
+
def draw_border(*positioning, &extra)
|
46
|
+
x, y, width, height = prepare_positioning positioning do |x2, y2, width2, height2|
|
47
|
+
next x2, y2, width2 + 2, height2 + 2
|
48
|
+
end
|
49
|
+
|
50
|
+
raise 'width,height must be great than 2' if (width < 2 or height < 2)
|
49
51
|
|
52
|
+
params = block_given? ? yield : {}
|
50
53
|
border = params[:border] ? params[:border] : BORDER_UTF
|
51
54
|
font = params[:font] ? params[:font] : @font
|
52
55
|
|
@@ -67,15 +70,20 @@ module Bash_Visual
|
|
67
70
|
print @builder.write(bash, font)
|
68
71
|
end
|
69
72
|
|
70
|
-
|
71
|
-
# @param [Array]
|
73
|
+
|
74
|
+
# @param [Array] positioning
|
72
75
|
# @param [String] text
|
73
|
-
|
74
|
-
|
75
|
-
x, y
|
76
|
-
|
76
|
+
def draw_window(*positioning, text, ¶ms)
|
77
|
+
|
78
|
+
x, y, width, height = prepare_positioning positioning do |x2, y2, width2, height2|
|
79
|
+
next x2, y2, width2 + 2, height2 + 2
|
80
|
+
end
|
81
|
+
|
77
82
|
raise 'width,height must be great than 2' if (width < 3 or height < 3)
|
78
83
|
|
84
|
+
params = block_given? ? yield : {}
|
85
|
+
|
86
|
+
|
79
87
|
wrap = params[:wrap].nil? ? @@default_window_wrap : params[:wrap]
|
80
88
|
border = params[:border] ? params[:border] : BORDER_UTF
|
81
89
|
font = params[:font] ? params[:font] : @font
|
@@ -84,7 +92,11 @@ module Bash_Visual
|
|
84
92
|
text = if wrap
|
85
93
|
wrap_size = wrap[0].size + wrap[1].size
|
86
94
|
text_width = body_width - wrap_size
|
87
|
-
|
95
|
+
if text_width < 0
|
96
|
+
text.to_s.slice(0, body_width)
|
97
|
+
else
|
98
|
+
wrap[0] + text.to_s[0, text_width] + wrap[1]
|
99
|
+
end
|
88
100
|
else
|
89
101
|
text.to_s.slice(0, body_width)
|
90
102
|
end
|
@@ -106,5 +118,27 @@ module Bash_Visual
|
|
106
118
|
bash << @builder.restore_position
|
107
119
|
print @builder.write(bash, font)
|
108
120
|
end
|
121
|
+
|
122
|
+
private
|
123
|
+
# @param [Array] positioning
|
124
|
+
def prepare_positioning(positioning, &extra)
|
125
|
+
if positioning.size == 2
|
126
|
+
x, y = positioning[0]
|
127
|
+
width, height = positioning[1]
|
128
|
+
else
|
129
|
+
fixed_object = positioning[0]
|
130
|
+
raise 'Must be FixedObject' unless fixed_object.kind_of?(FixedObject)
|
131
|
+
|
132
|
+
x, y = fixed_object.position
|
133
|
+
width, height = fixed_object.size
|
134
|
+
|
135
|
+
if block_given?
|
136
|
+
x,y,width,height = yield(x, y, width, height)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
return x, y, width, height
|
141
|
+
end
|
142
|
+
|
109
143
|
end
|
110
144
|
end
|
data/lib/bash-visual/version.rb
CHANGED
data/test/console_test.rb
CHANGED
data/test/painter_test.rb
CHANGED
@@ -15,18 +15,44 @@ class PainterTest < Test::Unit::TestCase
|
|
15
15
|
@painter.instance_variable_set(:@builder, builder)
|
16
16
|
end
|
17
17
|
|
18
|
-
def test_draw_window
|
19
|
-
@painter.draw_window([1, 1], [10, 10], 'logs')
|
20
|
-
@painter.draw_window([1, 1], [10, 10], 'logs', {font: Font.new(:bold)})
|
21
|
-
end
|
22
|
-
|
23
18
|
def test_draw_border
|
24
19
|
@painter.draw_border([1, 1], [10, 10])
|
25
|
-
@painter.draw_border([1, 1], [10, 10]
|
20
|
+
@painter.draw_border([1, 1], [10, 10]) {{font: Font.new(:bold)}}
|
21
|
+
|
22
|
+
scroll = VerticalScroll.new(position: [1,1], size: [1,1])
|
23
|
+
@painter.draw_border scroll
|
26
24
|
end
|
27
25
|
|
28
26
|
def test_draw_filled_rectangle
|
29
|
-
@painter.draw_filled_rectangle([1, 1], [10, 10])
|
30
|
-
@painter.draw_filled_rectangle([1, 1], [10, 10], :red)
|
27
|
+
@painter.draw_filled_rectangle([1, 1], [10, 10], :white)
|
28
|
+
@painter.draw_filled_rectangle([1, 1], [10, 10], :red) {{font: Font.new(:bold)}}
|
29
|
+
|
30
|
+
scroll = VerticalScroll.new(position: [1,1], size: [1,1])
|
31
|
+
@painter.draw_filled_rectangle scroll, :red
|
31
32
|
end
|
33
|
+
|
34
|
+
def test_draw_window_small
|
35
|
+
assert_raise_message "width,height must be great than 2" do
|
36
|
+
@painter.draw_window([0, 0] ,[2, 2], 'W')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def test_draw_window
|
42
|
+
scroll = VerticalScroll.new(position: [1,1], size: [1,1])
|
43
|
+
|
44
|
+
@painter.draw_window([0, 0] ,[3, 3], 'Win!')
|
45
|
+
|
46
|
+
@painter.draw_window(scroll, 'scroll 1')
|
47
|
+
|
48
|
+
@painter.draw_window(scroll, 'scroll 2') do
|
49
|
+
{border: Painter::BORDER_UTF_DOUBLE}
|
50
|
+
end
|
51
|
+
|
52
|
+
@painter.draw_window([0, 0] ,[4, 4], 'Win!') do
|
53
|
+
{border: Painter::BORDER_UTF_DOUBLE, font: Font.new(:bold)}
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
32
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bash-visual
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Bash visualisation tools
|
15
15
|
email:
|
@@ -23,7 +23,6 @@ files:
|
|
23
23
|
- LICENSE
|
24
24
|
- README.md
|
25
25
|
- Rakefile
|
26
|
-
- bash-visual-1.0.6.gem
|
27
26
|
- bash-visual.gemspec
|
28
27
|
- example/hello_world.rb
|
29
28
|
- example/painter.rb
|
data/bash-visual-1.0.6.gem
DELETED
Binary file
|