remedy 0.0.3 → 0.0.4.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,13 +16,13 @@ Installation
16
16
  Add this line to your application's Gemfile:
17
17
 
18
18
  ```ruby
19
- gem 'remedy'
19
+ gem 'remedy', '~> 0.0.4.pre'
20
20
  ```
21
21
 
22
22
  If you're only going to use part of Remedy, you can tell Bundler to not automatically require the whole thing:
23
23
 
24
24
  ```ruby
25
- gem 'remedy', require: false
25
+ gem 'remedy', '~> 0.0.4.pre', require: false
26
26
  ```
27
27
 
28
28
  And then execute:
@@ -31,7 +31,7 @@ And then execute:
31
31
 
32
32
  Or install it yourself as:
33
33
 
34
- $ gem install remedy
34
+ $ gem install remedy --pre
35
35
 
36
36
  Usage
37
37
  -----
@@ -1,4 +1,4 @@
1
- require 'partial'
1
+ require 'remedy/partial'
2
2
 
3
- class Content < Partial
3
+ class Content < Remedy::Partial
4
4
  end
@@ -1,7 +1,7 @@
1
1
  require 'remedy/partial'
2
2
 
3
3
  module Remedy
4
- class Footer < Partial
4
+ class Footer < Remedy::Partial
5
5
  end
6
6
  end
7
7
 
@@ -1,7 +1,7 @@
1
1
  require 'remedy/partial'
2
2
 
3
3
  module Remedy
4
- class Header < Partial
4
+ class Header < Remedy::Partial
5
5
  end
6
6
  end
7
7
 
@@ -1,65 +1,67 @@
1
1
  require 'remedy/keyboard'
2
2
  require 'remedy/ansi'
3
3
 
4
- class Interaction
5
- def initialize message = nil
6
- @message = message
7
- end
4
+ module Remedy
5
+ class Interaction
6
+ def initialize message = nil
7
+ @message = message
8
+ end
8
9
 
9
- attr_accessor :message
10
+ attr_accessor :message
10
11
 
11
- def confirm message = 'Confirm?'
12
- ANSI.cursor.home!
13
- ANSI.command.clear_line!
12
+ def confirm message = 'Confirm?'
13
+ ANSI.cursor.home!
14
+ ANSI.command.clear_line!
14
15
 
15
- print message, ' y/n '
16
- if Keyboard.get === :y then
17
- yield if block_given?
18
- true
19
- else
20
- false
16
+ print message, ' y/n '
17
+ if Keyboard.get === :y then
18
+ yield if block_given?
19
+ true
20
+ else
21
+ false
22
+ end
21
23
  end
22
- end
23
24
 
24
- def quit!
25
- confirm 'Are you sure you want to quit? You will lose everything. :(' do
26
- ANSI.cursor.home!
27
- ANSI.command.clear_down!
28
- ANSI.cursor.show!
25
+ def quit!
26
+ confirm 'Are you sure you want to quit? You will lose everything. :(' do
27
+ ANSI.cursor.home!
28
+ ANSI.command.clear_down!
29
+ ANSI.cursor.show!
30
+
31
+ puts " -- Bye!"
32
+ exit
33
+ end
34
+ end
29
35
 
30
- puts " -- Bye!"
31
- exit
36
+ def debug!
37
+ require 'pry'
38
+ binding.pry
32
39
  end
33
- end
34
40
 
35
- def debug!
36
- require 'pry'
37
- binding.pry
38
- end
41
+ def display key
42
+ ANSI.command.clear_line!
43
+ print " -- You pressed: #{key.inspect}"
44
+ end
39
45
 
40
- def display key
41
- ANSI.command.clear_line!
42
- print " -- You pressed: #{key.inspect}"
43
- end
46
+ def loop
47
+ Keyboard.raise_on_control_c!
44
48
 
45
- def loop
46
- Keyboard.raise_on_control_c!
49
+ super do
50
+ print " -- #{message}" if message
47
51
 
48
- super do
49
- print " -- #{message}" if message
52
+ ANSI.cursor.hide!
53
+ key = Keyboard.get
50
54
 
51
- ANSI.cursor.hide!
52
- key = Keyboard.get
55
+ if key == ?\C-q then
56
+ display key
57
+ quit!
58
+ elsif key == ?\C-d and defined? Pry then
59
+ display key
60
+ debug!
61
+ end
53
62
 
54
- if key == ?\C-q then
55
- display key
56
- quit!
57
- elsif key == ?\C-d and defined? Pry then
58
- display key
59
- debug!
63
+ yield key
60
64
  end
61
-
62
- yield key
63
65
  end
64
66
  end
65
67
  end
@@ -1,66 +1,67 @@
1
1
  require 'remedy/console'
2
2
  require 'remedy/key'
3
3
 
4
- module Keyboard
5
- module_function
4
+ module Remedy
5
+ module Keyboard
6
+ module_function
6
7
 
7
- def get
8
- parse raw_get
9
- end
8
+ def get
9
+ parse raw_get
10
+ end
10
11
 
11
- def raw_get
12
- Console.raw do
13
- input = STDIN.getc.chr
12
+ def raw_get
13
+ Console.raw do
14
+ input = STDIN.getc.chr
14
15
 
15
- if input == "\e" then
16
- input << STDIN.read_nonblock(3) rescue nil
17
- input << STDIN.read_nonblock(2) rescue nil
18
- end
16
+ if input == "\e" then
17
+ input << STDIN.read_nonblock(3) rescue nil
18
+ input << STDIN.read_nonblock(2) rescue nil
19
+ end
19
20
 
20
- input
21
+ input
22
+ end
21
23
  end
22
- end
23
24
 
24
- def parse sequence
25
- key = Key.new sequence
26
- $log.debug "Key read", key
25
+ def parse sequence
26
+ key = Key.new sequence
27
+ $log.debug "Key read", key
27
28
 
28
- if raise_on_control_c? && key.control_c? then
29
- raise ControlC, "User pressed Control-C"
30
- elsif key.recognized? then
31
- key
32
- elsif raise_on_unrecognized_key? then
33
- raise UnrecognizedInput, %Q{Unknown key or byte sequence: "#{sequence}" : #{key.inspect}}
34
- else
35
- key
29
+ if raise_on_control_c? && key.control_c? then
30
+ raise ControlC, "User pressed Control-C"
31
+ elsif key.recognized? then
32
+ key
33
+ elsif raise_on_unrecognized_key? then
34
+ raise UnrecognizedInput, %Q{Unknown key or byte sequence: "#{sequence}" : #{key.inspect}}
35
+ else
36
+ key
37
+ end
36
38
  end
37
- end
38
39
 
39
- def raise_on_unrecognized_key?
40
- @raise_on_unrecognized_key
41
- end
40
+ def raise_on_unrecognized_key?
41
+ @raise_on_unrecognized_key
42
+ end
42
43
 
43
- def raise_on_unrecognized_key!
44
- @raise_on_unrecognized_key = true
45
- end
44
+ def raise_on_unrecognized_key!
45
+ @raise_on_unrecognized_key = true
46
+ end
46
47
 
47
- def dont_raise_on_unrecognized_key!
48
- @raise_on_unrecognized_key = false
49
- end
48
+ def dont_raise_on_unrecognized_key!
49
+ @raise_on_unrecognized_key = false
50
+ end
50
51
 
51
- def raise_on_control_c?
52
- @raise_on_control_c
53
- end
52
+ def raise_on_control_c?
53
+ @raise_on_control_c
54
+ end
54
55
 
55
- def raise_on_control_c!
56
- @raise_on_control_c = true
57
- end
56
+ def raise_on_control_c!
57
+ @raise_on_control_c = true
58
+ end
58
59
 
59
- def dont_raise_on_control_c!
60
- @raise_on_control_c = false
61
- end
60
+ def dont_raise_on_control_c!
61
+ @raise_on_control_c = false
62
+ end
62
63
 
63
- class ControlC < Interrupt; end
64
- class UnrecognizedInput < IOError; end
64
+ class ControlC < Interrupt; end
65
+ class UnrecognizedInput < IOError; end
66
+ end
65
67
  end
66
-
@@ -0,0 +1,102 @@
1
+ module Remedy
2
+ class Size
3
+ def initialize *new_dimensions
4
+ new_dimensions.flatten!
5
+ if new_dimensions.first.is_a? Range then
6
+ new_dimensions.map! do |range|
7
+ range.to_a.length
8
+ end
9
+ end
10
+ @dimensions = new_dimensions
11
+ end
12
+ attr_accessor :dimensions
13
+
14
+ def - other_size
15
+ if other_size.respond_to? :length then
16
+ self.class.new subtract(other_size)
17
+ else
18
+ self.class.new deduct(other_size)
19
+ end
20
+ end
21
+
22
+ def / value
23
+ dimensions.map do |dimension|
24
+ dimension / value
25
+ end
26
+ end
27
+
28
+ def << value
29
+ self.dimensions << value
30
+ end
31
+
32
+
33
+ def fits_into? size_to_fit_into
34
+ other_size = Size(size_to_fit_into)
35
+ length.times.each do |index|
36
+ return false if self[index] > other_size[index]
37
+ end
38
+ true
39
+ end
40
+
41
+ def rows
42
+ dimensions.first
43
+ end
44
+
45
+ def cols
46
+ dimensions[1]
47
+ end
48
+
49
+ def [] index
50
+ dimensions[index]
51
+ end
52
+
53
+ def length
54
+ dimensions.length
55
+ end
56
+
57
+ def to_a
58
+ dimensions.dup
59
+ end
60
+
61
+ def to_ary
62
+ dimensions
63
+ end
64
+
65
+ def to_s
66
+ "(#{dimensions.join('x')})"
67
+ end
68
+
69
+ def inspect
70
+ "#<#{self.class}:#{to_s}>"
71
+ end
72
+
73
+ protected
74
+
75
+ def deduct amount
76
+ dimensions.map do |dimension|
77
+ dimension - amount
78
+ end
79
+ end
80
+
81
+ def subtract other_size
82
+ sizesame? other_size
83
+
84
+ length.times.inject Size.new do |difference, index|
85
+ difference << self[index] - other_size[index]
86
+ end
87
+ end
88
+
89
+ def sizesame? other_size
90
+ raise "Different numbers of dimensions!" unless length == other_size.length
91
+ end
92
+ end
93
+ end
94
+
95
+ def Size *sizeable
96
+ sizeable.flatten!
97
+ if sizeable.first.is_a? Remedy::Size then
98
+ sizeable
99
+ else
100
+ Remedy::Size.new sizeable
101
+ end
102
+ end
@@ -1,3 +1,3 @@
1
1
  module Remedy
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4.pre"
3
3
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remedy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.0.4.pre
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Anthony M. Cook
@@ -36,6 +36,7 @@ files:
36
36
  - lib/remedy/key.rb
37
37
  - lib/remedy/keyboard.rb
38
38
  - lib/remedy/partial.rb
39
+ - lib/remedy/size.rb
39
40
  - lib/remedy/version.rb
40
41
  - lib/remedy/view.rb
41
42
  - lib/remedy/viewport.rb
@@ -54,9 +55,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
55
  none: false
55
56
  required_rubygems_version: !ruby/object:Gem::Requirement
56
57
  requirements:
57
- - - ! '>='
58
+ - - ! '>'
58
59
  - !ruby/object:Gem::Version
59
- version: '0'
60
+ version: 1.3.1
60
61
  none: false
61
62
  requirements: []
62
63
  rubyforge_project: