run 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/lib/run/version.rb +1 -1
  4. data/lib/run.rb +24 -13
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56c488bdc8ebd612e4dd4189178fba5ae9ba8b2a09c4c191908f35b8265e01b9
4
- data.tar.gz: 0a7396df5efdd6374b59b3634b7cc6cdf326a4e1e5f5716ce6ba8d5a3d81414b
3
+ metadata.gz: 8f9c6f6ba4fc26aaf2318d02898e7bde47f74c71ae2f17c656b9877f939ddedc
4
+ data.tar.gz: 66c092630626dfbe12a8bce7531f1e890cd1825d2093193521fffccec71a8333
5
5
  SHA512:
6
- metadata.gz: 2d60cc84910d67f91573406c64785631675e8fbd605bb17ff297c2c4a225be60eb0b5458a868ebd9f0c050112175dc5f4e8803f58d7f0b0edc9df8a2c7b077bb
7
- data.tar.gz: d171c28a705c8ca5646b5f70e161e9ecd26e04ac94170f90f83114367d10cb0638675af1bfb3d008585d1934ebce62eecb9470055bc79c261a43206df9b84564
6
+ metadata.gz: a43e218dd3b40650c767d03baaef6dd0ff067ecd14eaaef034604a64bb516f1f826fe202f2e613b081db0bc518185ecdfb70a57dad0e941e8dd6ca4bbb7e21c1
7
+ data.tar.gz: 648ba6b86743aafb8d0a9c4d579d2a119aed9aaefc467fdb16235933c315d38a341b6d1b0ad48660bd63e7c082d8f1b18f10b6d8e1bfed01c045a16cd590afd9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- run (0.1.1)
4
+ run (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -42,4 +42,4 @@ DEPENDENCIES
42
42
  run!
43
43
 
44
44
  BUNDLED WITH
45
- 2.0.1
45
+ 2.1.4
data/lib/run/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Run
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/run.rb CHANGED
@@ -1,6 +1,7 @@
1
+ require 'io/console'
1
2
  require 'run/version'
2
- require 'byebug'
3
3
  require 'yaml'
4
+ require 'byebug'
4
5
 
5
6
  class RunError < StandardError; end
6
7
 
@@ -12,26 +13,24 @@ module Run
12
13
 
13
14
  parse_options(args) unless args.empty?
14
15
 
15
- trap('INT') { bye }
16
- trap('TERM') { bye }
16
+ @max_length||=4000
17
17
 
18
+ @eot=0x03
18
19
  @eof=0x04
19
- @max_length||=4000
20
20
 
21
21
  if quotes.empty?
22
22
  puts "No quotes with less than #{@max_length} characters found"
23
23
  exit
24
24
  end
25
25
 
26
- @text=quotes[rand(quotes.size)]
27
-
28
26
  @color="\e[4;32m"
29
27
  @no_color="\e[m"
30
28
 
29
+ @lines=quotes[rand(quotes.size)].chars.each_slice(term_width).map(&:join)
30
+ @line=0
31
31
  @pos=0
32
- max_pos=text.size
33
32
 
34
- # average English word length
33
+ # average length of English words
35
34
  @word_length=5
36
35
 
37
36
  @start_time=time
@@ -39,7 +38,7 @@ module Run
39
38
 
40
39
  loop do
41
40
  update_text
42
- break if pos==max_pos
41
+ break if @line==@lines.size-1 and pos==@lines.last.size
43
42
  end
44
43
 
45
44
  puts "\nWPM: #{wpm}"
@@ -88,7 +87,7 @@ module Run
88
87
  end
89
88
 
90
89
  def wpm
91
- text.size*60/((time-@start_time)*@word_length)
90
+ @lines.join(' ').size*60/((time-@start_time)*@word_length)
92
91
  end
93
92
 
94
93
  def quotes
@@ -104,20 +103,32 @@ module Run
104
103
  end
105
104
 
106
105
  def print_text
107
- print "\r"+text.sub(/(.{#{pos}})/,"#{@color}\\1#{@no_color}")
106
+ print "\r"+text.sub(/(.{#{pos}})/,"#{@color}\\1#{@no_color}")+"\r"
107
+ end
108
+
109
+ # width of the terminal
110
+ def term_width
111
+ IO.console.winsize.last
108
112
  end
109
113
 
110
114
  def update_text
111
115
  system('stty raw -echo')
112
- bye if (c=STDIN.getc)==@eof.chr
116
+ c=STDIN.getc
117
+ bye if c==@eof.chr or c==@eot.chr
118
+ carriage_return if @pos>=term_width-1
113
119
  @pos+=1 if c==text[pos]
114
120
  ensure
115
121
  system('stty -raw echo')
116
122
  print_text
117
123
  end
118
124
 
125
+ def carriage_return
126
+ @pos=0
127
+ @line+=1
128
+ end
129
+
119
130
  def text
120
- @text
131
+ @lines[@line]
121
132
  end
122
133
 
123
134
  def pos
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergioro
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  - !ruby/object:Gem::Version
165
165
  version: '0'
166
166
  requirements: []
167
- rubygems_version: 3.0.3
167
+ rubygems_version: 3.0.6
168
168
  signing_key:
169
169
  specification_version: 4
170
170
  summary: Increase your typing speed