examples/example3.rb in cli_spinnable-0.1 vs examples/example3.rb in cli_spinnable-0.2

- old
+ new

@@ -1,28 +1,39 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'cli_spinnable' -include CliSpinnable +module Cli + extend CliSpinnable +end -puts 'HAPPY RUN (ending with success):' -with_spinner do |cli| +# Close the block before reading from input. + +# Good: +Cli.with_spinner do |cli| cli.print 'Downloading something' sleep 1 - cli.print '...downloaded 1MB' cli.tick - cli.print 'Processing data' +end + +print 'Enter name: ' +name = gets.chomp + +Cli.with_spinner do |cli| + cli.print "Doing something with name #{name}" sleep 1 cli.tick end -puts 'SAD RUN (ending with fail):' -with_spinner do |cli| +# Bad: +Cli.with_spinner do |cli| cli.print 'Downloading something' sleep 1 - cli.print '...downloaded 1MB' cli.tick - cli.print 'Processing data' + + print 'Enter name: ' + name = gets.chomp + + cli.print "Doing something with name #{name}" sleep 1 - 1 / 0 cli.tick end