Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
#!/usr/bin/env ruby require 'osx/cocoa' include OSX class AppDelegate < NSObject def applicationDidFinishLaunching(aNotification) url = ARGV[0].dup url.gsub!(/http:\/\//, "http://slactoid:easy4kastner@") begin Thread.start { OSX::NSRunLoop.currentRunLoop.run } cmd = "cd ~ && axel -a #{url}" last_number = 0 IO.popen(cmd) do |pipe| pipe.each("\r") do |line| number = line[/[^\d]([\d]+)%/].to_i speed = line[/[^\d][\d\.]+KB\/s/].to_f # puts number + " / " + speed if last_number != number last_number = number advance_slider(number) write_speed(speed) end end end rescue end end def moveForward(sender) # advanceSlider(55) puts sender.setTitle("bob") # puts app.mainWindow end def advance_slider(value) # $pro.startAnimation($pro) $pro.setDoubleValue(value.to_f) $pro.stopAnimation($pro) end def write_speed(speed) $txt.setStringValue(speed) end end if $0 == __FILE__ then OSX.ruby_thread_switcher_start(0.001, 0.1) $stderr.print "just wait..." ; $stderr.flush app = NSApplication.sharedApplication() app.setDelegate(AppDelegate.alloc.init) frame = [400.0, 300.0, 452.0, 107.0] win = NSWindow.alloc.initWithContentRect_styleMask_backing_defer(frame, 15, 2, 0) win.setTitle 'Axel Progress' win.setLevel(3) # floating window $pro = NSProgressIndicator.alloc.initWithFrame [18.0, 48.0, 416.0, 20.0] $pro.setIndeterminate(0) $pro.setDoubleValue(0) win.contentView.addSubview($pro) # hel.setTarget( app.delegate ) $txt = NSTextField.alloc.initWithFrame [316.0, 10.0, 114.0, 22.0] # $txt.setTitle("Bob") $txt.setEditable(0) $txt.setSelectable(0) $txt.setBezeled(0) $txt.setDrawsBackground(0) # $txt.setStringValue("Bob") $txt.setAlignment(NSRightTextAlignment) win.contentView.addSubview($txt) # hel = NSButton.alloc.initWithFrame [356.0, 12.0, 82.0, 32.0] # win.contentView.addSubview(hel) # hel.setBezelStyle(1) # hel.setTitle( 'Advance!' ) # hel.setTarget( app.delegate ) # hel.setAction( "moveForward:" ) win.display() win.orderFrontRegardless() ## but this one does app.run() exit 0 end
This paste will be private.
From the Design Piracy series on my blog: