vedeu 0.0.10 → 0.0.11

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/README.md +21 -2
  3. data/Rakefile +8 -0
  4. data/bin/vedeu +1 -1
  5. data/config/cucumber.yml +8 -0
  6. data/features/getting_started.feature +10 -0
  7. data/features/step_definitions/vedeu_steps.rb +11 -0
  8. data/features/support/env.rb +12 -0
  9. data/lib/vedeu.rb +30 -9
  10. data/lib/vedeu/application.rb +1 -1
  11. data/lib/vedeu/launcher.rb +26 -0
  12. data/lib/vedeu/output/colour.rb +1 -1
  13. data/lib/vedeu/output/compositor.rb +9 -6
  14. data/lib/vedeu/output/directive.rb +1 -1
  15. data/lib/vedeu/output/geometry.rb +1 -1
  16. data/lib/vedeu/output/position.rb +2 -2
  17. data/lib/vedeu/output/style.rb +1 -1
  18. data/lib/vedeu/output/wordwrap.rb +2 -1
  19. data/lib/vedeu/process/event_loop.rb +2 -2
  20. data/lib/vedeu/process/input.rb +30 -0
  21. data/lib/vedeu/repository/command.rb +32 -0
  22. data/lib/vedeu/repository/command_repository.rb +27 -0
  23. data/lib/vedeu/{process → repository}/dummy_command.rb +2 -2
  24. data/lib/vedeu/repository/dummy_interface.rb +4 -0
  25. data/lib/vedeu/repository/interface.rb +52 -0
  26. data/lib/vedeu/repository/interface_repository.rb +49 -0
  27. data/lib/vedeu/repository/repository.rb +35 -0
  28. data/lib/vedeu/repository/storage.rb +46 -0
  29. data/lib/vedeu/support/terminal.rb +5 -6
  30. data/lib/vedeu/version.rb +1 -1
  31. data/test/lib/vedeu/application_test.rb +1 -1
  32. data/test/lib/vedeu/output/compositor_test.rb +15 -13
  33. data/test/lib/vedeu/output/directive_test.rb +1 -1
  34. data/test/lib/vedeu/output/position_test.rb +1 -1
  35. data/test/lib/vedeu/process/event_loop_test.rb +2 -3
  36. data/test/lib/vedeu/process/input_test.rb +19 -0
  37. data/test/lib/vedeu/repository/command_repository_test.rb +55 -0
  38. data/test/lib/vedeu/repository/command_test.rb +39 -0
  39. data/test/lib/vedeu/repository/interface_repository_test.rb +71 -0
  40. data/test/lib/vedeu/repository/interface_test.rb +65 -0
  41. data/test/lib/vedeu/repository/repository_test.rb +88 -0
  42. data/test/lib/vedeu/repository/storage_test.rb +50 -0
  43. data/test/test_helper.rb +8 -0
  44. data/vedeu.gemspec +3 -0
  45. metadata +75 -21
  46. data/lib/vedeu/interface/dummy_interface.rb +0 -14
  47. data/lib/vedeu/interface/interface.rb +0 -57
  48. data/lib/vedeu/interface/interfaces.rb +0 -66
  49. data/lib/vedeu/process/command.rb +0 -51
  50. data/lib/vedeu/process/commands.rb +0 -35
  51. data/test/lib/vedeu/interface/dummy_test.rb +0 -22
  52. data/test/lib/vedeu/interface/interface_test.rb +0 -45
  53. data/test/lib/vedeu/interface/interfaces_test.rb +0 -108
  54. data/test/lib/vedeu/process/command_test.rb +0 -48
  55. data/test/lib/vedeu/process/commands_test.rb +0 -56
  56. data/test/lib/vedeu/process/dummy_command_test.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f3422a6093ab6c6c7cf502bc9cec28cb3834d84
4
- data.tar.gz: c42685a3bdb1aa694e46665daccc70355e949ef3
3
+ metadata.gz: 91075694e8c8b20c64f154ab41f71176a871ca64
4
+ data.tar.gz: 1637599541bcad4e9895c55d58e2a180a0fe8f06
5
5
  SHA512:
6
- metadata.gz: 548489372e87fd7001f8dd805d21d9328f345306c65e055a58f1a078aa0736267d5f467871f719d39c2de089b8c5e6004ec742010fc26fc2c803fbe71d4ebb08
7
- data.tar.gz: 479d851256aa4961463fa0c7158e1b142c781fc529f29ea0075213aef661a9f6207a0abb4fce0fa50621af0aafff6deb90e7e686881313233e89489fd3b33f59
6
+ metadata.gz: b552c855f7c1b9d1774324ca2435d99dc85ed85bc5622a22b8284ee216dc93c5fe7f31c188cd19ce697085a821adae90f2359f49658e33acf4df268c34c93e73
7
+ data.tar.gz: f63e7b4cfff15aa2a65a6da620effc55c60544426fb50b334326adbe555f2f2ae6422a537742fe263185ed8cf53de570e8160db9ff3a566c4cfee23774f2a886
data/README.md CHANGED
@@ -25,9 +25,10 @@ TODO: Write detailed documentation
25
25
  ## Notes
26
26
 
27
27
  Application
28
- |-- Interfaces
29
- | |-- DummyInterface < Interface
28
+ |-- EventLoop
29
+ | |-- InterfaceRepository
30
30
  |
31
+ |-- InterfaceRepository
31
32
  |-- Terminal
32
33
 
33
34
  Base
@@ -37,6 +38,8 @@ TODO: Write detailed documentation
37
38
  Interface
38
39
  |-- Commands
39
40
  | |-- Command
41
+ | | |-- CommandRepository
42
+ | |
40
43
  | |-- Exit
41
44
  |
42
45
  |-- Compositor
@@ -51,6 +54,7 @@ TODO: Write detailed documentation
51
54
  | | |-- Style
52
55
  | | |-- Esc
53
56
  | |
57
+ | |-- InterfaceRepository
54
58
  | |-- Position
55
59
  | | |-- Esc
56
60
  | |
@@ -60,6 +64,9 @@ TODO: Write detailed documentation
60
64
  |-- Geometry
61
65
  | |-- Terminal
62
66
  |
67
+ |-- Input
68
+ |-- InterfaceRepository
69
+ |-- Position
63
70
  |-- Terminal
64
71
 
65
72
  Terminal
@@ -87,6 +94,18 @@ These numbers are based on the area available to the terminal. If the terminal i
87
94
  ]
88
95
  ]
89
96
 
97
+ ## Usage
98
+
99
+ class MyApp
100
+ include Vedeu
101
+
102
+ interface :status, geometry: { y: 1, x: 1, width: :auto, height: 1 }
103
+ interface :main, geometry: { y: 2, x: 1, width: :auto, height: :auto }
104
+
105
+ command :exit, Vedeu::Exit.dispatch, { keyword: "exit", keypress: "q" }
106
+ command :help, MyApp.help, { keyword: "help", keypress: "h" }
107
+ end
108
+
90
109
  ## Contributing
91
110
 
92
111
  1. Fork it ( http://github.com/<my-github-username>/vedeu/fork )
data/Rakefile CHANGED
@@ -1,5 +1,11 @@
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
3
9
 
4
10
  Rake::TestTask.new do |t|
5
11
  t.libs << 'lib/vedeu'
@@ -9,3 +15,5 @@ Rake::TestTask.new do |t|
9
15
  end
10
16
 
11
17
  task :default => :test
18
+
19
+ Rake::Task['cucumber'].execute
data/bin/vedeu CHANGED
@@ -6,4 +6,4 @@ trap('INT') { exit! }
6
6
 
7
7
  require 'vedeu'
8
8
 
9
- Vedeu::Application.start
9
+ Vedeu::Launcher.new(ARGV.dup).execute!
@@ -0,0 +1,8 @@
1
+ <%
2
+ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
+ rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
+ std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'rerun'} --strict --tags ~@wip --tags ~@ok --tags ~@pending --tags ~@failing"
5
+ %>
6
+ default: <%= std_opts %> features --format rerun
7
+ wip: --tags @wip:99 --wip features --format pretty
8
+ rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
@@ -0,0 +1,10 @@
1
+ Feature: Getting Started
2
+
3
+ Scenario: Hello World
4
+ Given the interface "main" is defined
5
+ And the command "hello" is defined
6
+ When the input "hello" is entered
7
+ Then the output should contain:
8
+ """
9
+ Hello World!
10
+ """
@@ -0,0 +1,11 @@
1
+ Given(/^the interface "(.*?)" is defined$/) do |interface|
2
+ Vedeu::Interface.create({ name: interface, klass: Vedeu::DummyInterface, options: {} })
3
+ end
4
+
5
+ Given(/^the command "(.*?)" is defined$/) do |command|
6
+ Vedeu::Command.create({ name: command, klass: Vedeu::DummyCommand, options: { keyword: command } })
7
+ end
8
+
9
+ When(/^the input "(.*?)" is entered$/) do |input|
10
+ pending
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'simplecov'
2
+ require 'aruba'
3
+ require 'aruba/cucumber'
4
+ require 'aruba/in_process'
5
+ require 'mocha/api'
6
+
7
+ require_relative '../../lib/vedeu.rb'
8
+
9
+ class CucumberError < StandardError; end
10
+
11
+ Aruba::InProcess.main_class = Vedeu::Launcher
12
+ Aruba.process = Aruba::InProcess
data/lib/vedeu.rb CHANGED
@@ -18,23 +18,44 @@ require_relative 'vedeu/output/style'
18
18
  require_relative 'vedeu/output/translator'
19
19
  require_relative 'vedeu/output/wordwrap'
20
20
 
21
- require_relative 'vedeu/interface/interfaces'
22
- require_relative 'vedeu/interface/interface'
23
- require_relative 'vedeu/interface/dummy_interface'
24
-
25
- require_relative 'vedeu/process/dummy_command'
26
- require_relative 'vedeu/process/commands'
27
- require_relative 'vedeu/process/command'
28
21
  require_relative 'vedeu/process/event_loop'
29
22
  require_relative 'vedeu/process/exit'
23
+ require_relative 'vedeu/process/input'
24
+
25
+ require_relative 'vedeu/repository/repository'
26
+ require_relative 'vedeu/repository/command_repository'
27
+ require_relative 'vedeu/repository/command'
28
+ require_relative 'vedeu/repository/interface_repository'
29
+ require_relative 'vedeu/repository/interface'
30
+ require_relative 'vedeu/repository/storage'
31
+ require_relative 'vedeu/repository/dummy_interface'
32
+ require_relative 'vedeu/repository/dummy_command'
30
33
 
31
34
  require_relative 'vedeu/application'
35
+ require_relative 'vedeu/launcher'
32
36
  require_relative 'vedeu/version'
33
37
 
34
38
  module Vedeu
39
+ module ClassMethods
40
+ def interface(name, options = {})
41
+ interface_name = name.is_a?(Symbol) ? name.to_s : name
42
+
43
+ Interface.create({ name: interface_name, options: options })
44
+ end
45
+
46
+ def command(name, klass, options = {})
47
+ command_name = name.is_a?(Symbol) ? name.to_s : name
48
+
49
+ Command.create({ name: command_name, klass: klass, options: options })
50
+ end
51
+ end
52
+
53
+ def self.included(receiver)
54
+ receiver.extend(ClassMethods)
55
+ end
56
+
35
57
  def self.logger
36
- @logger ||= Logger
37
- .new(root_path + '/logs/vedeu.log').tap do |log|
58
+ @logger ||= Logger.new(root_path + '/logs/vedeu.log').tap do |log|
38
59
  log.formatter = proc do |mode, time, prog, msg|
39
60
  "\n#{time.iso8601}: #{msg}\n"
40
61
  end
@@ -12,7 +12,7 @@ module Vedeu
12
12
 
13
13
  def start
14
14
  Terminal.open(options) do
15
- Interfaces.initial_state
15
+ InterfaceRepository.initial_state
16
16
 
17
17
  EventLoop.main_sequence
18
18
  end
@@ -0,0 +1,26 @@
1
+ module Vedeu
2
+ class Launcher
3
+ def initialize(argv, stdin = STDIN,
4
+ stdout = STDOUT,
5
+ stderr = STDERR,
6
+ kernel = Kernel)
7
+ @argv = argv
8
+ @stdin = stdin
9
+ @stdout = stdout
10
+ @stderr = stderr
11
+ @kernel = kernel
12
+ @exit_code = 1
13
+ end
14
+
15
+ def execute!
16
+ $stdin, $stdout, $stderr = @stdin, @stdout, @stderr
17
+
18
+ Vedeu::Application.start
19
+
20
+ @exit_code = 0
21
+ ensure
22
+ $stdin, $stdout, $stderr = STDIN, STDOUT, STDERR
23
+ @kernel.exit(@exit_code)
24
+ end
25
+ end
26
+ end
@@ -10,7 +10,7 @@ module Vedeu
10
10
  end
11
11
 
12
12
  def initialize(pair = [])
13
- @pair = pair
13
+ @pair = pair || []
14
14
  end
15
15
 
16
16
  def define
@@ -1,7 +1,9 @@
1
1
  module Vedeu
2
+ class UndefinedInterface < StandardError; end
3
+
2
4
  class Compositor
3
5
  class << self
4
- def arrange(output = [], interface = :dummy)
6
+ def arrange(output = [], interface = 'dummy')
5
7
  return if output.nil? || output.empty?
6
8
 
7
9
  if output.is_a?(Array)
@@ -14,8 +16,9 @@ module Vedeu
14
16
  end
15
17
  end
16
18
 
17
- def initialize(output = [], interface = :dummy)
18
- @output, @interface = output, interface
19
+ def initialize(output = [], interface = 'dummy')
20
+ @output = output || []
21
+ @interface = interface
19
22
  end
20
23
 
21
24
  def arrange
@@ -26,7 +29,7 @@ module Vedeu
26
29
 
27
30
  def composition
28
31
  container = []
29
- streams = []
32
+ streams = []
30
33
  output.map do |line|
31
34
  line.each_with_index do |stream, index|
32
35
  streams << clear(index)
@@ -43,7 +46,7 @@ module Vedeu
43
46
  end
44
47
 
45
48
  def origin(index)
46
- Position.set(geometry.vy(index), geometry.vx)
49
+ target_interface.origin(index)
47
50
  end
48
51
 
49
52
  def width
@@ -65,7 +68,7 @@ module Vedeu
65
68
  end
66
69
 
67
70
  def interface
68
- @_interface ||= Interfaces.defined.find(@interface)
71
+ @_interface ||= InterfaceRepository.find_by_name(@interface)
69
72
  end
70
73
  end
71
74
  end
@@ -9,7 +9,7 @@ module Vedeu
9
9
  end
10
10
 
11
11
  def initialize(directives = {})
12
- @directives = directives
12
+ @directives = directives || {}
13
13
  end
14
14
 
15
15
  def enact
@@ -1,7 +1,7 @@
1
1
  module Vedeu
2
2
  class Geometry
3
3
  def initialize(values = {})
4
- @values = values
4
+ @values = values || {}
5
5
  end
6
6
 
7
7
  def z
@@ -8,7 +8,7 @@ module Vedeu
8
8
  end
9
9
 
10
10
  def reset
11
- new(0, 0).set
11
+ new(1, 1).set
12
12
  end
13
13
  end
14
14
 
@@ -17,7 +17,7 @@ module Vedeu
17
17
  end
18
18
 
19
19
  def set
20
- [Esc.esc, (y + 1), ';', (x + 1), 'H'].join
20
+ [Esc.esc, y, ';', x, 'H'].join
21
21
  end
22
22
 
23
23
  private
@@ -21,7 +21,7 @@ module Vedeu
21
21
  when :show_cursor then Esc.show_cursor
22
22
  when :underline then Esc.underline
23
23
  else
24
- ""
24
+ ''
25
25
  end
26
26
  end
27
27
 
@@ -7,7 +7,8 @@ module Vedeu
7
7
  end
8
8
 
9
9
  def initialize(value, options = {})
10
- @value, @options = value, options
10
+ @value = value
11
+ @options = options || {}
11
12
  end
12
13
 
13
14
  def reformat
@@ -14,9 +14,9 @@ module Vedeu
14
14
 
15
15
  def main_sequence
16
16
  while @running do
17
- Interfaces.defined.input
17
+ InterfaceRepository.input
18
18
 
19
- Interfaces.defined.output
19
+ InterfaceRepository.output
20
20
  end
21
21
  rescue Collapse
22
22
  stop
@@ -0,0 +1,30 @@
1
+ module Vedeu
2
+ class Input
3
+ class << self
4
+ def evaluate(input, args = [])
5
+ new(input, args).evaluate
6
+ end
7
+ end
8
+
9
+ def initialize(input, args = [])
10
+ @input = input
11
+ @args = args || []
12
+ end
13
+
14
+ def evaluate
15
+ command.execute(*args) if exists?
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :input, :args
21
+
22
+ def exists?
23
+ command.is_a?(Command)
24
+ end
25
+
26
+ def command
27
+ @command ||= CommandRepository.find_by_input(input)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ module Vedeu
2
+ class Command
3
+ attr_accessor :id, :attributes, :name, :klass, :keyword, :keypress
4
+
5
+ class << self
6
+ def create(attributes = {})
7
+ new(attributes).create
8
+ end
9
+ end
10
+
11
+ def initialize(attributes = {})
12
+ @attributes = attributes || {}
13
+ @name = attributes[:name]
14
+ @klass = attributes[:klass]
15
+ @keyword = attributes.fetch(:options, {}).fetch(:keyword, "")
16
+ @keypress = attributes.fetch(:options, {}).fetch(:keypress, "")
17
+ end
18
+
19
+ def create
20
+ CommandRepository.create(self)
21
+ self
22
+ end
23
+
24
+ def execute(args = [])
25
+ executable.call(*args)
26
+ end
27
+
28
+ def executable
29
+ Proc.new { |*args| attributes[:klass].dispatch(*args) }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ module Vedeu
2
+ class CommandRepository
3
+ extend Repository
4
+
5
+ class << self
6
+ def find_by_input(input)
7
+ return nil if input.nil? || input.empty?
8
+ return by_keypress(input) if input.size == 1
9
+ return by_keyword(input) if input.size > 1
10
+ end
11
+
12
+ def klass
13
+ Command
14
+ end
15
+
16
+ private
17
+
18
+ def by_keypress(input)
19
+ query(klass, :keypress, input)
20
+ end
21
+
22
+ def by_keyword(input)
23
+ query(klass, :keyword, input)
24
+ end
25
+ end
26
+ end
27
+ end