vedeu 0.5.3 → 0.5.4

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/docs/events.md +4 -0
  4. data/examples/borders_app.rb +43 -39
  5. data/examples/focus_app.rb +4 -0
  6. data/examples/hello_world.rb +10 -3
  7. data/lib/vedeu/all.rb +1 -2
  8. data/lib/vedeu/api.rb +4 -1
  9. data/lib/vedeu/application/application_controller.rb +24 -0
  10. data/lib/vedeu/application/application_view.rb +9 -9
  11. data/lib/vedeu/bindings.rb +2 -0
  12. data/lib/vedeu/bindings/movement.rb +9 -9
  13. data/lib/vedeu/bindings/system.rb +3 -3
  14. data/lib/vedeu/buffers/buffer.rb +4 -9
  15. data/lib/vedeu/buffers/display_buffer.rb +2 -48
  16. data/lib/vedeu/cli/generator/application.rb +6 -0
  17. data/lib/vedeu/cli/generator/templates/application/.ruby-version +1 -0
  18. data/lib/vedeu/cli/generator/templates/application/app/controllers/name.erb +2 -11
  19. data/lib/vedeu/configuration/api.rb +6 -0
  20. data/lib/vedeu/configuration/configuration.rb +6 -0
  21. data/lib/vedeu/cursor/cursor.rb +49 -15
  22. data/lib/vedeu/cursor/move.rb +2 -2
  23. data/lib/vedeu/cursor/refresh_cursor.rb +2 -7
  24. data/lib/vedeu/distributed/server.rb +7 -21
  25. data/lib/vedeu/dsl/view.rb +31 -6
  26. data/lib/vedeu/internal_api.rb +7 -0
  27. data/lib/vedeu/log/log.rb +5 -2
  28. data/lib/vedeu/models/escape.rb +24 -6
  29. data/lib/vedeu/models/interface.rb +2 -14
  30. data/lib/vedeu/null/buffer.rb +7 -21
  31. data/lib/vedeu/null/generic.rb +5 -16
  32. data/lib/vedeu/null/interface.rb +6 -18
  33. data/lib/vedeu/runtime/bootstrap.rb +1 -1
  34. data/lib/vedeu/runtime/flags.rb +57 -0
  35. data/lib/vedeu/runtime/router.rb +2 -2
  36. data/lib/vedeu/version.rb +2 -1
  37. data/test/lib/vedeu/api_test.rb +1 -0
  38. data/test/lib/vedeu/application/application_controller_test.rb +26 -2
  39. data/test/lib/vedeu/application/application_view_test.rb +9 -4
  40. data/test/lib/vedeu/bindings_test.rb +9 -0
  41. data/test/lib/vedeu/borders/border_test.rb +25 -42
  42. data/test/lib/vedeu/buffers/display_buffer_test.rb +0 -10
  43. data/test/lib/vedeu/configuration/api_test.rb +7 -1
  44. data/test/lib/vedeu/configuration/cli_test.rb +0 -1
  45. data/test/lib/vedeu/configuration/configuration_test.rb +16 -0
  46. data/test/lib/vedeu/cursor/cursor_test.rb +122 -4
  47. data/test/lib/vedeu/dsl/view_test.rb +2 -2
  48. data/test/lib/vedeu/internal_api_test.rb +2 -0
  49. data/test/lib/vedeu/models/escape_test.rb +16 -6
  50. data/test/lib/vedeu/models/focus_test.rb +2 -1
  51. data/test/lib/vedeu/models/interface_test.rb +9 -5
  52. data/test/lib/vedeu/null/buffer_test.rb +7 -25
  53. data/test/lib/vedeu/null/generic_test.rb +6 -20
  54. data/test/lib/vedeu/null/interface_test.rb +8 -14
  55. data/test/lib/vedeu/output/compressor_test.rb +4 -4
  56. data/test/lib/vedeu/output/renderers_test.rb +1 -1
  57. data/test/lib/vedeu/runtime/flags_test.rb +47 -0
  58. data/test/lib/vedeu/runtime/router_test.rb +4 -4
  59. data/test/test_helper.rb +2 -0
  60. metadata +6 -10
  61. data/examples/geometry_app.rb +0 -147
  62. data/examples/panel_app.rb +0 -71
  63. data/lib/vedeu/geometry/index_position.rb +0 -85
  64. data/lib/vedeu/geometry/position_validator.rb +0 -69
  65. data/test/lib/vedeu/geometry/index_position_test.rb +0 -130
  66. data/test/lib/vedeu/geometry/position_validator_test.rb +0 -149
@@ -1,147 +0,0 @@
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
- require 'vedeu'
7
-
8
- # An example application to demonstrate geometry.
9
- # If you have cloned this repository from GitHub, you can run this example:
10
- #
11
- # ./examples/geometry_app.rb
12
- #
13
- class VedeuGeometryApp
14
-
15
- # Be aware that running an application with debugging enabled will affect
16
- # performance.
17
- Vedeu.configure do
18
- # debug!
19
- log '/tmp/vedeu_geometry_app.log'
20
- end
21
-
22
- Vedeu.interface 'main_interface' do
23
- colour foreground: '#ff0000', background: '#000000'
24
- cursor!
25
-
26
- # Geometry can be defined within the interface.
27
- geometry do
28
- height rows(4)
29
- width 8
30
- x 2
31
- y 2
32
- end
33
- end
34
-
35
- Vedeu.interface 'second' do
36
- colour foreground: '#0000ff', background: '#000000'
37
- cursor!
38
- end
39
-
40
- # Geometry can be defined either before or after the interface.
41
- Vedeu.geometry 'second' do
42
- height 8
43
- width columns(1)
44
- x 12
45
- y 2
46
- end
47
-
48
- Vedeu.keymap('_global_') do
49
- key(:up, 'k') { Vedeu.trigger(:_cursor_up_) }
50
- key(:right, 'l') { Vedeu.trigger(:_cursor_right_) }
51
- key(:down, 'j') { Vedeu.trigger(:_cursor_down_) }
52
- key(:left, 'h') { Vedeu.trigger(:_cursor_left_) }
53
-
54
- key('q') { Vedeu.trigger(:_exit_) }
55
- key(:escape) { Vedeu.trigger(:_mode_switch_) }
56
- key(:shift_tab) { Vedeu.trigger(:_focus_prev_) }
57
- key(:tab) { Vedeu.trigger(:_focus_next_) }
58
- end
59
-
60
- Vedeu.renders do
61
- view 'second' do
62
- border!
63
- lines do
64
- line 'A.987654321'
65
- line 'B.987654321'
66
- line 'C.987654321'
67
- line 'D.987654321'
68
- line 'E.987654321'
69
- line 'F.987654321'
70
- line 'G.987654321'
71
- line 'H.987654321'
72
- end
73
- end
74
- view 'main_interface' do
75
- border!
76
- lines do
77
- streams do
78
- text 'A.3456789 '
79
- end
80
- streams do
81
- background '#550000'
82
- foreground '#ffff00'
83
- text 'hydrogen'
84
- end
85
- streams do
86
- text ' helium'
87
- end
88
- end
89
- lines do
90
- streams do
91
- text 'B.3456789 lithium beryllium boron nitrogen'
92
- end
93
- end
94
- lines do
95
- streams do
96
- text 'C.3456789'
97
- text ' carbon oxygen '
98
- end
99
- streams do
100
- background '#aadd00'
101
- foreground '#000000'
102
- text 'fluorine'
103
- end
104
- end
105
- lines do
106
- streams do
107
- text 'D.3456789'
108
- end
109
- end
110
- lines do
111
- streams do
112
- text 'E.3456789 neon sodium'
113
- end
114
- end
115
- lines do
116
- streams do
117
- text 'F.3456789 magnesium '
118
- end
119
- streams do
120
- foreground '#00aaff'
121
- text 'aluminium'
122
- end
123
- end
124
- lines do
125
- streams do
126
- text 'G.3456789 silicon'
127
- end
128
- end
129
- lines do
130
- streams do
131
- background '#550000'
132
- foreground '#ff00ff'
133
- text 'H.34'
134
- end
135
- end
136
- end
137
- end
138
-
139
- Vedeu.focus_by_name 'main_interface'
140
-
141
- def self.start(argv = ARGV)
142
- Vedeu::Launcher.execute!(argv)
143
- end
144
-
145
- end # VedeuGeometryApp
146
-
147
- VedeuGeometryApp.start(ARGV)
@@ -1,71 +0,0 @@
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
- require 'vedeu'
7
-
8
- # An example application to demonstrate colours, cursor and interface movement,
9
- # maximising/unmaximising of interfaces and toggling of cursors and interfaces.
10
- #
11
- # If you have cloned this repository from GitHub, you can run this example:
12
- #
13
- # ./examples/panel_app.rb
14
- #
15
- class VedeuPanelApp
16
-
17
- # Be aware that running an application with debugging enabled will affect
18
- # performance.
19
- Vedeu.configure do
20
- # debug!
21
- log '/tmp/vedeu_panel_app.log'
22
- # renderers Vedeu::Renderers::File.new
23
- end
24
-
25
- # line { centre 'Blue', width: 20, background: '#2196f3' }
26
- Vedeu.interface 'main_interface' do
27
- border 'main_interface' do
28
- colour foreground: '#000000', background: '#cddc39' # lime
29
- title 'Panel: Yes/No'
30
- end
31
- colour foreground: '#000000', background: '#cddc39'
32
- cursor!
33
- geometry 'main_interface' do
34
- centred!
35
- width columns(10)
36
- height 9
37
- end
38
- end
39
-
40
- Vedeu.keymap('_global_') do
41
- key(:up) { Vedeu.trigger(:_cursor_up_) }
42
- key(:right) { Vedeu.trigger(:_cursor_right_) }
43
- key(:down) { Vedeu.trigger(:_cursor_down_) }
44
- key(:left) { Vedeu.trigger(:_cursor_left_) }
45
-
46
- key('q') { Vedeu.trigger(:_exit_) }
47
- key(:escape) { Vedeu.trigger(:_mode_switch_) }
48
- key(:shift_tab) { Vedeu.trigger(:_focus_prev_) }
49
- key(:tab) { Vedeu.trigger(:_focus_next_) }
50
- end
51
-
52
- Vedeu.renders do
53
- view 'main_interface' do
54
- lines do
55
- line ' '
56
- line 'This is an example panel. It should be used for Yes/No questions.'
57
- line 'Do you like it?'
58
- end
59
- button('Yes!', :confirm, true)
60
- end
61
- end
62
-
63
- Vedeu.focus_by_name 'main_interface'
64
-
65
- def self.start(argv = ARGV)
66
- Vedeu::Launcher.execute!(argv)
67
- end
68
-
69
- end # VedeuPanelApp
70
-
71
- VedeuPanelApp.start(ARGV)
@@ -1,85 +0,0 @@
1
- module Vedeu
2
-
3
- # Converts an index into a position for the terminal.
4
- #
5
- # When the optional offset `oy` and `ox` params are given, the they are used
6
- # for the starting position.
7
- #
8
- class IndexPosition
9
-
10
- # @param (see #initialize)
11
- # @return [Vedeu::Position]
12
- def self.[](iy, ix, oy = 1, ox = 1)
13
- new(iy, ix, oy, ox).[]
14
- end
15
-
16
- # Returns a new instance of Vedeu::IndexPosition.
17
- #
18
- # @param iy [Fixnum]
19
- # @param ix [Fixnum]
20
- # @param oy [Fixnum]
21
- # @param ox [Fixnum]
22
- # @return [Vedeu::IndexPosition]
23
- def initialize(iy, ix, oy = 1, ox = 1)
24
- @iy = iy
25
- @ix = ix
26
- @oy = oy
27
- @ox = ox
28
- end
29
-
30
- # @return [Vedeu::Position]
31
- def []
32
- Vedeu::Position[y, x]
33
- end
34
- alias_method :to_position, :[]
35
-
36
- # An object is equal when its values are the same.
37
- #
38
- # @param other [Vedeu::IndexPosition]
39
- # @return [Boolean]
40
- def eql?(other)
41
- self.class == other.class && (x == other.x && y == other.y)
42
- end
43
- alias_method :==, :eql?
44
-
45
- # Returns the y coordinate.
46
- #
47
- # @return [Fixnum]
48
- def y
49
- (iy <= 0) ? oy : (iy + oy)
50
- end
51
- alias_method :first, :y
52
-
53
- # Returns the x coordinate.
54
- #
55
- # @return [Fixnum]
56
- def x
57
- (ix <= 0) ? ox : (ix + ox)
58
- end
59
- alias_method :last, :x
60
-
61
- private
62
-
63
- # @return [Fixnum]
64
- def iy
65
- @_iy ||= (@iy <= 0) ? 0 : @iy
66
- end
67
-
68
- # @return [Fixnum]
69
- def ix
70
- @_ix ||= (@ix <= 0) ? 0 : @ix
71
- end
72
-
73
- # @return [Fixnum]
74
- def oy
75
- @_oy ||= (@oy <= 1) ? 1 : @oy
76
- end
77
-
78
- # @return [Fixnum]
79
- def ox
80
- @_ox ||= (@ox <= 1) ? 1 : @ox
81
- end
82
-
83
- end # IndexPosition
84
-
85
- end # Vedeu
@@ -1,69 +0,0 @@
1
- module Vedeu
2
-
3
- # Validates that the provided coordinates are within the terminal and
4
- # interface's geometry (with or without a border).
5
- #
6
- class PositionValidator
7
-
8
- extend Forwardable
9
-
10
- def_delegators :border,
11
- :bx,
12
- :bxn,
13
- :by,
14
- :byn
15
-
16
- # @!attribute [rw] x
17
- # @return [Fixnum]
18
- attr_accessor :x
19
-
20
- # @!attribute [rw] x
21
- # @return [Fixnum]
22
- attr_accessor :y
23
-
24
- # @param (see #initialize)
25
- def self.validate(name, x, y)
26
- new(name, x, y).validate
27
- end
28
-
29
- # Returns a new instance of Vedeu::PositionValidator.
30
- #
31
- # @param name [String]
32
- # @param y [Fixnum] The row/line coordinate.
33
- # @param x [Fixnum] The column/character coordinate.
34
- # @return [Vedeu::PositionValidator]
35
- def initialize(name, x, y)
36
- @name = name
37
- @x = x
38
- @y = y
39
- end
40
-
41
- # Ensures the coordinates provided are within the terminal, interface and
42
- # when applicable, bordered interface area.
43
- #
44
- # @return [PositionValidator]
45
- def validate
46
- @x = bx if x < bx
47
- @x = bxn if x > bxn
48
- @y = by if y < by
49
- @y = byn if y > byn
50
-
51
- self
52
- end
53
-
54
- protected
55
-
56
- # @!attribute [r] name
57
- # @return [String]
58
- attr_reader :name
59
-
60
- private
61
-
62
- # @see Vedeu::Borders#by_name
63
- def border
64
- @border ||= Vedeu.borders.by_name(name)
65
- end
66
-
67
- end # PositionValidator
68
-
69
- end # Vedeu
@@ -1,130 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
-
5
- describe IndexPosition do
6
-
7
- let(:described) { Vedeu::IndexPosition }
8
- let(:instance) { described.new(iy, ix, oy, ox) }
9
- let(:iy) { 6 }
10
- let(:ix) { 17 }
11
- let(:oy) { 3 }
12
- let(:ox) { 5 }
13
-
14
- describe '#initialize' do
15
- it { instance.must_be_instance_of(described) }
16
- it { instance.instance_variable_get('@oy').must_equal(3) }
17
- it { instance.instance_variable_get('@ox').must_equal(5) }
18
- it { instance.instance_variable_get('@iy').must_equal(6) }
19
- it { instance.instance_variable_get('@ix').must_equal(17) }
20
- end
21
-
22
- describe '.[]' do
23
- subject { described[iy, ix] }
24
-
25
- it { subject.must_be_instance_of(Vedeu::Position) }
26
- end
27
-
28
- describe '#[]' do
29
- subject { instance.[] }
30
-
31
- it { instance.must_respond_to(:to_position) }
32
-
33
- it { subject.must_be_instance_of(Vedeu::Position) }
34
- it { subject.y.must_equal(9) }
35
- it { subject.x.must_equal(22) }
36
- end
37
-
38
- describe '#eql?' do
39
- let(:other) { described.new(8, 21) }
40
-
41
- subject { instance.eql?(other) }
42
-
43
- it { subject.must_equal(true) }
44
-
45
- context 'when different to other' do
46
- let(:other) { described.new(2, 9) }
47
-
48
- it { subject.must_equal(false) }
49
- end
50
- end
51
-
52
- describe '#y' do
53
- subject { instance.y }
54
-
55
- it { instance.must_respond_to(:first) }
56
-
57
- context 'when iy is <= 0' do
58
- let(:iy) { -2 }
59
-
60
- context 'and oy is <= 1' do
61
- let(:oy) { -6 }
62
-
63
- it { subject.must_equal(1) }
64
- end
65
-
66
- context 'and oy is > 1' do
67
- let(:oy) { 4 }
68
-
69
- it { subject.must_equal(4) }
70
- end
71
- end
72
-
73
- context 'when iy is > 0' do
74
- let(:iy) { 3 }
75
-
76
- context 'and oy is <= 1' do
77
- let(:oy) { -7 }
78
-
79
- it { subject.must_equal(4) }
80
- end
81
-
82
- context 'and oy is > 1' do
83
- let(:oy) { 5 }
84
-
85
- it { subject.must_equal(8) }
86
- end
87
- end
88
- end
89
-
90
- describe '#x' do
91
- subject { instance.x }
92
-
93
- it { instance.must_respond_to(:last) }
94
-
95
- context 'when ix is <= 0' do
96
- let(:ix) { -2 }
97
-
98
- context 'and ox is <= 1' do
99
- let(:ox) { -6 }
100
-
101
- it { subject.must_equal(1) }
102
- end
103
-
104
- context 'and ox is > 1' do
105
- let(:ox) { 4 }
106
-
107
- it { subject.must_equal(4) }
108
- end
109
- end
110
-
111
- context 'when ix is > 0' do
112
- let(:ix) { 3 }
113
-
114
- context 'and ox is <= 1' do
115
- let(:ox) { -7 }
116
-
117
- it { subject.must_equal(4) }
118
- end
119
-
120
- context 'and ox is > 1' do
121
- let(:ox) { 5 }
122
-
123
- it { subject.must_equal(8) }
124
- end
125
- end
126
- end
127
-
128
- end # IndexPosition
129
-
130
- end # Vedeu