vedeu 0.0.29 → 0.0.30

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: 4e83dcfaeb94f1510b47187400a76e5dd8bba17c
4
- data.tar.gz: c53adf0c6ffc23920572cbdd4d34f8290e0286e9
3
+ metadata.gz: fad9751a79b86fc406d103fe1882055758c9ca52
4
+ data.tar.gz: 92d0385d33aee322dd606720acf85e2e892058e2
5
5
  SHA512:
6
- metadata.gz: c929b05c765cbc27391ff4488940675033d0b06786f06a5d85544cc037bfd66d1ee57cfba82bc6ab7b8df0f78f0143986ee362cf58b28a7ff2a3110e3847a087
7
- data.tar.gz: 8b244ea995073d9aa966050cb24064a7614e22232efb8b11bef36cb0d73b04240079336fef9b4adfa462d2495bdc739f0264709eceefb0fb371547c52c0c0d8f
6
+ metadata.gz: 1aa0f28cd2622a96f9bd39b0dfda454efc73e5fc330d6b7387cb74f041bc4b6725ccdd717166311dd4b9c8071b70de6cb50cc40bf6f429bd62a1d797496b9368
7
+ data.tar.gz: 08607e602dfb5d7a89688069dee68e3a34acf8b3a2f8b725f6c3ecbbaddf8fd65004d1c44dae8a088531c08f108973c95c1288cd22d622a3fca5ba57c84b9991
data/README.md CHANGED
@@ -34,6 +34,20 @@ Expect proper documentation soon!
34
34
  keyword: 'quit' }
35
35
  end
36
36
 
37
+
38
+ ### Some Terms
39
+
40
+ To understand how Vedeu works, you need to familiarise yourself with some terms.
41
+
42
+ - Interface: This is an area on the screen where you can take input or direct output. You will define it's colour and style, its dimensions, including position and give it a name. You can then direct the output of a command to this interface and Vedeu will ensure the content is placed there. Interfaces can be layered, allowing pseudo 3D effects (if that floats your boat), or to provide a richer application experience.
43
+
44
+ - Line: An interface is composed of many lines. Their length being the width of the interface and their number being the height of the interface.
45
+
46
+ An interface with `width: 12, height: 5` will have five lines, each made of 12 characters.
47
+
48
+ - Stream: A stream is a subset of a line. Having streams basically allow us to apply styles and colours to part of a line; their not necessary, but provide you with greater flexibility for your output.
49
+
50
+
37
51
  ### On Defining Interfaces
38
52
 
39
53
  interface :main, {
@@ -83,7 +97,18 @@ Geometry for Vedeu, as the same for ANSI terminals, is set top-left, which is po
83
97
 
84
98
  ### Colours
85
99
 
86
- Vedeu uses HTML/CSS style notation (i.e. '#aadd00').
100
+ Vedeu uses HTML/CSS style notation (i.e. '#aadd00'), they can be used at the stream level, the line level or for the whole interface.
101
+
102
+ "colour": { "foreground": "#ff0000", "background": "#ffffff" }
103
+
104
+
105
+ ### Styles
106
+
107
+ Vedeu has a range of symbol styles which are compatible with most terminals which are ANSI compatible.
108
+
109
+ "style": []
110
+
111
+ Like colours, they can be defined in either interfaces, for specific lines or within streams. Styles are applied as encountered.
87
112
 
88
113
 
89
114
  ### Layers
@@ -97,7 +122,7 @@ Vedeu uses two rules.
97
122
 
98
123
  ## Contributing
99
124
 
100
- 1. Fork it ( http://github.com/<my-github-username>/vedeu/fork )
125
+ 1. Fork it ( http://github.com/gavinlaking/vedeu/fork )
101
126
  2. Clone it
102
127
  3. `bundle`
103
128
  4. `rake` or `bundle exec guard`
@@ -28,8 +28,10 @@ module Vedeu
28
28
  def runner
29
29
  if interactive?
30
30
  interactive { yield }
31
+
31
32
  else
32
33
  run_once { yield }
34
+
33
35
  end
34
36
  end
35
37
 
@@ -18,14 +18,24 @@ module Vedeu
18
18
  interface.enqueue(interface.to_s)
19
19
  interface
20
20
  end
21
+
22
+ self
21
23
  end
22
24
 
23
25
  def to_json
24
- Oj.dump(attributes, mode: :compat)
26
+ Oj.dump(json_attributes, mode: :compat)
25
27
  end
26
28
 
27
29
  def to_s
28
30
  interfaces.map(&:to_s).join
29
31
  end
32
+
33
+ private
34
+
35
+ def json_attributes
36
+ {
37
+ interfaces: interfaces
38
+ }
39
+ end
30
40
  end
31
41
  end
@@ -4,7 +4,6 @@ require_relative 'presentation'
4
4
  require_relative 'line_collection'
5
5
  require_relative '../output/interface_renderer'
6
6
  require_relative '../support/esc'
7
- require_relative '../support/cursor'
8
7
  require_relative '../support/queue'
9
8
  require_relative '../support/terminal'
10
9
 
@@ -38,7 +37,7 @@ module Vedeu
38
37
  end
39
38
 
40
39
  def to_json
41
- Oj.dump(attributes, mode: :compat)
40
+ Oj.dump(json_attributes, mode: :compat)
42
41
  end
43
42
 
44
43
  def to_s
@@ -58,5 +57,20 @@ module Vedeu
58
57
  def clear_interface
59
58
  InterfaceRenderer.clear(self)
60
59
  end
60
+
61
+ def json_attributes
62
+ {
63
+ colour: colour, # TODO: translate back?
64
+ style: style,
65
+ name: name,
66
+ lines: lines,
67
+ y: y,
68
+ x: x,
69
+ z: z,
70
+ width: width,
71
+ height: height,
72
+ cursor: cursor
73
+ }
74
+ end
61
75
  end
62
76
  end
@@ -1,23 +1,14 @@
1
1
  require 'virtus'
2
2
 
3
3
  require_relative '../repository/interface_repository'
4
- require_relative 'coercions'
5
4
 
6
5
  module Vedeu
7
6
  class InterfaceCollection < Virtus::Attribute
8
- include Coercions
9
-
10
7
  def coerce(values)
11
- return [] if empty?(values)
12
-
13
- if multiple?(values)
14
- values.map do |value|
15
- InterfaceRepository.update(value[:name], value)
16
- end
17
-
18
- elsif single?(values)
19
- [InterfaceRepository.update(values[:name], values)]
8
+ return [] if values.nil? || values.empty?
20
9
 
10
+ [values].flatten.map do |value|
11
+ InterfaceRepository.update(value.fetch(:name, nil), value)
21
12
  end
22
13
  end
23
14
  end
@@ -9,14 +9,25 @@ module Vedeu
9
9
  include Virtus.model
10
10
  include Presentation
11
11
 
12
+ attribute :model, Hash
12
13
  attribute :streams, StreamCollection
13
14
 
14
15
  def to_json
15
- Oj.dump(attributes, mode: :compat)
16
+ Oj.dump(json_attributes, mode: :compat)
16
17
  end
17
18
 
18
19
  def to_s
19
20
  [colour, style, streams].join
20
21
  end
22
+
23
+ private
24
+
25
+ def json_attributes
26
+ {
27
+ colour: colour,
28
+ style: style,
29
+ streams: streams
30
+ }
31
+ end
21
32
  end
22
33
  end
@@ -1,26 +1,18 @@
1
1
  require 'virtus'
2
2
 
3
3
  require_relative 'line'
4
- require_relative 'coercions'
5
4
 
6
5
  module Vedeu
7
- class InvalidLine < StandardError; end
8
-
9
6
  class LineCollection < Virtus::Attribute
10
- include Coercions
11
-
12
7
  def coerce(values)
13
- return [] if empty?(values)
14
-
15
- if multiple?(values)
16
- values.map { |v| Line.new(v) }
8
+ return [] if values.nil? || values.empty?
17
9
 
18
- elsif single?(values)
19
- [Line.new(values)]
20
-
21
- elsif just_text?(values)
10
+ if values.is_a?(::String)
22
11
  [Line.new({ streams: values })]
23
12
 
13
+ else
14
+ [values].flatten.map { |value| Line.new(value) }
15
+
24
16
  end
25
17
  end
26
18
  end
@@ -11,11 +11,21 @@ module Vedeu
11
11
  attribute :text, String, default: ''
12
12
 
13
13
  def to_json
14
- Oj.dump(attributes, mode: :compat)
14
+ Oj.dump(json_attributes, mode: :compat)
15
15
  end
16
16
 
17
17
  def to_s(options = {})
18
18
  [colour, style, text].join
19
19
  end
20
+
21
+ private
22
+
23
+ def json_attributes
24
+ {
25
+ colour: colour,
26
+ style: style,
27
+ text: text
28
+ }
29
+ end
20
30
  end
21
31
  end
@@ -1,26 +1,18 @@
1
1
  require 'virtus'
2
2
 
3
3
  require_relative 'stream'
4
- require_relative 'coercions'
5
4
 
6
5
  module Vedeu
7
- class InvalidStream < StandardError; end
8
-
9
6
  class StreamCollection < Virtus::Attribute
10
- include Coercions
11
-
12
7
  def coerce(values)
13
- return [] if empty?(values)
14
-
15
- if multiple?(values)
16
- values.map { |v| Stream.new(v) }
8
+ return [] if values.nil? || values.empty?
17
9
 
18
- elsif single?(values)
19
- [Stream.new(values)]
20
-
21
- elsif values.is_a?(String)
10
+ if values.is_a?(::String)
22
11
  [Stream.new({ text: values })]
23
12
 
13
+ else
14
+ [values].flatten.map { |value| Stream.new(value) }
15
+
24
16
  end
25
17
  end
26
18
  end
@@ -1,21 +1,17 @@
1
1
  require 'virtus'
2
2
 
3
- require_relative '../support/cursor'
4
3
  require_relative '../support/esc'
5
- require_relative 'coercions'
6
4
 
7
5
  module Vedeu
8
6
  class StyleCollection < Virtus::Attribute
9
- include Coercions
10
-
11
7
  def coerce(values)
12
- return '' if empty?(values)
8
+ return '' if values.nil? || values.empty?
13
9
 
14
- if multiple?(values)
15
- values.map { |value| Esc.stylize(value) }.join
10
+ if values.is_a?(::Array)
11
+ values.map { |value| Esc.string(value) }.join
16
12
 
17
- elsif just_text?(values)
18
- Esc.stylize(values)
13
+ elsif values.is_a?(::String)
14
+ Esc.string(values)
19
15
 
20
16
  end
21
17
  end
@@ -2,12 +2,8 @@ require_relative '../repository/interface_repository'
2
2
  require_relative '../support/terminal'
3
3
 
4
4
  module Vedeu
5
- class Output
6
- def self.render
7
- new.render
8
- end
9
-
10
- def initialize; end
5
+ module Output
6
+ extend self
11
7
 
12
8
  def render
13
9
  InterfaceRepository.refresh.each do |interface|
@@ -22,10 +22,6 @@ module Vedeu
22
22
  adaptor.create(model)
23
23
  end
24
24
 
25
- def delete(model)
26
- adaptor.delete(model)
27
- end
28
-
29
25
  def reset
30
26
  adaptor.reset(entity)
31
27
  end
@@ -1,4 +1,3 @@
1
- require_relative 'cursor'
2
1
  require_relative 'terminal'
3
2
  require_relative 'translator'
4
3
 
@@ -7,102 +6,49 @@ module Vedeu
7
6
  extend self
8
7
 
9
8
  def background_colour(value = '#000000')
10
- [esc, '48;5;', colour_translator(value), 'm'].join
11
- end
12
-
13
- def blink
14
- [esc, '5m'].join
15
- end
16
-
17
- def blink_off
18
- [esc, '25m'].join
19
- end
20
-
21
- def bold
22
- [esc, '1m'].join
23
- end
24
-
25
- def bold_off
26
- [esc, '21m'].join
27
- end
28
-
29
- def clear
30
- [esc, '2J'].join
9
+ ["\e[48;5;", colour_translator(value), 'm'].join
31
10
  end
32
11
 
33
12
  def clear_line
34
- [esc, '2K'].join
13
+ "\e[2K"
35
14
  end
36
15
 
37
- def clear_last_line()
16
+ def clear_last_line
38
17
  set_position((Terminal.height - 1), 1) + clear_line
39
18
  end
40
19
 
41
- # def cursor(value)
42
- # Cursor.
43
- # end
44
-
45
- def esc
46
- [27.chr, '['].join
47
- end
48
-
49
20
  def foreground_colour(value = '#ffffff')
50
- [esc, '38;5;', colour_translator(value), 'm'].join
51
- end
52
- #
53
- def negative
54
- [esc, '7m'].join
55
- end
56
-
57
- def positive
58
- [esc, '27m'].join
59
- end
60
-
61
- def normal
62
- [underline_off, bold_off, positive].join
63
- end
64
-
65
- def dim
66
- [esc, '2m'].join
67
- end
68
-
69
- def reset
70
- [esc, '0m'].join
21
+ ["\e[38;5;", colour_translator(value), 'm'].join
71
22
  end
72
23
 
73
24
  def set_position(y = 1, x = 1)
74
- [esc, ((y == 0 || y == nil) ? 1 : y), ';', ((x == 0 || x == nil) ? 1 : x), 'H'].join
25
+ row = (y == 0 || y == nil) ? 1 : y
26
+ column = (x == 0 || x == nil) ? 1 : x
27
+
28
+ ["\e[", row, ';', column, 'H'].join
75
29
  end
76
30
 
77
- def stylize(value = 'normal')
31
+ def string(value = 'normal')
78
32
  case value
79
- when 'blink' then blink
80
- when 'blink_off' then blink_off
81
- when 'bold' then bold
82
- when 'bold_off' then bold_off
83
- when 'clear' then clear
84
- when 'hide_cursor' then Cursor.hide
85
- when 'negative' then negative
86
- when 'positive' then positive
87
- when 'reset' then reset
88
- when 'normal' then normal
89
- when 'dim' then dim
90
- when 'show_cursor' then Cursor.show
91
- when 'underline' then underline
92
- when 'underline_off' then underline_off
33
+ when 'blink' then "\e[5m"
34
+ when 'blink_off' then "\e[25m"
35
+ when 'bold' then "\e[1m"
36
+ when 'bold_off' then "\e[21m"
37
+ when 'clear' then "\e[2J"
38
+ when 'hide_cursor' then "\e[?25l"
39
+ when 'negative' then "\e[7m"
40
+ when 'positive' then "\e[27m"
41
+ when 'reset' then "\e[0m"
42
+ when 'normal' then "\e[24m\e[21m\e[27m"
43
+ when 'dim' then "\e[2m"
44
+ when 'show_cursor' then "\e[?25h"
45
+ when 'underline' then "\e[4m"
46
+ when 'underline_off' then "\e[24m"
93
47
  else
94
48
  ''
95
49
  end
96
50
  end
97
51
 
98
- def underline
99
- [esc, '4m'].join
100
- end
101
-
102
- def underline_off
103
- [esc, '24m'].join
104
- end
105
-
106
52
  private
107
53
 
108
54
  def colour_translator(value)