bash-visual 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
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
- border_font = Font.new(:std, :blue)
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(2, 2, 20, 5, 'Example', border_font, Console::BORDER_UTF_DOUBLE)
42
- console.write_to_position(5, 3, 'Hello World!')
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
 
@@ -6,6 +6,6 @@ include Bash_Visual
6
6
  console = Console.new
7
7
  console.clear
8
8
 
9
- console.draw_window [3, 3], [18, 5], 'Example', {font: Font.new(:std, :red)}
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
@@ -12,7 +12,7 @@ Thread.new {
12
12
  5.times {
13
13
  x, y = x+1, y+1
14
14
  width, height = width-2, height-2
15
- console.draw_border([x, y], [width, height], {font: Font::rand_font})
15
+ console.draw_border([x, y], [width, height]) {{font: Font::rand_font}}
16
16
  sleep 0.08
17
17
  }
18
18
  }
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",
@@ -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 -= 1 if @separator
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
- #msg_block_height = @adapt ? available_area_height : 1
41
+ msg_block_height = @adapt ? available_area_height : 1
42
42
 
43
- message = Scroll.form_block message, [msg_block_width, available_area_height], @fixed_message_block_size
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 = row + DEFAULT_SEPARATOR
46
+ row + @separator
47
47
  end
48
48
  end
49
49
 
50
- msg_block_width += 1
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 - msg_block_width, available_area_height]
52
+ [available_area_width - block_width, available_area_height]
54
53
  end
55
54
  end
56
55
  end
@@ -19,11 +19,12 @@ module Bash_Visual
19
19
  "\u2551", "\u2551",
20
20
  "\u255A", "\u2550", "\u255D"]
21
21
 
22
- # @param [Array] position
23
- # @param [Array] size
24
- def draw_filled_rectangle(position, size, color = :white)
25
- x, y = *position
26
- width, height = *size
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] position
44
- # @param [Array] size
45
- def draw_border(position, size, params = {})
46
- x, y = *position
47
- width, height = *size
48
- raise 'width,height must be great than 1' if (width < 2 or height < 2)
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
- # @param [Array] position
71
- # @param [Array] size
73
+
74
+ # @param [Array] positioning
72
75
  # @param [String] text
73
- # @param [Hash] params
74
- def draw_window(position, size, text = '', params = {})
75
- x, y = *position
76
- width, height = *size
76
+ def draw_window(*positioning, text, &params)
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
- wrap[0] + text.to_s[0, text_width] + wrap[1]
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
@@ -1,3 +1,3 @@
1
1
  module Bash_Visual
2
- VERSION = '1.0.7'
2
+ VERSION = '1.0.8'
3
3
  end
data/test/console_test.rb CHANGED
@@ -7,9 +7,5 @@ class ConsoleTest < Test::Unit::TestCase
7
7
 
8
8
  include Bash_Visual
9
9
 
10
- def test_draw_rectangle
11
-
12
-
13
- end
14
10
 
15
11
  end
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], {font: Font.new(:bold)})
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.7
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-07-30 00:00:00.000000000 Z
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
Binary file