vimgolf 0.4.2 → 0.4.3
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.
- data/lib/vimgolf/cli.rb +52 -20
- data/lib/vimgolf/version.rb +1 -1
- metadata +3 -3
data/lib/vimgolf/cli.rb
CHANGED
@@ -84,40 +84,57 @@ module VimGolf
|
|
84
84
|
diff = `#{GOLFDIFF} #{diff_files}`
|
85
85
|
log = Keylog.new(IO.read(challenge.log_path))
|
86
86
|
|
87
|
+
# Handle incorrect solutions
|
87
88
|
if diff.size > 0
|
88
|
-
VimGolf.ui.
|
89
|
+
VimGolf.ui.error "\nUh oh, looks like your entry does not match the desired output."
|
90
|
+
VimGolf.ui.error "Your score for this failed attempt was: #{log.score}"
|
91
|
+
|
89
92
|
loop do
|
90
|
-
|
93
|
+
VimGolf.ui.warn "[d] Show a diff"
|
94
|
+
VimGolf.ui.warn "[r] Retry the current challenge"
|
95
|
+
VimGolf.ui.warn "[q] Quit vimgolf"
|
96
|
+
|
97
|
+
case VimGolf.ui.ask_question "Choice> ",
|
91
98
|
:type => :warn,
|
92
99
|
:choices => [:diff, :retry, :quit]
|
93
100
|
when :diff
|
94
101
|
VimGolf.ui.warn "Showing vimdiff of your attempt (left) and correct output (right)"
|
95
102
|
system("#{GOLFSHOWDIFF} #{diff_files}")
|
96
103
|
when :retry
|
97
|
-
VimGolf.ui.warn "
|
104
|
+
VimGolf.ui.warn "Retrying current challenge..."
|
98
105
|
challenge.start
|
99
106
|
raise RetryException
|
100
107
|
when :quit
|
101
|
-
|
102
|
-
return
|
108
|
+
raise Interrupt
|
103
109
|
end
|
104
110
|
end
|
105
111
|
end
|
106
112
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
113
|
+
# Handle correct solutions
|
114
|
+
VimGolf.ui.info "\nSuccess! Your output matches. Your score: #{log.score}"
|
115
|
+
|
116
|
+
loop do
|
117
|
+
VimGolf.ui.warn "[w] Upload result and retry the challenge"
|
118
|
+
VimGolf.ui.warn "[x] Upload result and quit"
|
119
|
+
VimGolf.ui.warn "[r] Do not upload result and retry the challenge"
|
120
|
+
VimGolf.ui.warn "[q] Do not upload result and quit"
|
121
|
+
|
122
|
+
case VimGolf.ui.ask_question "Choice> ",
|
123
|
+
:type => :warn,
|
124
|
+
:choices => [:w, :x, :retry, :quit]
|
125
|
+
when :w
|
126
|
+
next unless upload?(challenge)
|
127
|
+
challenge.start
|
128
|
+
raise RetryException
|
129
|
+
when :x
|
130
|
+
next unless upload?(challenge)
|
131
|
+
raise Interrupt
|
132
|
+
when :retry
|
133
|
+
challenge.start
|
134
|
+
raise RetryException
|
135
|
+
when :quit
|
136
|
+
raise Interrupt
|
117
137
|
end
|
118
|
-
|
119
|
-
else
|
120
|
-
VimGolf.ui.warn "Skipping upload. Thanks for playing. Give it another shot!"
|
121
138
|
end
|
122
139
|
|
123
140
|
else
|
@@ -133,15 +150,30 @@ module VimGolf
|
|
133
150
|
retry
|
134
151
|
end
|
135
152
|
|
153
|
+
rescue Interrupt, StandardError
|
154
|
+
VimGolf.ui.info "\nThanks for playing!"
|
136
155
|
rescue Exception => e
|
137
156
|
VimGolf.ui.error "Uh oh, something went wrong! Error: #{e}"
|
138
157
|
VimGolf.ui.error "If the error persists, please report it to github.com/igrigorik/vimgolf"
|
139
158
|
end
|
140
159
|
|
141
160
|
private
|
142
|
-
|
143
|
-
|
161
|
+
|
162
|
+
def upload?(challenge)
|
163
|
+
VimGolf.ui.warn "Uploading to VimGolf..."
|
164
|
+
|
165
|
+
if challenge.upload == :ok
|
166
|
+
VimGolf.ui.warn "Uploaded entry."
|
167
|
+
VimGolf.ui.warn "View the leaderboard: #{GOLFHOST}/challenges/#{challenge.id}"
|
168
|
+
else
|
169
|
+
VimGolf.ui.error "Uh oh, upload failed. You're not cheating are you? :-)"
|
170
|
+
nil
|
144
171
|
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def debug(msg)
|
175
|
+
p [caller.first, msg] if GOLFDEBUG
|
176
|
+
end
|
145
177
|
end
|
146
178
|
|
147
179
|
end
|
data/lib/vimgolf/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vimgolf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-06-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -121,7 +121,7 @@ post_install_message: ! '
|
|
121
121
|
|
122
122
|
------------------------------------------------------------------------------
|
123
123
|
|
124
|
-
Thank you for installing vimgolf-0.4.
|
124
|
+
Thank you for installing vimgolf-0.4.3.
|
125
125
|
|
126
126
|
|
127
127
|
0.1.3: custom vimgolf .vimrc file to help level the playing field
|