vedeu 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +0 -1
  4. data/Guardfile +0 -8
  5. data/README.md +33 -1
  6. data/Rakefile +0 -8
  7. data/bin/vedeu +9 -0
  8. data/lib/vedeu.rb +23 -6
  9. data/lib/vedeu/application.rb +47 -0
  10. data/lib/vedeu/interface/interface.rb +37 -0
  11. data/lib/vedeu/interface/interfaces.rb +49 -0
  12. data/lib/vedeu/output/background.rb +23 -0
  13. data/lib/vedeu/output/base.rb +49 -0
  14. data/lib/vedeu/output/colour.rb +30 -0
  15. data/lib/vedeu/output/compositor.rb +60 -0
  16. data/lib/vedeu/output/directive.rb +34 -0
  17. data/lib/vedeu/output/esc.rb +37 -0
  18. data/lib/vedeu/output/foreground.rb +23 -0
  19. data/lib/vedeu/output/position.rb +22 -0
  20. data/lib/vedeu/output/style.rb +32 -0
  21. data/lib/vedeu/output/translator.rb +62 -0
  22. data/lib/vedeu/process/command.rb +51 -0
  23. data/lib/vedeu/process/commands.rb +58 -0
  24. data/lib/vedeu/process/process.rb +31 -0
  25. data/lib/vedeu/support/terminal.rb +139 -0
  26. data/lib/vedeu/version.rb +1 -1
  27. data/test/lib/vedeu/application_test.rb +18 -0
  28. data/test/lib/vedeu/interface/interface_test.rb +76 -0
  29. data/test/lib/vedeu/interface/interfaces_test.rb +63 -0
  30. data/test/lib/vedeu/output/background_test.rb +10 -0
  31. data/test/lib/vedeu/output/base_test.rb +10 -0
  32. data/test/lib/vedeu/output/colour_test.rb +67 -0
  33. data/test/lib/vedeu/output/compositor_test.rb +106 -0
  34. data/test/lib/vedeu/output/directive_test.rb +55 -0
  35. data/test/lib/vedeu/output/esc_test.rb +71 -0
  36. data/test/lib/vedeu/output/foreground_test.rb +10 -0
  37. data/test/lib/vedeu/output/position_test.rb +33 -0
  38. data/test/lib/vedeu/output/style_test.rb +59 -0
  39. data/test/lib/vedeu/output/translator_test.rb +52 -0
  40. data/test/lib/vedeu/process/command_test.rb +54 -0
  41. data/test/lib/vedeu/process/commands_test.rb +62 -0
  42. data/test/lib/vedeu/process/process_test.rb +11 -0
  43. data/test/lib/vedeu/support/terminal_test.rb +140 -0
  44. data/test/lib/vedeu/version_test.rb +9 -0
  45. data/test/support/test_app/bin/testapp +32 -0
  46. data/test/test_helper.rb +4 -0
  47. data/vedeu.gemspec +0 -6
  48. metadata +60 -99
  49. data/.rubocop.yml +0 -2
  50. data/features/.gitkeep +0 -0
  51. data/lib/vedeu/buffer.rb +0 -106
  52. data/lib/vedeu/colour.rb +0 -98
  53. data/lib/vedeu/terminal.rb +0 -25
  54. data/test/lib/vedeu/buffer_test.rb +0 -114
  55. data/test/lib/vedeu/colour_test.rb +0 -57
  56. data/test/lib/vedeu/terminal_test.rb +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7b69828438f5c4c2e1f77d6e896bbbfd457b274
4
- data.tar.gz: ee12ce2adccea5c742fa57481244ddcbe5361c51
3
+ metadata.gz: 2a1399f6a76d69ccbe0719a7b5fe44e830f875df
4
+ data.tar.gz: e12da3c72a4206b001e7e4edcebf92184bf16cfa
5
5
  SHA512:
6
- metadata.gz: b295f951023c13aac3d7a15982c8f9537d9bf44b8e3431b7019950baac7d90ec78f94efcac5549933d7e749b7ff2da2532079727bf5cf70c58281e5ac537c2ee
7
- data.tar.gz: 81a59ef69bdb6bea4e16d05b4beaa8f5723de52e651454ea54b22bfeea517c30553b92d4ff79a9b04b657e8acd478f66ab0df3deae6ac77fdf53d6e6920df05f
6
+ metadata.gz: 3ed55f709b264fea16d85ced18e5b39db468fa0a7e190ef0e05dd46fef640561d83f08efa634e97e498c92175aa042d21458f3609639795761892f376df16fcf
7
+ data.tar.gz: aad70ea8b6d3486cfeabebf1227b779553dcf224ffc6232e47d5b292515ea86a6eabc9b6a03a18e2433c7ef8f12ee367291beea132f264c68b2d00971eefbbe8
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .DS_Store
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
@@ -17,4 +18,4 @@ test/version_tmp
17
18
  tmp
18
19
  .gemtags
19
20
  .tags
20
- .tags_sorted_by_file
21
+ .tags_sorted_by_file
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in vedeu.gemspec
4
3
  gemspec
data/Guardfile CHANGED
@@ -1,11 +1,3 @@
1
- guard 'cucumber' do
2
- watch(%r{^features/.+\.feature$})
3
- watch(%r{^features/support/.+$}) { 'features' }
4
- watch(%r{^features/step_definitions/(.+)_steps\.rb$}) do |m|
5
- Dir[File.join("**/#{m[1]}.feature")][0] || 'features'
6
- end
7
- end
8
-
9
1
  guard :minitest, all_after_pass: true do
10
2
  watch(%r{^test/(.*)_test\.rb})
11
3
  watch(%r{^lib/(.+)\.rb}) do |m|
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Code Climate](https://codeclimate.com/github/gavinlaking/vedeu.png)](https://codeclimate.com/github/gavinlaking/vedeu)
2
+
1
3
  # Vedeu
2
4
 
3
5
  TODO: Write a gem description
@@ -18,7 +20,37 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ TODO: Write detailed documentation
24
+
25
+ ## Notes
26
+
27
+ Application
28
+ |-- Interfaces
29
+ | |-- Dummy < Interface
30
+ |
31
+ |-- Terminal
32
+ |-- Esc
33
+ |-- Colour
34
+
35
+ Base
36
+ |-- Translator
37
+ |-- Esc
38
+ |-- Colour
39
+
40
+ Compositor
41
+ |-- Colour
42
+ | |-- Foreground < Base
43
+ | |-- Background < Base
44
+ | |-- Translator
45
+ |
46
+ |-- Esc
47
+ |-- Colour
48
+
49
+ Interface
50
+ |-- Terminal
51
+ |-- Esc
52
+ |-- Colour
53
+
22
54
 
23
55
  ## Contributing
24
56
 
data/Rakefile CHANGED
@@ -1,11 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
- require 'cucumber'
4
- require 'cucumber/rake/task'
5
-
6
- Cucumber::Rake::Task.new(:cucumber) do |t|
7
- t.cucumber_opts = "features --format progress"
8
- end
9
3
 
10
4
  Rake::TestTask.new do |t|
11
5
  t.libs << 'lib/vedeu'
@@ -15,5 +9,3 @@ Rake::TestTask.new do |t|
15
9
  end
16
10
 
17
11
  task :default => :test
18
-
19
- Rake::Task['cucumber'].execute
data/bin/vedeu ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
+
4
+ -> { its -> { a } }
5
+ trap('INT') { exit! }
6
+
7
+ require 'vedeu'
8
+
9
+ Vedeu::Application.new(nil).start
data/lib/vedeu.rb CHANGED
@@ -1,8 +1,25 @@
1
1
  require 'io/console'
2
- require "vedeu/version"
3
- require 'vedeu/buffer'
4
- require 'vedeu/colour'
5
- require 'vedeu/terminal'
2
+ require 'singleton'
6
3
 
7
- module Vedeu
8
- end
4
+ require_relative 'vedeu/support/terminal'
5
+
6
+ require_relative 'vedeu/output/base'
7
+ require_relative 'vedeu/output/background'
8
+ require_relative 'vedeu/output/compositor'
9
+ require_relative 'vedeu/output/directive'
10
+ require_relative 'vedeu/output/foreground'
11
+ require_relative 'vedeu/output/esc'
12
+ require_relative 'vedeu/output/colour'
13
+ require_relative 'vedeu/output/position'
14
+ require_relative 'vedeu/output/style'
15
+ require_relative 'vedeu/output/translator'
16
+
17
+ require_relative 'vedeu/interface/interfaces'
18
+ require_relative 'vedeu/interface/interface'
19
+
20
+ require_relative 'vedeu/process/commands'
21
+ require_relative 'vedeu/process/command'
22
+ require_relative 'vedeu/process/process'
23
+
24
+ require_relative 'vedeu/application'
25
+ require_relative 'vedeu/version'
@@ -0,0 +1,47 @@
1
+ module Vedeu
2
+ class Application
3
+ class << self
4
+ def start(interfaces = nil, options = {}, &block)
5
+ new(interfaces, options).start(&block)
6
+ end
7
+ end
8
+
9
+ def initialize(interfaces = nil, options = {})
10
+ @interfaces, @options = interfaces, options
11
+ end
12
+
13
+ def start(&block)
14
+ if block_given?
15
+
16
+ else
17
+ Terminal.open(options) do
18
+ initial_state
19
+
20
+ Process.event_loop
21
+ end
22
+ end
23
+ ensure
24
+ Terminal.close
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :options
30
+
31
+ def initial_state
32
+ interfaces.initial
33
+ end
34
+
35
+ def interfaces
36
+ @interfaces ||= Interfaces.default
37
+ end
38
+
39
+ def options
40
+ defaults.merge!(@options)
41
+ end
42
+
43
+ def defaults
44
+ {}
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,37 @@
1
+ module Vedeu
2
+ class Interface
3
+ def initialize(options = {})
4
+ @options = options
5
+ end
6
+
7
+ def initial; end
8
+
9
+ def main
10
+ output
11
+
12
+ input
13
+ end
14
+
15
+ def output
16
+ Terminal.hide_cursor
17
+ end
18
+
19
+ def input
20
+ Terminal.show_cursor
21
+ end
22
+
23
+ def width
24
+ options[:width] || Terminal.width
25
+ end
26
+
27
+ def height
28
+ options[:height] || Terminal.height
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :options
34
+ end
35
+
36
+ class Dummy < Interface; end
37
+ end
@@ -0,0 +1,49 @@
1
+ module Vedeu
2
+ class UndefinedInterface < StandardError; end
3
+
4
+ class Interfaces
5
+ class << self
6
+ def default
7
+ new { |io| io.add(:dummy, Dummy) }
8
+ end
9
+
10
+ def define(&block)
11
+ new(&block)
12
+ end
13
+ end
14
+
15
+ def initialize(&block)
16
+ @interfaces ||= {}
17
+
18
+ yield self if block_given?
19
+ end
20
+
21
+ def add(name, klass, options = {})
22
+ if valid?(klass)
23
+ interfaces[name] = Proc.new { klass.new(options) }
24
+ interfaces
25
+ end
26
+ end
27
+
28
+ def show
29
+ interfaces
30
+ end
31
+
32
+ def initial
33
+ interfaces.values.map { |io| io.call.initial }
34
+ end
35
+
36
+ def main
37
+ interfaces.values.map { |io| io.call.main }
38
+ end
39
+
40
+ private
41
+
42
+ attr_accessor :interfaces
43
+
44
+ def valid?(klass)
45
+ raise UndefinedInterface unless Object.const_defined?(klass.to_s)
46
+ true
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,23 @@
1
+ module Vedeu
2
+ class Background < Base
3
+ private
4
+
5
+ def prefix
6
+ '48;5;'
7
+ end
8
+
9
+ def codes
10
+ {
11
+ black: 40,
12
+ red: 41,
13
+ green: 42,
14
+ yellow: 43,
15
+ blue: 44,
16
+ magenta: 45,
17
+ cyan: 46,
18
+ white: 47,
19
+ default: 49,
20
+ }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,49 @@
1
+ module Vedeu
2
+ class Base
3
+ class << self
4
+ def escape_sequence(colour = nil)
5
+ new(colour).escape_sequence
6
+ end
7
+ end
8
+
9
+ def initialize(colour = nil)
10
+ @colour = colour
11
+ end
12
+
13
+ def escape_sequence
14
+ [Esc.esc, prefix, code, suffix].join
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :colour
20
+
21
+ def code
22
+ no_colour || named || html || default
23
+ end
24
+
25
+ def no_colour
26
+ default unless colour
27
+ end
28
+
29
+ def named
30
+ codes[colour] || codes[:default] if named?
31
+ end
32
+
33
+ def named?
34
+ colour.is_a?(Symbol)
35
+ end
36
+
37
+ def html
38
+ Translator.translate(colour)
39
+ end
40
+
41
+ def default
42
+ codes[:default]
43
+ end
44
+
45
+ def suffix
46
+ 'm'
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,30 @@
1
+ module Vedeu
2
+ class Colour
3
+ class << self
4
+ def define(pair = [])
5
+ new(pair).define
6
+ end
7
+ alias_method :set, :define
8
+ end
9
+
10
+ def initialize(pair = [])
11
+ @pair = pair
12
+ end
13
+
14
+ def define
15
+ [foreground, background].join
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :pair
21
+
22
+ def foreground
23
+ Foreground.escape_sequence(pair[0])
24
+ end
25
+
26
+ def background
27
+ Background.escape_sequence(pair[1])
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,60 @@
1
+ module Vedeu
2
+ class Compositor
3
+ class << self
4
+ def write(output = [], options = {})
5
+ return if output.nil? || output.empty?
6
+
7
+ new(output, options).write
8
+ end
9
+ end
10
+
11
+ def initialize(output = [], options = {})
12
+ @output, @options = output, options
13
+ end
14
+
15
+ def write
16
+ parsed.each_with_index do |data, index|
17
+ clear_line(index)
18
+
19
+ write_line(data)
20
+ end.join("\n")
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :output
26
+
27
+ def parsed
28
+ container = []
29
+ streams = []
30
+ output.map do |line|
31
+ line.map do |stream|
32
+ if stream.is_a?(String)
33
+ streams << stream
34
+ else
35
+ streams << Directive.enact(stream)
36
+ end
37
+ end
38
+ container << streams.join
39
+ streams = []
40
+ end
41
+ container
42
+ end
43
+
44
+ def clear_line(index)
45
+ Terminal.clear_line(index)
46
+ end
47
+
48
+ def write_line(data)
49
+ Terminal.output(data)
50
+ end
51
+
52
+ def options
53
+ defaults.merge!(@options)
54
+ end
55
+
56
+ def defaults
57
+ {}
58
+ end
59
+ end
60
+ end