tp 0.6.2 → 0.7.0pre1

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: 566ce5c06eba734808dcab4f4b0a48f791806fc8
4
- data.tar.gz: 90d3243ec651183b1d1b913fe7e0d81acafaff4a
3
+ metadata.gz: 9813a862d681061c6eae802d73fa465781b9c552
4
+ data.tar.gz: 5e7e87045104c9d1fc27f81578428f53abc1c30a
5
5
  SHA512:
6
- metadata.gz: 64a4e3916c2b247635b10c2b08f95a1810603d99d41a59d927424bcc32e1be55827de3e55d6991629734cc46d0b9b2568cb62928ceda0211daa5aaa61292a44e
7
- data.tar.gz: 4373f999e8b7f0e2517cb56eeba690efc4f3a7cfcf269ddb72e4cb7aa8135a85ba4811158175178a4603aeec830ff278a63bff41ba0ca192c2444d4059a3e7ca
6
+ metadata.gz: ac5aeb3b0295ed94721d33e443699ced0e4dbd9f1db6832bec02203e4efe7427fafff37b2a39f0543055da71712048bac43363c9bd597b22d49e8dca884ebe54
7
+ data.tar.gz: 2d420ed3e99cda9fbaf6a4993977cf3777e32f0af987e8a1cf6c0f29bd2feb9046b6c43814847b03850754eba732b44f715bb9d7411a4dfee8e719e0038ee900
data/.cane CHANGED
@@ -1,5 +1,4 @@
1
1
  --abc-max 10
2
2
  --color
3
- --gte coverage/.last_run.json,100
4
3
  --no-doc
5
4
  --style-exclude spec/**/*
data/.travis.yml CHANGED
@@ -1,9 +1,8 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
3
  - 2.0.0
4
+ - 2.1
5
5
  - ruby-head
6
6
  matrix:
7
7
  allow_failures:
8
8
  - rvm: ruby-head
9
-
data/Gemfile CHANGED
@@ -2,11 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'cane', github: 'square/cane'
6
-
7
- group :development, :test do
8
- group :darwin do
9
- gem 'rb-fsevent'
10
- gem 'growl'
11
- end
5
+ group :development do
6
+ gem 'guard'
7
+ gem 'guard-cane'
8
+ gem 'guard-rspec'
12
9
  end
data/Guardfile CHANGED
@@ -1,4 +1,4 @@
1
- guard :rspec, env: { skip_coverage: true } do
1
+ guard :rspec do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec" }
data/Rakefile CHANGED
@@ -6,5 +6,9 @@ task default: :ci
6
6
 
7
7
  task ci: [:spec, :cane]
8
8
 
9
- Cane::RakeTask.new
9
+ Cane::RakeTask.new do |cane|
10
+ cane.canefile = '.cane'
11
+ cane.add_threshold 'coverage/.last_run.json', :>=, 100
12
+ end
13
+
10
14
  RSpec::Core::RakeTask.new
data/lib/screen.rb CHANGED
@@ -1,26 +1,43 @@
1
1
  module Screen
2
2
  extend self
3
3
 
4
+ X_GUTTER = 2
5
+ Y_GUTTER = 1
6
+
7
+ def add_gutter(text)
8
+ text = text.lines.map { |line|
9
+ line == "\n" ? line : " " * X_GUTTER + line
10
+ }.join
11
+ text = "\n" * Y_GUTTER + text
12
+ text
13
+ end
14
+
4
15
  def clear!
5
16
  print "\e[2J\e[f"
6
17
  end
7
18
 
8
19
  def hide_cursor
9
- print "\e[#{height};#{width}H"
20
+ print "\e[#{height};#{width + X_GUTTER * 2}H"
10
21
  end
11
22
 
12
23
  def height
13
24
  `tput lines`.to_i
14
25
  end
15
26
 
27
+ def print(text)
28
+ Kernel.print text
29
+ end
30
+
16
31
  def suggest(x, y)
32
+ Y_GUTTER.times { print "x" * (x + X_GUTTER * 2) + "\n" }
17
33
  y.times do |n|
18
34
  print "\n" if n.nonzero?
19
- print "\u2588" * x
35
+ print "x" * X_GUTTER + "\u2588" * x + "x" * X_GUTTER
20
36
  end
37
+ Y_GUTTER.times { print "\n" + "x" * (x + X_GUTTER * 2) }
21
38
  end
22
39
 
23
40
  def width
24
- `tput cols`.to_i
41
+ `tput cols`.to_i - X_GUTTER * 2
25
42
  end
26
43
  end
data/lib/tp/presenter.rb CHANGED
@@ -22,9 +22,9 @@ module TP
22
22
  Renderer.new(slide_deck.current_frame).render
23
23
 
24
24
  case Keyboard.read
25
- when :right, :down, :space, :return, 'l', 'k', 'd', 's'
25
+ when :right, :down, :space, :return, 'l', 'j', 'd', 's'
26
26
  slide_deck.next
27
- when :left, :up, :backspace, 'h', 'j', 'a', 'w'
27
+ when :left, :up, :backspace, 'h', 'k', 'a', 'w'
28
28
  slide_deck.previous
29
29
  when 'q'
30
30
  break
data/lib/tp/renderer.rb CHANGED
@@ -11,15 +11,11 @@ module TP
11
11
 
12
12
  return unless text
13
13
 
14
- print text unless testing?
14
+ Screen.print Screen.add_gutter(text)
15
15
 
16
16
  Screen.hide_cursor
17
17
 
18
18
  true
19
19
  end
20
-
21
- def testing?
22
- ENV['RUBY_ENV'] == 'test'
23
- end
24
20
  end
25
21
  end
@@ -28,7 +28,11 @@ class TP::Slide::Paragraph < TP::Slide
28
28
  end
29
29
 
30
30
  def width
31
- content.length
31
+ [Screen.width, content.length].min
32
+ end
33
+
34
+ def height
35
+ content.wrap(Screen.width).lines.count + 2
32
36
  end
33
37
 
34
38
  def hard_width?
data/lib/tp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TP
2
- VERSION = "0.6.2"
2
+ VERSION = "0.7.0pre1"
3
3
  end
@@ -3,10 +3,33 @@ require 'screen'
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Screen do
6
+ describe ".add_gutter" do
7
+ subject(:add_gutter) { klass.add_gutter(text) }
8
+
9
+ let(:text) { " Header " }
10
+
11
+ before do
12
+ klass.stub width: 10
13
+ end
14
+
15
+ it "adds a gutter on the top and left" do
16
+ expect(add_gutter).to eq("\n Header ")
17
+ end
18
+
19
+ context "with a paragraph slide" do
20
+ let(:text) { " Header \n\nAbc" }
21
+ it "indents the text and leaves a space on the right" do
22
+ expect(add_gutter).to eq("\n Header \n\n Abc")
23
+ end
24
+ end
25
+ end
26
+
6
27
  describe ".clear!" do
7
28
  subject(:clear!) { klass.clear! }
8
29
 
9
30
  it "clears the screen" do
31
+ Screen.unstub :clear!
32
+
10
33
  Screen.should_receive(:print).with("\e[2J\e[f")
11
34
 
12
35
  clear!
@@ -21,6 +44,34 @@ describe Screen do
21
44
  end
22
45
  end
23
46
 
47
+ describe ".hide_cursor" do
48
+ before do
49
+ klass.unstub :print
50
+ end
51
+
52
+ it "prints to the bottom right of the screen" do
53
+ expect(Kernel).to receive(:print) do |string|
54
+ string.match(/\\\e\[\d+;\d+/)
55
+ end
56
+
57
+ klass.hide_cursor
58
+ end
59
+ end
60
+
61
+ describe ".print" do
62
+ let(:text) { "foo" }
63
+
64
+ before do
65
+ klass.unstub :print
66
+ end
67
+
68
+ it "prints to the screen" do
69
+ expect(Kernel).to receive(:print).with(text)
70
+
71
+ klass.print text
72
+ end
73
+ end
74
+
24
75
  describe ".width" do
25
76
  subject(:width) { klass.width }
26
77
 
@@ -6,5 +6,13 @@ describe String do
6
6
 
7
7
  it { string.wrap(1).should == "One\ntwo\nthree\nfour\nfive" }
8
8
  it { string.wrap(10).should == "One two\nthree four\nfive" }
9
+
10
+ context "with multiple lines" do
11
+ let(:string) { "One two\nthree four\nfive" }
12
+
13
+ it { string.wrap(1).should == "One\ntwo\nthree\nfour\nfive" }
14
+ it { string.wrap(10).should == "One two\nthree four\nfive" }
15
+ it { string.wrap(100).should == string }
16
+ end
9
17
  end
10
18
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe TP::Renderer do
4
+ let(:renderer) { described_class.new(text) }
5
+ let(:text) { "foo" }
6
+
7
+ before do
8
+ renderer.stub :print
9
+ renderer.stub testing?: false
10
+ end
11
+
12
+ describe "#render" do
13
+ subject(:render) { renderer.render }
14
+
15
+ it "clears the screen" do
16
+ expect(Screen).to receive(:clear!)
17
+
18
+ render
19
+ end
20
+
21
+ it "prints the text to the screen" do
22
+ expect(Screen).to receive(:print).with(Screen.add_gutter(text))
23
+
24
+ render
25
+ end
26
+ end
27
+ end
@@ -13,6 +13,15 @@ describe TP::Slide::Paragraph do
13
13
  its(:width) { should == 15 }
14
14
  its(:height) { should == 3 }
15
15
 
16
+ context "when text is wrapped" do
17
+ before do
18
+ Screen.stub width: 10
19
+ end
20
+
21
+ its(:width) { should == 10 }
22
+ its(:height) { should == 4 }
23
+ end
24
+
16
25
  describe "#render_terminal" do
17
26
  subject(:lines) { slide.render_terminal.lines.to_a }
18
27
 
data/spec/spec_helper.rb CHANGED
@@ -4,10 +4,8 @@ require 'support/klass'
4
4
 
5
5
  puts RUBY_DESCRIPTION
6
6
 
7
- unless ENV['skip_coverage']
8
- require 'simplecov'
9
- SimpleCov.start
10
- end
7
+ require 'simplecov'
8
+ SimpleCov.start
11
9
 
12
10
  require 'tp'
13
11
 
@@ -16,5 +14,8 @@ RSpec.configure do |config|
16
14
  config.run_all_when_everything_filtered = true
17
15
  config.filter_run :focus
18
16
  config.order = :random
19
- end
20
17
 
18
+ config.before do
19
+ Screen.stub clear!: nil, print: nil
20
+ end
21
+ end
data/tp.gemspec CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.summary = "Terminal Presenter"
14
14
  gem.description = "Presents Markdown slides in your terminal"
15
15
  gem.homepage = "https://github.com/justincampbell/tp"
16
+ gem.license = "MIT"
16
17
 
17
18
  gem.post_install_message = File.read('WELCOME')
18
19
 
@@ -21,15 +22,14 @@ Gem::Specification.new do |gem|
21
22
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
23
  gem.require_paths = ["lib"]
23
24
 
24
- gem.add_dependency "coderay", "~> 1.0"
25
- gem.add_dependency "prawn", "~> 0.12"
26
- gem.add_dependency "thor", "~> 0.17"
27
-
28
- gem.add_development_dependency "cane"
29
- gem.add_development_dependency "guard"
30
- gem.add_development_dependency "guard-rspec"
31
- gem.add_development_dependency "guard-cane"
32
- gem.add_development_dependency "rake"
33
- gem.add_development_dependency "rspec"
34
- gem.add_development_dependency "simplecov" if RUBY_DESCRIPTION.start_with? "ruby"
25
+ gem.required_ruby_version = '>= 1.9.3'
26
+
27
+ gem.add_dependency 'coderay', '~> 1.0'
28
+ gem.add_dependency 'prawn', '~> 0.12'
29
+ gem.add_dependency 'thor', '~> 0.17'
30
+
31
+ gem.add_development_dependency 'cane'
32
+ gem.add_development_dependency 'rake'
33
+ gem.add_development_dependency 'rspec'
34
+ gem.add_development_dependency 'simplecov'
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Campbell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-24 00:00:00.000000000 Z
11
+ date: 2014-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coderay
@@ -66,48 +66,6 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: guard
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: guard-rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: guard-cane
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - '>='
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
69
  - !ruby/object:Gem::Dependency
112
70
  name: rake
113
71
  requirement: !ruby/object:Gem::Requirement
@@ -194,6 +152,7 @@ files:
194
152
  - spec/lib/tp/coderay/prawn_encoder_spec.rb
195
153
  - spec/lib/tp/presenter_spec.rb
196
154
  - spec/lib/tp/publisher/pdf_spec.rb
155
+ - spec/lib/tp/renderer_spec.rb
197
156
  - spec/lib/tp/slide/bulleted_spec.rb
198
157
  - spec/lib/tp/slide/code_spec.rb
199
158
  - spec/lib/tp/slide/header_only_spec.rb
@@ -206,7 +165,8 @@ files:
206
165
  - spec/support/klass.rb
207
166
  - tp.gemspec
208
167
  homepage: https://github.com/justincampbell/tp
209
- licenses: []
168
+ licenses:
169
+ - MIT
210
170
  metadata: {}
211
171
  post_install_message: |2+
212
172
 
@@ -242,15 +202,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
242
202
  requirements:
243
203
  - - '>='
244
204
  - !ruby/object:Gem::Version
245
- version: '0'
205
+ version: 1.9.3
246
206
  required_rubygems_version: !ruby/object:Gem::Requirement
247
207
  requirements:
248
- - - '>='
208
+ - - '>'
249
209
  - !ruby/object:Gem::Version
250
- version: '0'
210
+ version: 1.3.1
251
211
  requirements: []
252
212
  rubyforge_project:
253
- rubygems_version: 2.0.3
213
+ rubygems_version: 2.0.14
254
214
  signing_key:
255
215
  specification_version: 4
256
216
  summary: Terminal Presenter
@@ -262,6 +222,7 @@ test_files:
262
222
  - spec/lib/tp/coderay/prawn_encoder_spec.rb
263
223
  - spec/lib/tp/presenter_spec.rb
264
224
  - spec/lib/tp/publisher/pdf_spec.rb
225
+ - spec/lib/tp/renderer_spec.rb
265
226
  - spec/lib/tp/slide/bulleted_spec.rb
266
227
  - spec/lib/tp/slide/code_spec.rb
267
228
  - spec/lib/tp/slide/header_only_spec.rb