vedeu 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +5 -0
- data/Dockerfile +40 -0
- data/README.md +7 -30
- data/docs/api.md +79 -0
- data/docs/events.md +121 -0
- data/lib/vedeu.rb +61 -18
- data/lib/vedeu/api/api.rb +73 -53
- data/lib/vedeu/api/composition.rb +4 -1
- data/lib/vedeu/api/defined.rb +35 -0
- data/lib/vedeu/api/helpers.rb +20 -15
- data/lib/vedeu/api/interface.rb +17 -12
- data/lib/vedeu/api/line.rb +20 -12
- data/lib/vedeu/api/stream.rb +3 -0
- data/lib/vedeu/application.rb +34 -1
- data/lib/vedeu/configuration.rb +15 -3
- data/lib/vedeu/input/input.rb +77 -0
- data/lib/vedeu/launcher.rb +7 -0
- data/lib/vedeu/models/attributes/background.rb +15 -2
- data/lib/vedeu/models/attributes/coercions.rb +18 -3
- data/lib/vedeu/models/attributes/colour_translator.rb +23 -17
- data/lib/vedeu/models/attributes/foreground.rb +10 -2
- data/lib/vedeu/models/attributes/presentation.rb +62 -0
- data/lib/vedeu/models/colour.rb +7 -3
- data/lib/vedeu/models/composition.rb +17 -19
- data/lib/vedeu/models/geometry.rb +13 -5
- data/lib/vedeu/models/interface.rb +35 -19
- data/lib/vedeu/models/line.rb +24 -8
- data/lib/vedeu/models/stream.rb +13 -7
- data/lib/vedeu/models/style.rb +17 -7
- data/lib/vedeu/{support → output}/clear.rb +14 -0
- data/lib/vedeu/output/compositor.rb +77 -0
- data/lib/vedeu/output/refresh.rb +129 -0
- data/lib/vedeu/{support → output}/render.rb +49 -13
- data/lib/vedeu/{support → output}/view.rb +15 -8
- data/lib/vedeu/repositories/buffers.rb +181 -0
- data/lib/vedeu/{support → repositories}/events.rb +16 -6
- data/lib/vedeu/repositories/focus.rb +109 -0
- data/lib/vedeu/repositories/groups.rb +76 -0
- data/lib/vedeu/repositories/interfaces.rb +74 -0
- data/lib/vedeu/support/common.rb +20 -0
- data/lib/vedeu/support/cursor.rb +77 -0
- data/lib/vedeu/support/esc.rb +181 -46
- data/lib/vedeu/support/event.rb +22 -4
- data/lib/vedeu/support/grid.rb +10 -3
- data/lib/vedeu/support/log.rb +14 -1
- data/lib/vedeu/support/menu.rb +51 -12
- data/lib/vedeu/support/position.rb +9 -0
- data/lib/vedeu/support/terminal.rb +49 -15
- data/lib/vedeu/support/trace.rb +11 -4
- data/test/integration/defining_interfaces_test.rb +27 -0
- data/test/integration/views/basic_view_test.rb +767 -0
- data/test/lib/vedeu/api/api_test.rb +32 -37
- data/test/lib/vedeu/api/composition_test.rb +23 -61
- data/test/lib/vedeu/api/defined_test.rb +49 -0
- data/test/lib/vedeu/api/helpers_test.rb +91 -0
- data/test/lib/vedeu/api/interface_test.rb +136 -688
- data/test/lib/vedeu/api/line_test.rb +28 -32
- data/test/lib/vedeu/application_test.rb +6 -0
- data/test/lib/vedeu/configuration_test.rb +8 -4
- data/test/lib/vedeu/{support → input}/input_test.rb +9 -0
- data/test/lib/vedeu/launcher_test.rb +6 -0
- data/test/lib/vedeu/models/attributes/{coercer_test.rb → coercions_test.rb} +11 -10
- data/test/lib/vedeu/models/attributes/colour_translator_test.rb +13 -0
- data/test/lib/vedeu/models/attributes/presentation_test.rb +30 -0
- data/test/lib/vedeu/models/colour_test.rb +8 -0
- data/test/lib/vedeu/models/composition_test.rb +208 -200
- data/test/lib/vedeu/models/geometry_test.rb +39 -0
- data/test/lib/vedeu/models/interface_test.rb +11 -1
- data/test/lib/vedeu/models/line_test.rb +8 -1
- data/test/lib/vedeu/models/stream_test.rb +35 -0
- data/test/lib/vedeu/models/style_test.rb +8 -0
- data/test/lib/vedeu/{support → output}/clear_test.rb +1 -1
- data/test/lib/vedeu/output/compositor_test.rb +64 -0
- data/test/lib/vedeu/output/refresh_test.rb +48 -0
- data/test/lib/vedeu/{support → output}/render_test.rb +36 -0
- data/test/lib/vedeu/{support → output}/view_test.rb +0 -0
- data/test/lib/vedeu/repositories/buffers_test.rb +48 -0
- data/test/lib/vedeu/{support → repositories}/events_test.rb +0 -0
- data/test/lib/vedeu/repositories/focus_test.rb +74 -0
- data/test/lib/vedeu/repositories/groups_test.rb +66 -0
- data/test/lib/vedeu/repositories/interfaces_test.rb +6 -0
- data/test/lib/vedeu/support/common_test.rb +6 -0
- data/test/lib/vedeu/support/cursor_test.rb +79 -0
- data/test/lib/vedeu/support/log_test.rb +6 -0
- data/test/lib/vedeu/support/terminal_test.rb +6 -28
- data/test/lib/vedeu/support/trace_test.rb +6 -0
- data/test/test_helper.rb +37 -0
- data/vedeu.gemspec +1 -1
- metadata +65 -33
- data/bin/log +0 -13
- data/lib/vedeu/support/buffer.rb +0 -69
- data/lib/vedeu/support/buffers.rb +0 -106
- data/lib/vedeu/support/focus.rb +0 -83
- data/lib/vedeu/support/groups.rb +0 -61
- data/lib/vedeu/support/input.rb +0 -67
- data/test/lib/vedeu/support/buffer_test.rb +0 -83
- data/test/lib/vedeu/support/buffers_test.rb +0 -15
- data/test/lib/vedeu/support/focus_test.rb +0 -114
- data/test/lib/vedeu/support/groups_test.rb +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f042b9de9119e64b521192d7d59b203d54f7cd0b
|
4
|
+
data.tar.gz: 1e1bd9c449e053e95d163dbfd8833515f21e9f8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b6492e5404edf7622295e205fb8479537671b4dda4d9817a3b9ed2cf0c144b58ab13ec6e7cd786482995f33def8574c2c736ac8fff93a0d4f54cbae10d38083
|
7
|
+
data.tar.gz: 7709bce2742998b9e90c7f8521b4b3d131623ac3b0c35c3b91f98d9cd18f03952e7aba5d54cf2128ed35f1f3319f38adb3607f4511b03508e5d21a28e600bc39
|
data/.yardopts
CHANGED
data/Dockerfile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
FROM stackbrew/ubuntu:trusty
|
2
|
+
MAINTAINER Gavin Laking <gavinlaking@gmail.com>
|
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
|
data/README.md
CHANGED
@@ -117,34 +117,9 @@ Note: not setting a width or height will set the values to the terminal's report
|
|
117
117
|
- `cursor` is a Boolean specifying whether the cursor should show.
|
118
118
|
|
119
119
|
|
120
|
-
###
|
120
|
+
### Events
|
121
121
|
|
122
|
-
|
123
|
-
event :event_name do |arg1, arg2|
|
124
|
-
end
|
125
|
-
```
|
126
|
-
|
127
|
-
One can define events which perform work or trigger other events. Vedeu has built-in events which are namespaced with underscores:
|
128
|
-
|
129
|
-
- `:_initialize_` Special event which Vedeu triggers when it is ready to enter the main loop. Client applications can listen for this event and perform some action(s), like render the first screen, interface or make a sound.
|
130
|
-
|
131
|
-
- `:_cleanup_` This event is fired by Vedeu when `:_exit_` is triggered. You can hook into this to perform a special action before the application terminates. Saving the user's work, session or preferences might be popular here.
|
132
|
-
|
133
|
-
- `:_clear_` Clears the whole terminal space.
|
134
|
-
|
135
|
-
- `:_exit_` when triggered, Vedeu will trigger a `:_cleanup_` event which you can define (to save files, etc) and attempt to exit.
|
136
|
-
|
137
|
-
- `:_keypress_` triggering this event will cause the triggering of the `:key` event; which you should define to 'do things'. If the `escape` key is pressed, then `key` is triggered with the argument `:escape`, also an internal event `_mode_switch_` is triggered.
|
138
|
-
|
139
|
-
- `:_mode_switch_` when triggered (after the user presses `escape`), Vedeu switches from a "raw mode" terminal to a "cooked mode" terminal. The idea here being that the raw mode is for single keypress actions, whilst cooked mode allows the user to enter more elaborate commands- such as commands with arguments.
|
140
|
-
|
141
|
-
- `:_refresh_` triggering this event will cause all interfaces to refresh.
|
142
|
-
|
143
|
-
- `:_refresh_group_(group_name)_` will refresh all interfaces belonging to this group. E.g. `_refresh_group_home_` will refresh all interfaces with the group of `home`.
|
144
|
-
|
145
|
-
- `:_refresh_(interface_name)_` will refresh the interface with this name. E.g. `_refresh_widget_` will refresh the interface `widget`.
|
146
|
-
|
147
|
-
Note: Overriding or adding additional events to the Vedeu 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.
|
122
|
+
More information about events can be found here: [Vedeu Events](http://www.rubydoc.info/github/gavinlaking/vedeu/file/docs/events.md)
|
148
123
|
|
149
124
|
|
150
125
|
### Geometry
|
@@ -212,10 +187,10 @@ Pull requests are very welcome! Please try to follow these simple rules if appli
|
|
212
187
|
|
213
188
|
1. Fork it ([https://github.com/gavinlaking/vedeu/fork](https://github.com/gavinlaking/vedeu/fork))
|
214
189
|
2. Clone it
|
215
|
-
3. `bundle`
|
216
|
-
4. `rake` (runs all tests and coverage report) or `bundle exec guard`
|
190
|
+
3. Run `bundle`
|
191
|
+
4. Run `rake` (runs all tests and coverage report) or `bundle exec guard`
|
217
192
|
5. Create your feature branch (`git checkout -b my-new-feature`)
|
218
|
-
6. Write some tests, write some code, have some fun
|
193
|
+
6. Write some tests, write some code, **have some fun!**
|
219
194
|
7. Commit your changes (`git commit -am 'Add some feature'`)
|
220
195
|
8. Push to the branch (`git push origin my-new-feature`)
|
221
196
|
9. Create a new pull request.
|
@@ -223,6 +198,8 @@ Pull requests are very welcome! Please try to follow these simple rules if appli
|
|
223
198
|
|
224
199
|
## Author & Contributors
|
225
200
|
|
201
|
+
### Author
|
202
|
+
|
226
203
|
[Gavin Laking](https://github.com/gavinlaking) ([@gavinlaking](http://twitter.com/gavinlaking))
|
227
204
|
|
228
205
|
|
data/docs/api.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
## Vedeu API
|
2
|
+
|
3
|
+
Vedeu provides a simple DSL for the creation of terminal/console based
|
4
|
+
applications.
|
5
|
+
|
6
|
+
Below is a list of all the API methods. These can be accessed in your
|
7
|
+
application by including Vedeu in your class or module or by calling them directly.
|
8
|
+
|
9
|
+
|
10
|
+
### API 'include' example
|
11
|
+
|
12
|
+
Doing it this way will mean you can use any API method without the `Vedeu.` prefix.
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
class SomeClassInYourApplication
|
16
|
+
include Vedeu
|
17
|
+
|
18
|
+
...
|
19
|
+
```
|
20
|
+
|
21
|
+
|
22
|
+
### API direct example
|
23
|
+
|
24
|
+
Doing it this way means you need to use the `Vedeu.` prefix.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
class OtherClassInYourApplication
|
28
|
+
...
|
29
|
+
|
30
|
+
def some_method
|
31
|
+
Vedeu.some_api_method
|
32
|
+
end
|
33
|
+
|
34
|
+
...
|
35
|
+
```
|
36
|
+
|
37
|
+
... TODO ...
|
38
|
+
|
39
|
+
|
40
|
+
### API DSL methods
|
41
|
+
|
42
|
+
defined
|
43
|
+
event
|
44
|
+
events
|
45
|
+
height
|
46
|
+
interface
|
47
|
+
keypress
|
48
|
+
log
|
49
|
+
resize
|
50
|
+
trigger
|
51
|
+
unevent
|
52
|
+
use
|
53
|
+
view
|
54
|
+
views
|
55
|
+
width
|
56
|
+
|
57
|
+
colour
|
58
|
+
style
|
59
|
+
|
60
|
+
line
|
61
|
+
use
|
62
|
+
cursor
|
63
|
+
delay
|
64
|
+
group
|
65
|
+
name
|
66
|
+
x
|
67
|
+
y
|
68
|
+
width
|
69
|
+
height
|
70
|
+
centred
|
71
|
+
|
72
|
+
stream
|
73
|
+
text
|
74
|
+
foreground
|
75
|
+
background
|
76
|
+
|
77
|
+
align
|
78
|
+
text
|
79
|
+
width
|
data/docs/events.md
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
## Vedeu Events
|
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.
|
6
|
+
|
7
|
+
Events described in this document assume that you have included Vedeu in your
|
8
|
+
class:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
class SomeClassInYourApplication
|
12
|
+
include Vedeu
|
13
|
+
|
14
|
+
...
|
15
|
+
```
|
16
|
+
|
17
|
+
### System Events
|
18
|
+
|
19
|
+
System events generally control the internal state of Vedeu with respects to
|
20
|
+
your application. They are soft-namespaced using underscores.
|
21
|
+
|
22
|
+
#### `:_cleanup_`
|
23
|
+
|
24
|
+
This event is fired by Vedeu when `:_exit_` is triggered. You can hook into this to perform a special action before the application terminates. Saving the user's work, session or preferences might be popular here.
|
25
|
+
|
26
|
+
#### `:_clear_`
|
27
|
+
|
28
|
+
Clears the whole terminal space.
|
29
|
+
|
30
|
+
#### `:_exit_`
|
31
|
+
|
32
|
+
When triggered, Vedeu will trigger a `:_cleanup_` event which you can define (to save files, etc) and attempt to exit.
|
33
|
+
|
34
|
+
#### `:_focus_by_name_`
|
35
|
+
|
36
|
+
When triggered with an interface name will focus that interface.
|
37
|
+
|
38
|
+
#### `:_focus_next_`
|
39
|
+
|
40
|
+
When triggered will focus the next interface.
|
41
|
+
|
42
|
+
#### `:_focus_prev_`
|
43
|
+
|
44
|
+
When triggered will focus the previous interface.
|
45
|
+
|
46
|
+
#### `:_initialize_`
|
47
|
+
|
48
|
+
Special event which Vedeu triggers when it is ready to enter the main loop. Client applications can listen for this event and perform some action(s), like render the first screen, interface or make a sound.
|
49
|
+
|
50
|
+
#### `:_keypress_`
|
51
|
+
|
52
|
+
Triggering this event will cause the triggering of the `:key` event; which you should define to 'do things'. If the `escape` key is pressed, then `key` is triggered with the argument `:escape`, also an internal event `_mode_switch_` is triggered.
|
53
|
+
|
54
|
+
#### `:_log_`
|
55
|
+
|
56
|
+
When triggered with a message will cause Vedeu to log the message if logging is enabled in the configuration.
|
57
|
+
|
58
|
+
#### `:_mode_switch_`
|
59
|
+
|
60
|
+
When triggered (after the user presses `escape`), Vedeu switches from a "raw mode" terminal to a "cooked mode" terminal. The idea here being that the raw mode is for single keypress actions, whilst cooked mode allows the user to enter more elaborate commands- such as commands with arguments.
|
61
|
+
|
62
|
+
#### `:_refresh_`
|
63
|
+
|
64
|
+
Triggering this event will cause all interfaces to refresh.
|
65
|
+
|
66
|
+
#### `:_refresh_group_(group_name)_`
|
67
|
+
|
68
|
+
Will refresh all interfaces belonging to this group. E.g. `_refresh_group_home_` will refresh all interfaces with the group of `home`.
|
69
|
+
|
70
|
+
#### `:_refresh_(interface_name)_`
|
71
|
+
|
72
|
+
Will refresh the interface with this name. E.g. `_refresh_widget_` will refresh the interface `widget`.
|
73
|
+
|
74
|
+
#### `:_resize_`
|
75
|
+
|
76
|
+
When triggered will cause Vedeu to trigger the `:_clear_` and `:_refresh_`
|
77
|
+
events. Please see those events for their behaviour.
|
78
|
+
|
79
|
+
|
80
|
+
##### Notes:
|
81
|
+
|
82
|
+
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
|
83
|
+
to those events.
|
84
|
+
|
85
|
+
|
86
|
+
... TODO ... What about events in Vedeu::Menu?
|
87
|
+
|
88
|
+
... TODO ... More information about system events.
|
89
|
+
|
90
|
+
|
91
|
+
### User Events
|
92
|
+
|
93
|
+
User events allow you to orchestrate behaviour within your application, ie. the user presses a specific key, you trigger an event to make something happen. Eg. pressing 'p' instructs the player to play.
|
94
|
+
|
95
|
+
|
96
|
+
#### How to define user events
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
event :event_name do |arg1, arg2|
|
100
|
+
...
|
101
|
+
|
102
|
+
# Things that should happen when the event is triggered; these can be method
|
103
|
+
# calls or the triggering of another event or events.
|
104
|
+
|
105
|
+
...
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
109
|
+
... TODO ... How to define.
|
110
|
+
|
111
|
+
|
112
|
+
#### How to trigger user events
|
113
|
+
|
114
|
+
... TODO ... How to trigger.
|
115
|
+
|
116
|
+
|
117
|
+
#### More information.
|
118
|
+
|
119
|
+
... TODO ... More information about user events.
|
120
|
+
|
121
|
+
|
data/lib/vedeu.rb
CHANGED
@@ -1,14 +1,49 @@
|
|
1
|
+
#
|
2
|
+
#
|
3
|
+
# Vedeu is a GUI framework for terminal/console applications written in Ruby.
|
4
|
+
#
|
5
|
+
#
|
1
6
|
module Vedeu
|
2
7
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
+
# Raised when Vedeu attempts to access a named buffer that does not exist.
|
9
|
+
BufferNotFound = Class.new(StandardError)
|
10
|
+
|
11
|
+
# Raised when trying to access a group of interfaces which do not exist by
|
12
|
+
# this name.
|
13
|
+
GroupNotFound = Class.new(StandardError)
|
14
|
+
|
15
|
+
# Raised when an interface cannot be found by name.
|
16
|
+
InterfaceNotFound = Class.new(StandardError)
|
17
|
+
|
18
|
+
# Raised when Vedeu attempts to parse a {Vedeu.view} or {Vedeu.interface} and
|
19
|
+
# encounters a problem.
|
20
|
+
InvalidSyntax = Class.new(StandardError)
|
21
|
+
|
22
|
+
# Raised intentionally when the client application wishes to switch between
|
23
|
+
# cooked and raw (or vice versa) terminal modes. Vedeu is hard-wired to use
|
24
|
+
# the `Escape` key to trigger this change for the time being.
|
25
|
+
ModeSwitch = Class.new(StandardError)
|
26
|
+
|
27
|
+
# Raised when attempting to reach the currently in focus interface, when no
|
28
|
+
# interfaces have been defined yet.
|
8
29
|
NoInterfacesDefined = Class.new(StandardError)
|
9
|
-
NotImplemented = Class.new(StandardError)
|
10
|
-
OutOfRange = Class.new(StandardError)
|
11
30
|
|
31
|
+
# Raised to remind me (or client application developers) that the subclass
|
32
|
+
# implements the functionality sought.
|
33
|
+
NotImplemented = Class.new(StandardError)
|
34
|
+
|
35
|
+
# Raised when trying to access an interface column less than 1 or greater
|
36
|
+
# than 12. Vedeu is hard-wired to a 12-column layout for the time being.
|
37
|
+
OutOfRange = Class.new(StandardError)
|
38
|
+
|
39
|
+
# When Vedeu is included within one of your classes, you should have all
|
40
|
+
# API methods at your disposal.
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# class YourClassHere
|
44
|
+
# include Vedeu
|
45
|
+
# ...
|
46
|
+
#
|
12
47
|
def self.included(receiver)
|
13
48
|
receiver.send(:include, API)
|
14
49
|
receiver.extend(API)
|
@@ -23,6 +58,7 @@ require 'logger'
|
|
23
58
|
require 'optparse'
|
24
59
|
require 'set'
|
25
60
|
|
61
|
+
require 'vedeu/support/common'
|
26
62
|
require 'vedeu/support/log'
|
27
63
|
require 'vedeu/support/trace'
|
28
64
|
require 'vedeu/configuration'
|
@@ -38,7 +74,6 @@ require 'vedeu/support/position'
|
|
38
74
|
require 'vedeu/support/esc'
|
39
75
|
require 'vedeu/support/terminal'
|
40
76
|
require 'vedeu/support/event'
|
41
|
-
require 'vedeu/support/events'
|
42
77
|
|
43
78
|
require 'vedeu/models/geometry'
|
44
79
|
require 'vedeu/models/colour'
|
@@ -47,6 +82,9 @@ require 'vedeu/models/interface'
|
|
47
82
|
require 'vedeu/models/line'
|
48
83
|
require 'vedeu/models/stream'
|
49
84
|
|
85
|
+
require 'vedeu/repositories/events'
|
86
|
+
|
87
|
+
require 'vedeu/api/defined'
|
50
88
|
require 'vedeu/api/api'
|
51
89
|
require 'vedeu/api/composition'
|
52
90
|
require 'vedeu/api/helpers'
|
@@ -54,18 +92,23 @@ require 'vedeu/api/interface'
|
|
54
92
|
require 'vedeu/api/line'
|
55
93
|
require 'vedeu/api/stream'
|
56
94
|
|
57
|
-
require 'vedeu/
|
95
|
+
require 'vedeu/repositories/interfaces'
|
96
|
+
require 'vedeu/repositories/groups'
|
97
|
+
require 'vedeu/repositories/focus'
|
98
|
+
require 'vedeu/repositories/events'
|
99
|
+
require 'vedeu/repositories/buffers'
|
58
100
|
|
59
|
-
require 'vedeu/
|
60
|
-
require 'vedeu/
|
101
|
+
require 'vedeu/output/clear'
|
102
|
+
require 'vedeu/output/compositor'
|
103
|
+
require 'vedeu/output/refresh'
|
104
|
+
require 'vedeu/output/render'
|
105
|
+
require 'vedeu/output/view'
|
61
106
|
|
62
|
-
require 'vedeu/support/focus'
|
63
|
-
require 'vedeu/support/groups'
|
64
|
-
require 'vedeu/support/buffers'
|
65
|
-
require 'vedeu/support/clear'
|
66
|
-
require 'vedeu/support/render'
|
67
|
-
require 'vedeu/support/view'
|
68
|
-
require 'vedeu/support/buffer'
|
69
107
|
require 'vedeu/support/grid'
|
70
108
|
require 'vedeu/support/menu'
|
109
|
+
require 'vedeu/support/cursor'
|
71
110
|
|
111
|
+
require 'vedeu/input/input'
|
112
|
+
|
113
|
+
require 'vedeu/application'
|
114
|
+
require 'vedeu/launcher'
|
data/lib/vedeu/api/api.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
module Vedeu
|
2
|
+
|
3
|
+
# Provides the API to Vedeu. Methods therein, and classes belonging to this
|
4
|
+
# module expose Vedeu's core functionality.
|
2
5
|
module API
|
3
6
|
|
7
|
+
# Returns information about various registered subsystems when used with
|
8
|
+
# a defined method within {Vedeu::API::Defined}.
|
9
|
+
#
|
10
|
+
# @api public
|
11
|
+
# @see Vedeu::API::Defined
|
12
|
+
# @return [Vedeu::API::Defined]
|
13
|
+
def defined
|
14
|
+
Vedeu::API::Defined
|
15
|
+
end
|
16
|
+
|
4
17
|
# Register an event by name with optional delay (throttling) which when
|
5
18
|
# triggered will execute the code contained within the passed block.
|
6
19
|
#
|
@@ -49,19 +62,27 @@ module Vedeu
|
|
49
62
|
Vedeu.events.event(name, opts = {}, &block)
|
50
63
|
end
|
51
64
|
|
52
|
-
#
|
65
|
+
# Initially accessed by Vedeu itself, this sets up some basic events needed
|
66
|
+
# by Vedeu to run. Afterwards, it is simply a gateway to the Events class
|
67
|
+
# used by other API methods.
|
53
68
|
#
|
54
|
-
# @api
|
55
|
-
# @
|
56
|
-
|
57
|
-
|
58
|
-
|
69
|
+
# @api private
|
70
|
+
# @return [Events]
|
71
|
+
def events
|
72
|
+
@events ||= Vedeu::Events.new do
|
73
|
+
event(:_clear_) { Terminal.clear_screen }
|
74
|
+
event(:_exit_) { Vedeu::Application.stop }
|
75
|
+
event(:_focus_by_name_) { |name| Vedeu::Focus.by_name(name) }
|
76
|
+
event(:_focus_next_) { Vedeu::Focus.next_item }
|
77
|
+
event(:_focus_prev_) { Vedeu::Focus.prev_item }
|
78
|
+
event(:_keypress_) { |key| Vedeu.keypress(key) }
|
79
|
+
event(:_log_) { |msg| Vedeu.log(msg) }
|
80
|
+
event(:_mode_switch_) { fail ModeSwitch }
|
81
|
+
event(:_refresh_) { Vedeu::Refresh.all }
|
82
|
+
event(:_resize_, { delay: 0.25 }) { Vedeu.resize }
|
83
|
+
end
|
59
84
|
end
|
60
85
|
|
61
|
-
# def focus(name)
|
62
|
-
# Focus.by_name(name)
|
63
|
-
# end
|
64
|
-
|
65
86
|
# Find out how many lines the current terminal is able to display.
|
66
87
|
#
|
67
88
|
# @api public
|
@@ -97,7 +118,12 @@ module Vedeu
|
|
97
118
|
end
|
98
119
|
|
99
120
|
# Handles the keypress in your application. Can also be used to simulate a
|
100
|
-
# keypress.
|
121
|
+
# keypress. The example below will have the following workflow:
|
122
|
+
#
|
123
|
+
# 1) Trigger the event `:key` in your application, which you will handle
|
124
|
+
# and perform the appropriate action- maybe nothing.
|
125
|
+
# 2) If debugging is enabled in Vedeu, then the key is logged to the log
|
126
|
+
# file.
|
101
127
|
#
|
102
128
|
# @api public
|
103
129
|
# @param key [String|Symbol] The key which was pressed. Escape sequences
|
@@ -105,15 +131,15 @@ module Vedeu
|
|
105
131
|
# i.e. `:f4`. A list of these translations can be found at {Vedeu::Input}.
|
106
132
|
#
|
107
133
|
# @example
|
108
|
-
#
|
134
|
+
# Vedeu.keypress('s')
|
109
135
|
#
|
110
136
|
# @return []
|
111
137
|
def keypress(key)
|
112
|
-
Vedeu.
|
113
|
-
Vedeu.
|
114
|
-
Vedeu.
|
115
|
-
Vedeu.
|
116
|
-
Vedeu.
|
138
|
+
Vedeu.trigger(:key, key)
|
139
|
+
Vedeu.trigger(:_log_, "Key: #{key}") if Configuration.debug?
|
140
|
+
Vedeu.trigger(:_mode_switch_) if key == :escape
|
141
|
+
Vedeu.trigger(:_focus_next_) if key == :tab
|
142
|
+
Vedeu.trigger(:_focus_prev_) if key == :shift_tab
|
117
143
|
end
|
118
144
|
|
119
145
|
# Write a message to the Vedeu log file located at `$HOME/.vedeu/vedeu.log`
|
@@ -121,14 +147,30 @@ module Vedeu
|
|
121
147
|
# @api public
|
122
148
|
# @param message [String] The message you wish to emit to the log
|
123
149
|
# file, useful for debugging.
|
150
|
+
# @param force [TrueClass|FalseClass] When evaluates to true will
|
151
|
+
# write to the log file regardless of the Configuration setting.
|
124
152
|
#
|
125
153
|
# @example
|
126
154
|
# Vedeu.log('A useful debugging message: Error!')
|
127
155
|
#
|
128
156
|
# @return [TrueClass]
|
129
|
-
def log(message)
|
130
|
-
Vedeu::Log.logger.debug(message) if Configuration.debug?
|
157
|
+
def log(message, force = false)
|
158
|
+
Vedeu::Log.logger.debug(message) if Configuration.debug? || force
|
159
|
+
end
|
160
|
+
|
161
|
+
# When the terminal emit the 'SIGWINCH' signal, Vedeu can intercept this
|
162
|
+
# and attempt to redraw the current interface with varying degrees of
|
163
|
+
# success. Can also be used to simulate a terminal resize.
|
164
|
+
#
|
165
|
+
# @api private
|
166
|
+
# @return []
|
167
|
+
# :nocov:
|
168
|
+
def resize
|
169
|
+
trigger(:_clear_)
|
170
|
+
|
171
|
+
trigger(:_refresh_)
|
131
172
|
end
|
173
|
+
# :nocov:
|
132
174
|
|
133
175
|
# Trigger a registered or system event by name with arguments.
|
134
176
|
#
|
@@ -153,14 +195,13 @@ module Vedeu
|
|
153
195
|
#
|
154
196
|
# @example
|
155
197
|
# Vedeu.interface 'main_screen' do
|
156
|
-
# ... some attributes ...
|
157
198
|
# width use('my_interface').width
|
158
199
|
# x use('my_interface').east(1)
|
159
|
-
#
|
200
|
+
# ...
|
160
201
|
#
|
161
202
|
# @return [Vedeu::Interface]
|
162
203
|
def use(name)
|
163
|
-
Vedeu::Interface.new(Vedeu::
|
204
|
+
Vedeu::Interface.new(Vedeu::Interfaces.find(name))
|
164
205
|
end
|
165
206
|
|
166
207
|
# Define a view (content) for an interface. TODO: More help.
|
@@ -172,8 +213,7 @@ module Vedeu
|
|
172
213
|
#
|
173
214
|
# @example
|
174
215
|
# view 'my_interface' do
|
175
|
-
# ...
|
176
|
-
# end
|
216
|
+
# ...
|
177
217
|
#
|
178
218
|
# @return [Hash]
|
179
219
|
def view(name, &block)
|
@@ -195,7 +235,7 @@ module Vedeu
|
|
195
235
|
# view 'my_other_interface' do
|
196
236
|
# ... some other attributes ...
|
197
237
|
# end
|
198
|
-
#
|
238
|
+
# ...
|
199
239
|
#
|
200
240
|
# composition do
|
201
241
|
# view 'my_interface' do
|
@@ -221,34 +261,14 @@ module Vedeu
|
|
221
261
|
Terminal.width
|
222
262
|
end
|
223
263
|
|
224
|
-
#
|
225
|
-
#
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
event(:_refresh_) { Buffers.refresh_all }
|
233
|
-
event(:_resize_, { delay: 0.25 }) { Vedeu.resize }
|
234
|
-
event(:_keypress_) { |key| Vedeu.keypress(key) }
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
# @api private
|
239
|
-
# @return []
|
240
|
-
def resize
|
241
|
-
trigger(:_clear_)
|
242
|
-
|
243
|
-
trigger(:_refresh_)
|
244
|
-
end
|
245
|
-
|
246
|
-
# @api private
|
247
|
-
# @return [Exception]
|
248
|
-
def shutdown
|
249
|
-
trigger(:_cleanup_)
|
250
|
-
|
251
|
-
fail StopIteration
|
264
|
+
# Unregisters the event by name, effectively deleting the associated events
|
265
|
+
# bound with it also.
|
266
|
+
#
|
267
|
+
# @api public
|
268
|
+
# @param name [Symbol]
|
269
|
+
# @return [Hash]
|
270
|
+
def unevent(name)
|
271
|
+
Vedeu.events.unevent(name)
|
252
272
|
end
|
253
273
|
|
254
274
|
end
|