vedeu 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/README.md +1 -2
  4. data/Rakefile +5 -5
  5. data/bin/vedeu +8 -4
  6. data/docs/api.md +3 -1
  7. data/docs/events.md +43 -29
  8. data/docs/getting_started.md +2 -0
  9. data/examples/cursor_app/cursor_app.rb +85 -0
  10. data/examples/lines_app/lines_app.rb +60 -0
  11. data/lib/vedeu.rb +9 -3
  12. data/lib/vedeu/api/api.rb +28 -7
  13. data/lib/vedeu/api/composition.rb +2 -0
  14. data/lib/vedeu/api/helpers.rb +2 -0
  15. data/lib/vedeu/api/interface.rb +2 -20
  16. data/lib/vedeu/api/keymap.rb +2 -0
  17. data/lib/vedeu/api/line.rb +2 -0
  18. data/lib/vedeu/api/menu.rb +3 -1
  19. data/lib/vedeu/api/stream.rb +25 -2
  20. data/lib/vedeu/application.rb +4 -4
  21. data/lib/vedeu/configuration/api.rb +327 -0
  22. data/lib/vedeu/configuration/cli.rb +110 -0
  23. data/lib/vedeu/{configuration.rb → configuration/configuration.rb} +49 -99
  24. data/lib/vedeu/launcher.rb +0 -1
  25. data/lib/vedeu/models/attributes/colour_translator.rb +2 -2
  26. data/lib/vedeu/models/colour.rb +0 -1
  27. data/lib/vedeu/models/composition.rb +2 -8
  28. data/lib/vedeu/models/cursor.rb +261 -0
  29. data/lib/vedeu/models/geometry.rb +11 -19
  30. data/lib/vedeu/models/interface.rb +2 -12
  31. data/lib/vedeu/models/keymap.rb +2 -0
  32. data/lib/vedeu/models/line.rb +2 -0
  33. data/lib/vedeu/models/stream.rb +2 -0
  34. data/lib/vedeu/models/style.rb +2 -0
  35. data/lib/vedeu/output/clear.rb +0 -1
  36. data/lib/vedeu/output/compositor.rb +0 -1
  37. data/lib/vedeu/output/refresh.rb +3 -0
  38. data/lib/vedeu/output/render.rb +12 -6
  39. data/lib/vedeu/output/view.rb +1 -0
  40. data/lib/vedeu/repositories/cursors.rb +98 -0
  41. data/lib/vedeu/repositories/events.rb +0 -1
  42. data/lib/vedeu/repositories/focus.rb +18 -0
  43. data/lib/vedeu/repositories/menus.rb +4 -4
  44. data/lib/vedeu/support/common.rb +2 -1
  45. data/lib/vedeu/support/event.rb +1 -10
  46. data/lib/vedeu/support/grid.rb +1 -2
  47. data/lib/vedeu/{repositories → support}/keymap_validator.rb +5 -4
  48. data/lib/vedeu/support/log.rb +3 -0
  49. data/lib/vedeu/support/menu.rb +4 -1
  50. data/lib/vedeu/support/registrar.rb +2 -1
  51. data/test/integration/defining_interfaces_test.rb +0 -1
  52. data/test/integration/views/basic_view_test.rb +741 -739
  53. data/test/lib/vedeu/api/api_test.rb +14 -3
  54. data/test/lib/vedeu/api/helpers_test.rb +3 -3
  55. data/test/lib/vedeu/api/interface_test.rb +17 -70
  56. data/test/lib/vedeu/api/keymap_test.rb +2 -0
  57. data/test/lib/vedeu/api/line_test.rb +4 -4
  58. data/test/lib/vedeu/api/menu_test.rb +6 -5
  59. data/test/lib/vedeu/api/stream_test.rb +18 -0
  60. data/test/lib/vedeu/configuration/api_test.rb +248 -0
  61. data/test/lib/vedeu/configuration/cli_test.rb +88 -0
  62. data/test/lib/vedeu/configuration/configuration_test.rb +67 -0
  63. data/test/lib/vedeu/input/input_test.rb +2 -2
  64. data/test/lib/vedeu/models/attributes/background_test.rb +3 -3
  65. data/test/lib/vedeu/models/attributes/foreground_test.rb +3 -3
  66. data/test/lib/vedeu/models/composition_test.rb +0 -222
  67. data/test/lib/vedeu/models/cursor_test.rb +164 -0
  68. data/test/lib/vedeu/models/interface_test.rb +0 -11
  69. data/test/lib/vedeu/output/compositor_test.rb +2 -4
  70. data/test/lib/vedeu/output/render_test.rb +4 -41
  71. data/test/lib/vedeu/repositories/cursors_test.rb +13 -0
  72. data/test/lib/vedeu/repositories/focus_test.rb +14 -4
  73. data/test/lib/vedeu/repositories/menus_test.rb +36 -29
  74. data/test/lib/vedeu/{repositories → support}/keymap_validator_test.rb +0 -0
  75. data/test/lib/vedeu/support/menu_test.rb +3 -3
  76. data/test/lib/vedeu/support/registrar_test.rb +6 -0
  77. data/test/lib/vedeu/support/terminal_test.rb +2 -2
  78. data/test/test_helper.rb +1 -1
  79. data/vedeu.gemspec +1 -1
  80. metadata +23 -14
  81. data/elements.txt +0 -118
  82. data/lib/vedeu/support/cursor.rb +0 -96
  83. data/test/lib/vedeu/configuration_test.rb +0 -154
  84. data/test/lib/vedeu/support/cursor_test.rb +0 -79
  85. data/test/support/model_test_data.json +0 -437
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dec7d96b1f14de41e305192ec084b5f16ea39779
4
- data.tar.gz: afd4cc9b1eea2d7eb9c781abbdf71feab39514ed
3
+ metadata.gz: c51db32c71781208264d0ea69bf433a5bde9bf75
4
+ data.tar.gz: bb5067249adad44b4788b4abcb0471c513d0ec9b
5
5
  SHA512:
6
- metadata.gz: c008ae703f26a202bb20b3c0909dc1779a4d30606365f96342637e5c3715018fa75d16ddf12f7087599a99aa24785830ca55683b286246e77e2ad444101f2fbe
7
- data.tar.gz: f587307ac3e309e74b018770048f90dae43cae84b8805f041df8d29c0231c42191d5d92337a5625ceb11c71fc24aca8cb072170227bc7cde177082f299d42833
6
+ metadata.gz: 16bbad5b4ffb6b0748dbef756d4b5db9ef0abb562c842246a66aee21cbd3c3f1bcf7d0aeb43cf44171b958be9f8c821e199b61eea0439b571536238894341545
7
+ data.tar.gz: a29d38fd26002e43980502708196e9d3434a7a92f7b952feafc571e74dce7b27664c962bb0674a2607284824af145b6554f85616c256d48528b31c0288e986c3
data/.yardopts CHANGED
@@ -4,3 +4,4 @@
4
4
  -
5
5
  docs/api.md
6
6
  docs/events.md
7
+ docs/getting_started.md
data/README.md CHANGED
@@ -92,7 +92,6 @@ interface 'main' do
92
92
  width 10 # see notes below
93
93
  height 10
94
94
  colour foreground: '#ffffff', background: '#000000'
95
- cursor false
96
95
  end
97
96
  ```
98
97
 
@@ -108,7 +107,6 @@ Note: not setting a width or height will set the values to the terminal's report
108
107
 
109
108
  - `foreground` sets the default foreground colour. (See Colours)
110
109
  - `background` sets the default background colour.
111
- - `cursor` is a Boolean specifying whether the cursor should show.
112
110
 
113
111
 
114
112
  ### Events
@@ -176,6 +174,7 @@ Pull requests are very welcome! Please try to follow these simple rules if appli
176
174
  * Update the [README](https://github.com/gavinlaking/vedeu/blob/master/README.md).
177
175
  * Please **do not change** the version number.
178
176
 
177
+ Any branch on the repository that is not `master` is probably experimental; do not rely on anything in these branches.
179
178
 
180
179
  ### General contribution help
181
180
 
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
4
  task :default => :test
5
5
 
6
6
  Rake::TestTask.new do |t|
7
- t.libs.push "lib"
8
- t.libs.push "test"
9
- t.pattern = "test/**/*_test.rb"
7
+ t.libs.push 'lib'
8
+ t.libs.push 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
10
  end
data/bin/vedeu CHANGED
@@ -1,9 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
- $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib')
3
3
 
4
4
  -> { its -> { a } }
5
5
  trap('INT') { exit! }
6
6
 
7
- require 'vedeu'
8
-
9
- Vedeu::Launcher.new(ARGV.dup).execute!
7
+ puts ''
8
+ puts 'Vedeu is a Ruby gem. This executable serves for a future in which ' \
9
+ 'Vedeu can generate a starting point for your terminal-based GUI ' \
10
+ 'application.'
11
+ puts ''
12
+ puts 'Please see: https://github.com/gavinlaking/vedeu for more details.'
13
+ puts ''
@@ -39,6 +39,8 @@ class OtherClassInYourApplication
39
39
 
40
40
  ### API DSL methods
41
41
 
42
+ Note: Nesting indicates where an API method is allowed/supposed to be used.
43
+
42
44
  #### Events
43
45
 
44
46
  - event
@@ -59,7 +61,6 @@ class OtherClassInYourApplication
59
61
  - interface
60
62
  - centred
61
63
  - colour
62
- - cursor
63
64
  - delay
64
65
  - group
65
66
  - height
@@ -104,6 +105,7 @@ class OtherClassInYourApplication
104
105
  #### Miscellany
105
106
 
106
107
  - defined
108
+ - focus
107
109
  - height
108
110
  - log
109
111
  - resize
@@ -1,11 +1,8 @@
1
1
  ## Vedeu Events
2
2
 
3
- Vedeu provides an event mechanism to facilitate the functionality of your
4
- application. The events are either Vedeu defined, ie. system events or
5
- user defined, ie. user events.
3
+ Vedeu provides an event mechanism to facilitate the functionality of your application. The events are either Vedeu defined, ie. system events or user defined, ie. user events.
6
4
 
7
- Events described in this document assume that you have included Vedeu in your
8
- class:
5
+ Events described in this document assume that you have included Vedeu in your class:
9
6
 
10
7
  ```ruby
11
8
  class SomeClassInYourApplication
@@ -16,8 +13,7 @@ class:
16
13
 
17
14
  ## System Events
18
15
 
19
- System events generally control the internal state of Vedeu with respects to
20
- your application. They are soft-namespaced using underscores.
16
+ System events generally control the internal state of Vedeu with respects to your application. They are soft-namespaced using underscores.
21
17
 
22
18
  ### `:_cleanup_`
23
19
 
@@ -27,21 +23,49 @@ This event is fired by Vedeu when `:_exit_` is triggered. You can hook into this
27
23
 
28
24
  Clears the whole terminal space.
29
25
 
26
+ ### `:_cursor_up_`
27
+
28
+ Moves the cursor for the focussed interface up one row, but will not exceed the boundary of the interface.
29
+
30
+ ### `:_cursor_right_`
31
+
32
+ Moves the cursor for the focussed interface right one column, but will not exceed the boundary of the interface.
33
+
34
+ ### `:_cursor_down_`
35
+
36
+ Moves the cursor for the focussed interface down one row, but will not exceed the boundary of the interface.
37
+
38
+ ### `:_cursor_left_`
39
+
40
+ Moves the cursor for the focussed interface left one column, but will not exceed the boundary of the interface.
41
+
42
+ ### `:_cursor_hide_`
43
+
44
+ Hides the cursor for the focussed interface.
45
+
46
+ ### `:_cursor_show_`
47
+
48
+ Shows the cursor for the focussed interface.
49
+
50
+ ### `:_cursor_refresh_`
51
+
52
+ Refreshes the cursor for the focussed interface.
53
+
30
54
  ### `:_exit_`
31
55
 
32
56
  When triggered, Vedeu will trigger a `:_cleanup_` event which you can define (to save files, etc) and attempt to exit.
33
57
 
34
58
  ### `:_focus_by_name_`
35
59
 
36
- When triggered with an interface name will focus that interface.
60
+ When triggered with an interface name will focus that interface and restore the cursor position and visibility.
37
61
 
38
62
  ### `:_focus_next_`
39
63
 
40
- When triggered will focus the next interface.
64
+ When triggered will focus the next interface and restore the cursor position and visibility.
41
65
 
42
66
  ### `:_focus_prev_`
43
67
 
44
- When triggered will focus the previous interface.
68
+ When triggered will focus the previous interface and restore the cursor position and visibility.
45
69
 
46
70
  ### `:_initialize_`
47
71
 
@@ -65,28 +89,23 @@ Requires target menu name as argument. Returns the selected menu item.
65
89
 
66
90
  ### `:_menu_next_`
67
91
 
68
- Requires target menu name as argument. Makes the next menu item the current menu
69
- item, until it reaches the last item.
92
+ Requires target menu name as argument. Makes the next menu item the current menu item, until it reaches the last item.
70
93
 
71
94
  ### `:_menu_prev_`
72
95
 
73
- Requires target menu name as argument. Makes the previous menu item the current
74
- menu item, until it reaches the first item.
96
+ Requires target menu name as argument. Makes the previous menu item the current menu item, until it reaches the first item.
75
97
 
76
98
  ### `:_menu_top_`
77
99
 
78
- Requires target menu name as argument. Makes the first menu item the current
79
- menu item.
100
+ Requires target menu name as argument. Makes the first menu item the current menu item.
80
101
 
81
102
  ### `:_menu_bottom_`
82
103
 
83
- Requires target menu name as argument. Makes the last menu item the current menu
84
- item.
104
+ Requires target menu name as argument. Makes the last menu item the current menu item.
85
105
 
86
106
  ### `:_menu_select_`
87
107
 
88
- Requires target menu name as argument. Makes the current menu item also the
89
- selected menu item.
108
+ Requires target menu name as argument. Makes the current menu item also the selected menu item.
90
109
 
91
110
  ### `:_menu_deselect_`
92
111
 
@@ -94,13 +113,11 @@ Requires target menu name as argument. Deselects all menu items.
94
113
 
95
114
  ### `:_menu_items_`
96
115
 
97
- Requires target menu name as argument. Returns all the menu items with
98
- respective `current` or `selected` boolean indicators.
116
+ Requires target menu name as argument. Returns all the menu items with respective `current` or `selected` boolean indicators.
99
117
 
100
118
  ### `:_menu_view_`
101
119
 
102
- Requires target menu name as argument. Returns a subset of the menu items;
103
- starting at the current item to the last item.
120
+ Requires target menu name as argument. Returns a subset of the menu items; starting at the current item to the last item.
104
121
 
105
122
  ### `:_mode_switch_`
106
123
 
@@ -120,15 +137,12 @@ Will refresh the interface with this name. E.g. `_refresh_widget_` will refresh
120
137
 
121
138
  ### `:_resize_`
122
139
 
123
- When triggered will cause Vedeu to trigger the `:_clear_` and `:_refresh_`
124
- events. Please see those events for their behaviour.
140
+ When triggered will cause Vedeu to trigger the `:_clear_` and `:_refresh_` events. Please see those events for their behaviour.
125
141
 
126
142
 
127
143
  ##### Notes:
128
144
 
129
- System events can be handled or triggered by your application also, but overriding or adding additional events to the Vedeu system event namespace may cause unpredictable results. It is recommended to only to hook into events like :_cleanup_, :_initialize_ and :key if you need to do something respective
130
- to those events.
131
-
145
+ System events can be handled or triggered by your application also, but overriding or adding additional events to the Vedeu system event namespace may cause unpredictable results. It is recommended to only to hook into events like :_cleanup_, :_initialize_ and :key if you need to do something respective to those events.
132
146
 
133
147
  ... TODO ... What about events in Vedeu::Menu?
134
148
 
@@ -0,0 +1,2 @@
1
+ ## Getting Started with Vedeu
2
+
@@ -0,0 +1,85 @@
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 VedeuCursorApp
12
+ include Vedeu
13
+
14
+ event(:_initialize_) { trigger(:_refresh_) }
15
+
16
+ interface 'iron' do
17
+ centred true
18
+ colour foreground: '#ff0000', background: '#000000'
19
+ height 4
20
+ width 12
21
+ end
22
+
23
+ interface 'krypton' do
24
+ centred false
25
+ colour foreground: '#ffff00', background: '#000000'
26
+ height 4
27
+ width 12
28
+ y { use('iron').south }
29
+ x { use('iron').east(1) }
30
+ end
31
+
32
+ interface 'francium' do
33
+ centred false
34
+ colour foreground: '#ff00ff', background: '#000000'
35
+ height 4
36
+ width 12
37
+ y { use('iron').north(5) }
38
+ x { use('iron').west(13) }
39
+ end
40
+
41
+ interface 'argon' do
42
+ centred false
43
+ colour foreground: '#00ff00', background: '#000000'
44
+ height 4
45
+ width 12
46
+ y { use('iron').south }
47
+ x { use('iron').west(13) }
48
+ end
49
+
50
+ keys do
51
+ key(:up) { trigger(:_cursor_up_) }
52
+ key(:right) { trigger(:_cursor_right_) }
53
+ key(:down) { trigger(:_cursor_down_) }
54
+ key(:left) { trigger(:_cursor_left_) }
55
+ end
56
+
57
+ render do
58
+ view 'iron' do
59
+ line 'shift+tab to'
60
+ line 'move to the'
61
+ line 'previous one'
62
+ end
63
+ view 'francium' do
64
+ line 'Press tab to'
65
+ line 'move to next'
66
+ line 'interface or'
67
+ end
68
+ view 'krypton' do
69
+ line 'Position is'
70
+ line 'remembered'
71
+ line 'between'
72
+ line 'interfaces.'
73
+ end
74
+ view 'argon' do
75
+ line 'To exit this'
76
+ line 'just press Q'
77
+ end
78
+ end
79
+
80
+ def self.start
81
+ Vedeu::Launcher.new(['--debug']).execute!
82
+ end
83
+ end
84
+
85
+ VedeuCursorApp.start
@@ -0,0 +1,60 @@
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 VedeuLinesApp
12
+ include Vedeu
13
+
14
+ event(:_initialize_) { trigger(:_refresh_) }
15
+
16
+ interface 'ruthenium' do
17
+ centred true
18
+ colour foreground: '#ffffff', background: '#000000'
19
+ height 5
20
+ width 40
21
+ end
22
+
23
+ interface 'tantalum' do
24
+ colour foreground: '#00aadd', background: '#000000'
25
+ height 1
26
+ width 40
27
+ x use('ruthenium').left
28
+ y use('ruthenium').south
29
+ end
30
+
31
+ keys do
32
+ key(:up) { trigger(:_cursor_up_) }
33
+ key(:right) { trigger(:_cursor_right_) }
34
+ key(:down) { trigger(:_cursor_down_) }
35
+ key(:left) { trigger(:_cursor_left_) }
36
+ end
37
+
38
+ render do
39
+ view 'ruthenium' do
40
+ line 'Ruthenium is a chemical element with'
41
+ line 'symbol Ru and atomic number 44. It is a'
42
+ line 'rare transition metal belonging to the'
43
+ line 'platinum group of the periodic table.'
44
+ line 'Like the other metals of the platinum'
45
+ line 'group, ruthenium is inert to most other'
46
+ line 'chemicals.'
47
+ end
48
+ view 'tantalum' do
49
+ line 'Use cursor keys to navigate, Q to quit.'
50
+ end
51
+ end
52
+
53
+ focus 'ruthenium'
54
+
55
+ def self.start
56
+ Vedeu::Launcher.new(['--debug']).execute!
57
+ end
58
+ end
59
+
60
+ VedeuLinesApp.start
@@ -5,6 +5,9 @@ module Vedeu
5
5
  # Raised when Vedeu attempts to access a named buffer that does not exist.
6
6
  BufferNotFound = Class.new(StandardError)
7
7
 
8
+ # Raised when a cursor cannot be found by name.
9
+ CursorNotFound = Class.new(StandardError)
10
+
8
11
  # Raised when trying to access a group of interfaces which do not exist by
9
12
  # this name.
10
13
  GroupNotFound = Class.new(StandardError)
@@ -65,8 +68,10 @@ require 'logger'
65
68
  require 'optparse'
66
69
  require 'set'
67
70
 
68
- require 'vedeu/configuration'
69
71
  require 'vedeu/support/common'
72
+ require 'vedeu/configuration/cli'
73
+ require 'vedeu/configuration/api'
74
+ require 'vedeu/configuration/configuration'
70
75
  require 'vedeu/support/log'
71
76
  require 'vedeu/support/trace'
72
77
 
@@ -86,6 +91,7 @@ require 'vedeu/models/geometry'
86
91
  require 'vedeu/models/colour'
87
92
  require 'vedeu/models/style'
88
93
  require 'vedeu/models/interface'
94
+ require 'vedeu/models/cursor'
89
95
  require 'vedeu/models/keymap'
90
96
  require 'vedeu/models/line'
91
97
  require 'vedeu/models/stream'
@@ -102,14 +108,15 @@ require 'vedeu/api/line'
102
108
  require 'vedeu/api/menu'
103
109
  require 'vedeu/api/stream'
104
110
 
111
+ require 'vedeu/support/keymap_validator'
105
112
  require 'vedeu/repositories/menus'
106
- require 'vedeu/repositories/keymap_validator'
107
113
  require 'vedeu/repositories/keymaps'
108
114
  require 'vedeu/repositories/interfaces'
109
115
  require 'vedeu/repositories/groups'
110
116
  require 'vedeu/repositories/focus'
111
117
  require 'vedeu/repositories/events'
112
118
  require 'vedeu/repositories/buffers'
119
+ require 'vedeu/repositories/cursors'
113
120
 
114
121
  require 'vedeu/support/registrar'
115
122
 
@@ -121,7 +128,6 @@ require 'vedeu/output/view'
121
128
 
122
129
  require 'vedeu/support/grid'
123
130
  require 'vedeu/support/menu'
124
- require 'vedeu/support/cursor'
125
131
 
126
132
  require 'vedeu/input/input'
127
133