vedeu 0.1.17 → 0.1.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/README.md +17 -3
  4. data/lib/vedeu.rb +12 -7
  5. data/lib/vedeu/api/api.rb +37 -13
  6. data/lib/vedeu/api/composition.rb +1 -6
  7. data/lib/vedeu/api/helpers.rb +2 -0
  8. data/lib/vedeu/api/interface.rb +47 -55
  9. data/lib/vedeu/api/line.rb +6 -0
  10. data/lib/vedeu/api/stream.rb +9 -1
  11. data/lib/vedeu/application.rb +38 -50
  12. data/lib/vedeu/configuration.rb +163 -44
  13. data/lib/vedeu/launcher.rb +3 -6
  14. data/lib/vedeu/models/attributes/background.rb +9 -1
  15. data/lib/vedeu/models/attributes/colour_translator.rb +40 -2
  16. data/lib/vedeu/models/attributes/foreground.rb +9 -1
  17. data/lib/vedeu/models/colour.rb +6 -0
  18. data/lib/vedeu/models/composition.rb +8 -1
  19. data/lib/vedeu/models/geometry.rb +27 -14
  20. data/lib/vedeu/models/interface.rb +59 -0
  21. data/lib/vedeu/models/line.rb +4 -0
  22. data/lib/vedeu/models/stream.rb +10 -0
  23. data/lib/vedeu/models/style.rb +2 -0
  24. data/lib/vedeu/support/buffer.rb +12 -1
  25. data/lib/vedeu/support/buffers.rb +10 -0
  26. data/lib/vedeu/support/clear.rb +4 -0
  27. data/lib/vedeu/support/esc.rb +26 -8
  28. data/lib/vedeu/support/event.rb +28 -0
  29. data/lib/vedeu/support/events.rb +2 -0
  30. data/lib/vedeu/support/focus.rb +14 -6
  31. data/lib/vedeu/support/grid.rb +6 -0
  32. data/lib/vedeu/support/groups.rb +13 -3
  33. data/lib/vedeu/support/input.rb +7 -2
  34. data/lib/vedeu/support/log.rb +7 -1
  35. data/lib/vedeu/support/position.rb +6 -0
  36. data/lib/vedeu/support/render.rb +38 -0
  37. data/lib/vedeu/support/terminal.rb +69 -15
  38. data/lib/vedeu/support/trace.rb +8 -0
  39. data/lib/vedeu/support/view.rb +6 -0
  40. data/test/integration/run_once_test.rb +26 -0
  41. data/test/lib/vedeu/api/api_test.rb +19 -6
  42. data/test/lib/vedeu/api/interface_test.rb +67 -1
  43. data/test/lib/vedeu/api/line_test.rb +10 -0
  44. data/test/lib/vedeu/api/stream_test.rb +8 -0
  45. data/test/lib/vedeu/configuration_test.rb +119 -12
  46. data/test/lib/vedeu/models/attributes/background_test.rb +1 -1
  47. data/test/lib/vedeu/models/attributes/foreground_test.rb +1 -1
  48. data/test/lib/vedeu/models/interface_test.rb +22 -0
  49. data/test/lib/vedeu/support/buffer_test.rb +44 -0
  50. data/test/lib/vedeu/support/events_test.rb +3 -9
  51. data/test/lib/vedeu/support/input_test.rb +1 -0
  52. data/test/lib/vedeu/support/terminal_test.rb +128 -5
  53. data/test/test_helper.rb +2 -2
  54. data/vedeu.gemspec +1 -1
  55. metadata +5 -2
@@ -35,10 +35,14 @@ module Vedeu
35
35
 
36
36
  private
37
37
 
38
+ # @api private
39
+ # @return [String]
38
40
  def data
39
41
  width? ? aligned : text
40
42
  end
41
43
 
44
+ # @api private
45
+ # @return [String]
42
46
  def aligned
43
47
  case align
44
48
  when :right then text.rjust(width, ' ')
@@ -47,10 +51,14 @@ module Vedeu
47
51
  end
48
52
  end
49
53
 
54
+ # @api private
55
+ # @return [TrueClass|FalseClass]
50
56
  def width?
51
57
  !!width
52
58
  end
53
59
 
60
+ # @api private
61
+ # @return [Hash]
54
62
  def defaults
55
63
  {
56
64
  colour: {},
@@ -61,6 +69,8 @@ module Vedeu
61
69
  }
62
70
  end
63
71
 
72
+ # @api private
73
+ # @return []
64
74
  def method_missing(method, *args, &block)
65
75
  @self_before_instance_eval.send(method, *args, &block)
66
76
  end
@@ -16,6 +16,8 @@ module Vedeu
16
16
 
17
17
  private
18
18
 
19
+ # @api private
20
+ # @return [String]
19
21
  def escape_sequences
20
22
  @_sequences ||= if values.nil? || values.empty?
21
23
  ''
@@ -3,7 +3,11 @@ module Vedeu
3
3
 
4
4
  attr_reader :back, :front, :interface
5
5
 
6
- # @param attributes [Hash]
6
+ # @param [Hash] attributes The buffer attributes.
7
+ # @option attributes :back [Hash] The next view to be rendered.
8
+ # @option attributes :front [Hash] The view which is currently on screen.
9
+ # @option attributes :interface [Hash] An attribute form of the interface from
10
+ # which we can create a new front or back.
7
11
  # @return [Buffer]
8
12
  def initialize(attributes = {})
9
13
  @attributes = attributes
@@ -42,14 +46,21 @@ module Vedeu
42
46
 
43
47
  private
44
48
 
49
+ # @api private
50
+ # @param new_attributes [Hash]
51
+ # @return [Buffer]
45
52
  def merge(new_attributes)
46
53
  Buffer.new(@attributes.merge(new_attributes))
47
54
  end
48
55
 
56
+ # @api private
57
+ # @return [TrueClass|FalseClass]
49
58
  def content_available?
50
59
  !!(back)
51
60
  end
52
61
 
62
+ # @api private
63
+ # @return [TrueClass|FalseClass]
53
64
  def no_content_available?
54
65
  front.nil?
55
66
  end
@@ -72,22 +72,32 @@ module Vedeu
72
72
 
73
73
  private
74
74
 
75
+ # @api private
76
+ # @return []
75
77
  def update(name, buffer)
76
78
  buffers.store(name, buffer)
77
79
  end
78
80
 
81
+ # @api private
82
+ # @return [Focus]
79
83
  def focus
80
84
  @_focus ||= Focus.new
81
85
  end
82
86
 
87
+ # @api private
88
+ # @return [Groups]
83
89
  def groups
84
90
  @_groups ||= Groups.new
85
91
  end
86
92
 
93
+ # @api private
94
+ # @return [Hash]
87
95
  def buffers
88
96
  @_buffers ||= {}
89
97
  end
90
98
 
99
+ # @api private
100
+ # @return [Hash]
91
101
  def storage
92
102
  @_storage ||= {}
93
103
  end
@@ -24,10 +24,14 @@ module Vedeu
24
24
 
25
25
  attr_reader :interface
26
26
 
27
+ # @api private
28
+ # @return [String]
27
29
  def colours
28
30
  interface.colour.to_s
29
31
  end
30
32
 
33
+ # @api private
34
+ # @return [Enumerator]
31
35
  def rows
32
36
  interface.viewport_height.times
33
37
  end
@@ -3,10 +3,14 @@ module Vedeu
3
3
 
4
4
  extend self
5
5
 
6
- # @param y [Fixnum]
7
- # @param x [Fixnum]
6
+ # Return the escape sequence required to position the cursor at a particular
7
+ # point on the screen. When passed a block, will do the aforementioned,
8
+ # call the block and then reposition to this location.
9
+ #
10
+ # @param y [Fixnum] The row/line position.
11
+ # @param x [Fixnum] The column/character position.
8
12
  # @param block [Proc]
9
- # @return [String]
13
+ # @return [String]
10
14
  def set_position(y = 1, x = 1, &block)
11
15
  Position.new(y, x).to_s(&block)
12
16
  end
@@ -22,16 +26,30 @@ module Vedeu
22
26
  when 'bold_off' then "\e[22m"
23
27
  when 'clear' then "\e[38;2;39m\e[48;2;49m\e[2J"
24
28
  when 'clear_line' then "\e[38;2;39m\e[48;2;49m\e[2K"
25
- when 'colour_reset' then "\e[38;2;39m\e[48;2;49m"
29
+ when 'colour_reset' then
30
+ [ string('fg_reset'),
31
+ string('bg_reset') ].join
32
+
33
+ when 'dim' then "\e[2m"
26
34
  when 'fg_reset' then "\e[38;2;39m"
27
35
  when 'hide_cursor' then "\e[?25l"
28
- when 'screen_init' then "\e[0m\e[38;2;39m\e[48;2;49m\e[2J\e[?25l"
29
- when 'screen_exit' then "\e[?25h\e[38;2;39m\e[48;2;49m\e[0m"
30
36
  when 'negative' then "\e[7m"
37
+ when 'normal' then
38
+ [ string('underline_off'),
39
+ string('bold_off'),
40
+ string('positive') ].join
41
+
31
42
  when 'positive' then "\e[27m"
32
43
  when 'reset' then "\e[0m"
33
- when 'normal' then "\e[24m\e[22m\e[27m"
34
- when 'dim' then "\e[2m"
44
+ when 'screen_init' then
45
+ [ string('reset'),
46
+ string('clear'),
47
+ string('hide_cursor') ].join
48
+
49
+ when 'screen_exit' then
50
+ [ string('show_cursor'),
51
+ string('colour_reset'),
52
+ string('reset') ].join
35
53
  when 'show_cursor' then "\e[?25h"
36
54
  when 'underline' then "\e[4m"
37
55
  when 'underline_off' then "\e[24m"
@@ -27,6 +27,8 @@ module Vedeu
27
27
  attr_reader :closure
28
28
  attr_accessor :deadline, :executed_at, :now
29
29
 
30
+ # @api private
31
+ # @return []
30
32
  def execute(*args)
31
33
  reset_deadline
32
34
 
@@ -37,12 +39,16 @@ module Vedeu
37
39
  closure.call(*args)
38
40
  end
39
41
 
42
+ # @api private
43
+ # @return [TrueClass|FalseClass]
40
44
  def throttling?
41
45
  set_time
42
46
 
43
47
  options[:delay] > 0
44
48
  end
45
49
 
50
+ # @api private
51
+ # @return [TrueClass|FalseClass]
46
52
  def debouncing?
47
53
  set_time
48
54
 
@@ -51,48 +57,70 @@ module Vedeu
51
57
  options[:debounce] > 0
52
58
  end
53
59
 
60
+ # @api private
61
+ # @return [Float]
54
62
  def elapsed_time
55
63
  now - @executed_at
56
64
  end
57
65
 
66
+ # @api private
67
+ # @return [Float]
58
68
  def set_executed
59
69
  @executed_at = now
60
70
  end
61
71
 
72
+ # @api private
73
+ # @return [Float]
62
74
  def set_time
63
75
  @now = Time.now.to_f
64
76
  end
65
77
 
78
+ # @api private
79
+ # @return [Fixnum]
66
80
  def reset_time
67
81
  @now = 0
68
82
  end
69
83
 
84
+ # @api private
85
+ # @return [TrueClass|FalseClass]
70
86
  def has_deadline?
71
87
  @deadline > 0
72
88
  end
73
89
 
90
+ # @api private
91
+ # @return [Fixnum]
74
92
  def reset_deadline
75
93
  @deadline = 0
76
94
  end
77
95
 
96
+ # @api private
97
+ # @return [NilClass]
78
98
  def set_deadline
79
99
  @deadline = now + debounce
80
100
 
81
101
  nil
82
102
  end
83
103
 
104
+ # @api private
105
+ # @return [Fixnum|Float]
84
106
  def debounce
85
107
  options[:debounce]
86
108
  end
87
109
 
110
+ # @api private
111
+ # @return [Fixnum|Float]
88
112
  def delay
89
113
  options[:delay]
90
114
  end
91
115
 
116
+ # @api private
117
+ # @return [Hash]
92
118
  def options
93
119
  defaults.merge!(@options)
94
120
  end
95
121
 
122
+ # @api private
123
+ # @return [Hash]
96
124
  def defaults
97
125
  {
98
126
  delay: 0,
@@ -56,6 +56,8 @@ module Vedeu
56
56
 
57
57
  attr_reader :handlers
58
58
 
59
+ # @api private
60
+ # @return []
59
61
  def method_missing(method, *args, &block)
60
62
  @self_before_instance_eval.send(method, *args, &block)
61
63
  end
@@ -3,6 +3,7 @@ module Vedeu
3
3
  # Maintains which interface is current in focus.
4
4
  class Focus
5
5
 
6
+ # @return [Focus]
6
7
  def initialize
7
8
  register_events
8
9
 
@@ -10,7 +11,7 @@ module Vedeu
10
11
  end
11
12
 
12
13
  # @param name [String]
13
- # @return []
14
+ # @return [Array]
14
15
  def add(name)
15
16
  if registered?(name)
16
17
  storage
@@ -22,7 +23,7 @@ module Vedeu
22
23
  end
23
24
 
24
25
  # @param name [String]
25
- # @return []
26
+ # @return [String]
26
27
  def by_name(name)
27
28
  fail InterfaceNotFound unless storage.include?(name)
28
29
 
@@ -31,42 +32,49 @@ module Vedeu
31
32
  current
32
33
  end
33
34
 
34
- # @return []
35
+ # @return [String]
35
36
  def current
36
37
  fail NoInterfacesDefined if storage.empty?
37
38
 
38
39
  storage.first
39
40
  end
40
41
 
41
- # @return []
42
+ # @return [String]
42
43
  def next_item
43
44
  storage.rotate!
44
45
 
45
46
  current
46
47
  end
47
48
 
48
- # @return []
49
+ # @return [String]
49
50
  def prev_item
50
51
  storage.rotate!(-1)
51
52
 
52
53
  current
53
54
  end
54
55
 
55
- # @return []
56
+ # @return [TrueClass]
56
57
  def register_events
57
58
  Vedeu.event(:_focus_next_) { next_item }
58
59
  Vedeu.event(:_focus_prev_) { prev_item }
59
60
  Vedeu.event(:_focus_by_name_) { |name| by_name(name) }
61
+ Vedeu.event(:_focussed_) { current }
62
+
63
+ true
60
64
  end
61
65
 
62
66
  private
63
67
 
68
+ # @api private
69
+ # @return [TrueClass|FalseClass]
64
70
  def registered?(name)
65
71
  return false if storage.empty?
66
72
 
67
73
  storage.include?(name)
68
74
  end
69
75
 
76
+ # @api private
77
+ # @return [Array]
70
78
  def storage
71
79
  @storage ||= []
72
80
  end
@@ -42,14 +42,20 @@ module Vedeu
42
42
 
43
43
  attr_reader :value
44
44
 
45
+ # @api private
46
+ # @return [Fixnum]
45
47
  def column
46
48
  actual / 12
47
49
  end
48
50
 
51
+ # @api private
52
+ # @return [Fixnum]
49
53
  def actual
50
54
  Terminal.width
51
55
  end
52
56
 
57
+ # @api private
58
+ # @return [TrueClass|FalseClass]
53
59
  def out_of_range?
54
60
  value < 1 || value > 12
55
61
  end
@@ -26,9 +26,7 @@ module Vedeu
26
26
 
27
27
  storage[group] << name
28
28
 
29
- Vedeu.event("_refresh_group_#{group}_".to_sym, { delay: delay }) do
30
- Buffers.refresh_group(group)
31
- end
29
+ register_group_refresh_event(group, delay)
32
30
 
33
31
  self
34
32
  end
@@ -40,10 +38,22 @@ module Vedeu
40
38
 
41
39
  private
42
40
 
41
+ # @api private
42
+ # @return []
43
+ def register_group_refresh_event(group, delay = 0.0)
44
+ Vedeu.event("_refresh_group_#{group}_".to_sym, { delay: delay }) do
45
+ Buffers.refresh_group(group)
46
+ end
47
+ end
48
+
49
+ # @api private
50
+ # @return [Hash]
43
51
  def storage
44
52
  @_storage ||= in_memory
45
53
  end
46
54
 
55
+ # @api private
56
+ # @return [Hash]
47
57
  def in_memory
48
58
  Hash.new { |hash, key| hash[key] = Set.new }
49
59
  end
@@ -1,12 +1,12 @@
1
1
  module Vedeu
2
2
  class Input
3
3
 
4
- # @return []
4
+ # @return [String|Symbol]
5
5
  def self.capture
6
6
  new.capture
7
7
  end
8
8
 
9
- # @return []
9
+ # @return [Input]
10
10
  def initialize; end
11
11
 
12
12
  # @return []
@@ -16,10 +16,14 @@ module Vedeu
16
16
 
17
17
  private
18
18
 
19
+ # @api private
20
+ # @return [String]
19
21
  def input
20
22
  @_input ||= Terminal.input
21
23
  end
22
24
 
25
+ # @api private
26
+ # @return [String|Symbol]
23
27
  def keypress
24
28
  key = input
25
29
  translated = case key
@@ -35,6 +39,7 @@ module Vedeu
35
39
  when "\e[H" then :home
36
40
  when "\e[3~" then :delete
37
41
  when "\e[F" then :end
42
+ when "\e[Z" then :shift_tab
38
43
  when "\eOP" then :f1
39
44
  when "\eOQ" then :f2
40
45
  when "\eOR" then :f3