vedeu 0.4.43 → 0.4.44

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/bin/vedeu +19 -0
  4. data/lib/vedeu.rb +0 -34
  5. data/lib/vedeu/all.rb +4 -1
  6. data/lib/vedeu/application/application_view.rb +9 -9
  7. data/lib/vedeu/application/controller.rb +6 -5
  8. data/lib/vedeu/application/helper.rb +3 -16
  9. data/lib/vedeu/application/view.rb +3 -16
  10. data/lib/vedeu/bindings/all.rb +5 -0
  11. data/lib/vedeu/bindings/bindings.rb +115 -0
  12. data/lib/vedeu/bindings/drb.rb +45 -0
  13. data/lib/vedeu/bindings/menus.rb +53 -0
  14. data/lib/vedeu/bindings/movement.rb +76 -0
  15. data/lib/vedeu/bindings/visibility.rb +53 -0
  16. data/lib/vedeu/buffers/buffer.rb +2 -0
  17. data/lib/vedeu/cli/generator/templates/application/app/controllers/name.erb +2 -2
  18. data/lib/vedeu/cli/generator/templates/application/app/helpers/name.erb +2 -0
  19. data/lib/vedeu/cli/generator/templates/application/config/configuration.erb +3 -0
  20. data/lib/vedeu/cli/generator/view.rb +0 -5
  21. data/lib/vedeu/cli/main.rb +12 -0
  22. data/lib/vedeu/cursor/reposition.rb +4 -4
  23. data/lib/vedeu/dsl/interface.rb +0 -27
  24. data/lib/vedeu/exceptions.rb +65 -0
  25. data/lib/vedeu/geometry/geometry.rb +2 -2
  26. data/lib/vedeu/geometry/grid.rb +2 -2
  27. data/lib/vedeu/input/input.rb +34 -28
  28. data/lib/vedeu/null/geometry.rb +2 -2
  29. data/lib/vedeu/output/colour.rb +0 -2
  30. data/lib/vedeu/output/esc.rb +7 -1
  31. data/lib/vedeu/output/render_border.rb +5 -0
  32. data/lib/vedeu/output/renderers/json.rb +7 -2
  33. data/lib/vedeu/support/terminal.rb +1 -1
  34. data/lib/vedeu/version.rb +1 -1
  35. data/test/lib/vedeu/application/controller_test.rb +0 -4
  36. data/test/lib/vedeu/application/helper_test.rb +0 -8
  37. data/test/lib/vedeu/application/view_test.rb +0 -8
  38. data/test/lib/vedeu/bindings/bindings_test.rb +43 -0
  39. data/test/lib/vedeu/bindings/drb_test.rb +23 -0
  40. data/test/lib/vedeu/bindings/menus_test.rb +26 -0
  41. data/test/lib/vedeu/bindings/movement_test.rb +28 -0
  42. data/test/lib/vedeu/bindings/visibility_test.rb +27 -0
  43. data/test/lib/vedeu/buffers/buffer_test.rb +73 -38
  44. data/test/lib/vedeu/cli/main_test.rb +47 -0
  45. data/test/lib/vedeu/dsl/interface_test.rb +4 -7
  46. data/test/lib/vedeu/exceptions_test.rb +5 -0
  47. data/test/lib/vedeu/input/input_test.rb +9 -0
  48. data/test/lib/vedeu/output/esc_test.rb +4 -1
  49. metadata +21 -5
  50. data/lib/vedeu/bindings.rb +0 -275
  51. data/test/lib/vedeu/bindings_test.rb +0 -88
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cffdbe3379ae8f53f8e224ad01f554f697291aeb
4
- data.tar.gz: 48dacd852a9ece5238fd2986a64897335416f0c6
3
+ metadata.gz: 0e923ab136ae9285466e5526700a91bd23b78f03
4
+ data.tar.gz: 8af995c9b432d7ee21c51837bb6dd6a508b5e485
5
5
  SHA512:
6
- metadata.gz: b36dc6810c4e595f8ddacb09f2c076c0b9d00d457b281a4d03b31cb980db8a547881b458707e6f456b4be1a5ab2c7cbdfd65a8da3b8d06fb7c2463a03b440857
7
- data.tar.gz: 2709588855899d5f3d107ab9ccccc66d6b93bfb7693d59cad06865d84bff61e3be0398b8c07d532d3614ffd32bf019c1c96c576941fec30da6d075127c56f08a
6
+ metadata.gz: b907622dd0291801638870f6456ecf0876c1e66395e3b87a75d433c5ba4449ca9ce23ad27c1520832d0843e7067dcd4969dd7a5b35735dadead4ff2365881f7e
7
+ data.tar.gz: 1533041a4c03464a27846e11bca3b6f4a4e948fcd8f95f5bfb6a33c8cae92e0a6e398e545785e78101888a59d96c25547c806f5d5d6e38026f5a75425202cbfa
data/Dockerfile CHANGED
@@ -71,6 +71,6 @@ USER vedeu
71
71
  # Once we're up and running, we can create a shell to the docker instance and
72
72
  # start running commands against it.
73
73
  #
74
- # sudo docker run -it -v $PWD:/home/vedeu/gem:rw vedeu/my_first_app /bin/bash
74
+ # sudo docker run -it -v $PWD:/home/vedeu/gem:rw -v ~/Docker/:/home/vedeu/docker:rw vedeu/my_first_app /bin/bash
75
75
  #
76
76
  #
data/bin/vedeu CHANGED
@@ -1,5 +1,24 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rake'
4
+
5
+ bundler_message = 'Bundler is required. Please install bundler with ' \
6
+ "'gem install bundler'"
7
+ begin
8
+ require 'bundler'
9
+
10
+ rescue LoadError
11
+ puts bundler_message
12
+
13
+ end
14
+
15
+ fail bundler_message unless defined?(Bundler)
16
+
17
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
18
+ # load Gem.bin_path('bundler', 'bundle')
19
+
20
+ Bundler.setup
21
+
3
22
  gem_dir = File.expand_path('..', File.dirname(__FILE__))
4
23
  $LOAD_PATH.unshift(gem_dir) unless $LOAD_PATH.include?(gem_dir)
5
24
 
data/lib/vedeu.rb CHANGED
@@ -49,40 +49,6 @@ module Vedeu
49
49
  receiver.extend(API)
50
50
  end
51
51
 
52
- # ModelNotFound: Raised with Vedeu attempts to access a named model that does
53
- # not exist.
54
- #
55
- # InvalidSyntax: Raised when Vedeu attempts to parse a {Vedeu.view} or
56
- # {Vedeu.interface} and encounters a problem.
57
- #
58
- # MissingRequired: Raised when a name is not provided for a model when
59
- # attempting to store it in a repository.
60
- #
61
- # ModeSwitch: Raised intentionally when the client application wishes to
62
- # switch between cooked and raw (or vice versa) terminal modes. Vedeu is
63
- # hard-wired to use the `Escape` key to trigger this change for the time
64
- # being.
65
- #
66
- # NotImplemented: Raised to remind me (or client application developers) that
67
- # the subclass implements the functionality sought.
68
- #
69
- # OutOfRange: Raised when trying to access an interface column less than 1 or
70
- # greater than 12. Vedeu is hard-wired to a 12-column layout for the time
71
- # being.
72
- #
73
- # VedeuInterrupt: Raised when Vedeu wishes to exit.
74
- #
75
- EXCEPTIONS = %w(
76
- ModelNotFound
77
- InvalidSyntax
78
- MissingRequired
79
- ModeSwitch
80
- NotImplemented
81
- OutOfRange
82
- VedeuInterrupt
83
- )
84
- EXCEPTIONS.each { |e| const_set(e, Class.new(StandardError)) }
85
-
86
52
  end # Vedeu
87
53
 
88
54
  require 'vedeu/all'
data/lib/vedeu/all.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  # load order is important
3
3
 
4
4
  require 'vedeu/version'
5
+ require 'vedeu/exceptions'
5
6
  require 'vedeu/debug'
6
7
  require 'vedeu/traps'
7
8
 
@@ -11,7 +12,9 @@ require 'vedeu/storage/all'
11
12
  require 'vedeu/repositories/all'
12
13
 
13
14
  require 'vedeu/api'
14
- require 'vedeu/bindings'
15
+ require 'vedeu/bindings/drb'
16
+ require 'vedeu/bindings/menus'
17
+ require 'vedeu/bindings/bindings'
15
18
 
16
19
  require 'vedeu/cli/generator/all'
17
20
 
@@ -11,25 +11,25 @@ module Vedeu
11
11
 
12
12
  # Renders the view.
13
13
  #
14
- # @param object [void]
14
+ # @param args [void]
15
15
  # @return [void]
16
- def self.render(object = nil)
17
- new(object).render
16
+ def self.render(*args)
17
+ new(args).render
18
18
  end
19
19
 
20
20
  # Returns a new instance of Vedeu::ApplicationView.
21
21
  #
22
- # @param object [void]
22
+ # @param args [void]
23
23
  # @return [Vedeu::ApplicationView]
24
- def initialize(object = nil)
25
- @object = object
24
+ def initialize(*args)
25
+ @args = args
26
26
  end
27
27
 
28
28
  protected
29
29
 
30
- # @!attribute [r] object
30
+ # @!attribute [r] args
31
31
  # @return [void]
32
- attr_reader :object
32
+ attr_reader :args
33
33
 
34
34
  # # @!attribute [r] template
35
35
  # # @return [void]
@@ -41,7 +41,7 @@ module Vedeu
41
41
  # @return [String]
42
42
  def template(value)
43
43
  @template = Vedeu::Configuration.base_path +
44
- "/app/views/templates/#{value}.erb"
44
+ "/app/views/templates/#{value}.erb"
45
45
  end
46
46
 
47
47
  end # ApplicationView
@@ -1,18 +1,20 @@
1
1
  module Vedeu
2
2
 
3
+ # Provides methods to be used by Vedeu::ApplicationController.
4
+ #
5
+ # @api private
3
6
  module Controller
4
7
 
8
+ # When included, provide these methods as class methods.
5
9
  module ClassMethods
6
10
 
11
+ # @param name [Symbol] The name of the controller.
7
12
  def controller_name(name)
8
- Vedeu.bind("show_#{name}".to_sym) { self.new }
13
+ Vedeu.bind("show_#{name}".to_sym) { new }
9
14
  end
10
15
 
11
16
  end # ClassMethods
12
17
 
13
- module InstanceMethods
14
- end # InstanceMethods
15
-
16
18
  # When this module is included in a class, provide ClassMethods as class
17
19
  # methods for the class.
18
20
  #
@@ -20,7 +22,6 @@ module Vedeu
20
22
  # @return [void]
21
23
  def self.included(klass)
22
24
  klass.send :extend, ClassMethods
23
- klass.send :include, InstanceMethods
24
25
  end
25
26
 
26
27
  end # Controller
@@ -1,23 +1,10 @@
1
1
  module Vedeu
2
2
 
3
+ # Provides methods to be used by Vedeu::ApplicationHelper.
4
+ #
5
+ # @api private
3
6
  module Helper
4
7
 
5
- module ClassMethods
6
- end # ClassMethods
7
-
8
- module InstanceMethods
9
- end # InstanceMethods
10
-
11
- # When this module is included in a class, provide ClassMethods as class
12
- # methods for the class.
13
- #
14
- # @param klass [Class]
15
- # @return [void]
16
- def self.included(klass)
17
- klass.send :extend, ClassMethods
18
- klass.send :include, InstanceMethods
19
- end
20
-
21
8
  end # Helper
22
9
 
23
10
  end # Vedeu
@@ -1,23 +1,10 @@
1
1
  module Vedeu
2
2
 
3
+ # Provides methods to be used by Vedeu::ApplicationView.
4
+ #
5
+ # @api private
3
6
  module View
4
7
 
5
- module ClassMethods
6
- end # ClassMethods
7
-
8
- module InstanceMethods
9
- end # InstanceMethods
10
-
11
- # When this module is included in a class, provide ClassMethods as class
12
- # methods for the class.
13
- #
14
- # @param klass [Class]
15
- # @return [void]
16
- def self.included(klass)
17
- klass.send :extend, ClassMethods
18
- klass.send :include, InstanceMethods
19
- end
20
-
21
8
  end # View
22
9
 
23
10
  end # Vedeu
@@ -0,0 +1,5 @@
1
+ require_relative 'visibility'
2
+ require_relative 'movement'
3
+ require_relative 'menus'
4
+ require_relative 'drb'
5
+ require_relative 'bindings'
@@ -0,0 +1,115 @@
1
+ require_relative 'drb'
2
+ require_relative 'menus'
3
+ require_relative 'movement'
4
+ require_relative 'visibility'
5
+
6
+ module Vedeu
7
+
8
+ # Creates system events which when called provide a variety of core functions
9
+ # and behaviours. They are soft-namespaced using underscores.
10
+ #
11
+ # @note
12
+ # Unbinding any of these events is likely to cause problems, so I would
13
+ # advise leaving them alone. A safe rule: if the name starts with an
14
+ # underscore, it's probably used by Vedeu internally.
15
+ #
16
+ # @api public
17
+ module Bindings
18
+
19
+ include Vedeu::Bindings::DRB
20
+ include Vedeu::Bindings::Menus
21
+ include Vedeu::Bindings::Movement
22
+ include Vedeu::Bindings::Visibility
23
+
24
+ # Vedeu triggers this event when `:_exit_` is triggered. You can hook into
25
+ # this to perform a special action before the application terminates. Saving
26
+ # the user's work, session or preferences might be popular here.
27
+ Vedeu.bind(:_cleanup_) do
28
+ Vedeu.trigger(:_drb_stop_)
29
+ Vedeu.trigger(:cleanup)
30
+ end
31
+
32
+ # When triggered, Vedeu will trigger a `:cleanup` event which you can define
33
+ # (to save files, etc) and attempt to exit.
34
+ Vedeu.bind(:_exit_) { Vedeu::Application.stop }
35
+
36
+ # Vedeu triggers this event when it is ready to enter the main loop. Client
37
+ # applications can listen for this event and perform some action(s), like
38
+ # render the first screen, interface or make a sound. When Vedeu triggers
39
+ # this event, the :_refresh_ event is also triggered automatically.
40
+ Vedeu.bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
41
+
42
+ # Will cause the triggering of the `:key` event; which
43
+ # you should define to 'do things'. If the `escape` key is pressed, then
44
+ # `key` is triggered with the argument `:escape`, also an internal event
45
+ # `_mode_switch_` is triggered.
46
+ Vedeu.bind(:_keypress_) { |key| Vedeu.keypress(key) }
47
+
48
+ # Will cause the triggering of the `:command` event; which you should define
49
+ # to 'do things'.
50
+ Vedeu.bind(:_command_) { |command| Vedeu.trigger(:command, command) }
51
+
52
+ # When triggered with a message will cause Vedeu to log the message if
53
+ # logging is enabled in the configuration.
54
+ Vedeu.bind(:_log_) { |msg| Vedeu.log(type: :debug, message: msg) }
55
+
56
+ # When triggered (after the user presses `escape`), Vedeu switches from a
57
+ # "raw mode" terminal to a "cooked mode" terminal. The idea here being that
58
+ # the raw mode is for single keypress actions, whilst cooked mode allows the
59
+ # user to enter more elaborate commands- such as commands with arguments.
60
+ Vedeu.bind(:_mode_switch_) { fail ModeSwitch }
61
+
62
+ # When triggered will cause Vedeu to trigger the `:_clear_` and `:_refresh_`
63
+ # events. Please see those events for their behaviour.
64
+ Vedeu.bind(:_resize_, delay: 0.15) { Vedeu.resize }
65
+
66
+ # When triggered will return the current position of the cursor.
67
+ Vedeu.bind(:_cursor_position_) do |name|
68
+ Vedeu.cursors.by_name(name).position
69
+ end
70
+
71
+ # When triggered with an interface name will focus that interface and
72
+ # restore the cursor position and visibility.
73
+ Vedeu.bind(:_focus_by_name_) { |name| Vedeu.focus_by_name(name) }
74
+
75
+ # When triggered will focus the next interface and restore the cursor
76
+ # position and visibility.
77
+ Vedeu.bind(:_focus_next_) { Vedeu.focus_next }
78
+
79
+ # When triggered will focus the previous interface and restore the cursor
80
+ # position and visibility.
81
+ Vedeu.bind(:_focus_prev_) { Vedeu.focus_previous }
82
+
83
+ # Clears the whole terminal space, or the named interface area to be cleared
84
+ # if given.
85
+ Vedeu.bind(:_clear_) { |name| Vedeu::Clear.by_name(name) }
86
+
87
+ # Will cause all interfaces to refresh, or the named interface if given.
88
+ #
89
+ # @note
90
+ # Hidden interfaces will be still refreshed in memory but not shown.
91
+ Vedeu.bind(:_refresh_) do |name|
92
+ name ? Vedeu::Refresh.by_name(name) : Vedeu::Refresh.all
93
+ end
94
+
95
+ # Will cause the named cursor to refresh, or the cursor of the interface
96
+ # which is currently in focus.
97
+ Vedeu.bind(:_refresh_cursor_) { |name| Vedeu::RefreshCursor.render(name) }
98
+
99
+ # Will cause all interfaces in the named group to refresh.
100
+ Vedeu.bind(:_refresh_group_) { |name| Vedeu::Refresh.by_group(name) }
101
+
102
+ # Clears the spaces occupied by the interfaces belonging to the named group.
103
+ Vedeu.bind(:_clear_group_) { |name| Vedeu::Clear.by_group(name) }
104
+
105
+ # @see Vedeu::Geometry#maximise
106
+ Vedeu.bind(:_maximise_) { |name| Vedeu.geometries.by_name(name).maximise }
107
+
108
+ # @see Vedeu::Geometry#unmaximise
109
+ Vedeu.bind(:_unmaximise_) do |name|
110
+ Vedeu.geometries.by_name(name).unmaximise
111
+ end
112
+
113
+ end # Bindings
114
+
115
+ end # Vedeu
@@ -0,0 +1,45 @@
1
+ module Vedeu
2
+
3
+ module Bindings
4
+
5
+ # System events relating to the DRb server implementation.
6
+ #
7
+ # @api public
8
+ module DRB
9
+
10
+ # Triggering this event will send input to the running application as long
11
+ # as it has the DRb server running.
12
+ Vedeu.bind(:_drb_input_) do |data, type|
13
+ Vedeu.log(type: :drb, message: "Sending input (#{type})")
14
+
15
+ case type
16
+ when :command then Vedeu.trigger(:_command_, data)
17
+ else Vedeu.trigger(:_keypress_, data)
18
+ end
19
+ end
20
+
21
+ Vedeu.bind(:_drb_retrieve_output_) { Vedeu::VirtualBuffer.retrieve }
22
+
23
+ # Triggering this event with 'data' will push data into the running
24
+ # application's virtual buffer.
25
+ Vedeu.bind(:_drb_store_output_) do |data|
26
+ Vedeu::VirtualBuffer.store(Vedeu::Terminal.virtual.output(data))
27
+ end
28
+
29
+ # Use the DRb server to request the client application to restart.
30
+ Vedeu.bind(:_drb_restart_) { Vedeu::Distributed::Server.restart }
31
+
32
+ # Use the DRb server to request the client application to start.
33
+ Vedeu.bind(:_drb_start_) { Vedeu::Distributed::Server.start }
34
+
35
+ # Use the DRb server to request the status of the client application.
36
+ Vedeu.bind(:_drb_status_) { Vedeu::Distributed::Server.status }
37
+
38
+ # Use the DRb server to request the client application to stop.
39
+ Vedeu.bind(:_drb_stop_) { Vedeu::Distributed::Server.stop }
40
+
41
+ end # DRB
42
+
43
+ end # Bindings
44
+
45
+ end # Vedeu
@@ -0,0 +1,53 @@
1
+ module Vedeu
2
+
3
+ module Bindings
4
+
5
+ # Each of the Bindings::Menus events require a target menu name as an
6
+ # argument.
7
+ #
8
+ # @api public
9
+ module Menus
10
+
11
+ # Makes the last menu item the current menu item.
12
+ Vedeu.bind(:_menu_bottom_) { |name| Vedeu.menus.find(name).bottom_item }
13
+
14
+ # Returns the current menu item.
15
+ Vedeu.bind(:_menu_current_) { |name| Vedeu.menus.find(name).current_item }
16
+
17
+ # Deselects all menu items.
18
+ Vedeu.bind(:_menu_deselect_) do |name|
19
+ Vedeu.menus.find(name).deselect_item
20
+ end
21
+
22
+ # Returns all the menu items with respective `current` or `selected`
23
+ # boolean indicators.
24
+ Vedeu.bind(:_menu_items_) { |name| Vedeu.menus.find(name).items }
25
+
26
+ # Makes the next menu item the current menu item, until it reaches the
27
+ # last item.
28
+ Vedeu.bind(:_menu_next_) { |name| Vedeu.menus.find(name).next_item }
29
+
30
+ # Makes the previous menu item the current menu item, until it reaches the
31
+ # first item.
32
+ Vedeu.bind(:_menu_prev_) { |name| Vedeu.menus.find(name).prev_item }
33
+
34
+ # Returns the selected menu item.
35
+ Vedeu.bind(:_menu_selected_) do |name|
36
+ Vedeu.menus.find(name).selected_item
37
+ end
38
+
39
+ # Makes the current menu item also the selected menu item.
40
+ Vedeu.bind(:_menu_select_) { |name| Vedeu.menus.find(name).select_item }
41
+
42
+ # Makes the first menu item the current menu item.
43
+ Vedeu.bind(:_menu_top_) { |name| Vedeu.menus.find(name).top_item }
44
+
45
+ # Returns a subset of the menu items; starting at the current item to the
46
+ # last item.
47
+ Vedeu.bind(:_menu_view_) { |name| Vedeu.menus.find(name).view }
48
+
49
+ end # Menus
50
+
51
+ end # Bindings
52
+
53
+ end # Vedeu