Class: Cxxproject::Utils::Progress

Inherits:
Object
  • Object
show all
Defined in:
lib/cxxproject/utils/rbcurse_progress.rb

Instance Method Summary collapse

Constructor Details

#initialize(form, size) ⇒ Progress

Returns a new instance of Progress.



4
5
6
7
8
9
# File 'lib/cxxproject/utils/rbcurse_progress.rb', line 4

def initialize(form, size)
  @width = size[0]
  initialize_progress(form, size)
  initialize_title(form, size)
  max = 100
end

Instance Method Details

#format_progressObject



50
51
52
53
54
55
# File 'lib/cxxproject/utils/rbcurse_progress.rb', line 50

def format_progress
  total = (percentage * @width.to_f).to_i
  text = "#" * total
  @progress.text = text
  @progress.repaint_all(true)
end

#format_titleObject



57
58
59
60
61
# File 'lib/cxxproject/utils/rbcurse_progress.rb', line 57

def format_title
  format = "%3d%% - worked on %s                                                                    "
  @title.text = sprintf(format, (percentage*100).to_i, @title_text)
  @title.repaint_all(true)
end

#inc(i) ⇒ Object



40
41
42
43
44
# File 'lib/cxxproject/utils/rbcurse_progress.rb', line 40

def inc(i)
  @current += i
  format_title
  format_progress
end

#initialize_progress(form, size) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cxxproject/utils/rbcurse_progress.rb', line 11

def initialize_progress(form, size)
  @progress = Label.new form do
    name 'progress'
    row size[1]-1
    col 0
    width size[0]
    height 1
  end
  @progress.display_length(@width)
  @progress.text = ' '*@width
end

#initialize_title(form, size) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cxxproject/utils/rbcurse_progress.rb', line 23

def initialize_title(form, size)
  @title = Label.new form do
    name 'title'
    row size[1]-2
    col 0
    width size[0]
    height 1
  end
  @title.display_length(@widget)
  @title.text = 'Idle'
end

#max=(f) ⇒ Object



63
64
65
66
67
68
# File 'lib/cxxproject/utils/rbcurse_progress.rb', line 63

def max=(f)
  @max = f.to_f
  @current = 0.0
  format_progress
  format_title
end

#percentageObject



46
47
48
# File 'lib/cxxproject/utils/rbcurse_progress.rb', line 46

def percentage
  return @current.to_f / @max.to_f
end

#title=(t) ⇒ Object



35
36
37
38
# File 'lib/cxxproject/utils/rbcurse_progress.rb', line 35

def title=(t)
  @title_text = t
  format_title
end