remedy 0.0.5 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fdbe9a3b67f8ad38de63244c77014eb1ba7ddbce
4
- data.tar.gz: 7ef6bbf5a6010383486459e468db45fbf20ed92e
3
+ metadata.gz: c57a50932b4e8ce59e0c961d944c67c5cb93b444
4
+ data.tar.gz: ed2b6bfb4d72f4dab134e3cbdec8abb89a1477c9
5
5
  SHA512:
6
- metadata.gz: ca6f9629d52f68d5ef4012f4e7883d63b5b51441c028905b2b43c20b6bdd95da1c27c1653a6179728d6bc9d068573242d2812bc772af02ea3115ad2574be082f
7
- data.tar.gz: 54356ac5892f891fb28c491a31c2b344bdce5e7fe28c8e4d556b85511e0f2fdcd1f079260dd3c0d1ebe7010d493237bcbdeb8b81c52d1b0ad262e4c311585bbe
6
+ metadata.gz: 7c458b0e9eacccfb956afd4f29456ece91dc17eec562f37b7ee2fd05bf3ec40f7067bea1d0f46feb6250cc0cd4862a4811d80b805aae1d613ed70e55edc8a97a
7
+ data.tar.gz: 20cc90d989ec4545ae2fb697b7a1520175f2a27a377f6aa63e10c5db492c9a5b5450e9e4d84ee3c581b2dafb08324d70ee98bc90906e0b88514af2cc97dceb40
@@ -1,4 +1,16 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.2
3
+ - 2.3.1
4
+ - 2.2.5
5
+ - 2.1.9
6
+ - ruby-head
7
+
8
+ before_install:
9
+ - gem update bundler
4
10
  script: bundle exec rspec
11
+
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: ruby-head
15
+
16
+ sudo: false
data/Gemfile CHANGED
@@ -3,6 +3,8 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in remedy.gemspec
4
4
  gemspec
5
5
 
6
- gem 'pry'
7
- gem 'pry-doc'
8
- gem 'pry-theme'
6
+ unless ENV['CI'] then
7
+ gem 'pry'
8
+ gem 'pry-doc'
9
+ gem 'pry-theme'
10
+ end
@@ -1,14 +1,10 @@
1
1
  Remedy
2
2
  ======
3
3
 
4
- Remedy is a console interaction framework along the lines of Curses written in pure Ruby with an Object-Oriented approach and baked-in support for bulding MVC applications.
4
+ Remedy is a console interaction framework along the lines of Curses written in pure Ruby with an Object-Oriented approach and well-seperated concerns making it easy to use what you need and ignore the rest.
5
5
 
6
6
  [![TravisCI](http://img.shields.io/travis/acook/remedy.svg?style=flat)](https://travis-ci.org/acook/remedy)
7
-
8
- THIS SOFTWARE IS PRE-ALPHA!!
9
- ----------------------------
10
-
11
- It's under active development and is being used in my own projects. However, expect bugs, missing features, etc.
7
+ [![Code Climate](https://codeclimate.com/github/acook/remedy/badges/gpa.svg)](https://codeclimate.com/github/acook/remedy)
12
8
 
13
9
  If you have any suggestions or find any bugs, drop them in GitHub/issues so I can keep track of them. Thanks!
14
10
 
@@ -18,13 +14,13 @@ Installation
18
14
  Add this line to your application's Gemfile:
19
15
 
20
16
  ```ruby
21
- gem 'remedy', '~> 0.0.4.pre'
17
+ gem 'remedy'
22
18
  ```
23
19
 
24
20
  If you're only going to use part of Remedy, you can tell Bundler to not automatically require the whole thing:
25
21
 
26
22
  ```ruby
27
- gem 'remedy', '~> 0.0.4.pre', require: false
23
+ gem 'remedy', require: false
28
24
  ```
29
25
 
30
26
  And then execute:
@@ -33,7 +29,7 @@ And then execute:
33
29
 
34
30
  Or install it yourself as:
35
31
 
36
- $ gem install remedy --pre
32
+ $ gem install remedy
37
33
 
38
34
  Usage
39
35
  -----
@@ -3,7 +3,7 @@ module Remedy
3
3
 
4
4
  def libs
5
5
  %w{
6
- version ansi characters console console_resized content header footer
6
+ version ansi characters console console_resize content header footer
7
7
  interaction key keyboard partial view viewport
8
8
  }
9
9
  end
@@ -12,4 +12,3 @@ end
12
12
  Remedy.libs.each do |lib|
13
13
  require "remedy/#{lib}"
14
14
  end
15
-
@@ -6,6 +6,8 @@ module Remedy
6
6
  all[sequence_to_match]
7
7
  end
8
8
 
9
+ # Character Groups
10
+
9
11
  def all
10
12
  @all ||= printable.merge(nonprintable)
11
13
  end
@@ -14,39 +16,46 @@ module Remedy
14
16
  @printable ||= whitespace.merge(
15
17
  alphabetical.merge(
16
18
  numeric.merge(
17
- punctuation)))
18
- end
19
-
20
- def whitespace
21
- {
22
- ' ' => :space,
23
- "\t" => :tab,
24
- "\r" => :carriage_return,
25
- "\n" => :line_feed
26
- }
19
+ punctuation
20
+ )
21
+ )
22
+ )
27
23
  end
28
24
 
29
25
  def alphabetical
30
26
  @alphabetics ||= get_alphabetics
31
27
  end
32
28
 
29
+ def nonprintable
30
+ @nonprintable ||= special.merge(directional).merge(escape).merge(control)
31
+ end
32
+
33
+ def whitespace
34
+ @whitespace ||= {
35
+ ?\s => :space,
36
+ ?\t => :tab,
37
+ ?\r => :carriage_return,
38
+ ?\n => :line_feed
39
+ }
40
+ end
41
+
33
42
  def numeric
34
- {
35
- '0' => :zero,
36
- '1' => :one,
37
- '2' => :two,
38
- '3' => :three,
39
- '4' => :four,
40
- '5' => :five,
41
- '6' => :six,
42
- '7' => :seven,
43
- '8' => :eight,
44
- '9' => :nine
43
+ @numeric ||= {
44
+ ?0 => :zero,
45
+ ?1 => :one,
46
+ ?2 => :two,
47
+ ?3 => :three,
48
+ ?4 => :four,
49
+ ?5 => :five,
50
+ ?6 => :six,
51
+ ?7 => :seven,
52
+ ?8 => :eight,
53
+ ?9 => :nine
45
54
  }
46
55
  end
47
56
 
48
57
  def punctuation
49
- {
58
+ @punctuation ||= {
50
59
  '.' => :period,
51
60
  ',' => :comma,
52
61
  ':' => :colon,
@@ -77,18 +86,13 @@ module Remedy
77
86
  }
78
87
  end
79
88
 
80
- def nonprintable
81
- @nonprintable ||= special.merge(directional).merge(escape).merge(control)
82
- end
83
-
84
89
  def special
85
90
  {
86
- "\177" => :backspace
87
91
  }
88
92
  end
89
93
 
90
94
  def directional
91
- {
95
+ @directional ||= {
92
96
  "\e[A" => :up,
93
97
  "\e[B" => :down,
94
98
  "\e[D" => :left,
@@ -97,7 +101,7 @@ module Remedy
97
101
  end
98
102
 
99
103
  def escape
100
- {
104
+ @escape ||= {
101
105
  "\e" => :escape,
102
106
 
103
107
  "\e[3~" => :delete
@@ -105,13 +109,24 @@ module Remedy
105
109
  end
106
110
 
107
111
  def control
108
- {
109
- "\u0003" => :control_c,
110
- "\u0004" => :control_d,
111
- "\u0012" => :control_r
112
+ control_chars = {
113
+ 27.chr => :control_left_square_bracket,
114
+ 28.chr => :control_backslash,
115
+ 29.chr => :control_right_square_bracket,
116
+ 30.chr => :control_caret,
117
+ 31.chr => :control_underscore,
118
+ 127.chr => :delete,
119
+ 177.chr => :backspace
112
120
  }
121
+ (?a..?z).each.with_index do |letter, index|
122
+ control_chars.merge!({(index + 1).chr => "control_#{letter}".to_sym})
123
+ end
124
+
125
+ control_chars
113
126
  end
114
127
 
128
+ # Glyphs and Alternate Names
129
+
115
130
  def gremlins
116
131
  {
117
132
  space: "\u2420",
@@ -137,10 +152,38 @@ module Remedy
137
152
 
138
153
  def alternate_names
139
154
  {
155
+ control_a: :start_of_heading,
156
+ control_b: :start_of_text,
140
157
  control_c: :end_of_transmission,
141
158
  control_d: :end_of_text,
142
-
143
- control_r: :device_control_two
159
+ control_e: :enquiry,
160
+ control_f: :acknowledge,
161
+ control_g: :bel,
162
+ control_h: :backspace,
163
+ control_i: :horizontal_tabulation,
164
+ control_j: :line_feed,
165
+ control_k: :vertical_tabulation,
166
+ control_l: :form_feed,
167
+ control_m: :carriage_return,
168
+ control_n: :shift_out,
169
+ control_o: :shift_in,
170
+ control_p: :data_link_escape,
171
+ control_q: :device_control_one,
172
+ control_r: :device_control_two,
173
+ control_s: :device_control_three,
174
+ control_t: :device_control_four,
175
+ control_u: :negative_acknowledge,
176
+ control_v: :sychnronous_idle,
177
+ control_w: :end_of_transmission_block,
178
+ control_x: :cancel,
179
+ control_y: :end_of_medium,
180
+ control_z: :substitute,
181
+
182
+ control_left_square_bracket: :escape,
183
+ control_backslash: :file_separator,
184
+ control_right_square_bracket: :group_separator,
185
+ control_caret: :record_separator,
186
+ control_underscore: :unit_separator
144
187
  }
145
188
  end
146
189
 
@@ -1,4 +1,4 @@
1
- require 'remedy/console_resized'
1
+ require 'remedy/console_resize'
2
2
 
3
3
  module Remedy
4
4
  module Console
@@ -9,11 +9,11 @@ module Remedy
9
9
  module_function
10
10
 
11
11
  def input
12
- STDIN
12
+ @input ||= $stdin
13
13
  end
14
14
 
15
15
  def output
16
- STDOUT
16
+ @output ||= $stdout
17
17
  end
18
18
 
19
19
  def raw
@@ -21,7 +21,6 @@ module Remedy
21
21
  result = yield
22
22
  ensure
23
23
  cooked!
24
-
25
24
  return result
26
25
  end
27
26
 
@@ -33,15 +32,13 @@ module Remedy
33
32
  def cooked!
34
33
  input.echo = true
35
34
  input.cooked!
36
- rescue NoMethodError
37
- %x{stty -raw echo 2> /dev/null}
38
35
  end
39
36
 
40
37
  def columns
41
38
  size.last
42
39
  end
43
40
  alias_method :width, :columns
44
-
41
+
45
42
  def rows
46
43
  size.first
47
44
  end
@@ -61,7 +58,7 @@ module Remedy
61
58
  end
62
59
 
63
60
  def set_console_resized_hook!
64
- ConsoleResized.set_console_resized_hook! do
61
+ Console::Resize.set_console_resized_hook! do
65
62
  yield
66
63
  end
67
64
  end
@@ -0,0 +1,44 @@
1
+ module Remedy; module Console; module Resize
2
+ module_function
3
+
4
+ def resizing?
5
+ @resize_count > 0
6
+ end
7
+
8
+ def resizing!
9
+ @resize_count = @resize_count < 1 ? 1 : @resize_count + 1
10
+ end
11
+
12
+ def resized?
13
+ @resize_count <= 1
14
+ end
15
+
16
+ def resized!
17
+ @resize_count = @resize_count < 0 ? 0 : @resize_count - 1
18
+ end
19
+
20
+ def resizer?
21
+ @resize_count == 1
22
+ end
23
+
24
+ def set_console_resized_hook!
25
+ @resize_count = 0
26
+
27
+ command = lambda { |x|
28
+ resizing!
29
+ sleep 0.25
30
+
31
+ if resized? then
32
+ yield
33
+ end
34
+
35
+ resized!
36
+ }
37
+
38
+ Signal.trap 'SIGWINCH', command
39
+ end
40
+
41
+ def default_console_resized_hook!
42
+ Signal.trap 'SIGWINCH', 'DEFAULT'
43
+ end
44
+ end; end; end
@@ -1,4 +1,4 @@
1
1
  require 'remedy/partial'
2
2
 
3
- class Content < Remedy::Partial
3
+ class Remedy::Content < Remedy::Partial
4
4
  end
@@ -1,7 +1,4 @@
1
1
  require 'remedy/partial'
2
2
 
3
- module Remedy
4
- class Footer < Remedy::Partial
5
- end
3
+ class Remedy::Footer < Remedy::Partial
6
4
  end
7
-
@@ -1,7 +1,4 @@
1
1
  require 'remedy/partial'
2
2
 
3
- module Remedy
4
- class Header < Remedy::Partial
5
- end
3
+ class Remedy::Header < Remedy::Partial
6
4
  end
7
-
@@ -63,5 +63,12 @@ module Remedy
63
63
  yield key
64
64
  end
65
65
  end
66
+
67
+ def get_key
68
+ print " -- #{message}" if message
69
+
70
+ ANSI.cursor.hide!
71
+ key = Keyboard.get
72
+ end
66
73
  end
67
74
  end
@@ -56,7 +56,7 @@ module Remedy
56
56
  end
57
57
 
58
58
  def sequence?
59
- @sequence ||= raw.legnth > 1
59
+ @sequence ||= raw.length > 1
60
60
  end
61
61
 
62
62
  def to_s
@@ -1,3 +1,3 @@
1
1
  module Remedy
2
- VERSION = '0.0.5'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,46 @@
1
+ require_relative 'spec_helper'
2
+ require 'remedy/key'
3
+
4
+ describe Remedy::Key do
5
+ subject(:key){ described_class.new keypress }
6
+
7
+ let(:keypress){ "\e[A" }
8
+
9
+ describe '#raw' do
10
+ it 'gives the same sequence it was initialized with' do
11
+ expect(key.raw).to equal(keypress)
12
+ end
13
+ end
14
+
15
+ describe '#name' do
16
+ it 'gives the name of the key' do
17
+ expect(key.name).to equal(:up)
18
+ end
19
+ end
20
+
21
+ describe '#glyph' do
22
+ it 'gives the individual character respresentation of the key' do
23
+ expect(key.glyph).to eq("\u2191")
24
+ end
25
+ end
26
+
27
+ describe '#nonprintable?' do
28
+ it 'indicates that a keypress is a nonprintable character or sequence' do
29
+ expect(key.nonprintable?).to be(true)
30
+ end
31
+ end
32
+
33
+ describe '#sequence?' do
34
+ it 'determines if a keypress is an escape sequence' do
35
+ expect(key.sequence?).to be(true)
36
+ end
37
+ end
38
+
39
+ describe 'control characters' do
40
+ let(:keypress){ 3.chr }
41
+
42
+ it 'recognizes control c' do
43
+ expect(key.control_c?).to be(true)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler.require(:test)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remedy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony M. Cook
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-27 00:00:00.000000000 Z
11
+ date: 2016-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -44,7 +44,7 @@ files:
44
44
  - lib/remedy/ansi.rb
45
45
  - lib/remedy/characters.rb
46
46
  - lib/remedy/console.rb
47
- - lib/remedy/console_resized.rb
47
+ - lib/remedy/console_resize.rb
48
48
  - lib/remedy/content.rb
49
49
  - lib/remedy/footer.rb
50
50
  - lib/remedy/header.rb
@@ -57,6 +57,7 @@ files:
57
57
  - lib/remedy/view.rb
58
58
  - lib/remedy/viewport.rb
59
59
  - remedy.gemspec
60
+ - spec/key_spec.rb
60
61
  - spec/remedy_spec.rb
61
62
  - spec/spec_helper.rb
62
63
  homepage: http://github.com/acook/remedy
@@ -78,11 +79,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
79
  version: '0'
79
80
  requirements: []
80
81
  rubyforge_project:
81
- rubygems_version: 2.6.4
82
+ rubygems_version: 2.6.7
82
83
  signing_key:
83
84
  specification_version: 4
84
85
  summary: MVC Console Interaction Library
85
86
  test_files:
87
+ - spec/key_spec.rb
86
88
  - spec/remedy_spec.rb
87
89
  - spec/spec_helper.rb
88
- has_rdoc:
@@ -1,46 +0,0 @@
1
- module Remedy
2
- module ConsoleResized
3
- module_function
4
-
5
- def resizing?
6
- @resize_count > 0
7
- end
8
-
9
- def resizing!
10
- @resize_count = @resize_count < 1 ? 1 : @resize_count + 1
11
- end
12
-
13
- def resized?
14
- @resize_count <= 1
15
- end
16
-
17
- def resized!
18
- @resize_count = @resize_count < 0 ? 0 : @resize_count - 1
19
- end
20
-
21
- def resizer?
22
- @resize_count == 1
23
- end
24
-
25
- def set_console_resized_hook!
26
- @resize_count = 0
27
-
28
- command = lambda { |x|
29
- resizing!
30
- sleep 0.25
31
-
32
- if resized? then
33
- yield
34
- end
35
-
36
- resized!
37
- }
38
-
39
- Signal.trap 'SIGWINCH', command
40
- end
41
-
42
- def default_console_resized_hook!
43
- Signal.trap 'SIGWINCH', 'DEFAULT'
44
- end
45
- end
46
- end