Skip to content

Commit

Permalink
preserve input filetype for syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
igrigorik committed Dec 28, 2010
1 parent be1fe51 commit 283bd16
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/vimgolf/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ def setup
def put(id = nil)
VimGolf.ui.warn "Launching VimGolf session for challenge: #{id}"

if download(id) == :ok
type = download(id)

# - Z - start in restricted mode - no system commands
if !type.nil? && !type.empty?
# - n - no swap file, memory only editing
# - --noplugin - don't load any plugins, lets be fair!
# - +0 - always start on line 0
system("vim -Z -n --noplugin +0 -W #{log(id)} #{input(id)}")
system("vim -n --noplugin +0 -W #{log(id)} #{input(id, type)}")

if $?.exitstatus.zero?
diff = `diff --strip-trailing-cr #{input(id)} #{output(id)}`
diff = `diff --strip-trailing-cr #{input(id, type)} #{output(id)}`

if diff.size > 0
VimGolf.ui.warn "Uh oh, looks like your entry does not match the desired output:"
Expand Down Expand Up @@ -120,10 +120,11 @@ def download(id)
raise
end

File.open(Config.put_path + "/#{id}.input", "w") {|f| f.puts data['in']}
File.open(Config.put_path + "/#{id}.output", "w") {|f| f.puts data['out']}
File.open(Config.put_path + "/#{id}.#{data['in']['type']}", "w") {|f| f.puts data['in']['data']}
File.open(Config.put_path + "/#{id}.output", "w") {|f| f.puts data['out']['data']}

data['in']['type']

:ok
rescue Exception => e
VimGolf.ui.error "Uh oh, couldn't download or parse challenge, please verify your challenge id and client version."
end
Expand All @@ -148,7 +149,7 @@ def upload(id)
end
end

def input(id); challenge(id) + ".input"; end
def input(id, type); challenge(id) + ".#{type}"; end
def output(id); challenge(id) + ".output"; end
def log(id); challenge(id) + ".log"; end

Expand Down

0 comments on commit 283bd16

Please sign in to comment.