Class: ProgressWindow

Inherits:
Curses::Window
  • Object
show all
Defined in:
lib/profanity_fe/progress_window.rb

Constant Summary collapse

@@list =
Array.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ProgressWindow

Returns a new instance of ProgressWindow.



11
12
13
14
15
16
17
18
19
# File 'lib/profanity_fe/progress_window.rb', line 11

def initialize(*args)
	@label = String.new
	@fg = [ ]
	@bg = [ '0000aa', '000055' ]
	@value = 0
	@max_value = 100
	@@list.push(self)
	super(*args)
end

Instance Attribute Details

#bgObject

Returns the value of attribute bg.



2
3
4
# File 'lib/profanity_fe/progress_window.rb', line 2

def bg
  @bg
end

#fgObject

Returns the value of attribute fg.



2
3
4
# File 'lib/profanity_fe/progress_window.rb', line 2

def fg
  @fg
end

#labelObject

Returns the value of attribute label.



2
3
4
# File 'lib/profanity_fe/progress_window.rb', line 2

def label
  @label
end

#layoutObject

Returns the value of attribute layout.



2
3
4
# File 'lib/profanity_fe/progress_window.rb', line 2

def layout
  @layout
end

#max_valueObject (readonly)

Returns the value of attribute max_value.



3
4
5
# File 'lib/profanity_fe/progress_window.rb', line 3

def max_value
  @max_value
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/profanity_fe/progress_window.rb', line 3

def value
  @value
end

Class Method Details

.listObject



7
8
9
# File 'lib/profanity_fe/progress_window.rb', line 7

def ProgressWindow.list
	@@list
end

Instance Method Details

#redrawObject



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
# File 'lib/profanity_fe/progress_window.rb', line 30

def redraw
	str = "#{@label}#{@value.to_s.rjust(self.maxx - @label.length)}"
	percent = [[(@value/@max_value.to_f), 0.to_f].max, 1].min
	if (@value == 0) and (fg[3] or bg[3])
		setpos(0, 0)
		attron(color_pair(get_color_pair_id(@fg[3], @bg[3]))|Curses::A_NORMAL) {
			addstr str
		}
	else
		left_str = str[0,(str.length*percent).floor].to_s
		if (@fg[1] or @bg[1]) and (left_str.length < str.length) and (((left_str.length+0.5)*(1/str.length.to_f)) < percent)
			middle_str = str[left_str.length,1].to_s
		else
			middle_str = ''
		end
		right_str = str[(left_str.length + middle_str.length),(@label.length + (self.maxx - @label.length))].to_s
		setpos(0, 0)
		if left_str.length > 0
			attron(color_pair(get_color_pair_id(@fg[0], @bg[0]))|Curses::A_NORMAL) {
				addstr left_str
			}
		end
		if middle_str.length > 0
			attron(color_pair(get_color_pair_id(@fg[1], @bg[1]))|Curses::A_NORMAL) {
				addstr middle_str
			}
		end
		if right_str.length > 0
			attron(color_pair(get_color_pair_id(@fg[2], @bg[2]))|Curses::A_NORMAL) {
				addstr right_str
			}
		end
	end
	noutrefresh
	true
end

#update(new_value, new_max_value = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/profanity_fe/progress_window.rb', line 20

def update(new_value, new_max_value=nil)
	new_max_value ||= @max_value
	if (new_value == @value) and (new_max_value == @max_value)
		false
	else
		@value = new_value
		@max_value = [new_max_value, 1].max
		redraw
	end
end