Class: Toolman::ToolmanS

Inherits:
Object
  • Object
show all
Defined in:
lib/toolman.rb

Instance Method Summary collapse

Constructor Details

#initializeToolmanS

Returns a new instance of ToolmanS.



63
64
65
66
67
68
69
# File 'lib/toolman.rb', line 63

def initialize
	@tempPoint = 0 
	@circle = ["|","\\","-","/"]
	@circleSize = @circle.size
	@loadBarPid = 0
	@colorMechine = Color.new
end

Instance Method Details

#loading_bar(nowPoint, endPoint) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/toolman.rb', line 82

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

#loading_bar_addObject



131
132
133
# File 'lib/toolman.rb', line 131

def loading_bar_add()
	@write.write(1)
end

#loading_bar_endObject



135
136
137
# File 'lib/toolman.rb', line 135

def loading_bar_end()
	@write.write(0)
end

#putsObject



71
72
73
# File 'lib/toolman.rb', line 71

def puts
	@colorMechine
end

#say(data) ⇒ Object



76
77
78
79
80
# File 'lib/toolman.rb', line 76

def say(data)
	puts "\n>>>>>>>>>>>>>>>>>Messange>>>>>>>>>>>>>>>>>"
	puts "#{data}"
	puts ">>>>>>>>>>>>>>>>>Messange>>>>>>>>>>>>>>>>>\n"
end