Method: ToolmanS#loading_bar

Defined in:
lib/toolman/toolS.rb

#loading_bar(nowPoint, endPoint) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/toolman/toolS.rb', line 23

def loading_bar(nowPoint,endPoint)
	read, write = IO.pipe
	@loadBarPid = fork {
			
		
		write.close
		continue = true
		sleep_time = 1.0/7.0
		index = 0 
		while(continue) do
			p = (( (nowPoint*1.0) / endPoint) * 100).floor
			print "\r"
			print "                                                  \r"
			print "%5d%s%3s%-3s" % [p,"%","#{@circle[@tempPoint]}",""]
			@tempPoint = (@tempPoint + 1) % @circleSize
			if p == 100
				print "\r"
				print "                                                  \r"
				print "%5d%s%3s%-3s" % [p,"%","",""]
				read.close
				exit(0)
			end
			sleep(sleep_time)
			s = IO.select([read],[],[],sleep_time)
			if s 
				result = read.read(1)
				if result
					if result.to_i == 1
						nowPoint += 1
					elsif result.to_i == 0
						puts ""
						puts "Early break..."
						read.close
						exit(0)
					end
				end
				index += 1
			end

			
		end

	}
	read.close
	@write = write
	# Process.wait(@loadBarPid)
	# puts "hi"
end