vedeu 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +40 -0
  3. data/README.md +1 -0
  4. data/docs/dsl.md +24 -24
  5. data/lib/vedeu/all.rb +21 -44
  6. data/lib/vedeu/api.rb +13 -13
  7. data/lib/vedeu/application/application_controller.rb +2 -0
  8. data/lib/vedeu/bindings/movement.rb +53 -18
  9. data/lib/vedeu/bindings/refresh.rb +1 -1
  10. data/lib/vedeu/bindings/system.rb +2 -2
  11. data/lib/vedeu/bindings/visibility.rb +3 -3
  12. data/lib/vedeu/borders/all.rb +13 -0
  13. data/lib/vedeu/borders/border.rb +209 -202
  14. data/lib/vedeu/{dsl/border.rb → borders/dsl.rb} +15 -15
  15. data/lib/vedeu/{null/border.rb → borders/null.rb} +9 -9
  16. data/lib/vedeu/borders/render.rb +347 -0
  17. data/lib/vedeu/borders/repository.rb +19 -0
  18. data/lib/vedeu/buffers/all.rb +13 -0
  19. data/lib/vedeu/buffers/buffer.rb +182 -176
  20. data/lib/vedeu/{null/buffer.rb → buffers/null.rb} +8 -8
  21. data/lib/vedeu/buffers/repository.rb +24 -0
  22. data/lib/vedeu/buffers/virtual_buffer.rb +2 -2
  23. data/lib/vedeu/cursors/all.rb +11 -0
  24. data/lib/vedeu/cursors/cursor.rb +276 -0
  25. data/lib/vedeu/cursors/refresh.rb +84 -0
  26. data/lib/vedeu/cursors/repository.rb +34 -0
  27. data/lib/vedeu/dsl/interface.rb +9 -9
  28. data/lib/vedeu/dsl/shared.rb +11 -11
  29. data/lib/vedeu/{exceptions.rb → error.rb} +2 -2
  30. data/lib/vedeu/esc/esc.rb +1 -1
  31. data/lib/vedeu/geometry/all.rb +18 -0
  32. data/lib/vedeu/geometry/area.rb +170 -160
  33. data/lib/vedeu/geometry/coordinate.rb +61 -39
  34. data/lib/vedeu/geometry/dimension.rb +139 -132
  35. data/lib/vedeu/{dsl/geometry.rb → geometry/dsl.rb} +11 -11
  36. data/lib/vedeu/geometry/generic_coordinate.rb +159 -153
  37. data/lib/vedeu/geometry/geometry.rb +310 -212
  38. data/lib/vedeu/geometry/grid.rb +73 -69
  39. data/lib/vedeu/{null/geometry.rb → geometry/null.rb} +10 -10
  40. data/lib/vedeu/geometry/position.rb +124 -120
  41. data/lib/vedeu/geometry/repository.rb +19 -0
  42. data/lib/vedeu/input/editor/document.rb +2 -2
  43. data/lib/vedeu/internal_api.rb +8 -8
  44. data/lib/vedeu/models/escape.rb +2 -2
  45. data/lib/vedeu/models/interface.rb +1 -1
  46. data/lib/vedeu/models/page.rb +89 -0
  47. data/lib/vedeu/models/row.rb +66 -0
  48. data/lib/vedeu/models/toggleable.rb +1 -1
  49. data/lib/vedeu/models/views/char.rb +7 -6
  50. data/lib/vedeu/models/views/line.rb +1 -1
  51. data/lib/vedeu/models/views/view.rb +2 -2
  52. data/lib/vedeu/options.rb +19 -0
  53. data/lib/vedeu/output/clear/named_interface.rb +1 -1
  54. data/lib/vedeu/output/direct.rb +1 -1
  55. data/lib/vedeu/output/presentation.rb +2 -1
  56. data/lib/vedeu/output/viewport.rb +3 -3
  57. data/lib/vedeu/repositories/model.rb +9 -1
  58. data/lib/vedeu/repositories/repository.rb +5 -0
  59. data/lib/vedeu/terminal/terminal.rb +3 -3
  60. data/lib/vedeu/version.rb +1 -1
  61. data/test/lib/vedeu/borders/border_test.rb +299 -291
  62. data/test/lib/vedeu/{dsl/border_test.rb → borders/dsl_test.rb} +6 -6
  63. data/test/lib/vedeu/{null/border_test.rb → borders/null_test.rb} +6 -6
  64. data/test/lib/vedeu/borders/render_test.rb +125 -0
  65. data/test/lib/vedeu/borders/repository_test.rb +17 -0
  66. data/test/lib/vedeu/buffers/buffer_test.rb +116 -112
  67. data/test/lib/vedeu/{null/buffer_test.rb → buffers/null_test.rb} +5 -5
  68. data/test/lib/vedeu/buffers/repository_test.rb +18 -0
  69. data/test/lib/vedeu/cursors/cursor_test.rb +370 -0
  70. data/test/lib/vedeu/cursors/refresh_test.rb +69 -0
  71. data/test/lib/vedeu/cursors/repository_test.rb +41 -0
  72. data/test/lib/vedeu/dsl/interface_test.rb +5 -5
  73. data/test/lib/vedeu/{exceptions_test.rb → error_test.rb} +0 -0
  74. data/test/lib/vedeu/geometry/area_test.rb +141 -137
  75. data/test/lib/vedeu/geometry/coordinate_test.rb +93 -89
  76. data/test/lib/vedeu/geometry/dimension_test.rb +137 -133
  77. data/test/lib/vedeu/{dsl/geometry_test.rb → geometry/dsl_test.rb} +17 -17
  78. data/test/lib/vedeu/geometry/generic_coordinate_test.rb +32 -28
  79. data/test/lib/vedeu/geometry/geometry_test.rb +282 -157
  80. data/test/lib/vedeu/geometry/grid_test.rb +35 -31
  81. data/test/lib/vedeu/{null/geometry_test.rb → geometry/null_test.rb} +5 -5
  82. data/test/lib/vedeu/geometry/position_test.rb +146 -142
  83. data/test/lib/vedeu/geometry/repository_test.rb +19 -0
  84. data/test/lib/vedeu/input/editor/document_test.rb +1 -1
  85. data/test/lib/vedeu/models/escape_test.rb +1 -1
  86. data/test/lib/vedeu/models/interface_test.rb +2 -2
  87. data/test/lib/vedeu/models/page_test.rb +235 -0
  88. data/test/lib/vedeu/models/row_test.rb +111 -0
  89. data/test/lib/vedeu/models/views/char_test.rb +3 -3
  90. data/test/lib/vedeu/options_test.rb +57 -0
  91. data/test/lib/vedeu/output/clear/named_interface_test.rb +1 -1
  92. data/test/lib/vedeu/output/renderers/json_test.rb +1 -1
  93. data/test/lib/vedeu/output/viewport_test.rb +15 -9
  94. data/test/lib/vedeu/refresh/refresh_buffer_test.rb +12 -12
  95. data/test/lib/vedeu/repositories/repositories_test.rb +1 -1
  96. data/test/lib/vedeu/repositories/repository_test.rb +7 -0
  97. data/test/lib/vedeu/terminal/terminal_test.rb +1 -1
  98. data/test/test_helper.rb +1 -1
  99. data/vedeu.gemspec +2 -2
  100. metadata +57 -63
  101. data/lib/vedeu/borders/borders.rb +0 -15
  102. data/lib/vedeu/borders/render_border.rb +0 -331
  103. data/lib/vedeu/buffers/buffers.rb +0 -20
  104. data/lib/vedeu/cursor/cursor.rb +0 -174
  105. data/lib/vedeu/cursor/cursors.rb +0 -30
  106. data/lib/vedeu/cursor/move.rb +0 -239
  107. data/lib/vedeu/cursor/reposition.rb +0 -78
  108. data/lib/vedeu/geometry/geometries.rb +0 -15
  109. data/lib/vedeu/refresh/refresh_cursor.rb +0 -92
  110. data/test/lib/vedeu/borders/borders_test.rb +0 -13
  111. data/test/lib/vedeu/borders/render_border_test.rb +0 -121
  112. data/test/lib/vedeu/buffers/buffers_test.rb +0 -14
  113. data/test/lib/vedeu/cursor/cursor_test.rb +0 -246
  114. data/test/lib/vedeu/cursor/cursors_test.rb +0 -37
  115. data/test/lib/vedeu/cursor/move_test.rb +0 -301
  116. data/test/lib/vedeu/cursor/reposition_test.rb +0 -63
  117. data/test/lib/vedeu/geometry/geometries_test.rb +0 -15
  118. data/test/lib/vedeu/refresh/refresh_cursor_test.rb +0 -65
@@ -1,75 +1,79 @@
1
1
  module Vedeu
2
2
 
3
- # The grid system splits the terminal height and width into 12 equal parts, by
4
- # dividing the available height and width by 12. If the terminal height or
5
- # width is not a multiple of 12, then Grid chooses the maximum value which
6
- # will fit.
7
- #
8
- class Grid
9
-
10
- # @see #initialize
11
- # @see #columns
12
- def self.columns(value)
13
- new(value).columns
14
- end
15
-
16
- # @see #initialize
17
- # @see #rows
18
- def self.rows(value)
19
- new(value).rows
20
- end
21
-
22
- # Returns a new instance of Vedeu::Grid.
23
- #
24
- # @param value [Fixnum]
25
- # @return [Grid]
26
- def initialize(value)
27
- @value = value
28
- end
29
-
30
- # @see Vedeu::DSL::Geometry#columns
31
- def columns
32
- fail Vedeu::Error::OutOfRange if out_of_range?
33
-
34
- column * value
35
- end
36
-
37
- # @see Vedeu::DSL::Geometry#rows
38
- def rows
39
- fail Vedeu::Error::OutOfRange if out_of_range?
40
-
41
- row * value
42
- end
43
-
44
- protected
45
-
46
- # @!attribute [r] value
47
- # @return [Fixnum]
48
- attr_reader :value
3
+ module Geometry
49
4
 
50
- private
51
-
52
- # Returns the height of a single row in characters.
53
- #
54
- # @return [Fixnum]
55
- def row
56
- Vedeu.height / 12
57
- end
58
-
59
- # Returns a boolean indicating whether the value is out of range.
5
+ # The grid system splits the terminal height and width into 12 equal parts,
6
+ # by dividing the available height and width by 12. If the terminal height
7
+ # or width is not a multiple of 12, then Grid chooses the maximum value
8
+ # which will fit.
60
9
  #
61
- # @return [Boolean]
62
- def out_of_range?
63
- value < 1 || value > 12
64
- end
65
-
66
- # Returns the width of a single column in characters.
67
- #
68
- # @return [Fixnum]
69
- def column
70
- Vedeu.width / 12
71
- end
72
-
73
- end # Grid
10
+ class Grid
11
+
12
+ # @see #initialize
13
+ # @see #columns
14
+ def self.columns(value)
15
+ new(value).columns
16
+ end
17
+
18
+ # @see #initialize
19
+ # @see #rows
20
+ def self.rows(value)
21
+ new(value).rows
22
+ end
23
+
24
+ # Returns a new instance of Vedeu::Geometry::Grid.
25
+ #
26
+ # @param value [Fixnum]
27
+ # @return [Vedeu::Geometry::Grid]
28
+ def initialize(value)
29
+ @value = value
30
+ end
31
+
32
+ # @see Vedeu::Geometry::DSL#columns
33
+ def columns
34
+ fail Vedeu::Error::OutOfRange if out_of_range?
35
+
36
+ column * value
37
+ end
38
+
39
+ # @see Vedeu::Geometry::DSL#rows
40
+ def rows
41
+ fail Vedeu::Error::OutOfRange if out_of_range?
42
+
43
+ row * value
44
+ end
45
+
46
+ protected
47
+
48
+ # @!attribute [r] value
49
+ # @return [Fixnum]
50
+ attr_reader :value
51
+
52
+ private
53
+
54
+ # Returns the height of a single row in characters.
55
+ #
56
+ # @return [Fixnum]
57
+ def row
58
+ Vedeu.height / 12
59
+ end
60
+
61
+ # Returns a boolean indicating whether the value is out of range.
62
+ #
63
+ # @return [Boolean]
64
+ def out_of_range?
65
+ value < 1 || value > 12
66
+ end
67
+
68
+ # Returns the width of a single column in characters.
69
+ #
70
+ # @return [Fixnum]
71
+ def column
72
+ Vedeu.width / 12
73
+ end
74
+
75
+ end # Grid
76
+
77
+ end # Geometry
74
78
 
75
79
  end # Vedeu
@@ -1,10 +1,10 @@
1
1
  module Vedeu
2
2
 
3
- module Null
3
+ module Geometry
4
4
 
5
5
  # Provides a non-existent model to swallow messages.
6
6
  #
7
- class Geometry
7
+ class Null
8
8
 
9
9
  extend Forwardable
10
10
 
@@ -32,11 +32,11 @@ module Vedeu
32
32
  # @return [String|NilClass]
33
33
  attr_reader :name
34
34
 
35
- # Returns a new instance of Vedeu::Null::Geometry.
35
+ # Returns a new instance of Vedeu::Geometry::Null.
36
36
  #
37
37
  # @param attributes [Hash<Symbol => void>]
38
38
  # @option attributes name [String|NilClass]
39
- # @return [Vedeu::Null::Geometry]
39
+ # @return [Vedeu::Geometry::Null]
40
40
  def initialize(attributes = {})
41
41
  @attributes = attributes
42
42
  @name = @attributes[:name]
@@ -60,21 +60,21 @@ module Vedeu
60
60
  true
61
61
  end
62
62
 
63
- # @return [Vedeu::Null::Geometry]
63
+ # @return [Vedeu::Geometry::Null]
64
64
  def store
65
65
  self
66
66
  end
67
67
 
68
68
  private
69
69
 
70
- # @return [Vedeu::Area]
70
+ # @return [Vedeu::Geometry::Area]
71
71
  def area
72
- @area ||= Vedeu::Area.from_attributes(y_default: Vedeu.height,
73
- x_default: Vedeu.width)
72
+ @area ||= Vedeu::Geometry::Area.from_attributes(y_default: Vedeu.height,
73
+ x_default: Vedeu.width)
74
74
  end
75
75
 
76
- end # Geometry
76
+ end # Null
77
77
 
78
- end # Null
78
+ end # Geometry
79
79
 
80
80
  end # Vedeu
@@ -1,147 +1,151 @@
1
1
  module Vedeu
2
2
 
3
- # Change coordinates into an escape sequence to set the cursor position.
4
- #
5
- class Position
3
+ module Geometry
6
4
 
7
- # @!attribute [r] y
8
- # @return [Fixnum]
9
- attr_reader :y
10
- alias_method :first, :y
5
+ # Change coordinates into an escape sequence to set the cursor position.
6
+ #
7
+ class Position
8
+
9
+ # @!attribute [r] y
10
+ # @return [Fixnum]
11
+ attr_reader :y
12
+ alias_method :first, :y
13
+
14
+ # @!attribute [r] x
15
+ # @return [Fixnum]
16
+ attr_reader :x
17
+ alias_method :last, :x
18
+
19
+ # Convenience constructor for Vedeu::Geometry::Position.
20
+ #
21
+ # @param (see #initialize)
22
+ def self.[](y, x)
23
+ new(y, x)
24
+ end
11
25
 
12
- # @!attribute [r] x
13
- # @return [Fixnum]
14
- attr_reader :x
15
- alias_method :last, :x
26
+ # @param value [Array<Fixnum>|Vedeu::Position]
27
+ # @return [void]
28
+ def self.coerce(value)
29
+ if value.is_a?(self)
30
+ value
16
31
 
17
- # Convenience constructor for Vedeu::Position.
18
- #
19
- # @param (see #initialize)
20
- def self.[](y, x)
21
- new(y, x)
22
- end
32
+ elsif value.is_a?(Array)
33
+ new(*value)
23
34
 
24
- # @param value [Array<Fixnum>|Vedeu::Position]
25
- # @return [void]
26
- def self.coerce(value)
27
- if value.is_a?(self)
28
- value
35
+ elsif value.is_a?(Hash)
36
+ new(value.fetch(:y, 1), value.fetch(:x, 1))
29
37
 
30
- elsif value.is_a?(Array)
31
- new(*value)
38
+ end
39
+ end
32
40
 
33
- elsif value.is_a?(Hash)
34
- new(value.fetch(:y, 1), value.fetch(:x, 1))
41
+ # Initializes a new instance of Vedeu::Geometry::Position.
42
+ #
43
+ # @param y [Fixnum] The row/line position.
44
+ # @param x [Fixnum] The column/character position.
45
+ # @return [Vedeu::Geometry::Position]
46
+ def initialize(y = 1, x = 1)
47
+ @y = (y.nil? || y < 1) ? 1 : y
48
+ @x = (x.nil? || x < 1) ? 1 : x
49
+ end
50
+
51
+ # Converts a position into an index for the terminal. An index is the
52
+ # position minus 1.
53
+ #
54
+ # @return [Array<Fixnum>]
55
+ def as_indices
56
+ xi = ((x - 1) <= 1) ? 0 : (x - 1)
57
+ yi = ((y - 1) <= 1) ? 0 : (y - 1)
35
58
 
59
+ [yi, xi]
36
60
  end
37
- end
38
61
 
39
- # Initializes a new instance of Vedeu::Position.
40
- #
41
- # @param y [Fixnum] The row/line position.
42
- # @param x [Fixnum] The column/character position.
43
- # @return [Vedeu::Position]
44
- def initialize(y = 1, x = 1)
45
- @y = (y.nil? || y < 1) ? 1 : y
46
- @x = (x.nil? || x < 1) ? 1 : x
47
- end
48
-
49
- # Converts a position into an index for the terminal. An index is the
50
- # position minus 1.
51
- #
52
- # @return [Array<Fixnum>]
53
- def as_indices
54
- xi = ((x - 1) <= 1) ? 0 : (x - 1)
55
- yi = ((y - 1) <= 1) ? 0 : (y - 1)
62
+ # @param other [Vedeu::Geometry::Position]
63
+ # @return [Fixnum]
64
+ def <=>(other)
65
+ if y == other.y
66
+ x <=> other.x
56
67
 
57
- [yi, xi]
58
- end
68
+ else
69
+ y <=> other.y
59
70
 
60
- # @param other [Vedeu::Position]
61
- # @return [Fixnum]
62
- def <=>(other)
63
- if y == other.y
64
- x <=> other.x
71
+ end
72
+ end
65
73
 
66
- else
67
- y <=> other.y
74
+ # An object is equal when its values are the same.
75
+ #
76
+ # @param other [Vedeu::Geometry::Position]
77
+ # @return [Boolean]
78
+ def eql?(other)
79
+ self.class == other.class && (x == other.x && y == other.y)
80
+ end
81
+ alias_method :==, :eql?
68
82
 
83
+ # Return a tuple containing the y and x coordinates.
84
+ #
85
+ # @return [Array<Fixnum>]
86
+ def to_a
87
+ [y, x]
69
88
  end
70
- end
71
89
 
72
- # An object is equal when its values are the same.
73
- #
74
- # @param other [Vedeu::Position]
75
- # @return [Boolean]
76
- def eql?(other)
77
- self.class == other.class && (x == other.x && y == other.y)
78
- end
79
- alias_method :==, :eql?
80
-
81
- # Return a tuple containing the y and x coordinates.
82
- #
83
- # @return [Array<Fixnum>]
84
- def to_a
85
- [y, x]
86
- end
87
-
88
- # @return [Vedeu::Position]
89
- def to_position
90
- self
91
- end
92
-
93
- # Return the escape sequence required to position the cursor at a particular
94
- # point on the screen. When passed a block, will do the aforementioned,
95
- # call the block and then reposition to this location.
96
- #
97
- # @return [String]
98
- # @yieldreturn [void] Returns the block wrapped in position escape
99
- # sequences.
100
- def to_s
101
- return "#{sequence}#{yield}" if block_given?
90
+ # @return [Vedeu::Geometry::Position]
91
+ def to_position
92
+ self
93
+ end
102
94
 
103
- sequence
104
- end
105
- alias_method :to_str, :to_s
95
+ # Return the escape sequence required to position the cursor at a
96
+ # particular point on the screen. When passed a block, will do the
97
+ # aforementioned, call the block and then reposition to this location.
98
+ #
99
+ # @return [String]
100
+ # @yieldreturn [void] Returns the block wrapped in position escape
101
+ # sequences.
102
+ def to_s
103
+ return "#{sequence}#{yield}" if block_given?
104
+
105
+ sequence
106
+ end
107
+ alias_method :to_str, :to_s
106
108
 
107
- # Increase y coordinate; moves down.
108
- #
109
- # @return [Vedeu::Position]
110
- def down
111
- Vedeu::Position.new(y + 1, x)
112
- end
109
+ # Increase y coordinate; moves down.
110
+ #
111
+ # @return [Vedeu::Geometry::Position]
112
+ def down
113
+ Vedeu::Geometry::Position.new(y + 1, x)
114
+ end
113
115
 
114
- # Decrease x coordinate; moves left.
115
- #
116
- # @return [Vedeu::Position]
117
- def left
118
- Vedeu::Position.new(y, x - 1)
119
- end
116
+ # Decrease x coordinate; moves left.
117
+ #
118
+ # @return [Vedeu::Geometry::Position]
119
+ def left
120
+ Vedeu::Geometry::Position.new(y, x - 1)
121
+ end
120
122
 
121
- # Increase x coordinate; moves right.
122
- #
123
- # @return [Vedeu::Position]
124
- def right
125
- Vedeu::Position.new(y, x + 1)
126
- end
123
+ # Increase x coordinate; moves right.
124
+ #
125
+ # @return [Vedeu::Geometry::Position]
126
+ def right
127
+ Vedeu::Geometry::Position.new(y, x + 1)
128
+ end
127
129
 
128
- # Decrease y coordinate; moves up.
129
- #
130
- # @return [Vedeu::Position]
131
- def up
132
- Vedeu::Position.new(y - 1, x)
133
- end
130
+ # Decrease y coordinate; moves up.
131
+ #
132
+ # @return [Vedeu::Geometry::Position]
133
+ def up
134
+ Vedeu::Geometry::Position.new(y - 1, x)
135
+ end
134
136
 
135
- private
137
+ private
136
138
 
137
- # Returns the escape sequence to reposition the cursors at the coordinates
138
- # specified by x and y.
139
- #
140
- # @return [String]
141
- def sequence
142
- "\e[#{y};#{x}H"
143
- end
139
+ # Returns the escape sequence to reposition the cursors at the coordinates
140
+ # specified by x and y.
141
+ #
142
+ # @return [String]
143
+ def sequence
144
+ "\e[#{y};#{x}H"
145
+ end
146
+
147
+ end # Position
144
148
 
145
- end # Position
149
+ end # Geometry
146
150
 
147
151
  end # Vedeu