vedeu 0.4.59 → 0.4.60

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.
@@ -69,6 +69,7 @@ module Vedeu
69
69
  #
70
70
  # @example
71
71
  # Vedeu.trigger(:_drb_restart_)
72
+ # Vedeu.drb_restart
72
73
  #
73
74
  # @return [void]
74
75
  def drb_restart!
@@ -79,6 +80,7 @@ module Vedeu
79
80
  #
80
81
  # @example
81
82
  # Vedeu.trigger(:_drb_start_)
83
+ # Vedeu.drb_start
82
84
  #
83
85
  # @return [void]
84
86
  def drb_start!
@@ -89,6 +91,7 @@ module Vedeu
89
91
  #
90
92
  # @example
91
93
  # Vedeu.trigger(:_drb_status_)
94
+ # Vedeu.drb_status
92
95
  #
93
96
  # @return [void]
94
97
  def drb_status!
@@ -99,6 +102,7 @@ module Vedeu
99
102
  #
100
103
  # @example
101
104
  # Vedeu.trigger(:_drb_stop_)
105
+ # Vedeu.drb_stop
102
106
  #
103
107
  # @return [void]
104
108
  def drb_stop!
@@ -35,7 +35,9 @@ module Vedeu
35
35
  #
36
36
  # @return [void]
37
37
  def menu_bottom!
38
- Vedeu.bind(:_menu_bottom_) { |name| Vedeu.menus.find(name).bottom_item }
38
+ Vedeu.bind(:_menu_bottom_) do |name|
39
+ Vedeu.menus.by_name(name).bottom_item
40
+ end
39
41
  end
40
42
 
41
43
  # Returns the current menu item.
@@ -46,7 +48,7 @@ module Vedeu
46
48
  # @return [void]
47
49
  def menu_current!
48
50
  Vedeu.bind(:_menu_current_) do |name|
49
- Vedeu.menus.find(name).current_item
51
+ Vedeu.menus.by_name(name).current_item
50
52
  end
51
53
  end
52
54
 
@@ -58,7 +60,7 @@ module Vedeu
58
60
  # @return [void]
59
61
  def menu_deselect!
60
62
  Vedeu.bind(:_menu_deselect_) do |name|
61
- Vedeu.menus.find(name).deselect_item
63
+ Vedeu.menus.by_name(name).deselect_item
62
64
  end
63
65
  end
64
66
 
@@ -70,7 +72,7 @@ module Vedeu
70
72
  #
71
73
  # @return [void]
72
74
  def menu_items!
73
- Vedeu.bind(:_menu_items_) { |name| Vedeu.menus.find(name).items }
75
+ Vedeu.bind(:_menu_items_) { |name| Vedeu.menus.by_name(name).items }
74
76
  end
75
77
 
76
78
  # Makes the next menu item the current menu item, until it reaches the
@@ -81,7 +83,7 @@ module Vedeu
81
83
  #
82
84
  # @return [void]
83
85
  def menu_next!
84
- Vedeu.bind(:_menu_next_) { |name| Vedeu.menus.find(name).next_item }
86
+ Vedeu.bind(:_menu_next_) { |name| Vedeu.menus.by_name(name).next_item }
85
87
  end
86
88
 
87
89
  # Makes the previous menu item the current menu item, until it reaches the
@@ -92,7 +94,7 @@ module Vedeu
92
94
  #
93
95
  # @return [void]
94
96
  def menu_prev!
95
- Vedeu.bind(:_menu_prev_) { |name| Vedeu.menus.find(name).prev_item }
97
+ Vedeu.bind(:_menu_prev_) { |name| Vedeu.menus.by_name(name).prev_item }
96
98
  end
97
99
 
98
100
  # Returns the selected menu item.
@@ -103,7 +105,7 @@ module Vedeu
103
105
  # @return [void]
104
106
  def menu_selected!
105
107
  Vedeu.bind(:_menu_selected_) do |name|
106
- Vedeu.menus.find(name).selected_item
108
+ Vedeu.menus.by_name(name).selected_item
107
109
  end
108
110
  end
109
111
 
@@ -114,7 +116,9 @@ module Vedeu
114
116
  #
115
117
  # @return [void]
116
118
  def menu_select!
117
- Vedeu.bind(:_menu_select_) { |name| Vedeu.menus.find(name).select_item }
119
+ Vedeu.bind(:_menu_select_) do |name|
120
+ Vedeu.menus.by_name(name).select_item
121
+ end
118
122
  end
119
123
 
120
124
  # Makes the first menu item the current menu item.
@@ -124,7 +128,7 @@ module Vedeu
124
128
  #
125
129
  # @return [void]
126
130
  def menu_top!
127
- Vedeu.bind(:_menu_top_) { |name| Vedeu.menus.find(name).top_item }
131
+ Vedeu.bind(:_menu_top_) { |name| Vedeu.menus.by_name(name).top_item }
128
132
  end
129
133
 
130
134
  # Returns a subset of the menu items; starting at the current item to the
@@ -135,7 +139,7 @@ module Vedeu
135
139
  #
136
140
  # @return [void]
137
141
  def menu_view!
138
- Vedeu.bind(:_menu_view_) { |name| Vedeu.menus.find(name).view }
142
+ Vedeu.bind(:_menu_view_) { |name| Vedeu.menus.by_name(name).view }
139
143
  end
140
144
 
141
145
  end # Menus
@@ -29,26 +29,13 @@ module Vedeu
29
29
  #
30
30
  # @return [void]
31
31
  def start
32
- unless Vedeu::Configuration.log?
33
- Vedeu.configure { log('/tmp/vedeu_bootstrap.log') }
34
- end
32
+ configure_log!
35
33
 
36
- # config/configuration.rb is already loaded so don't load it twice
37
- Dir[File.join(Vedeu::Configuration.base_path, 'config/**/*')].each do |f|
38
- next if f =~ %r{config/configuration\.rb}
39
- load f
40
- end
34
+ client_configuration!
41
35
 
42
- [
43
- 'app/views/templates/**/*',
44
- 'app/views/interfaces/**/*',
45
- 'app/controllers/**/*',
46
- 'app/helpers/**/*',
47
- 'app/views/**/*',
48
- 'app/models/keymaps/**/*',
49
- ].each { |path| load(File.join(Vedeu::Configuration.base_path, path)) }
36
+ client_application!
50
37
 
51
- entry_point || eval(Vedeu::Configuration.root)
38
+ client_initialize!
52
39
 
53
40
  Vedeu::Launcher.execute!(argv)
54
41
  end
@@ -65,6 +52,39 @@ module Vedeu
65
52
 
66
53
  private
67
54
 
55
+ # @return [String]
56
+ def base_path
57
+ Vedeu::Configuration.base_path
58
+ end
59
+
60
+ # @note
61
+ # config/configuration.rb is already loaded so don't load it twice
62
+ # @return [void]
63
+ def client_configuration!
64
+ Dir[File.join(base_path, 'config/**/*')].each do |path|
65
+ next if path =~ %r{config/configuration\.rb}
66
+
67
+ load(path)
68
+ end
69
+ end
70
+
71
+ # @return [void]
72
+ def client_application!
73
+ [
74
+ 'app/views/templates/**/*',
75
+ 'app/views/interfaces/**/*',
76
+ 'app/controllers/**/*',
77
+ 'app/helpers/**/*',
78
+ 'app/views/**/*',
79
+ 'app/models/keymaps/**/*',
80
+ ].each { |path| load(File.join(base_path, path)) }
81
+ end
82
+
83
+ # @return [void]
84
+ def client_initialize!
85
+ entry_point || eval(Vedeu::Configuration.root)
86
+ end
87
+
68
88
  # Load each of the loadable files.
69
89
  #
70
90
  # @param path [String]
@@ -86,6 +106,13 @@ module Vedeu
86
106
  end
87
107
  end
88
108
 
109
+ # @return [void]
110
+ def configure_log!
111
+ Vedeu.configure do
112
+ log('/tmp/vedeu_bootstrap.log')
113
+ end unless Vedeu::Configuration.log?
114
+ end
115
+
89
116
  end # Bootstrap
90
117
 
91
118
  end # Vedeu
@@ -0,0 +1,125 @@
1
+ module Vedeu
2
+
3
+ # Provides escape sequence strings for terminal colours and some actions.
4
+ #
5
+ module EscapeSequences
6
+
7
+ extend self
8
+
9
+ # @return [Hash<Symbol => String>]
10
+ def actions
11
+ {
12
+ hide_cursor: "\e[?25l",
13
+ show_cursor: "\e[?25h",
14
+ cursor_position: "\e[6n",
15
+ bg_reset: "\e[49m",
16
+ blink: "\e[5m",
17
+ blink_off: "\e[25m",
18
+ bold: "\e[1m",
19
+ bold_off: "\e[22m",
20
+ border_on: "\e(0",
21
+ border_off: "\e(B",
22
+ dim: "\e[2m",
23
+ fg_reset: "\e[39m",
24
+ negative: "\e[7m",
25
+ positive: "\e[27m",
26
+ reset: "\e[0m",
27
+ underline: "\e[4m",
28
+ underline_off: "\e[24m",
29
+ }
30
+ end
31
+
32
+ # Produces the background named colour escape sequence hash from the
33
+ # foreground escape sequence hash.
34
+ #
35
+ # @return [Hash<Symbol => Fixnum>]
36
+ def background_codes
37
+ hash = {}
38
+ Vedeu::EscapeSequences.foreground_codes.inject(hash) do |h, (k, v)|
39
+ h.merge!(k => v + 10)
40
+ end
41
+ end
42
+
43
+ # Produces the foreground named colour escape sequence hash. The background
44
+ # escape sequences are also generated from this by adding 10 to the values.
45
+ # This hash gives rise to methods you can call directly on `Esc` to produce
46
+ # the desired colours:
47
+ #
48
+ # @example
49
+ # Esc.red # => "\e[31m"
50
+ #
51
+ # Esc.red { 'some text' } # => "\e[31msome text\e[39m"
52
+ #
53
+ # Esc.on_blue # => "\e[44m"
54
+ #
55
+ # Esc.on_blue { 'some text' } # => "\e[44msome text\e[49m"
56
+ #
57
+ # # Valid names:
58
+ # :black, :red, :green, :yellow, :blue, :magenta, :cyan, :light_grey,
59
+ # :default, :dark_grey, :light_red, :light_green, :light_yellow,
60
+ # :light_blue, :light_magenta, :light_cyan, :white
61
+ #
62
+ # @return [Hash<Symbol => Fixnum>]
63
+ def foreground_codes
64
+ {
65
+ black: 30,
66
+ red: 31,
67
+ green: 32,
68
+ yellow: 33,
69
+ blue: 34,
70
+ magenta: 35,
71
+ cyan: 36,
72
+ light_grey: 37,
73
+ default: 39,
74
+ dark_grey: 90,
75
+ light_red: 91,
76
+ light_green: 92,
77
+ light_yellow: 93,
78
+ light_blue: 94,
79
+ light_magenta: 95,
80
+ light_cyan: 96,
81
+ white: 97,
82
+ }
83
+ end
84
+ alias_method :codes, :foreground_codes
85
+
86
+ # @return [void]
87
+ def setup!
88
+ define_actions!
89
+ define_backgrounds!
90
+ define_foregrounds!
91
+ end
92
+
93
+ private
94
+
95
+ # @return [void]
96
+ def define_actions!
97
+ actions.each { |key, code| define_method(key) { code } }
98
+ end
99
+
100
+ # @return [void]
101
+ def define_backgrounds!
102
+ background_codes.each do |key, code|
103
+ define_method('on_' + key.to_s) do |&blk|
104
+ "\e[#{code}m" + (blk ? blk.call + "\e[49m" : '')
105
+ end
106
+ end
107
+ end
108
+
109
+ # Dynamically creates methods for each terminal named colour. When a block
110
+ # is given, then the colour is reset to 'default' once the block is called.
111
+ #
112
+ # @return [void]
113
+ def define_foregrounds!
114
+ foreground_codes.each do |key, code|
115
+ define_method(key) do |&blk|
116
+ "\e[#{code}m" + (blk ? blk.call + "\e[39m" : '')
117
+ end
118
+ end
119
+ end
120
+
121
+ end # EscapeSequences
122
+
123
+ end # Vedeu
124
+
125
+ Vedeu::EscapeSequences.setup!
@@ -11,47 +11,55 @@ module Vedeu
11
11
 
12
12
  include Singleton
13
13
 
14
- # @param (see #input)
15
- # @see #input
16
- def self.input(data, type = :key)
17
- instance.input(data, type)
18
- end
14
+ class << self
19
15
 
20
- # @return [void]
21
- # @see #output
22
- def self.output
23
- instance.output
24
- end
16
+ # @param (see #input)
17
+ # @see #input
18
+ def input(data, type = :key)
19
+ instance.input(data, type)
20
+ end
25
21
 
26
- # @return [void]
27
- # @see #restart
28
- def self.restart
29
- instance.restart
30
- end
22
+ # @return [void]
23
+ # @see #output
24
+ def output
25
+ instance.output
26
+ end
31
27
 
32
- # @return [void]
33
- # @see #shutdown
34
- def self.shutdown
35
- instance.shutdown
36
- end
28
+ # @return [void]
29
+ # @see #restart
30
+ def restart
31
+ instance.restart
32
+ end
33
+ alias_method :drb_restart, :restart
37
34
 
38
- # @return [void]
39
- # @see #start
40
- def self.start
41
- instance.start
42
- end
35
+ # @return [void]
36
+ # @see #shutdown
37
+ def shutdown
38
+ instance.shutdown
39
+ end
43
40
 
44
- # @return [Symbol]
45
- # @see #status
46
- def self.status
47
- instance.status
48
- end
41
+ # @return [void]
42
+ # @see #start
43
+ def start
44
+ instance.start
45
+ end
46
+ alias_method :drb_start, :start
49
47
 
50
- # @return [void]
51
- # @see #stop
52
- def self.stop
53
- instance.stop
54
- end
48
+ # @return [Symbol]
49
+ # @see #status
50
+ def status
51
+ instance.status
52
+ end
53
+ alias_method :drb_status, :status
54
+
55
+ # @return [void]
56
+ # @see #stop
57
+ def stop
58
+ instance.stop
59
+ end
60
+ alias_method :drb_stop, :stop
61
+
62
+ end # Eigenclass
55
63
 
56
64
  # @param data [String|Symbol]
57
65
  # @param type [Symbol] Either :keypress or :command.
@@ -2,7 +2,80 @@ module Vedeu
2
2
 
3
3
  module DSL
4
4
 
5
- # DSL for creating views.
5
+ # There are two ways to construct views with Vedeu. You would like to draw
6
+ # the view to the screen immediately (immediate render) or you want to save
7
+ # a view to be drawn when you trigger a refresh event later (deferred view).
8
+ #
9
+ # Both of these approaches require that you have defined an interface (or
10
+ # 'visible area') first. You can find out how to define an interface with
11
+ # Vedeu here. The examples in 'Immediate Render' and 'Deferred View' use
12
+ # these interface definitions: (Note: if you use these examples, ensure your
13
+ # terminal is at least 70 characters in width and 5 lines in height.)
14
+ #
15
+ # Vedeu.interface 'main' do
16
+ # geometry do
17
+ # centred!
18
+ # height 4
19
+ # width 50
20
+ # end
21
+ # end
22
+ #
23
+ # Vedeu.interface 'title' do
24
+ # geometry do
25
+ # height 1
26
+ # width 50
27
+ # x use('main').left
28
+ # y use('main').north
29
+ # end
30
+ # end
31
+ #
32
+ # Both of these approaches use a concept of Buffers in Vedeu. There are
33
+ # three buffers for any defined interface. These are imaginatively called:
34
+ # 'back', 'front' and 'previous'.
35
+ #
36
+ # The 'back' buffer is the content for an interface which will be shown next
37
+ # time a refresh event is fired globally or for that interface. So, 'back'
38
+ # becomes 'front'.
39
+ #
40
+ # The 'front' buffer is the content for an interface which is currently
41
+ # showing. When a refresh event is fired, again, globally or for that
42
+ # interface specifically, the content of this 'front' buffer is first copied
43
+ # to the 'previous' buffer, and then the current 'back' buffer overwrites
44
+ # this 'front' buffer.
45
+ #
46
+ # The 'previous' buffer contains what was shown on the 'front' before the
47
+ # current 'front'.
48
+ #
49
+ # You can only write to either the 'front' (you want the content to be drawn
50
+ # immediately (immediate render)) or the 'back' (you would like the content
51
+ # to be drawn on the next refresh (deferred view)).
52
+ #
53
+ # The basic view DSL methods look like this:
54
+ #
55
+ # renders/views
56
+ # |- view
57
+ # |- lines
58
+ # | |- line
59
+ # | |- streams
60
+ # | | |- stream
61
+ # | | |- char
62
+ # | |
63
+ # | |- stream
64
+ # | |- char
65
+ # |
66
+ # |- line
67
+ # |- streams
68
+ # | |- stream
69
+ # | |- char
70
+ # |
71
+ # |- stream
72
+ # |- char
73
+ #
74
+ # renders/views
75
+ # |- view
76
+ # |- lines/line
77
+ # |- streams/stream
78
+ # |- char
6
79
  #
7
80
  class View
8
81
 
@@ -41,9 +114,24 @@ module Vedeu
41
114
  # the views, though can be later triggered if needed.
42
115
  #
43
116
  # Vedeu.renders do
44
- # view 'my_interface' do
45
- # # ... some code
117
+ # view 'some_interface' do
118
+ # line do
119
+ # stream do
120
+ # left 'Title goes here', width: 35
121
+ # end
122
+ # stream do
123
+ # right Time.now.strftime('%H:%m'), width: 7
124
+ # end
125
+ # end
46
126
  # end
127
+ # view 'other_interface' do
128
+ # lines do
129
+ # line 'This is content for the main interface.'
130
+ # line ''
131
+ # line 'Pretty easy eh?'
132
+ # end
133
+ # end
134
+ # # ... some code
47
135
  # end
48
136
  #
49
137
  # # or...
@@ -67,6 +155,10 @@ module Vedeu
67
155
 
68
156
  # Define a view (content) for an interface.
69
157
  #
158
+ # As you can see by comparing the examples above to these below, the
159
+ # immediate render simply wraps what is already here in the deferred
160
+ # view.
161
+ #
70
162
  # The views declared within this block are stored in their respective
71
163
  # interface back buffers until a refresh event occurs. When the refresh
72
164
  # event is triggered, the back buffers are swapped into the front
@@ -74,11 +166,22 @@ module Vedeu
74
166
  # {Vedeu::Terminal.output}.
75
167
  #
76
168
  # Vedeu.views do
77
- # view 'my_interface' do
78
- # # ... some attributes ...
169
+ # view 'some_interface' do
170
+ # line do
171
+ # stream do
172
+ # left 'Title goes here', width: 35
173
+ # end
174
+ # stream do
175
+ # right Time.now.strftime('%H:%m'), width: 7
176
+ # end
177
+ # end
79
178
  # end
80
- # view 'my_other_interface' do
81
- # # ... some other attributes ...
179
+ # view 'other_interface' do
180
+ # lines do
181
+ # line 'This is content for the main interface.'
182
+ # line ''
183
+ # line 'Pretty easy eh?'
184
+ # end
82
185
  # end
83
186
  # # ... some code
84
187
  # end