vedeu 0.2.11 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/examples/borders_app.rb +171 -0
  3. data/lib/vedeu.rb +1 -1
  4. data/lib/vedeu/api/interface.rb +12 -0
  5. data/lib/vedeu/api/menu.rb +1 -1
  6. data/lib/vedeu/colours/colour.rb +1 -1
  7. data/lib/vedeu/models/border.rb +238 -0
  8. data/lib/vedeu/models/char.rb +1 -1
  9. data/lib/vedeu/models/composition.rb +1 -1
  10. data/lib/vedeu/models/geometry.rb +1 -1
  11. data/lib/vedeu/models/line.rb +1 -1
  12. data/lib/vedeu/models/stream.rb +1 -1
  13. data/lib/vedeu/output/output.rb +1 -1
  14. data/lib/vedeu/output/viewport.rb +34 -3
  15. data/lib/vedeu/repositories/models/cursor.rb +34 -7
  16. data/lib/vedeu/repositories/models/event.rb +1 -1
  17. data/lib/vedeu/repositories/models/group.rb +1 -1
  18. data/lib/vedeu/repositories/models/interface.rb +14 -6
  19. data/lib/vedeu/repositories/models/keymap.rb +1 -1
  20. data/lib/vedeu/repositories/models/offset.rb +1 -1
  21. data/lib/vedeu/support/trace.rb +1 -1
  22. data/test/integration/views/basic_view_test.rb +19 -0
  23. data/test/lib/vedeu/api/api_test.rb +6 -5
  24. data/test/lib/vedeu/api/helpers_test.rb +2 -6
  25. data/test/lib/vedeu/api/interface_test.rb +53 -45
  26. data/test/lib/vedeu/api/menu_test.rb +6 -0
  27. data/test/lib/vedeu/api/stream_test.rb +1 -3
  28. data/test/lib/vedeu/application_test.rb +6 -12
  29. data/test/lib/vedeu/colours/colour_test.rb +16 -5
  30. data/test/lib/vedeu/colours/translator_test.rb +7 -2
  31. data/test/lib/vedeu/configuration/cli_test.rb +9 -0
  32. data/test/lib/vedeu/input/input_test.rb +5 -5
  33. data/test/lib/vedeu/launcher_test.rb +9 -3
  34. data/test/lib/vedeu/models/border_test.rb +197 -0
  35. data/test/lib/vedeu/models/char_test.rb +18 -15
  36. data/test/lib/vedeu/models/composition_test.rb +6 -7
  37. data/test/lib/vedeu/models/geometry_test.rb +43 -49
  38. data/test/lib/vedeu/models/key_test.rb +7 -5
  39. data/test/lib/vedeu/models/line_test.rb +12 -16
  40. data/test/lib/vedeu/models/stream_test.rb +20 -10
  41. data/test/lib/vedeu/models/style_test.rb +9 -10
  42. data/test/lib/vedeu/output/compositor_test.rb +7 -22
  43. data/test/lib/vedeu/output/output_test.rb +34 -33
  44. data/test/lib/vedeu/output/viewport_test.rb +6 -6
  45. data/test/lib/vedeu/repositories/models/buffer_test.rb +13 -18
  46. data/test/lib/vedeu/repositories/models/cursor_test.rb +21 -21
  47. data/test/lib/vedeu/repositories/models/event_test.rb +10 -4
  48. data/test/lib/vedeu/{models → repositories/models}/group_test.rb +8 -9
  49. data/test/lib/vedeu/repositories/models/interface_test.rb +37 -17
  50. data/test/lib/vedeu/repositories/models/keymap_test.rb +6 -6
  51. data/test/lib/vedeu/repositories/models/menu_test.rb +6 -3
  52. data/test/lib/vedeu/repositories/models/offset_test.rb +6 -3
  53. data/test/lib/vedeu/support/bounding_area_test.rb +28 -36
  54. data/test/lib/vedeu/support/grid_test.rb +8 -0
  55. data/test/lib/vedeu/support/keymap_validator_test.rb +5 -8
  56. data/test/lib/vedeu/support/position_test.rb +3 -3
  57. data/test/lib/vedeu/support/registrar_test.rb +13 -7
  58. data/test/lib/vedeu/support/sentence_test.rb +9 -2
  59. data/test/lib/vedeu/support/trace_test.rb +5 -3
  60. data/test/test_helper.rb +12 -0
  61. data/vedeu.gemspec +1 -1
  62. metadata +8 -7
  63. data/lib/vedeu/output/view.rb +0 -64
  64. data/test/lib/vedeu/output/view_test.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2e18e1de7f428b1890aacc71abffae0ea935431
4
- data.tar.gz: 3c32f191ff6dfead712551de9c4375261d46dc54
3
+ metadata.gz: b2a6839a91cbe235601f64318bbeae95e5be439d
4
+ data.tar.gz: a3eb219aab24bf02d8cdf2280754c3a5a8375066
5
5
  SHA512:
6
- metadata.gz: 5b2dc0ebd0bfa591774ead8d58fdd090ca80152619545226230a02d72c2b9a0f991aa0813eec3bffeee38070091cedfce8a0e6df2648a8a740ffe6589bfe6c18
7
- data.tar.gz: a785503d6086eaa2b8a4d1c4aa882f99d03ff4a791c42828fef352e053d0f146b67b4b6fa0e6bb2f9f87b46be82d8e1c42100e4d64c6d059263cff3cd9d9c01a
6
+ metadata.gz: d202139c56d5f1d12763ed282387d0c99059d820d2527940d6ae8805e0eb73bd58029aba5fc7ddb511f00ea628ff487dd3349bbf17bdb7a7670b7676b296cac4
7
+ data.tar.gz: c941ca66c0c66128ae4d1dd125fe02180d42b0bd28c6f23f8e5697409d4b4c17376ad7a2e801a13f242b00414b83c2c6e6e4dd02cd85e31156e9d37c832c3001
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib_dir = File.dirname(__FILE__) + '/../lib'
4
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
5
+
6
+ -> { its -> { a } }
7
+ trap('INT') { exit! }
8
+
9
+ require 'vedeu'
10
+
11
+ class VedeuBordersApp
12
+ include Vedeu
13
+
14
+ event(:_initialize_) { trigger(:_refresh_) }
15
+
16
+ interface 'lur' do
17
+ border
18
+ x 2
19
+ y 2
20
+ height 3
21
+ width 7
22
+ colour foreground: '#ffffff', background: '#ff0000'
23
+ end
24
+
25
+ interface 'tan' do
26
+ x 11
27
+ y 2
28
+ height 3
29
+ width 7
30
+ colour foreground: '#ffffff', background: '#00ff00'
31
+ end
32
+
33
+ interface 'tal' do
34
+ border show_top: false
35
+ x 20
36
+ y 2
37
+ height 3
38
+ width 7
39
+ colour foreground: '#ffffff', background: '#0000ff'
40
+ end
41
+
42
+ interface 'ums' do
43
+ border show_bottom: false
44
+ x 29
45
+ y 2
46
+ height 3
47
+ width 7
48
+ colour foreground: '#000000', background: '#ffff00'
49
+ end
50
+
51
+ interface 'ulp' do
52
+ border show_left: false
53
+ x 38
54
+ y 2
55
+ height 3
56
+ width 7
57
+ colour foreground: '#000000', background: '#ffff00'
58
+ end
59
+
60
+ interface 'hur' do
61
+ border show_right: false
62
+ x 47
63
+ y 2
64
+ height 3
65
+ width 7
66
+ colour foreground: '#000000', background: '#ffff00'
67
+ end
68
+
69
+ interface 'sto' do
70
+ border top_right: 'B', top_left: 'A', bottom_right: 'D', bottom_left: 'C'
71
+ x 2
72
+ y 7
73
+ height 3
74
+ width 7
75
+ colour foreground: '#ffffff', background: '#ff0000'
76
+ end
77
+
78
+ interface 'sod' do
79
+ border horizontal: '*', vertical: '$'
80
+ x 11
81
+ y 7
82
+ height 3
83
+ width 7
84
+ colour foreground: '#ffffff', background: '#00ff00'
85
+ end
86
+
87
+ interface 'sil' do
88
+ border show_right: false, show_bottom: false, show_left: false
89
+ x 20
90
+ y 7
91
+ height 3
92
+ width 7
93
+ colour foreground: '#ffffff', background: '#0000ff'
94
+ end
95
+
96
+ interface 'ver' do
97
+ border show_top: false, show_right: false, show_left: false
98
+ x 29
99
+ y 7
100
+ height 3
101
+ width 7
102
+ colour foreground: '#000000', background: '#ffff00'
103
+ end
104
+
105
+ interface 'ico' do
106
+ border show_top: false, show_bottom: false, show_right: false
107
+ x 38
108
+ y 7
109
+ height 3
110
+ width 7
111
+ colour foreground: '#000000', background: '#ffff00'
112
+ end
113
+
114
+ interface 'sel' do
115
+ border show_top: false, show_bottom: false, show_left: false
116
+ x 47
117
+ y 7
118
+ height 3
119
+ width 7
120
+ colour foreground: '#000000', background: '#ffff00'
121
+ end
122
+
123
+ interface 'ens' do
124
+ border colour: { foreground: '#ffff00', background: '#0000ff' }
125
+ x 2
126
+ y 12
127
+ height 3
128
+ width 7
129
+ colour foreground: '#ffffff', background: '#ff0000'
130
+ end
131
+
132
+ interface 'eab' do
133
+ border style: 'negative'
134
+ x 11
135
+ y 12
136
+ height 3
137
+ width 7
138
+ colour foreground: '#000000', background: '#00ff00'
139
+ style 'normal'
140
+ end
141
+
142
+ render do
143
+ view('lur') { line 'on' }
144
+ view('tan') { line 'off' }
145
+ view('tal') { line 'no t' }
146
+ view('ums') { line 'no b' }
147
+ view('ulp') { line 'no l' }
148
+ view('hur') { line 'no r' }
149
+
150
+ view('sto') { line 'chars'; line '1' }
151
+ view('sod') { line 'chars'; line '2' }
152
+ view('sil') { line 'only'; line 't' }
153
+ view('ver') { line 'only'; line 'b' }
154
+ view('ico') { line 'only'; line 'l' }
155
+ view('sel') { line 'only'; line 'r' }
156
+
157
+ view('ens') { line 'color' }
158
+ view('eab') { line 'style' }
159
+ end
160
+
161
+ Vedeu.configure do
162
+ debug!
163
+ log '/tmp/vedeu_borders_app.log'
164
+ end
165
+
166
+ def self.start(argv = ARGV)
167
+ Vedeu::Launcher.new(argv).execute!
168
+ end
169
+ end
170
+
171
+ VedeuBordersApp.start(ARGV)
data/lib/vedeu.rb CHANGED
@@ -75,6 +75,7 @@ require 'vedeu/support/presentation'
75
75
  require 'vedeu/support/sentence'
76
76
  require 'vedeu/support/terminal'
77
77
 
78
+ require 'vedeu/models/border'
78
79
  require 'vedeu/models/char'
79
80
  require 'vedeu/models/composition'
80
81
  require 'vedeu/models/geometry'
@@ -114,7 +115,6 @@ require 'vedeu/support/refresh'
114
115
 
115
116
  require 'vedeu/output/compositor'
116
117
  require 'vedeu/output/output'
117
- require 'vedeu/output/view'
118
118
  require 'vedeu/output/viewport'
119
119
 
120
120
  require 'vedeu/support/bounding_area'
@@ -9,6 +9,18 @@ module Vedeu
9
9
 
10
10
  include Helpers
11
11
 
12
+ # Allows the setting of a border for the interface. Via the `values`
13
+ # parameter, the various characters for the borders sides and corners can
14
+ # be set, a custom foreground and background, a custom style, and whether
15
+ # a particular side should be drawn or not. See {Border#initialize} for
16
+ # more details.
17
+ #
18
+ # @return [Hash]
19
+ def border(values = {})
20
+ auto_enable = { enabled: true }
21
+ attributes[:border] = auto_enable.merge(values)
22
+ end
23
+
12
24
  # Instructs Vedeu to calculate x and y geometry automatically based on the
13
25
  # centre character of the terminal, the width and the height.
14
26
  #
@@ -26,7 +26,7 @@ module Vedeu
26
26
  # @param attributes [Hash]
27
27
  # @return [API::Menu]
28
28
  def initialize(attributes = {})
29
- @attributes = defaults.merge!(attributes)
29
+ @attributes = defaults.merge(attributes)
30
30
  end
31
31
 
32
32
  # @param block [Proc]
@@ -14,7 +14,7 @@ module Vedeu
14
14
  # @param attributes [Hash]
15
15
  # @return [Colour]
16
16
  def initialize(attributes = {})
17
- @attributes = defaults.merge!(attributes)
17
+ @attributes = defaults.merge(attributes)
18
18
  end
19
19
 
20
20
  # Converts the `:foreground` attribute into a terminal escape sequence.
@@ -0,0 +1,238 @@
1
+ module Vedeu
2
+
3
+ #
4
+ #
5
+ # @note Refer to UTF-8 U+2500 to U+257F for border characters. More details
6
+ # can be found at: http://en.wikipedia.org/wiki/Box-drawing_character
7
+ #
8
+ class Border
9
+
10
+ # Returns a new instance of Border.
11
+ #
12
+ # @param interface [Interface]
13
+ # @param attributes [Hash]
14
+ # @return [Border]
15
+ def initialize(interface, attributes = {})
16
+ @interface = interface
17
+ @attributes = defaults.merge(attributes)
18
+ end
19
+
20
+ def enabled?
21
+ attributes[:enabled]
22
+ end
23
+
24
+ def bottom?
25
+ attributes[:show_bottom]
26
+ end
27
+
28
+ def left?
29
+ attributes[:show_left]
30
+ end
31
+
32
+ def right?
33
+ attributes[:show_right]
34
+ end
35
+
36
+ def top?
37
+ attributes[:show_top]
38
+ end
39
+
40
+ def to_s
41
+ to_viewport.map { |line| line.flatten.join }.join("\n")
42
+ end
43
+
44
+ def to_viewport
45
+ return viewport unless enabled?
46
+
47
+ out = []
48
+
49
+ out << top if top?
50
+
51
+ viewport[0...height].each do |line|
52
+ out << [left, line[0...width], right].flatten
53
+ end
54
+
55
+ out << bottom if bottom?
56
+
57
+ out
58
+ end
59
+
60
+ private
61
+
62
+ attr_reader :attributes, :interface, :attributes
63
+
64
+ def bottom
65
+ return [] unless bottom?
66
+
67
+ out = []
68
+
69
+ out << bottom_left if left?
70
+ horizontal_border.each do |border|
71
+ out << border
72
+ end
73
+ out << bottom_right if right?
74
+
75
+ out
76
+ end
77
+
78
+ def left
79
+ return '' unless left?
80
+
81
+ vertical_border
82
+ end
83
+
84
+ def right
85
+ return '' unless right?
86
+
87
+ vertical_border
88
+ end
89
+
90
+ def top
91
+ return [] unless top?
92
+
93
+ out = []
94
+ out << top_left if left?
95
+ horizontal_border.each do |border|
96
+ out << border
97
+ end
98
+ out << top_right if right?
99
+
100
+ out
101
+ end
102
+
103
+ def bottom_left
104
+ [*presentation, on, bl, off, *reset].join
105
+ end
106
+
107
+ def bottom_right
108
+ [*presentation, on, br, off, *reset].join
109
+ end
110
+
111
+ def top_left
112
+ [*presentation, on, tl, off, *reset].join
113
+ end
114
+
115
+ def top_right
116
+ [*presentation, on, tr, off, *reset].join
117
+ end
118
+
119
+ def width
120
+ if left? && right?
121
+ interface.width - 2
122
+
123
+ elsif left? || right?
124
+ interface.width - 1
125
+
126
+ else
127
+ interface.width
128
+
129
+ end
130
+ end
131
+
132
+ def height
133
+ if top? && bottom?
134
+ interface.height - 2
135
+
136
+ elsif top? || bottom?
137
+ interface.height - 1
138
+
139
+ else
140
+ interface.height
141
+
142
+ end
143
+ end
144
+
145
+ def horizontal_border
146
+ [[*presentation, on, h, off, *reset].join] * width
147
+ end
148
+
149
+ def horizontal_space
150
+ [' '] * width
151
+ end
152
+
153
+ def vertical_border
154
+ [*presentation, on, v, off, *reset].join
155
+ end
156
+
157
+ def h
158
+ attributes[:horizontal]
159
+ end
160
+
161
+ def v
162
+ attributes[:vertical]
163
+ end
164
+
165
+ def tr
166
+ attributes[:top_right]
167
+ end
168
+
169
+ def tl
170
+ attributes[:top_left]
171
+ end
172
+
173
+ def br
174
+ attributes[:bottom_right]
175
+ end
176
+
177
+ def bl
178
+ attributes[:bottom_left]
179
+ end
180
+
181
+ def on
182
+ "\e(0"
183
+ end
184
+
185
+ def off
186
+ "\e(B"
187
+ end
188
+
189
+ def viewport
190
+ interface.viewport
191
+ end
192
+
193
+ def presentation
194
+ [colour.to_s, style.to_s]
195
+ end
196
+
197
+ def reset
198
+ [interface.colour.to_s, interface.style.to_s]
199
+ end
200
+
201
+ # Returns a new Colour instance.
202
+ #
203
+ # @return [Colour]
204
+ def colour
205
+ @colour ||= Colour.new(attributes[:colour])
206
+ end
207
+
208
+ # Returns a new Style instance.
209
+ #
210
+ # @return [Style]
211
+ def style
212
+ @style ||= Style.new(attributes[:style])
213
+ end
214
+
215
+ # The default values for a new instance of Border.
216
+ #
217
+ # @return [Hash]
218
+ def defaults
219
+ {
220
+ enabled: false,
221
+ show_bottom: true,
222
+ show_left: true,
223
+ show_right: true,
224
+ show_top: true,
225
+ bottom_right: "\x6A", # ┘
226
+ top_right: "\x6B", # ┐
227
+ top_left: "\x6C", # ┌
228
+ bottom_left: "\x6D", # └
229
+ horizontal: "\x71", # ─
230
+ colour: {},
231
+ style: [],
232
+ vertical: "\x78", # │
233
+ }
234
+ end
235
+
236
+ end # Border
237
+
238
+ end # Vedeu