vedeu 0.6.7 → 0.6.8

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 (126) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/docs/dsl.md +4 -4
  4. data/lib/vedeu/all.rb +6 -18
  5. data/lib/vedeu/api.rb +14 -13
  6. data/lib/vedeu/bindings/system.rb +5 -4
  7. data/lib/vedeu/buffers/virtual_buffer.rb +13 -11
  8. data/lib/vedeu/configuration/api.rb +4 -3
  9. data/lib/vedeu/cursors/cursor.rb +23 -18
  10. data/lib/vedeu/distributed/client.rb +11 -6
  11. data/lib/vedeu/distributed/server.rb +4 -3
  12. data/lib/vedeu/dsl/keymap.rb +6 -6
  13. data/lib/vedeu/editor/all.rb +19 -0
  14. data/lib/vedeu/{input/editor → editor}/capture.rb +1 -1
  15. data/lib/vedeu/{input/editor → editor}/cropper.rb +0 -0
  16. data/lib/vedeu/{input/editor → editor}/cursor.rb +0 -0
  17. data/lib/vedeu/{input/editor → editor}/document.rb +0 -0
  18. data/lib/vedeu/{input/editor → editor}/documents.rb +0 -0
  19. data/lib/vedeu/{input/editor → editor}/editor.rb +0 -0
  20. data/lib/vedeu/{input/editor → editor}/insert.rb +0 -0
  21. data/lib/vedeu/{input/editor → editor}/line.rb +0 -0
  22. data/lib/vedeu/{input/editor → editor}/lines.rb +0 -0
  23. data/lib/vedeu/error.rb +21 -18
  24. data/lib/vedeu/esc/borders.rb +6 -4
  25. data/lib/vedeu/esc/colours.rb +13 -12
  26. data/lib/vedeu/esc/esc.rb +11 -10
  27. data/lib/vedeu/input/all.rb +15 -0
  28. data/lib/vedeu/input/input.rb +55 -52
  29. data/lib/vedeu/input/key.rb +36 -30
  30. data/lib/vedeu/input/keymap.rb +101 -92
  31. data/lib/vedeu/input/keymaps.rb +10 -6
  32. data/lib/vedeu/input/keys.rb +8 -4
  33. data/lib/vedeu/input/mapper.rb +125 -121
  34. data/lib/vedeu/input/translator.rb +159 -0
  35. data/lib/vedeu/internal_api.rb +16 -15
  36. data/lib/vedeu/logging/all.rb +13 -0
  37. data/lib/vedeu/logging/debug.rb +84 -0
  38. data/lib/vedeu/logging/lockless_log_device.rb +65 -0
  39. data/lib/vedeu/logging/log.rb +179 -0
  40. data/lib/vedeu/logging/mono_logger.rb +26 -0
  41. data/lib/vedeu/logging/timer.rb +68 -0
  42. data/lib/vedeu/menus/all.rb +12 -0
  43. data/lib/vedeu/{dsl/menu.rb → menus/dsl.rb} +19 -18
  44. data/lib/vedeu/menus/menu.rb +234 -0
  45. data/lib/vedeu/{null/menu.rb → menus/null.rb} +6 -6
  46. data/lib/vedeu/menus/repository.rb +18 -0
  47. data/lib/vedeu/models/cell.rb +62 -55
  48. data/lib/vedeu/models/escape.rb +55 -50
  49. data/lib/vedeu/models/page.rb +74 -69
  50. data/lib/vedeu/models/row.rb +55 -51
  51. data/lib/vedeu/models/views/all.rb +1 -0
  52. data/lib/vedeu/models/views/char.rb +1 -1
  53. data/lib/vedeu/models/views/html_char.rb +165 -0
  54. data/lib/vedeu/output/renderers/html.rb +5 -4
  55. data/lib/vedeu/repositories/model.rb +2 -0
  56. data/lib/vedeu/runtime/application.rb +110 -103
  57. data/lib/vedeu/runtime/bootstrap.rb +109 -103
  58. data/lib/vedeu/runtime/flags.rb +45 -41
  59. data/lib/vedeu/runtime/launcher.rb +1 -1
  60. data/lib/vedeu/runtime/main_loop.rb +51 -46
  61. data/lib/vedeu/runtime/traps.rb +20 -16
  62. data/lib/vedeu/version.rb +1 -1
  63. data/lib/vedeu.rb +2 -2
  64. data/test/lib/vedeu/buffers/virtual_buffer_test.rb +1 -1
  65. data/test/lib/vedeu/cursors/cursor_test.rb +11 -5
  66. data/test/lib/vedeu/dsl/interface_test.rb +1 -1
  67. data/test/lib/vedeu/dsl/keymap_test.rb +2 -2
  68. data/test/lib/vedeu/{input/editor → editor}/capture_test.rb +0 -0
  69. data/test/lib/vedeu/{input/editor → editor}/cropper_test.rb +0 -0
  70. data/test/lib/vedeu/{input/editor → editor}/cursor_test.rb +0 -0
  71. data/test/lib/vedeu/{input/editor → editor}/document_test.rb +0 -0
  72. data/test/lib/vedeu/{input/editor → editor}/documents_test.rb +0 -0
  73. data/test/lib/vedeu/{input/editor → editor}/editor_test.rb +0 -0
  74. data/test/lib/vedeu/{input/editor → editor}/insert_test.rb +0 -0
  75. data/test/lib/vedeu/{input/editor → editor}/line_test.rb +0 -0
  76. data/test/lib/vedeu/{input/editor → editor}/lines_test.rb +0 -0
  77. data/test/lib/vedeu/input/input_test.rb +58 -54
  78. data/test/lib/vedeu/input/key_test.rb +29 -25
  79. data/test/lib/vedeu/input/keymap_test.rb +74 -70
  80. data/test/lib/vedeu/input/keymaps_test.rb +8 -4
  81. data/test/lib/vedeu/input/keys_test.rb +12 -8
  82. data/test/lib/vedeu/input/mapper_test.rb +64 -56
  83. data/test/lib/vedeu/input/translator_test.rb +36 -0
  84. data/test/lib/vedeu/logging/debug_test.rb +39 -0
  85. data/test/lib/vedeu/logging/lockless_log_device_test.rb +42 -0
  86. data/test/lib/vedeu/logging/log_test.rb +52 -0
  87. data/test/lib/vedeu/logging/mono_logger_test.rb +43 -0
  88. data/test/lib/vedeu/logging/timer_test.rb +44 -0
  89. data/test/lib/vedeu/{dsl/menu_test.rb → menus/dsl_test.rb} +6 -6
  90. data/test/lib/vedeu/menus/menu_test.rb +305 -0
  91. data/test/lib/vedeu/{null/menu_test.rb → menus/null_test.rb} +5 -5
  92. data/test/lib/vedeu/menus/repository_test.rb +17 -0
  93. data/test/lib/vedeu/models/cell_test.rb +54 -50
  94. data/test/lib/vedeu/models/escape_test.rb +49 -45
  95. data/test/lib/vedeu/models/page_test.rb +167 -160
  96. data/test/lib/vedeu/models/row_test.rb +71 -67
  97. data/test/lib/vedeu/models/views/html_char_test.rb +110 -0
  98. data/test/lib/vedeu/output/compressor_test.rb +44 -22
  99. data/test/lib/vedeu/output/renderers_test.rb +4 -2
  100. data/test/lib/vedeu/runtime/application_test.rb +36 -32
  101. data/test/lib/vedeu/runtime/bootstrap_test.rb +31 -26
  102. data/test/lib/vedeu/runtime/flags_test.rb +33 -29
  103. data/test/lib/vedeu/runtime/launcher_test.rb +4 -2
  104. data/test/lib/vedeu/runtime/main_loop_test.rb +28 -24
  105. data/test/lib/vedeu/runtime/traps_test.rb +8 -4
  106. data/test/test_helper.rb +4 -2
  107. metadata +66 -63
  108. data/lib/vedeu/input/editor/all.rb +0 -19
  109. data/lib/vedeu/input/input_translator.rb +0 -155
  110. data/lib/vedeu/log/debug.rb +0 -79
  111. data/lib/vedeu/log/lockless_log_device.rb +0 -61
  112. data/lib/vedeu/log/log.rb +0 -172
  113. data/lib/vedeu/log/mono_logger.rb +0 -21
  114. data/lib/vedeu/log/timer.rb +0 -63
  115. data/lib/vedeu/models/menu.rb +0 -217
  116. data/lib/vedeu/models/menus.rb +0 -14
  117. data/lib/vedeu/output/html_char.rb +0 -161
  118. data/test/lib/vedeu/input/input_translator_test.rb +0 -32
  119. data/test/lib/vedeu/log/debug_test.rb +0 -35
  120. data/test/lib/vedeu/log/lockless_log_device_test.rb +0 -29
  121. data/test/lib/vedeu/log/log_test.rb +0 -48
  122. data/test/lib/vedeu/log/mono_logger_test.rb +0 -31
  123. data/test/lib/vedeu/log/timer_test.rb +0 -40
  124. data/test/lib/vedeu/models/menu_test.rb +0 -301
  125. data/test/lib/vedeu/models/menus_test.rb +0 -13
  126. data/test/lib/vedeu/output/html_char_test.rb +0 -106
data/lib/vedeu/log/log.rb DELETED
@@ -1,172 +0,0 @@
1
- module Vedeu
2
-
3
- # Provides the ability to log anything to the Vedeu log file.
4
- #
5
- class Log
6
-
7
- class << self
8
-
9
- # Write a message to the Vedeu log file.
10
- #
11
- # @example
12
- # Vedeu.log(type: :debug, message: 'A useful debugging message: Error!')
13
- #
14
- # @param message [String] The message you wish to emit to the log file,
15
- # useful for debugging.
16
- # @param force [Boolean] When evaluates to true will attempt to write to
17
- # the log file regardless of the Configuration setting.
18
- # @param type [Symbol] Colour code messages in the log file depending
19
- # on their source. See {message_types}
20
- #
21
- # @return [TrueClass]
22
- def log(message:, force: false, type: :info)
23
- output = log_entry(type, message)
24
-
25
- if (enabled? || force) && (Vedeu::Configuration.log_only.empty? ||
26
- Vedeu::Configuration.log_only.include?(type))
27
- logger.debug(output)
28
- end
29
-
30
- output
31
- end
32
-
33
- # Write a message to STDOUT.
34
- #
35
- # @example
36
- # Vedeu.log_stdout
37
- #
38
- # @return [TrueClass]
39
- def log_stdout(type: :info, message:)
40
- $stdout.puts log_entry(type, message)
41
- end
42
-
43
- # Write a message to STDERR.
44
- #
45
- # @example
46
- # Vedeu.log_stderr
47
- #
48
- # @return [TrueClass]
49
- def log_stderr(type: :info, message:)
50
- $stderr.puts log_entry(type, message)
51
- end
52
-
53
- private
54
-
55
- # @return [TrueClass]
56
- def logger
57
- MonoLogger.new(log_file).tap do |log|
58
- log.formatter = proc do |_, _, _, message|
59
- formatted_message(message)
60
- end
61
- end
62
- end
63
-
64
- # Returns the message with timestamp.
65
- #
66
- # [ 0.0987] [debug] Something happened.
67
- #
68
- # @param message [String] The message type and message coloured and
69
- # combined.
70
- # @return [String]
71
- def formatted_message(message)
72
- "#{timestamp}#{message}\n" if message
73
- end
74
-
75
- # Returns the message:
76
- #
77
- # [type] message
78
- #
79
- # @param type [Symbol] The type of log message.
80
- # @param message [String] The message you wish to emit to the log file,
81
- # useful for debugging.
82
- # @return [String]
83
- def log_entry(type, message)
84
- "#{message_type(type)}#{message_body(type, message)}"
85
- end
86
-
87
- # Fetches the filename from the configuration.
88
- #
89
- # @return [String]
90
- def log_file
91
- Vedeu::Configuration.log
92
- end
93
- alias_method :enabled?, :log_file
94
-
95
- # Displays the message body using the colour specified in the last element
96
- # of {message_types}.
97
- #
98
- # @param type [Symbol] The type of log message.
99
- # @param body [String] The log message itself.
100
- # @return [String]
101
- def message_body(type, body)
102
- Vedeu::Esc.send(message_types.fetch(type, :default)[-1]) do
103
- body
104
- end
105
- end
106
-
107
- # Displays the message type using the colour specified in the first
108
- # element of {message_types}.
109
- #
110
- # @param type [Symbol] The type of log message.
111
- # @return [String]
112
- def message_type(type)
113
- Vedeu::Esc.send(message_types.fetch(type, :default)[0]) do
114
- "[#{type}]".ljust(9)
115
- end
116
- end
117
-
118
- # The defined message types for Vedeu with their respective colours.
119
- # When used, produces a log entry of the format:
120
- #
121
- # [type] message
122
- #
123
- # The 'type' will be shown as the first colour defined in the value
124
- # array, whilst the 'message' will be shown using the last colour.
125
- #
126
- # Valid types available:
127
- #
128
- # :config, :create, :debug, :error, :drb, :event, :info, :input,
129
- # :output, :reset, :store, :test, :timer, :update
130
- #
131
- # @return [Hash<Symbol => Array<Symbol>>]
132
- def message_types
133
- {
134
- config: [:light_yellow, :yellow],
135
- create: [:light_green, :green],
136
- debug: [:light_red, :red],
137
- error: [:light_red, :red],
138
- drb: [:light_blue, :blue],
139
- event: [:light_magenta, :magenta],
140
- info: [:white, :default],
141
- input: [:light_yellow, :yellow],
142
- output: [:light_green, :green],
143
- reset: [:light_cyan, :cyan],
144
- store: [:light_cyan, :cyan],
145
- test: [:light_white, :white],
146
- timer: [:light_yellow, :yellow],
147
- update: [:light_cyan, :cyan],
148
- }
149
- end
150
-
151
- # Returns a formatted timestamp.
152
- # eg. [137.7824]
153
- #
154
- # @return [String]
155
- def timestamp
156
- @now = Time.now.to_f
157
- @time = 0.0 unless @time
158
- @last = @now unless @last
159
-
160
- unless @last == @time
161
- @time += (@now - @last).round(4)
162
- @last = @now
163
- end
164
-
165
- "[#{format('%7.4f', @time.to_s)}] ".rjust(7)
166
- end
167
-
168
- end # Eigenclass
169
-
170
- end # Log
171
-
172
- end # Vedeu
@@ -1,21 +0,0 @@
1
- module Vedeu
2
-
3
- # Allows the creation of a lock-less log device.
4
- #
5
- class MonoLogger < Logger
6
-
7
- # Create a trappable Logger instance.
8
- #
9
- # @param logdev [String|IO] The filename (String) or IO object (typically
10
- # STDOUT, STDERR or an open file).
11
- # @return [Vedeu::MonoLogger]
12
- def initialize(logdev)
13
- @level = Logger::DEBUG
14
- @default_formatter = Logger::Formatter.new
15
- @formatter = nil
16
- @logdev = Vedeu::LocklessLogDevice.new(logdev) if logdev
17
- end
18
-
19
- end # MonoLogger
20
-
21
- end # Vedeu
@@ -1,63 +0,0 @@
1
- module Vedeu
2
-
3
- # Measure the duration. Used for debugging.
4
- #
5
- class Timer
6
-
7
- class << self
8
-
9
- # @example
10
- # Vedeu.timer 'message' do
11
- # # ... code to be measured
12
- # end
13
- #
14
- # @param message [String]
15
- # @param block [Proc]
16
- # @return [void] The return value of the executed block.
17
- def timer(message = '', &block)
18
- new(message).measure(&block)
19
- end
20
-
21
- end # Eigenclass
22
-
23
- # Returns a new instance of Vedeu::Timer.
24
- #
25
- # @param message [String]
26
- # @return [Vedeu::Timer]
27
- def initialize(message = '')
28
- @message = message
29
- @started = Time.now.to_f
30
- end
31
-
32
- # Write an entry to the log file stating how long a section of code took in
33
- # milliseconds. Useful for debugging performance.
34
- #
35
- # @return [void] The return value of the executed block.
36
- def measure
37
- work = yield
38
-
39
- Vedeu.log(type: :timer, message: "#{message} took #{elapsed}ms.")
40
-
41
- work
42
- end
43
-
44
- protected
45
-
46
- # @!attribute [r] started
47
- # @return [Time]
48
- attr_reader :started
49
-
50
- # @!attribute [r] message
51
- # @return [String]
52
- attr_reader :message
53
-
54
- # Returns the elapsed time in milliseconds with 3 decimal places.
55
- #
56
- # @return [Float]
57
- def elapsed
58
- ((Time.now.to_f - started) * 1000).round(3)
59
- end
60
-
61
- end # Timer
62
-
63
- end # Vedeu
@@ -1,217 +0,0 @@
1
- module Vedeu
2
-
3
- # Converts the collection passed into a list of menu items which can be
4
- # navigated using the instance methods or events provided.
5
- #
6
- class Menu
7
-
8
- include Vedeu::Model
9
-
10
- # @!attribute [rw] collection
11
- # @return [Array]
12
- attr_accessor :collection
13
-
14
- # Returns the index of the value in the collection which is current.
15
- #
16
- # @!attribute [rw] current
17
- # @return [Fixnum]
18
- attr_accessor :current
19
-
20
- # The name of the menu. Used to reference the menu throughout the
21
- # application's execution lifetime.
22
- #
23
- # @!attribute [rw] name
24
- # @return [String]
25
- attr_accessor :name
26
-
27
- # Returns the index of the value in the collection which is selected.
28
- #
29
- # @!attribute [rw] selected
30
- # @return [Fixnum]
31
- attr_accessor :selected
32
-
33
- # Register a menu by name which will display a collection of items for
34
- # your users to select; and provide interactivity within your application.
35
- #
36
- # @param name [String]
37
- # @param block [Proc] A set of attributes which define the features of the
38
- # menu. See {Vedeu::DSL::Menu#items} and {Vedeu::DSL::Menu#name}.
39
- #
40
- # @example
41
- # Vedeu.menu 'my_interface' do
42
- # items [:item_1, :item_2, :item_3]
43
- # # ...
44
- # end
45
- #
46
- # Vedeu.menu do
47
- # name 'menus_must_have_a_name'
48
- # items Track.all_my_favourites
49
- # # ...
50
- # end
51
- #
52
- # @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
53
- # @return [API::Menu]
54
- def self.menu(name = '', &block)
55
- fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?
56
-
57
- build(name: name, &block).store
58
- end
59
-
60
- # Returns a new instance of Vedeu::Menu.
61
- #
62
- # @param attributes [Hash]
63
- # @option attributes collection [Array]
64
- # @option attributes name [String]
65
- # @option attributes current [Fixnum]
66
- # @option attributes selected [Fixnum|NilClass]
67
- # @return [Vedeu::Menu]
68
- def initialize(attributes = {})
69
- @attributes = defaults.merge!(attributes)
70
-
71
- @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
72
- end
73
-
74
- # Returns the item from the collection which shares the same index as the
75
- # value of {Vedeu::Menu#current}.
76
- #
77
- # @return [void]
78
- def current_item
79
- @collection[@current]
80
- end
81
-
82
- # Returns the item from the collection which shares the same index as the
83
- # value of {Vedeu::Menu#selected}.
84
- #
85
- # @return [|NilClass]
86
- def selected_item
87
- return nil unless @selected
88
-
89
- @collection[@selected]
90
- end
91
-
92
- # Returns a new collection of items.
93
- # Each element of the collection is of the format:
94
- #
95
- # [selected, current, item]
96
- #
97
- # `selected` is a boolean indicating whether the item is selected.
98
- # `current` is a boolean indicating whether the item is current.
99
- # `item` is the item itself.
100
- #
101
- # @return [Array]
102
- def items
103
- items = []
104
- @collection.each_with_index do |item, index|
105
- if index == @current && index == @selected
106
- items << [true, true, item]
107
-
108
- elsif index == @current
109
- items << [false, true, item]
110
-
111
- elsif index == @selected
112
- items << [true, false, item]
113
-
114
- else
115
- items << [false, false, item]
116
-
117
- end
118
- end
119
- items
120
- end
121
-
122
- # Returns a subset of all the items.
123
- #
124
- # @return [Array]
125
- def view
126
- items[@current, @collection.size]
127
- end
128
-
129
- # Sets the value of current to be the first item of the collection.
130
- #
131
- # @return [Array]
132
- def top_item
133
- @current = 0
134
-
135
- items
136
- end
137
-
138
- # Sets the value of current to be the last item of the collection.
139
- #
140
- # @return [Array]
141
- def bottom_item
142
- @current = last
143
-
144
- items
145
- end
146
-
147
- # Sets the value of current to be the next item in the collection until we
148
- # reach the last.
149
- #
150
- # @return [Array]
151
- def next_item
152
- @current += 1 if @current < last
153
-
154
- items
155
- end
156
-
157
- # Sets the value of current to be the previous item in the collection until
158
- # we reach the first.
159
- #
160
- # @return [Array]
161
- def prev_item
162
- @current -= 1 if @current > 0
163
-
164
- items
165
- end
166
-
167
- # Sets the selected item to be the same value as the current item.
168
- #
169
- # @return [Array]
170
- def select_item
171
- @selected = @current
172
-
173
- items
174
- end
175
-
176
- # Removes the value of `selected`, meaning no items are selected.
177
- #
178
- # @return [Array]
179
- def deselect_item
180
- @selected = nil
181
-
182
- items
183
- end
184
-
185
- # Returns the last index of the collection.
186
- #
187
- # @return [Fixnum]
188
- def last
189
- @collection.size - 1
190
- end
191
-
192
- # Returns the size of the collection.
193
- #
194
- # @return [Fixnum]
195
- def size
196
- @collection.size
197
- end
198
-
199
- private
200
-
201
- # The default values for a new instance of this class.
202
- #
203
- # @return [Hash]
204
- def defaults
205
- {
206
- client: nil,
207
- collection: [],
208
- current: 0,
209
- name: '',
210
- repository: Vedeu.menus,
211
- selected: nil,
212
- }
213
- end
214
-
215
- end # Menu
216
-
217
- end # Vedeu
@@ -1,14 +0,0 @@
1
- module Vedeu
2
-
3
- # Allows the storing of menus by name.
4
- #
5
- class Menus < Vedeu::Repository
6
-
7
- singleton_class.send(:alias_method, :menus, :repository)
8
-
9
- real Vedeu::Menu
10
- null Vedeu::Null::Menu
11
-
12
- end # Menus
13
-
14
- end # Vedeu
@@ -1,161 +0,0 @@
1
- module Vedeu
2
-
3
- # Represents a {Vedeu::Views::Char} as a HTML tag with value. By default, a
4
- # table cell is used.
5
- #
6
- class HTMLChar
7
-
8
- include Vedeu::Common
9
-
10
- # @param char [Vedeu::Views::Char]
11
- # @param options [Hash<Symbol => String>]
12
- # @option options start_tag [String]
13
- # @option options end_tag [String]
14
- # @return [String]
15
- def self.render(char, options = {})
16
- new(char, options).render
17
- end
18
-
19
- # Returns a new instance of Vedeu::HTMLChar.
20
- #
21
- # @param char [Vedeu::Views::Char]
22
- # @param options [Hash<Symbol => String>]
23
- # @option options start_tag [String]
24
- # @option options end_tag [String]
25
- # @return [Vedeu::HTMLChar]
26
- def initialize(char, options = {})
27
- @char = char
28
- @options = options
29
- end
30
-
31
- # @return [String]
32
- def render
33
- "#{start_tag}#{tag_style}>#{tag_value}#{end_tag}"
34
- end
35
-
36
- protected
37
-
38
- # @!attribute [r] char
39
- # @return [Vedeu::Views::Char]
40
- attr_reader :char
41
-
42
- private
43
-
44
- # @return [String]
45
- def tag_style
46
- return '' unless border || present?(value)
47
-
48
- out = " style='"
49
- out << tag_style_background unless char.background.empty?
50
- out << tag_style_foreground unless char.foreground.empty?
51
- out << "'"
52
- end
53
-
54
- # @return [String]
55
- def tag_style_background
56
- "border:1px #{char.background.to_html} solid;" \
57
- "background:#{char.background.to_html};"
58
- end
59
-
60
- # @return [String]
61
- def tag_style_foreground
62
- "color:#{char.foreground.to_html};#{border_style}"
63
- end
64
-
65
- # @return [String]
66
- def tag_value
67
- return '&nbsp;' if border || !present?(value)
68
-
69
- value
70
- end
71
-
72
- # @return [String]
73
- def border_style
74
- case border
75
- when :top_horizontal then css('top')
76
- when :left_vertical then css('left')
77
- when :right_vertical then css('right')
78
- when :bottom_horizontal then css('bottom')
79
- when :top_left then "#{css('top')}#{css('left')}"
80
- when :top_right then "#{css('top')}#{css('right')}"
81
- when :bottom_left then "#{css('bottom')}#{css('left')}"
82
- when :bottom_right then "#{css('bottom')}#{css('right')}"
83
- else
84
- ''
85
- end
86
- end
87
-
88
- # @return [String]
89
- def css(direction = '')
90
- "border-#{direction}:1px #{char.foreground.to_html} solid;"
91
- end
92
-
93
- # # @return [String]
94
- # def fg
95
- # @fg ||= colour(char, 'foreground', '#222')
96
- # end
97
-
98
- # # @return [String]
99
- # def bg
100
- # @bg ||= colour(char, 'background', '#000')
101
- # end
102
-
103
- # @param char [Vedeu::Views::Char]
104
- # @param type [String] 'background' or 'foreground'
105
- # @param default [String] A default colour (CSS style; e.g. '#b2adf2')
106
- # @return [String]
107
- # def colour(char, type, default)
108
- # parent_type = char.send(:parent).send(type).send(:to_html)
109
- # #parent_type = ('parent_' + type).to_sym
110
- # type_to_html = char.send(type).send(:to_html)
111
- # #parent_type_to_html = char.send(parent_type).send(:to_html)
112
-
113
- # if present?(type_to_html)
114
- # type_to_html
115
-
116
- # elsif char.parent
117
- # parent_type
118
- # #char.parent.send(type).send(:to_html)
119
-
120
- # else
121
- # default
122
-
123
- # end
124
- # end
125
-
126
- # @return [Symbol|NilClass]
127
- def border
128
- char.border
129
- end
130
-
131
- # @return [String]
132
- def value
133
- char.value
134
- end
135
-
136
- # @return [String]
137
- def start_tag
138
- options[:start_tag]
139
- end
140
-
141
- # @return [String]
142
- def end_tag
143
- options[:end_tag]
144
- end
145
-
146
- # @return [Hash<Symbol => String>]
147
- def options
148
- defaults.merge!(@options)
149
- end
150
-
151
- # @return [Hash<Symbol => String>]
152
- def defaults
153
- {
154
- start_tag: '<td',
155
- end_tag: '</td>',
156
- }
157
- end
158
-
159
- end # HTMLChar
160
-
161
- end # Vedeu
@@ -1,32 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
-
5
- describe InputTranslator do
6
-
7
- let(:described) { Vedeu::InputTranslator }
8
- let(:instance) { described.new(code) }
9
- let(:code) {}
10
-
11
- describe '#initialize' do
12
- it { instance.must_be_instance_of(described) }
13
- it { instance.instance_variable_get('@code').must_equal(code) }
14
- end
15
-
16
- describe '.translate' do
17
- context 'when the code is not recognised' do
18
- it { described.translate('a').must_equal('a') }
19
- end
20
-
21
- context 'when the code is recognised' do
22
- it { described.translate("\e[H").must_equal(:home) }
23
- end
24
- end
25
-
26
- describe '#translate' do
27
- it { instance.must_respond_to(:translate) }
28
- end
29
-
30
- end # InputTranslator
31
-
32
- end # Vedeu
@@ -1,35 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
-
5
- describe Debug do
6
-
7
- let(:described) { Vedeu::Debug }
8
-
9
- before do
10
- File.stubs(:open).with('/tmp/profile.html', 'w').returns(:some_code)
11
- end
12
-
13
- describe '.debug' do
14
- let(:filename) { 'profile.html' }
15
- let(:some_code) { :some_code }
16
-
17
- context 'when the block is not given' do
18
- subject { described.debug(filename) }
19
-
20
- it { subject.must_equal(nil) }
21
- end
22
-
23
- context 'when the block is given' do
24
- subject { described.debug(filename) { some_code } }
25
-
26
- it {
27
- ::File.expects(:open).with('/tmp/profile.html', 'w')
28
- subject
29
- }
30
- end
31
- end
32
-
33
- end # Debug
34
-
35
- end # Vedeu