vedeu 0.4.29 → 0.4.30

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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +57 -38
  3. data/README.md +10 -110
  4. data/docs/getting_started.md +9 -0
  5. data/lib/vedeu/all.rb +1 -1
  6. data/lib/vedeu/api.rb +6 -5
  7. data/lib/vedeu/buffers/display_buffer.rb +1 -1
  8. data/lib/vedeu/configuration/api.rb +1 -1
  9. data/lib/vedeu/cursor/move.rb +2 -2
  10. data/lib/vedeu/debug.rb +3 -1
  11. data/lib/vedeu/dsl/all.rb +15 -9
  12. data/lib/vedeu/dsl/{components/border.rb → border.rb} +0 -3
  13. data/lib/vedeu/dsl/composition.rb +33 -0
  14. data/lib/vedeu/dsl/{components/geometry.rb → geometry.rb} +18 -0
  15. data/lib/vedeu/dsl/interface.rb +2 -2
  16. data/lib/vedeu/dsl/{components/keymap.rb → keymap.rb} +2 -4
  17. data/lib/vedeu/dsl/{components/menu.rb → menu.rb} +0 -0
  18. data/lib/vedeu/dsl/{shared/presentation.rb → presentation.rb} +0 -0
  19. data/lib/vedeu/dsl/{shared/text.rb → text.rb} +0 -0
  20. data/lib/vedeu/dsl/{shared/use.rb → use.rb} +0 -0
  21. data/lib/vedeu/events/event.rb +11 -53
  22. data/lib/vedeu/geometry/area.rb +1 -2
  23. data/lib/vedeu/geometry/coordinate.rb +1 -1
  24. data/lib/vedeu/geometry/geometry.rb +0 -12
  25. data/lib/vedeu/geometry/position_validator.rb +1 -1
  26. data/lib/vedeu/input/keymap.rb +1 -1
  27. data/lib/vedeu/models/interface.rb +1 -0
  28. data/lib/vedeu/models/panel.rb +2 -0
  29. data/lib/vedeu/null/geometry.rb +3 -2
  30. data/lib/vedeu/output/border.rb +6 -6
  31. data/lib/vedeu/output/clear.rb +4 -4
  32. data/lib/vedeu/output/compressor.rb +10 -4
  33. data/lib/vedeu/output/html_char.rb +4 -4
  34. data/lib/vedeu/output/refresh.rb +3 -3
  35. data/lib/vedeu/output/renderers/file.rb +1 -1
  36. data/lib/vedeu/output/renderers/terminal.rb +2 -2
  37. data/lib/vedeu/output/renderers/text.rb +1 -1
  38. data/lib/vedeu/output/style.rb +1 -1
  39. data/lib/vedeu/output/translator.rb +0 -8
  40. data/lib/vedeu/output/viewport.rb +1 -1
  41. data/lib/vedeu/repositories/all.rb +1 -1
  42. data/lib/vedeu/repositories/repository.rb +1 -1
  43. data/lib/vedeu/support/common.rb +1 -1
  44. data/lib/vedeu/support/template.rb +1 -1
  45. data/lib/vedeu/support/timer.rb +11 -14
  46. data/lib/vedeu/templating/all.rb +9 -0
  47. data/lib/vedeu/templating/helpers.rb +9 -3
  48. data/lib/vedeu/templating/preprocessor.rb +4 -1
  49. data/lib/vedeu/version.rb +3 -0
  50. data/test/lib/vedeu/api_test.rb +38 -297
  51. data/test/lib/vedeu/buffers/display_buffer_test.rb +1 -0
  52. data/test/lib/vedeu/dsl/{components/border_test.rb → border_test.rb} +0 -0
  53. data/test/lib/vedeu/dsl/{components/geometry_test.rb → geometry_test.rb} +0 -0
  54. data/test/lib/vedeu/dsl/{components/keymap_test.rb → keymap_test.rb} +0 -0
  55. data/test/lib/vedeu/dsl/{components/menu_test.rb → menu_test.rb} +0 -0
  56. data/test/lib/vedeu/dsl/{shared/presentation_test.rb → presentation_test.rb} +0 -0
  57. data/test/lib/vedeu/dsl/{shared/text_test.rb → text_test.rb} +0 -0
  58. data/test/lib/vedeu/dsl/{shared/use_test.rb → use_test.rb} +0 -0
  59. data/test/lib/vedeu/dsl/view_test.rb +2 -0
  60. data/test/lib/vedeu/main_loop_test.rb +0 -3
  61. data/test/lib/vedeu/output/background_test.rb +18 -22
  62. data/test/lib/vedeu/output/compressor_test.rb +4 -0
  63. data/test/lib/vedeu/output/foreground_test.rb +13 -17
  64. data/test/lib/vedeu/repositories/repositories/borders_test.rb +2 -1
  65. data/test/lib/vedeu/repositories/repositories/buffers_test.rb +5 -1
  66. data/test/lib/vedeu/repositories/repositories/geometries_test.rb +2 -0
  67. data/test/lib/vedeu/support/common_test.rb +2 -2
  68. data/test/lib/vedeu/support/timer_test.rb +4 -6
  69. data/test/test_helper.rb +22 -0
  70. data/vedeu.gemspec +3 -1
  71. metadata +24 -25
  72. data/lib/vedeu/dsl/components/all.rb +0 -4
  73. data/lib/vedeu/dsl/shared/all.rb +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5054f0cadfac0fb38b0b9c4c800c3cd0f7aa08b7
4
- data.tar.gz: a94e10fb79245068619c7cb78d4d6aaf5639e647
3
+ metadata.gz: cbab7c48189a1680b2d50a4f9733a5853e608fcd
4
+ data.tar.gz: b8bc0dd0380007c146707d34ea96fab02b930c0a
5
5
  SHA512:
6
- metadata.gz: c8f6d315b3bcd9f768ff40508b00be0e2360e65c42c1402fbc133ba0e5dedb1f7ebe9a1201500cb25be4483b407d07a57b7b03fc45dd8d07f28949fa34885c7d
7
- data.tar.gz: 467d9b7608d6ff0e057b33f3c86579c7204c905f61f237fd753d940e26f86fcb56ada657a1f1639c6a4cf5c8b0c76e843eff8f143293729faf59bfe3dca58fea
6
+ metadata.gz: a0bc17406bfc0e9991486212b93312a5b5ef3b4d0277b39936fbbff3dbaf8c101d4678bbb1a34a2f95f89c54db5b9d4ccc5edd2d8ed5797e9b878b42d6107fba
7
+ data.tar.gz: 2575e61017ed69db73d68c38722d872e3f4a35da3c8be81c597ceba3bfc52fe73f32e16f30c27756932a2387a1190a876b0c2e08a7e1fe7fd3aebc4855f85500
data/Dockerfile CHANGED
@@ -1,40 +1,59 @@
1
- FROM stackbrew/ubuntu:trusty
1
+ FROM ubuntu:15.04
2
2
  MAINTAINER Gavin Laking <gavinlaking@gmail.com>
3
3
 
4
- ENV DEBIAN_FRONTEND noninteractive
5
-
6
- RUN sudo apt-get update;\
7
- sudo apt-get install -y --force-yes \
8
- software-properties-common \
9
- build-essential \
10
- openssl \
11
- ca-certificates \
12
- git-core \
13
- autoconf \
14
- gawk \
15
- libreadline6-dev \
16
- libyaml-dev \
17
- libgdbm-dev \
18
- libncurses5-dev \
19
- automake \
20
- libtool \
21
- bison \
22
- pkg-config \
23
- curl \
24
- libxslt-dev \
25
- libxml2-dev \
26
- make; \
27
- sudo apt-get clean -y; \
28
- sudo apt-get autoremove -y;
29
-
30
- RUN sudo add-apt-repository "deb http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu $(lsb_release -sc) main";\
31
- sudo apt-get update; \
32
- sudo apt-get install ruby2.1 ruby2.1-dev -y --force-yes; \
33
- sudo apt-get clean -y; \
34
- sudo apt-get autoremove -y;
35
-
36
- RUN echo "---\n:benchmark: false\n:bulk_threshold: 1000\n:backtrace: false\n:verbose: true\ngem: --no-ri --no-rdoc" > ~/.gemrc; \
37
- /bin/bash -l -c "gem install bundler" ;
38
-
39
- RUN git clone https://github.com/gavinlaking/vedeu.git
40
- RUN cd vedeu; bundle install; rake
4
+ # Build dependencies
5
+ RUN apt-get update
6
+ RUN apt-get install -y --force-yes \
7
+ software-properties-common \
8
+ build-essential \
9
+ openssl \
10
+ ca-certificates \
11
+ git-core \
12
+ autoconf \
13
+ gawk \
14
+ libreadline-dev \
15
+ libyaml-dev \
16
+ libgdbm-dev \
17
+ libncurses5-dev \
18
+ automake \
19
+ libtool \
20
+ bison \
21
+ pkg-config \
22
+ curl \
23
+ wget \
24
+ libxslt-dev \
25
+ libxml2-dev \
26
+ libffi-dev \
27
+ libssl-dev \
28
+ zlib1g-dev \
29
+ make
30
+ RUN apt-get clean -y
31
+ RUN apt-get autoremove -y
32
+
33
+ # Chruby
34
+ RUN wget -O chruby-0.3.9.tar.gz https://github.com/postmodern/chruby/archive/v0.3.9.tar.gz
35
+ RUN tar -xzvf chruby-0.3.9.tar.gz
36
+ RUN cd chruby-0.3.9/ && make install
37
+
38
+ # Ruby Install
39
+ RUN wget -O ruby-install-0.5.0.tar.gz https://github.com/postmodern/ruby-install/archive/v0.5.0.tar.gz
40
+ RUN tar -xzvf ruby-install-0.5.0.tar.gz
41
+ RUN cd ruby-install-0.5.0/ && make install
42
+
43
+ # Install Ruby 2.2.2
44
+ RUN ruby-install ruby 2.2.2
45
+
46
+ # Setup Chruby
47
+ RUN echo '[ -n "$BASH_VERSION" ] || [ -n "$ZSH_VERSION" ] || return' >> /etc/profile.d/chruby.sh
48
+ RUN echo 'source /usr/local/share/chruby/chruby.sh' >> /etc/profile.d/chruby.sh
49
+ RUN echo 'source /usr/local/share/chruby/auto.sh' >> $HOME/.bashrc
50
+ RUN echo 'chruby ruby-2.2.2' >> $HOME/.bash_profile
51
+
52
+ # Setup .gemrc
53
+ RUN echo "---\n:benchmark: false\n:bulk_threshold: 1000\n:backtrace: false\n:verbose: true\ngem: --no-ri --no-rdoc" > $HOME/.gemrc
54
+
55
+ # Setup PATH
56
+ ENV PATH /opt/rubies/ruby-2.2.2/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
57
+
58
+ # Get ruby version
59
+ RUN ruby -v
data/README.md CHANGED
@@ -11,8 +11,9 @@ Vedeu (vee-dee-you; aka VDU) is my attempt at creating a terminal based
11
11
 
12
12
  ## Requirements
13
13
 
14
- Vedeu has been built primarily on MacOSX 10.9/10.10 (Mavericks/Yosemite) with
15
- Ruby v2.1.
14
+ Vedeu was been built primarily with Ruby v2.1.
15
+
16
+ When Vedeu started I was a MacOSX user, I've since moved to Linux. You shouldn't have any problems with either of these operating systems.
16
17
 
17
18
  Note: You may have trouble running Vedeu with Windows installations. (Pull
18
19
  requests welcome!)
@@ -31,118 +32,16 @@ And then execute:
31
32
 
32
33
  ## Example
33
34
 
34
- Have a look at: [Playa](https://github.com/gavinlaking/playa). Please browse the
35
- source of Playa and Vedeu to get a feel for how it all works. The
36
- [RubyDoc](http://rubydoc.info/gems/vedeu) may also help!
37
-
38
-
39
- ## Usage
40
-
41
- Expect proper documentation soon!
42
-
43
- ### Getting Started
44
-
45
- The basic mechanics of a Vedeu app are outlined below:
46
-
47
- ```ruby
48
- require 'vedeu'
49
-
50
- class MyApp
51
- include Vedeu
52
-
53
- interface 'main' do
54
- # ...
55
- end
56
-
57
- bind :some_event do
58
- # ...
59
- end
60
-
61
- bind :other_event do |hash_args, array_args, args|
62
- # ...
63
- end
64
-
65
- keys do
66
- key('a') { Vedeu.trigger(':apple') }
67
- key('b') { Vedeu.trigger(':banana') }
68
- end
69
- end
70
- ```
71
-
72
- ### Building Interfaces & Views
73
-
74
- Views with Vedeu are made up of simple building blocks. These blocks can be
75
- arranged in a multitude of ways which I hope is more than sufficient for your
76
- design needs.
77
-
78
- - A view (`Composition`) is made up of one or more interfaces.
79
- - An interface is an area on the screen where you can take input or direct
80
- output. You will define it's colour and style, its dimensions, including
81
- position and give it a name. You can then direct the output of a command, or
82
- event, to this interface and Vedeu will ensure the content is placed there.
83
- - Interfaces (`Interface`) are made up of lines (`Line`), their length being the
84
- width of the interface and their number being the height of the interface.
85
- - An interface with `width: 12, height: 5` will have five lines, each made of 12
86
- characters- providing 60 cells. Colours and styles are handled by terminal
87
- escape sequences and therefore do not consume a cell.
88
- - Lines are made up of zero, one or multiple streams (`Stream`) which are
89
- basically subsets of the line.
90
- - An interface, line or stream can have a colour (`colour`) attribute.
91
- - An interface, line or stream can have a style (`style`) attribute.
92
- - Interfaces have a position (`y`, `x`) on the screen, and a size.
93
- (`width`, `height`)
94
- - Interfaces can be placed relative to each other based on their attributes.
95
- - An interface has a `top`, `right`, `bottom`, `left`.
96
- - An interface also has a `north` and `west` (`top` and `left` minus 1
97
- respectively).
98
- - An interface also has a `south` and `east` (`bottom` and `right` plus 1
99
- respectively).
100
- - Colours are defined in CSS-style values, i.e. `#ff0000` would be red.
101
- - Styles are named. See the table below for supported styles.
102
-
103
-
104
- ### On Defining Interfaces
105
-
106
- ```ruby
107
- interface 'main' do
108
- geometry do
109
- y 1
110
- x 1
111
- width 10 # see notes below
112
- height 10
113
- end
114
- colour foreground: '#ffffff', background: '#000000'
115
- end
116
- ```
117
-
118
- Referring to the above example, interfaces have a name, and various default
119
- attributes.
120
-
121
- - `y` sets the starting row point. (See Geometry)
122
- - `x` sets the starting column point.
123
-
124
- - `width` sets the character width of the interface
125
- - `height` sets the character height of the interface
126
-
127
- Note: not setting a width or height will set the values to the terminal's
128
- reported width and height.
129
-
130
- - `foreground` sets the default foreground colour.
131
- - `background` sets the default background colour.
132
-
133
-
134
- ### Events
35
+ Have a look at: [Playa](https://github.com/gavinlaking/playa). Please browse the source of Playa and Vedeu to get a feel for how it all works.
135
36
 
136
- More information about events can be found in the
137
- [RubyDoc](http://rubydoc.info/gems/vedeu).
37
+ If you have produced software which uses Vedeu, please let me know, I'll link
38
+ to your project here.
138
39
 
139
40
 
140
- ### Geometry
41
+ ## Documentation & Usage
141
42
 
142
- Geometry for Vedeu, as the same for ANSI terminals, is set top-left, which is
143
- cell/point 1, 1. Interfaces themselves have internal geometry which is handled
144
- automatically. Unless you are doing something special, you will probably only
145
- set it on a per-interface basis.
43
+ Vedeu is largely documented using Yard. I hope to produce more 'General Usage'
44
+ documentation shortly. In the meantime, please browse the [RubyDoc](http://rubydoc.info/gems/vedeu).
146
45
 
147
46
 
148
47
  ## Development / Contributing
@@ -156,6 +55,7 @@ Pull requests are very welcome! Please try to follow these simple rules if
156
55
  * Please create a topic branch for every separate change you make.
157
56
  * Make sure your patches are well tested.
158
57
  * Update the [Yard](http://yardoc.org/) documentation.
58
+ (Use `yard stats --list-undoc` to locate undocumented code)
159
59
  * Update the [README](https://github.com/gavinlaking/vedeu/blob/master/README.md).
160
60
  * Please **do not change** the version number.
161
61
 
@@ -1,5 +1,14 @@
1
1
  ## Getting Started with Vedeu
2
2
 
3
+ - Set your configuration.
4
+ - Define your interfaces.
5
+ - Define the border.
6
+ - Define the geometry.
7
+ - Define the keymap.
8
+ - Define the global keymap, this will be used irrespective of the interface
9
+ currently in focus.
10
+
11
+
3
12
  ### Predefined Keys
4
13
 
5
14
  Vedeu automatically defines four keys for your client application:
data/lib/vedeu/all.rb CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  # load order is important
3
3
 
4
+ require 'vedeu/version'
4
5
  require 'vedeu/debug'
5
6
  require 'vedeu/traps'
6
7
 
@@ -19,7 +20,6 @@ require 'vedeu/configuration/all'
19
20
  require 'vedeu/cursor/all'
20
21
  require 'vedeu/distributed/all'
21
22
 
22
- require 'vedeu/dsl/shared/all'
23
23
  require 'vedeu/dsl/all'
24
24
 
25
25
  require 'vedeu/events/all'
data/lib/vedeu/api.rb CHANGED
@@ -1,14 +1,11 @@
1
1
  require 'vedeu/support/common'
2
2
  require 'vedeu/support/terminal'
3
+ require 'vedeu/support/timer'
3
4
  require 'vedeu/output/renderers/all'
4
5
  require 'vedeu/events/all'
5
6
  require 'vedeu/models/all'
6
7
  require 'vedeu/input/all'
7
- require 'vedeu/dsl/components/all'
8
- require 'vedeu/dsl/composition'
9
- require 'vedeu/dsl/shared/all'
10
- require 'vedeu/dsl/group'
11
- require 'vedeu/dsl/view'
8
+ require 'vedeu/dsl/all'
12
9
 
13
10
  module Vedeu
14
11
 
@@ -157,6 +154,10 @@ module Vedeu
157
154
  # @see Vedeu::Terminal#resize
158
155
  def_delegators Vedeu::Terminal, :height, :width, :resize
159
156
 
157
+ # @!method timer
158
+ # @see Vedeu::Timer.timer
159
+ def_delegators Vedeu::Timer, :timer
160
+
160
161
  # @!method trigger
161
162
  # @see Vedeu::Trigger.trigger
162
163
  def_delegators Vedeu::Trigger, :trigger
@@ -25,7 +25,7 @@ module Vedeu
25
25
  # @raise [InvalidSyntax] The name is not defined.
26
26
  # @return [Vedeu::Interface]
27
27
  def store_deferred
28
- unless defined_value?(name)
28
+ unless present?(name)
29
29
  fail InvalidSyntax, 'Cannot store an interface without a name.'
30
30
  end
31
31
 
@@ -409,7 +409,7 @@ module Vedeu
409
409
 
410
410
  return false if value.is_a?(String) && value.size != 1
411
411
 
412
- (value.is_a?(String) || value.is_a?(Symbol)) && defined_value?(value)
412
+ (value.is_a?(String) || value.is_a?(Symbol)) && present?(value)
413
413
  end
414
414
 
415
415
  # Raises an exception on behalf of the calling method to report that the
@@ -195,7 +195,7 @@ module Vedeu
195
195
  @coordinate ||= Vedeu::Coordinate.new(name)
196
196
  end
197
197
 
198
- # @return (see Vedeu::Cursors#by_name)
198
+ # @see Vedeu::Cursors#by_name
199
199
  def cursor
200
200
  @cursor ||= Vedeu.cursors.by_name(name)
201
201
  end
@@ -205,7 +205,7 @@ module Vedeu
205
205
  cursor.attributes.merge!(x: x_position, y: y_position, ox: ox, oy: oy)
206
206
  end
207
207
 
208
- # @return (see Vedeu::Geometries#by_name)
208
+ # @see Vedeu::Geometries#by_name
209
209
  def geometry
210
210
  @geometry ||= Vedeu.geometries.by_name(name)
211
211
  end
data/lib/vedeu/debug.rb CHANGED
@@ -22,7 +22,7 @@ module Vedeu
22
22
 
23
23
  RubyProf.start
24
24
 
25
- yield
25
+ work = yield
26
26
 
27
27
  result = RubyProf.stop
28
28
  result.eliminate_methods!([
@@ -61,6 +61,8 @@ module Vedeu
61
61
  # - Uses the other printers to create several reports in one profiling run
62
62
  # RubyProf::MultiPrinter
63
63
  end
64
+
65
+ work
64
66
  end
65
67
  # :nocov:
66
68
 
data/lib/vedeu/dsl/all.rb CHANGED
@@ -1,12 +1,18 @@
1
- require 'vedeu/dsl/components/all'
2
- require 'vedeu/dsl/shared/all'
3
-
4
- require_relative 'composition'
5
- require_relative 'group'
6
- require_relative 'interface'
7
- require_relative 'line'
8
- require_relative 'stream'
9
- require_relative 'view'
1
+ require 'vedeu/support/common'
2
+
3
+ require 'vedeu/dsl/use'
4
+ require 'vedeu/dsl/presentation'
5
+ require 'vedeu/dsl/border'
6
+ require 'vedeu/dsl/composition'
7
+ require 'vedeu/dsl/geometry'
8
+ require 'vedeu/dsl/group'
9
+ require 'vedeu/dsl/keymap'
10
+ require 'vedeu/dsl/text'
11
+ require 'vedeu/dsl/interface'
12
+ require 'vedeu/dsl/line'
13
+ require 'vedeu/dsl/menu'
14
+ require 'vedeu/dsl/stream'
15
+ require 'vedeu/dsl/view'
10
16
 
11
17
  module Vedeu
12
18
 
@@ -1,6 +1,3 @@
1
- require 'vedeu/dsl/shared/presentation'
2
- require 'vedeu/dsl/shared/use'
3
-
4
1
  module Vedeu
5
2
 
6
3
  module DSL
@@ -3,6 +3,39 @@ module Vedeu
3
3
  module DSL
4
4
 
5
5
  # DSL for creating collections of interfaces.
6
+ #
7
+ # Views with Vedeu are made up of simple building blocks. These blocks can
8
+ # be arranged in a multitude of ways which I hope is more than sufficient
9
+ # for your design needs.
10
+
11
+ # - A view (`Composition`) is made up of one or more interfaces.
12
+ # - An interface is an area on the screen where you can take input or direct
13
+ # output. You will define it's colour and style, its dimensions, including
14
+ # position and give it a name. You can then direct the output of a
15
+ # command, or event, to this interface and Vedeu will ensure the content
16
+ # is placed there.
17
+ # - Interfaces (`Interface`) are made up of lines (`Line`), their length
18
+ # being the width of the interface and their number being the height of
19
+ # the interface.
20
+ # - An interface with `width: 12, height: 5` will have five lines, each made
21
+ # of 12 characters- providing 60 cells. Colours and styles are handled by
22
+ # terminal escape sequences and therefore do not consume a cell.
23
+ # - Lines are made up of zero, one or multiple streams (`Stream`) which are
24
+ # basically subsets of the line.
25
+ # - An interface, line or stream can have a colour (`colour`) attribute.
26
+ # - An interface, line or stream can have a style (`style`) attribute.
27
+ # - Interfaces have a position (`y`, `x`) on the screen, and a size.
28
+ # (`width`, `height`)
29
+ # - Interfaces can be placed relative to each other based on their
30
+ # attributes.
31
+ # - An interface has a `top`, `right`, `bottom`, `left`.
32
+ # - An interface also has a `north` and `west` (`top` and `left` minus 1
33
+ # respectively).
34
+ # - An interface also has a `south` and `east` (`bottom` and `right`
35
+ # plus 1 respectively).
36
+ # - Colours are defined in CSS-style values, i.e. `#ff0000` would be red.
37
+ # - Styles are named. See the table below for supported styles.
38
+ #
6
39
  class Composition
7
40
 
8
41
  include Vedeu::DSL
@@ -3,6 +3,24 @@ module Vedeu
3
3
  module DSL
4
4
 
5
5
  # Provide DSL methods for configuring the geometry of an interface.
6
+ #
7
+ # Geometry for Vedeu, as the same for ANSI terminals, has the origin at
8
+ # top-left, y = 1, x = 1. The 'y' coordinate is deliberately first.
9
+ #
10
+ # @example
11
+ # This crude ASCII diagram represents a Geometry within Vedeu, each of the
12
+ # labels is a value you can access or define.
13
+ #
14
+ # x north xn # north: y - 1
15
+ # y +--------------+ # top: y
16
+ # | top | # west: x - 1
17
+ # | | # left: x
18
+ # west | left right | east # right: xn
19
+ # | | # east: xn + 1
20
+ # | bottom | # bottom: yn
21
+ # yn +--------------+ # south: yn + 1
22
+ # south
23
+ #
6
24
  class Geometry
7
25
 
8
26
  include Vedeu::DSL
@@ -106,7 +106,7 @@ module Vedeu
106
106
  #
107
107
  # @return [String] The name of the interface in focus.
108
108
  def focus!
109
- Vedeu::Focus.add(model.name, true) if defined_value?(model.name)
109
+ Vedeu::Focus.add(model.name, true) if present?(model.name)
110
110
  end
111
111
 
112
112
  # Define the geometry for an interface.
@@ -144,7 +144,7 @@ module Vedeu
144
144
  # should belong.
145
145
  # @return [Vedeu::Group]
146
146
  def group(name)
147
- return false unless defined_value?(name)
147
+ return false unless present?(name)
148
148
 
149
149
  model.group = name
150
150
 
@@ -1,5 +1,3 @@
1
- require 'vedeu/support/common'
2
-
3
1
  module Vedeu
4
2
 
5
3
  module DSL
@@ -89,12 +87,12 @@ module Vedeu
89
87
  def key(*value_or_values, &block)
90
88
  fail InvalidSyntax, 'No action defined for `key`.' unless block_given?
91
89
 
92
- unless defined_value?(value_or_values)
90
+ unless present?(value_or_values)
93
91
  fail InvalidSyntax, 'No keypress(es) defined for `key`.'
94
92
  end
95
93
 
96
94
  value_or_values.each do |value|
97
- unless defined_value?(value)
95
+ unless present?(value)
98
96
  fail InvalidSyntax, 'An invalid value for `key` was encountered.'
99
97
  end
100
98
 
File without changes
File without changes
File without changes
@@ -96,6 +96,7 @@ module Vedeu
96
96
  Vedeu.log(type: :event, message: "Unbinding: '#{name.inspect}'")
97
97
 
98
98
  Vedeu.events.remove(name)
99
+
99
100
  true
100
101
  end
101
102
  alias_method :unevent, :unbind
@@ -165,10 +166,6 @@ module Vedeu
165
166
  # @return [String]
166
167
  attr_accessor :executed_at
167
168
 
168
- # @!attribute [rw] now
169
- # @return [String]
170
- attr_accessor :now
171
-
172
169
  private
173
170
 
174
171
  # Execute the code stored in the event closure.
@@ -176,11 +173,9 @@ module Vedeu
176
173
  # @param args [void]
177
174
  # @return [void]
178
175
  def execute(*args)
179
- reset_deadline
180
-
181
- set_executed
182
-
183
- reset_time
176
+ @deadline = 0 # reset deadline
177
+ @executed_at = @now # set execution time to now
178
+ @now = 0 # reset now
184
179
 
185
180
  Vedeu.log(type: :event, message: "Triggering: '#{name.inspect}'")
186
181
 
@@ -193,7 +188,7 @@ module Vedeu
193
188
  #
194
189
  # @return [Boolean]
195
190
  def throttling?
196
- set_time
191
+ @now = Time.now.to_f
197
192
 
198
193
  options[:delay] > 0
199
194
  end
@@ -202,7 +197,7 @@ module Vedeu
202
197
  #
203
198
  # @return [Boolean]
204
199
  def throttle_expired?
205
- return true if elapsed_time > delay
200
+ return true if (@now - @executed_at) > delay
206
201
 
207
202
  Vedeu.log(type: :event, message: "Throttling: '#{name.inspect}'")
208
203
 
@@ -212,12 +207,14 @@ module Vedeu
212
207
  # Returns a boolean indicating whether debouncing is required for this
213
208
  # event. Setting the debounce option to any value greater than 0 will
214
209
  # enable debouncing.
210
+ # Sets the deadline for when this event can be executed to a point in the
211
+ # future determined by the amount of debounce time left.
215
212
  #
216
213
  # @return [Boolean]
217
214
  def debouncing?
218
- set_time
215
+ @now = Time.now.to_f
219
216
 
220
- set_deadline unless deadline?
217
+ @deadline = @now + debounce unless deadline?
221
218
 
222
219
  options[:debounce] > 0
223
220
  end
@@ -226,35 +223,13 @@ module Vedeu
226
223
  #
227
224
  # @return [Boolean]
228
225
  def debounce_expired?
229
- return true if set_executed > deadline
226
+ return true if (@executed_at = @now) > @deadline
230
227
 
231
228
  Vedeu.log(type: :event, message: "Debouncing: '#{name.inspect}'")
232
229
 
233
230
  false
234
231
  end
235
232
 
236
- # Returns the time in seconds since the last triggering of this event.
237
- #
238
- # @return [Float]
239
- def elapsed_time
240
- now - @executed_at
241
- end
242
-
243
- # @return [Float]
244
- def set_executed
245
- @executed_at = now
246
- end
247
-
248
- # @return [Float]
249
- def set_time
250
- @now = Time.now.to_f
251
- end
252
-
253
- # @return [Fixnum]
254
- def reset_time
255
- @now = 0
256
- end
257
-
258
233
  # Returns a boolean indicating if this event has a deadline.
259
234
  #
260
235
  # @return [Boolean]
@@ -262,23 +237,6 @@ module Vedeu
262
237
  @deadline > 0
263
238
  end
264
239
 
265
- # Resets the deadline of this event.
266
- #
267
- # @return [Fixnum]
268
- def reset_deadline
269
- @deadline = 0
270
- end
271
-
272
- # Sets the deadline for when this event can be executed to a point in the
273
- # future determined by the amount of debounce time left.
274
- #
275
- # @return [NilClass]
276
- def set_deadline
277
- @deadline = now + debounce
278
-
279
- nil
280
- end
281
-
282
240
  # Return the amount of time in seconds to debounce the event by.
283
241
  #
284
242
  # @return [Fixnum|Float]
@@ -27,12 +27,11 @@ module Vedeu
27
27
  # @param yn [Fixnum]
28
28
  # @param y_yn [Fixnum]
29
29
  # @param y_default [Fixnum]
30
- # @param y_options [Hash<Symbol => Boolean>]
31
30
  # @param x [Fixnum]
32
31
  # @param xn [Fixnum]
33
32
  # @param x_xn [Fixnum]
34
33
  # @param x_default [Fixnum]
35
- # @param x_options [Hash<Symbol => Boolean>]
34
+ # @param options [Hash<Symbol => Boolean>]
36
35
  # @return [Vedeu::Area]
37
36
  def self.from_attributes(y:, yn:, y_yn:, y_default:,
38
37
  x:, xn:, x_xn:, x_default:, options:)