vedeu 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d097569d9ae161024a467480aee254bf3ea16db
4
- data.tar.gz: a1f6e430f3a22d102ede5020716dc16a932126ce
3
+ metadata.gz: fd2666b59001c06c50ffd12741aff8bbf24eb926
4
+ data.tar.gz: c0198ab59c679313bc8faa58cb65438a8874e88f
5
5
  SHA512:
6
- metadata.gz: ae5f70b23729b9eb744efac5ed4fcc8182ad9c4738b29b914cfb892a4d15ef83fcb5d04960955f3e8c01979990bf043aa229df1b6e89522260a1e82ccab23645
7
- data.tar.gz: af4164804508dd1dc6cc58c2faf5f2e6248de9d31b62bab1d7fb6c70c0f8fbff09848071a08598280fadfcdc471d58550f45ed051fa6f859dd8da7e2da2b8bf2
6
+ metadata.gz: 6f561391d510a520f2846143e0def865aed71b737b42d9d1c76d310a1f12f96d619b4a8fe0b4cca4192c865b06b4eaf7911dc2321db2a0801d1b96ad8b1141fb
7
+ data.tar.gz: b1456ac646748bbd04cf397dc20286e9ff1408b9a098fed2cbb4722511e516ad8a212dd95c475b68ba900a374549ede282a4d3481af0b58b55b02eb1300ed38b
data/lib/vedeu.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  module Vedeu
2
2
 
3
- EntityNotFound = Class.new(StandardError)
4
- GroupNotFound = Class.new(StandardError)
5
- ModeSwitch = Class.new(StandardError)
6
- NotImplemented = Class.new(StandardError)
7
- OutOfRange = Class.new(StandardError)
3
+ EntityNotFound = Class.new(StandardError)
4
+ GroupNotFound = Class.new(StandardError)
5
+ InterfaceNotFound = Class.new(StandardError)
6
+ ModeSwitch = Class.new(StandardError)
7
+ NoInterfacesDefined = Class.new(StandardError)
8
+ NotImplemented = Class.new(StandardError)
9
+ OutOfRange = Class.new(StandardError)
8
10
 
9
11
  def self.included(receiver)
10
12
  receiver.send(:include, API)
@@ -18,6 +20,7 @@ require 'forwardable'
18
20
  require 'io/console'
19
21
  require 'logger'
20
22
  require 'optparse'
23
+ require 'set'
21
24
 
22
25
  require 'vedeu/configuration'
23
26
 
@@ -3,6 +3,7 @@ module Vedeu
3
3
  class Interface < Vedeu::Interface
4
4
  include Helpers
5
5
 
6
+ # @see Vedeu::API#interface
6
7
  # @param attributes [Hash]
7
8
  # @param block [Proc]
8
9
  # @return []
@@ -10,6 +11,7 @@ module Vedeu
10
11
  new(attributes).define(&block)
11
12
  end
12
13
 
14
+ # @see Vedeu::API#interface
13
15
  # @param block [Proc]
14
16
  #
15
17
  # @example
@@ -1,6 +1,18 @@
1
1
  module Vedeu
2
2
  class ColourTranslator
3
3
 
4
+ # Convert a CSS/HTML colour string into a terminal escape sequence.
5
+ #
6
+ # If provided with an empty value or a string it cannot convert, it will
7
+ # return an empty string.
8
+ #
9
+ # When provided with a named colour, uses the terminal's value for that
10
+ # colour. If a theme is being used with the terminal, which overrides the
11
+ # defaults, then the theme's colour will be used. The recognised names are:
12
+ # :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, :default.
13
+ #
14
+ # TODO: add more documentation
15
+ #
4
16
  # @param colour [String]
5
17
  # @return [String]
6
18
  def self.escape_sequence(colour = '')
@@ -14,6 +26,7 @@ module Vedeu
14
26
  end
15
27
 
16
28
  # @return [String]
29
+ # @see Vedeu::ColourTranslator.escape_sequence
17
30
  def escape_sequence
18
31
  if no_colour?
19
32
  ''
@@ -9,16 +9,23 @@ module Vedeu
9
9
  @attributes = defaults.merge!(attributes)
10
10
  end
11
11
 
12
+ # Converts the `:foreground` attribute into a terminal escape sequence.
13
+ #
12
14
  # @return [String]
13
15
  def foreground
14
16
  @foreground ||= Foreground.escape_sequence(attributes[:foreground])
15
17
  end
16
18
 
19
+ # Converts the `:background` attribute into a terminal escape sequence.
20
+ #
17
21
  # @return [String]
18
22
  def background
19
23
  @background ||= Background.escape_sequence(attributes[:background])
20
24
  end
21
25
 
26
+ # Returns both or either of the converted attributes into a single escape
27
+ # sequence.
28
+ #
22
29
  # @return [String]
23
30
  def to_s
24
31
  foreground + background
@@ -3,6 +3,9 @@ module Vedeu
3
3
 
4
4
  attr_reader :attributes
5
5
 
6
+ # Builds a new composition, which is a collection of interfaces, ready to be
7
+ # rendered to the screen.
8
+ #
6
9
  # @param attributes [Hash]
7
10
  # @param block [Proc]
8
11
  # @return [Hash]
@@ -23,6 +26,9 @@ module Vedeu
23
26
  end
24
27
  end
25
28
 
29
+ # Returns a collection of interface attributes associated with this
30
+ # composition.
31
+ #
26
32
  # @return [Array]
27
33
  def interfaces
28
34
  @interfaces ||= if attributes[:interfaces].nil? || attributes[:interfaces].empty?
@@ -42,6 +48,9 @@ module Vedeu
42
48
  end
43
49
  end
44
50
 
51
+ # Returns the complete escape sequence which this composition renders to.
52
+ # This is used by `Terminal.output` to draw the view.
53
+ #
45
54
  # @return [String]
46
55
  def to_s
47
56
  interfaces.map(&:to_s).join
@@ -13,6 +13,8 @@ module Vedeu
13
13
  @width = @attributes[:width]
14
14
  end
15
15
 
16
+ # Returns the row/line position for the interface.
17
+ #
16
18
  # @return [Fixnum]
17
19
  def y
18
20
  if attributes[:y].is_a?(Proc)
@@ -24,6 +26,8 @@ module Vedeu
24
26
  end
25
27
  end
26
28
 
29
+ # Returns the column position for the interface.
30
+ #
27
31
  # @return [Fixnum]
28
32
  def x
29
33
  if attributes[:x].is_a?(Proc)
@@ -35,6 +39,16 @@ module Vedeu
35
39
  end
36
40
  end
37
41
 
42
+ # Returns a dynamic value calculated from the current terminal width,
43
+ # combined with the desired column start point.
44
+ #
45
+ # If the interface is `centred` then if the terminal resizes, this value
46
+ # should attempt to accommodate that.
47
+ #
48
+ # For uncentred interfaces, when the terminal resizes, then this will help
49
+ # Vedeu render the view to ensure no row/line overruns or that the content
50
+ # is not off-screen.
51
+ #
38
52
  # @return [Fixnum]
39
53
  def viewport_width
40
54
  if (x + width) > Terminal.width
@@ -46,6 +60,15 @@ module Vedeu
46
60
  end
47
61
  end
48
62
 
63
+ # Returns a dynamic value calculated from the current terminal height,
64
+ # combined with the desired row start point.
65
+ #
66
+ # If the interface is `centred` then if the terminal resizes, this value
67
+ # should attempt to accommodate that.
68
+ #
69
+ # For uncentred interfaces, when the terminal resizes, then this will help
70
+ # Vedeu render the view to ensure the content is not off-screen.
71
+ #
49
72
  # @return [Fixnum]
50
73
  def viewport_height
51
74
  if (y + height) > Terminal.height
@@ -26,12 +26,14 @@ module Vedeu
26
26
  return render
27
27
  end
28
28
 
29
+ # @return [Buffer]
29
30
  def render
30
31
  Terminal.output(front.to_s)
31
32
 
32
33
  self
33
34
  end
34
35
 
36
+ # @return [Buffer]
35
37
  def clear
36
38
  Terminal.output(interface.clear)
37
39
 
@@ -10,6 +10,8 @@ module Vedeu
10
10
 
11
11
  groups.add(attributes[:group], attributes[:name], attributes[:delay])
12
12
 
13
+ focus.add(attributes[:name])
14
+
13
15
  store_interface(Interface.new(attributes))
14
16
  end
15
17
 
@@ -62,6 +64,8 @@ module Vedeu
62
64
  groups.find(group_name).map { |name| refresh(name) }
63
65
  end
64
66
 
67
+ # @param name [String]
68
+ # @return []
65
69
  def refresh(name)
66
70
  update(name, retrieve_interface(name).refresh)
67
71
  end
@@ -72,6 +76,10 @@ module Vedeu
72
76
  buffers.store(name, buffer)
73
77
  end
74
78
 
79
+ def focus
80
+ @_focus ||= Focus.new
81
+ end
82
+
75
83
  def groups
76
84
  @_groups ||= Groups.new
77
85
  end
@@ -12,7 +12,7 @@ module Vedeu
12
12
  @now = 0
13
13
  end
14
14
 
15
- # @params args [Array]
15
+ # @param args [Array]
16
16
  # @return []
17
17
  def trigger(*args)
18
18
  return execute(*args) unless debouncing? || throttling?
@@ -45,6 +45,9 @@ module Vedeu
45
45
  handlers[name][:events].each { |event| event.trigger(*args) }
46
46
  end
47
47
 
48
+ # Remove all registered events. Used for testing purposes.
49
+ #
50
+ # @return []
48
51
  def reset
49
52
  @handlers = Hash.new { |hash, key| hash[key] = { events: [] } }
50
53
  end
@@ -1,6 +1,4 @@
1
1
  module Vedeu
2
- NoInterfacesDefined = Class.new(StandardError)
3
- InterfaceNotFound = Class.new(StandardError)
4
2
 
5
3
  # Maintains which interface is current in focus.
6
4
  class Focus
@@ -11,6 +9,8 @@ module Vedeu
11
9
  self
12
10
  end
13
11
 
12
+ # @param name [String]
13
+ # @return []
14
14
  def add(name)
15
15
  if registered?(name)
16
16
  storage
@@ -21,6 +21,8 @@ module Vedeu
21
21
  end
22
22
  end
23
23
 
24
+ # @param name [String]
25
+ # @return []
24
26
  def by_name(name)
25
27
  fail InterfaceNotFound unless storage.include?(name)
26
28
 
@@ -29,24 +31,28 @@ module Vedeu
29
31
  current
30
32
  end
31
33
 
34
+ # @return []
32
35
  def current
33
36
  fail NoInterfacesDefined if storage.empty?
34
37
 
35
38
  storage.first
36
39
  end
37
40
 
41
+ # @return []
38
42
  def next_item
39
43
  storage.rotate!
40
44
 
41
45
  current
42
46
  end
43
47
 
48
+ # @return []
44
49
  def prev_item
45
50
  storage.rotate!(-1)
46
51
 
47
52
  current
48
53
  end
49
54
 
55
+ # @return []
50
56
  def register_events
51
57
  Vedeu.event(:_focus_next_) { next_item }
52
58
  Vedeu.event(:_focus_prev_) { prev_item }
data/vedeu.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'vedeu'
7
- spec.version = '0.1.16'
7
+ spec.version = '0.1.17'
8
8
  spec.authors = ['Gavin Laking']
9
9
  spec.email = ['gavinlaking@gmail.com']
10
10
  spec.summary = %q{A terminal case of wonderland.}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-27 00:00:00.000000000 Z
11
+ date: 2014-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler