vedeu 0.2.4 → 0.2.5

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.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/LICENSE.txt +5 -0
  4. data/bin/vedeu +3 -1
  5. data/docs/api.md +2 -0
  6. data/examples/cursor_app/cursor_app.rb +22 -7
  7. data/examples/hello_world.rb +42 -0
  8. data/lib/vedeu.rb +5 -5
  9. data/lib/vedeu/api/api.rb +16 -33
  10. data/lib/vedeu/api/helpers.rb +86 -0
  11. data/lib/vedeu/api/interface.rb +60 -17
  12. data/lib/vedeu/api/keymap.rb +5 -0
  13. data/lib/vedeu/api/line.rb +52 -34
  14. data/lib/vedeu/api/menu.rb +1 -1
  15. data/lib/vedeu/api/stream.rb +0 -34
  16. data/lib/vedeu/configuration/api.rb +10 -10
  17. data/lib/vedeu/configuration/cli.rb +1 -1
  18. data/lib/vedeu/launcher.rb +21 -6
  19. data/lib/vedeu/models/background.rb +1 -1
  20. data/lib/vedeu/models/composition.rb +1 -1
  21. data/lib/vedeu/models/cursor.rb +25 -35
  22. data/lib/vedeu/models/foreground.rb +1 -1
  23. data/lib/vedeu/models/geometry.rb +216 -6
  24. data/lib/vedeu/models/interface.rb +14 -16
  25. data/lib/vedeu/models/keymap.rb +38 -6
  26. data/lib/vedeu/models/line.rb +1 -1
  27. data/lib/vedeu/models/stream.rb +1 -1
  28. data/lib/vedeu/output/compositor.rb +1 -1
  29. data/lib/vedeu/output/render.rb +1 -5
  30. data/lib/vedeu/output/viewport.rb +37 -2
  31. data/lib/vedeu/repositories/buffers.rb +21 -27
  32. data/lib/vedeu/repositories/cursors.rb +3 -15
  33. data/lib/vedeu/repositories/focus.rb +2 -6
  34. data/lib/vedeu/repositories/groups.rb +1 -1
  35. data/lib/vedeu/repositories/interfaces.rb +1 -1
  36. data/lib/vedeu/repositories/keymaps.rb +26 -22
  37. data/lib/vedeu/repositories/menus.rb +1 -1
  38. data/lib/vedeu/repositories/offsets.rb +30 -12
  39. data/lib/vedeu/repositories/positional.rb +23 -0
  40. data/lib/vedeu/support/colour_translator.rb +1 -16
  41. data/lib/vedeu/support/esc.rb +23 -28
  42. data/lib/vedeu/support/event.rb +6 -14
  43. data/lib/vedeu/{output → support}/refresh.rb +0 -0
  44. data/lib/vedeu/support/registrar.rb +6 -14
  45. data/lib/vedeu/support/repository.rb +3 -2
  46. data/lib/vedeu/support/terminal.rb +9 -13
  47. data/lib/vedeu/support/trace.rb +2 -3
  48. data/test/integration/cursors_test.rb +9 -0
  49. data/test/integration/views/basic_view_test.rb +19 -0
  50. data/test/lib/vedeu/api/api_test.rb +28 -5
  51. data/test/lib/vedeu/api/composition_test.rb +7 -3
  52. data/test/lib/vedeu/api/defined_test.rb +9 -3
  53. data/test/lib/vedeu/api/helpers_test.rb +39 -5
  54. data/test/lib/vedeu/api/interface_test.rb +88 -8
  55. data/test/lib/vedeu/api/keymap_test.rb +5 -3
  56. data/test/lib/vedeu/api/line_test.rb +9 -3
  57. data/test/lib/vedeu/api/menu_test.rb +11 -7
  58. data/test/lib/vedeu/api/stream_test.rb +9 -31
  59. data/test/lib/vedeu/application_test.rb +25 -2
  60. data/test/lib/vedeu/configuration/api_test.rb +5 -3
  61. data/test/lib/vedeu/configuration/cli_test.rb +5 -3
  62. data/test/lib/vedeu/configuration/configuration_test.rb +5 -2
  63. data/test/lib/vedeu/input/input_test.rb +5 -2
  64. data/test/lib/vedeu/launcher_test.rb +37 -2
  65. data/test/lib/vedeu/models/background_test.rb +6 -2
  66. data/test/lib/vedeu/models/char_test.rb +9 -6
  67. data/test/lib/vedeu/models/colour_test.rb +6 -2
  68. data/test/lib/vedeu/models/composition_test.rb +4 -2
  69. data/test/lib/vedeu/models/cursor_test.rb +27 -16
  70. data/test/lib/vedeu/models/foreground_test.rb +6 -2
  71. data/test/lib/vedeu/models/geometry_test.rb +6 -2
  72. data/test/lib/vedeu/models/interface_test.rb +5 -2
  73. data/test/lib/vedeu/models/keymap_test.rb +6 -4
  74. data/test/lib/vedeu/models/line_test.rb +5 -2
  75. data/test/lib/vedeu/models/offset_test.rb +7 -3
  76. data/test/lib/vedeu/models/stream_test.rb +4 -2
  77. data/test/lib/vedeu/models/style_test.rb +5 -2
  78. data/test/lib/vedeu/output/clear_test.rb +6 -2
  79. data/test/lib/vedeu/output/compositor_test.rb +8 -4
  80. data/test/lib/vedeu/output/render_test.rb +9 -6
  81. data/test/lib/vedeu/output/view_test.rb +7 -3
  82. data/test/lib/vedeu/output/viewport_test.rb +42 -9
  83. data/test/lib/vedeu/repositories/buffers_test.rb +52 -12
  84. data/test/lib/vedeu/repositories/cursors_test.rb +4 -26
  85. data/test/lib/vedeu/repositories/events_test.rb +6 -2
  86. data/test/lib/vedeu/repositories/focus_test.rb +5 -2
  87. data/test/lib/vedeu/repositories/groups_test.rb +5 -2
  88. data/test/lib/vedeu/repositories/interfaces_test.rb +4 -2
  89. data/test/lib/vedeu/repositories/keymaps_test.rb +8 -2
  90. data/test/lib/vedeu/repositories/menus_test.rb +3 -2
  91. data/test/lib/vedeu/repositories/offsets_test.rb +26 -19
  92. data/test/lib/vedeu/repositories/positional_test.rb +50 -0
  93. data/test/lib/vedeu/support/coercions_test.rb +7 -3
  94. data/test/lib/vedeu/support/colour_translator_test.rb +6 -2
  95. data/test/lib/vedeu/support/common_test.rb +5 -3
  96. data/test/lib/vedeu/support/esc_test.rb +6 -2
  97. data/test/lib/vedeu/support/event_test.rb +6 -2
  98. data/test/lib/vedeu/support/grid_test.rb +9 -3
  99. data/test/lib/vedeu/support/keymap_validator_test.rb +5 -2
  100. data/test/lib/vedeu/support/log_test.rb +4 -2
  101. data/test/lib/vedeu/support/menu_test.rb +10 -2
  102. data/test/lib/vedeu/support/position_test.rb +10 -2
  103. data/test/lib/vedeu/support/presentation_test.rb +6 -3
  104. data/test/lib/vedeu/{output → support}/refresh_test.rb +6 -2
  105. data/test/lib/vedeu/support/registrar_test.rb +2 -2
  106. data/test/lib/vedeu/support/repository_test.rb +4 -3
  107. data/test/lib/vedeu/support/terminal_test.rb +6 -2
  108. data/test/lib/vedeu/support/trace_test.rb +17 -2
  109. data/test/lib/vedeu_test.rb +1 -1
  110. data/vedeu.gemspec +2 -2
  111. metadata +13 -13
  112. data/lib/vedeu/output/area.rb +0 -284
  113. data/lib/vedeu/support/move.rb +0 -50
  114. data/test/lib/vedeu/output/area_test.rb +0 -242
  115. data/test/lib/vedeu/support/move_test.rb +0 -35
@@ -58,10 +58,15 @@ module Vedeu
58
58
  # key('s') { :something }
59
59
  # ...
60
60
  #
61
+ # keys do
62
+ # interfaces('main', 'other')
63
+ # ...
64
+ #
61
65
  # @return [Array]
62
66
  def interface(*name_or_names)
63
67
  attributes[:interfaces] = name_or_names
64
68
  end
69
+ alias_method :interfaces, :interface
65
70
 
66
71
  end # Keymap
67
72
 
@@ -4,11 +4,63 @@ module Vedeu
4
4
 
5
5
  # Provides methods to be used to define views.
6
6
  #
7
+ # @example
8
+ # line do
9
+ #
10
+ # background '#ffffff'
11
+ #
12
+ # colour background: '#222222', foreground: '#ff0000'
13
+ #
14
+ # foreground '#000000'
15
+ #
16
+ # stream do
17
+ # # see {API::Stream} for directives
18
+ # end
19
+ #
20
+ # style 'normal' # or a collection: ['bold', 'underline']
21
+ #
22
+ # text 'Some text...'
23
+ #
24
+ #
7
25
  # @api public
8
26
  class Line < Vedeu::Line
9
27
 
10
28
  include Helpers
11
29
 
30
+ # @param value [String]
31
+ # @param block [Proc]
32
+ #
33
+ # @example
34
+ # ...
35
+ # line do
36
+ # background '#0022ff' do
37
+ # ... other stream directives ...
38
+ #
39
+ # @return [Array]
40
+ def background(value = '', &block)
41
+ stream = API::Stream.build({ colour: { background: value },
42
+ parent: self.view_attributes }, &block)
43
+
44
+ attributes[:streams] << stream
45
+ end
46
+
47
+ # @param value [String]
48
+ # @param block [Proc]
49
+ #
50
+ # @example
51
+ # ...
52
+ # line do
53
+ # foreground '#00ff00' do
54
+ # ... other stream directives ...
55
+ #
56
+ # @return [Array]
57
+ def foreground(value = '', &block)
58
+ stream = API::Stream.build({ colour: { foreground: value },
59
+ parent: self.view_attributes }, &block)
60
+
61
+ attributes[:streams] << stream
62
+ end
63
+
12
64
  # Define a stream (a subset of a line).
13
65
  #
14
66
  # @param block [Proc] Block contains directives relating to API::Stream.
@@ -48,40 +100,6 @@ module Vedeu
48
100
  attributes[:streams] << { text: value }
49
101
  end
50
102
 
51
- # @param value [String]
52
- # @param block [Proc]
53
- #
54
- # @example
55
- # ...
56
- # line do
57
- # foreground '#00ff00' do
58
- # ... other stream directives ...
59
- #
60
- # @return [Array]
61
- def foreground(value = '', &block)
62
- stream = API::Stream.build({ colour: { foreground: value },
63
- parent: self.view_attributes }, &block)
64
-
65
- attributes[:streams] << stream
66
- end
67
-
68
- # @param value [String]
69
- # @param block [Proc]
70
- #
71
- # @example
72
- # ...
73
- # line do
74
- # background '#0022ff' do
75
- # ... other stream directives ...
76
- #
77
- # @return [Array]
78
- def background(value = '', &block)
79
- stream = API::Stream.build({ colour: { background: value },
80
- parent: self.view_attributes }, &block)
81
-
82
- attributes[:streams] << stream
83
- end
84
-
85
103
  end # Line
86
104
 
87
105
  end # API
@@ -97,7 +97,7 @@ module Vedeu
97
97
  # @param block [Proc] The optional block provided to the method.
98
98
  # @return []
99
99
  def method_missing(method, *args, &block)
100
- Vedeu.log("API::Menu#method_missing '#{method.to_s}' (args: #{args.inspect})")
100
+ Vedeu.log("API::Menu#method_missing '#{method}' (args: #{args.inspect})")
101
101
 
102
102
  @self_before_instance_eval.send(method, *args, &block) if @self_before_instance_eval
103
103
  end
@@ -34,40 +34,6 @@ module Vedeu
34
34
  attributes[:align] = value.to_sym
35
35
  end
36
36
 
37
- # Specify the background colour for a stream.
38
- #
39
- # @param value [String]
40
- #
41
- # @example
42
- # ...
43
- # stream do
44
- # background '#0022ff'
45
- # ... other stream directives ...
46
- #
47
- # @return [Hash]
48
- def background(value = '')
49
- fail InvalidSyntax, '`background` requires a value.' unless defined_value?(value)
50
-
51
- attributes[:colour].merge!({ background: value })
52
- end
53
-
54
- # Specify the foreground colour for a stream.
55
- #
56
- # @param value [String]
57
- #
58
- # @example
59
- # ...
60
- # stream do
61
- # foreground '#0022ff'
62
- # ... other stream directives ...
63
- #
64
- # @return [Hash]
65
- def foreground(value = '')
66
- fail InvalidSyntax, '`foreground` requires a value.' unless defined_value?(value)
67
-
68
- attributes[:colour].merge!({ foreground: value })
69
- end
70
-
71
37
  # Syntactic sugar used with {#align} to left align content.
72
38
  #
73
39
  # @return [Symbol]
@@ -60,7 +60,7 @@ module Vedeu
60
60
  # @param value [Boolean]
61
61
  # @return [Boolean]
62
62
  def interactive!(value = true)
63
- Vedeu.log("Configuration::API interactive: #{value.to_s}")
63
+ Vedeu.log("Configuration::API interactive: #{value}")
64
64
 
65
65
  options[:interactive] = value
66
66
  end
@@ -77,7 +77,7 @@ module Vedeu
77
77
  # @param value [Boolean]
78
78
  # @return [Boolean]
79
79
  def standalone!(value = true)
80
- Vedeu.log("Configuration::API interactive: #{!value.to_s}")
80
+ Vedeu.log("Configuration::API interactive: #{!value}")
81
81
 
82
82
  options[:interactive] = !value
83
83
  end
@@ -95,7 +95,7 @@ module Vedeu
95
95
  # @param value [Boolean]
96
96
  # @return [Boolean]
97
97
  def run_once!(value = true)
98
- Vedeu.log("Configuration::API once: #{value.to_s}")
98
+ Vedeu.log("Configuration::API once: #{value}")
99
99
 
100
100
  options[:once] = value
101
101
  end
@@ -154,7 +154,7 @@ module Vedeu
154
154
  options[:debug] = true
155
155
 
156
156
  else
157
- Vedeu.log("Configuration::API debug: #{value.to_s}")
157
+ Vedeu.log("Configuration::API debug: #{value}")
158
158
 
159
159
  options[:debug] = value
160
160
 
@@ -180,7 +180,7 @@ module Vedeu
180
180
  def trace!(value = true)
181
181
  options[:debug] = true if value === true
182
182
 
183
- Vedeu.log("Configuration::API trace: #{value.to_s}")
183
+ Vedeu.log("Configuration::API trace: #{value}")
184
184
 
185
185
  options[:trace] = value
186
186
  end
@@ -201,7 +201,7 @@ module Vedeu
201
201
  fail InvalidSyntax, '`colour_mode` must be `8`, `16`, `256`, ' \
202
202
  '`16777216`.' unless valid_colour_mode?(value)
203
203
 
204
- Vedeu.log("Configuration::API colour_mode: #{value.to_s}")
204
+ Vedeu.log("Configuration::API colour_mode: #{value}")
205
205
 
206
206
  options[:colour_mode] = value
207
207
  end
@@ -222,7 +222,7 @@ module Vedeu
222
222
  def exit_key(value)
223
223
  return invalid_key('exit_key') unless valid_key?(value)
224
224
 
225
- Vedeu.log("Configuration::API exit_key: #{value.to_s}")
225
+ Vedeu.log("Configuration::API exit_key: #{value}")
226
226
 
227
227
  system_key_options[:exit] = value
228
228
  end
@@ -244,7 +244,7 @@ module Vedeu
244
244
  def focus_next_key(value)
245
245
  return invalid_key('exit_key') unless valid_key?(value)
246
246
 
247
- Vedeu.log("Configuration::API focus_next: #{value.to_s}")
247
+ Vedeu.log("Configuration::API focus_next: #{value}")
248
248
 
249
249
  system_key_options[:focus_next] = value
250
250
  end
@@ -266,7 +266,7 @@ module Vedeu
266
266
  def focus_prev_key(value)
267
267
  return invalid_key('exit_key') unless valid_key?(value)
268
268
 
269
- Vedeu.log("Configuration::API focus_prev: #{value.to_s}")
269
+ Vedeu.log("Configuration::API focus_prev: #{value}")
270
270
 
271
271
  system_key_options[:focus_prev] = value
272
272
  end
@@ -288,7 +288,7 @@ module Vedeu
288
288
  def mode_switch_key(value)
289
289
  return invalid_key('exit_key') unless valid_key?(value)
290
290
 
291
- Vedeu.log("Configuration::API mode_switch: #{value.to_s}")
291
+ Vedeu.log("Configuration::API mode_switch: #{value}")
292
292
 
293
293
  system_key_options[:mode_switch] = value
294
294
  end
@@ -93,7 +93,7 @@ module Vedeu
93
93
  'Run application in either `8`, `16`, `256` or `16777216` ' \
94
94
  'colour mode.') do |colours|
95
95
  if [8, 16, 256, 16777216].include?(colours)
96
- Vedeu.log("Configuration::CLI colour_mode: #{colours.to_s}")
96
+ Vedeu.log("Configuration::CLI colour_mode: #{colours}")
97
97
 
98
98
  options[:colour_mode] = colours
99
99
 
@@ -8,16 +8,32 @@ module Vedeu
8
8
  # @api public
9
9
  class Launcher
10
10
 
11
+ attr_reader :exit_code
12
+
13
+ # @see Vedeu::Launcher#initialize
14
+ def self.execute!(argv = [],
15
+ stdin = STDIN,
16
+ stdout = STDOUT,
17
+ stderr = STDERR,
18
+ kernel = Kernel)
19
+ new(argv,
20
+ stdin = STDIN,
21
+ stdout = STDOUT,
22
+ stderr = STDERR,
23
+ kernel = Kernel).execute!
24
+ end
25
+
11
26
  # @param argv [Array]
12
27
  # @param stdin []
13
28
  # @param stdout []
14
29
  # @param stderr []
15
30
  # @param kernel []
16
31
  # @return [Launcher]
17
- def initialize(argv, stdin = STDIN,
18
- stdout = STDOUT,
19
- stderr = STDERR,
20
- kernel = Kernel)
32
+ def initialize(argv = [],
33
+ stdin = STDIN,
34
+ stdout = STDOUT,
35
+ stderr = STDERR,
36
+ kernel = Kernel)
21
37
  @argv = argv
22
38
  @stdin = stdin
23
39
  @stdout = stdout
@@ -43,8 +59,7 @@ module Vedeu
43
59
  Vedeu.log("Exiting gracefully.")
44
60
 
45
61
  $stdin, $stdout, $stderr = STDIN, STDOUT, STDERR
46
- @kernel.exit(@exit_code)
47
-
62
+ @kernel.exit(exit_code)
48
63
  end
49
64
 
50
65
  private
@@ -39,7 +39,7 @@ module Vedeu
39
39
  #
40
40
  # @return [Hash]
41
41
  def background_codes
42
- codes.inject({}){ |h, (k, v)| h.merge(k => v + 10) }
42
+ Esc.codes.inject({}) { |h, (k, v)| h.merge(k => v + 10) }
43
43
  end
44
44
 
45
45
  end # Background
@@ -62,7 +62,7 @@ module Vedeu
62
62
  # @param block [Proc] The optional block provided to the method.
63
63
  # @return []
64
64
  def method_missing(method, *args, &block)
65
- Vedeu.log("Composition#method_missing '#{method.to_s}' (args: #{args.inspect})")
65
+ Vedeu.log("Composition#method_missing '#{method}' (args: #{args.inspect})")
66
66
 
67
67
  @self_before_instance_eval.send(method, *args, &block) if @self_before_instance_eval
68
68
  end
@@ -19,17 +19,17 @@ module Vedeu
19
19
  # belongs to.
20
20
  # @option attributes :state [Symbol] The visibility of the cursor, either
21
21
  # +:hide+ or +:show+.
22
- # @option attributes :x [Fixnum]
23
- # @option attributes :y [Fixnum]
22
+ # @option attributes :x [Fixnum] The terminal x coordinate for the cursor.
23
+ # @option attributes :y [Fixnum] The terminal y coordinate for the cursor.
24
24
  #
25
25
  # @return [Cursor]
26
26
  def initialize(attributes = {})
27
27
  @attributes = defaults.merge!(attributes)
28
28
 
29
- @name = @attributes[:name]
30
- @state = @attributes[:state]
31
- @x = @attributes[:x]
32
- @y = @attributes[:y]
29
+ @name = @attributes[:name]
30
+ @state = @attributes[:state]
31
+ @x = @attributes[:x]
32
+ @y = @attributes[:y]
33
33
  end
34
34
 
35
35
  # Returns an attribute hash for the current position and visibility of the
@@ -38,19 +38,23 @@ module Vedeu
38
38
  # @return [Hash]
39
39
  def attributes
40
40
  {
41
- name: name,
42
- state: state,
43
- x: x,
44
- y: y,
41
+ name: name,
42
+ state: state,
43
+ x: x,
44
+ y: y,
45
45
  }
46
46
  end
47
47
  alias_method :refresh, :attributes
48
48
 
49
49
  # Returns the x coordinate (column/character) of the cursor. Attempts to
50
- # sensibly reposition the cursor if it is currently outside the interface.
50
+ # sensibly reposition the cursor if it is currently outside the interface,
51
+ # or outside the visible area of the terminal.
51
52
  #
52
53
  # @return [Fixnum]
53
54
  def x
55
+ @x = 1 if @x <= 1
56
+ @x = Terminal.width if @x >= Terminal.width
57
+
54
58
  if @x <= left
55
59
  @x = left
56
60
 
@@ -64,10 +68,14 @@ module Vedeu
64
68
  end
65
69
 
66
70
  # Returns the y coordinate (row/line) of the cursor. Attempts to sensibly
67
- # reposition the cursor if it is currently outside the interface.
71
+ # reposition the cursor if it is currently outside the interface, or outside
72
+ # the visible area of the terminal.
68
73
  #
69
74
  # @return [Fixnum]
70
75
  def y
76
+ @y = 1 if @y <= 1
77
+ @y = Terminal.height if @y >= Terminal.height
78
+
71
79
  if @y <= top
72
80
  @y = top
73
81
 
@@ -114,17 +122,6 @@ module Vedeu
114
122
  end
115
123
  end
116
124
 
117
- # Return a boolean indicating the visibility of the cursor, invisible if
118
- # the state is not defined.
119
- #
120
- # @return [Boolean]
121
- def visible?
122
- return false unless states.include?(state)
123
- return false if state == :hide
124
-
125
- true
126
- end
127
-
128
125
  private
129
126
 
130
127
  # Returns the escape sequence to position the cursor and set its visibility.
@@ -145,7 +142,7 @@ module Vedeu
145
142
  #
146
143
  # @return [String]
147
144
  def visibility
148
- return Esc.string('show_cursor') if visible?
145
+ return Esc.string('show_cursor') if state == :show
149
146
 
150
147
  Esc.string('hide_cursor')
151
148
  end
@@ -162,22 +159,15 @@ module Vedeu
162
159
  @interface ||= Interfaces.build(name)
163
160
  end
164
161
 
165
- # The valid visibility states for the cursor.
166
- #
167
- # @return [Array]
168
- def states
169
- [:show, :hide]
170
- end
171
-
172
162
  # The default values for a new instance of Cursor.
173
163
  #
174
164
  # @return [Hash]
175
165
  def defaults
176
166
  {
177
- name: '',
178
- state: :show,
179
- x: 1,
180
- y: 1,
167
+ name: '',
168
+ state: :hide,
169
+ x: 1,
170
+ y: 1,
181
171
  }
182
172
  end
183
173