run 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/run/version.rb +1 -1
- data/lib/run.rb +24 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f9c6f6ba4fc26aaf2318d02898e7bde47f74c71ae2f17c656b9877f939ddedc
|
4
|
+
data.tar.gz: 66c092630626dfbe12a8bce7531f1e890cd1825d2093193521fffccec71a8333
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a43e218dd3b40650c767d03baaef6dd0ff067ecd14eaaef034604a64bb516f1f826fe202f2e613b081db0bc518185ecdfb70a57dad0e941e8dd6ca4bbb7e21c1
|
7
|
+
data.tar.gz: 648ba6b86743aafb8d0a9c4d579d2a119aed9aaefc467fdb16235933c315d38a341b6d1b0ad48660bd63e7c082d8f1b18f10b6d8e1bfed01c045a16cd590afd9
|
data/Gemfile.lock
CHANGED
data/lib/run/version.rb
CHANGED
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
|
-
|
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
|
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
|
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
|
-
|
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
|
-
|
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
|
-
@
|
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.
|
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.
|
167
|
+
rubygems_version: 3.0.6
|
168
168
|
signing_key:
|
169
169
|
specification_version: 4
|
170
170
|
summary: Increase your typing speed
|