Class: PPool::CursesProcessController
Instance Method Summary
collapse
#dec_size, #delay, #finished, #finishing, #finishing?, #inc_size, #num_processes, #process_started, #running?, #set_size
#delete_log_file, #info, #process_ended, #run_process
#delay, #info, #num_processes, #process_ended, #process_started, #run_process, #running?, #time_running, #time_running_secs
Constructor Details
#initialize(size, delay, script, time, logdir, rmlogs) ⇒ CursesProcessController
Returns a new instance of CursesProcessController.
31
32
33
34
35
36
|
# File 'lib/curses_process_controller.rb', line 31
def initialize(size, delay, script, time, logdir, rmlogs)
super(size, delay, script, time, logdir, rmlogs)
@msg = ""
@last_stats = {}
init_window
end
|
Instance Method Details
#draw_window ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/curses_process_controller.rb', line 97
def draw_window
@win.clear
@win.attron(Curses.color_pair(1)|Curses::A_NORMAL) {
@win.box('|', '-')
}
end
|
#init_window ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/curses_process_controller.rb', line 76
def init_window
info "init_window"
Curses.init_screen
Curses.start_color
Curses.init_pair(1, Curses::COLOR_BLUE, Curses::COLOR_BLACK)
Curses.init_pair(2, Curses::COLOR_RED, Curses::COLOR_BLACK)
Curses.init_pair(3, Curses::COLOR_WHITE, Curses::COLOR_BLACK)
lines = Curses.lines
cols = Curses.cols
height = 12
width = 70
@win = Curses::Window.new(height, width, 2, 2)
draw_window
end
|
#process_keys ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/curses_process_controller.rb', line 126
def process_keys
Curses.noecho
Curses.cbreak
Curses.nonl
Curses.curs_set(0)
@win.keypad = true
@win.nodelay = true
c = @win.getch
case c
when '+', Curses::KEY_UP
inc_size
when '-', Curses::KEY_DOWN
dec_size
when '0'..'9'
set_size(c.to_i)
when 'q', 'Q'
finishing
when 'x', 'X'
terminate
end
end
|
#progress(stats) ⇒ Object
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
71
72
73
74
|
# File 'lib/curses_process_controller.rb', line 38
def progress(stats)
@last_stats = stats
draw_window
@win.attron(Curses.color_pair(3)|Curses::A_BOLD) {
@win.setpos(2 , 5)
@win.addstr("Time #{time_running}")
@win.setpos(3 , 5)
@win.addstr("Size #{@size}")
@win.setpos(4 , 5)
@win.addstr("Running #{stats[:active_processes]}")
@win.setpos(5 , 5)
@win.addstr("Started #{stats[:processes_started]}")
@win.setpos(6 , 5)
@win.addstr("Ended #{stats[:processes_ended]}")
@win.setpos(7 , 5)
@win.addstr("Avg Elapsed Time #{stats[:avg_elapsed_time]} (ms)")
@win.setpos(8 , 5)
@win.addstr("Errors #{stats[:errors]}")
@win.setpos(9 , 5)
@win.addstr("Logs #{@logdir}")
@win.setpos(10 , 5)
@win.addstr(" #{@msg}")
}
process_keys
if finishing?
if stats[:active_processes] == 0
finished
end
end
@win.refresh
end
|
#terminate ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/curses_process_controller.rb', line 105
def terminate
info "terminate"
Curses.close_screen
puts ""
puts "Time #{time_running}"
puts "Size #{@size}"
puts "Running #{@last_stats[:active_processes]}"
puts "Started #{@last_stats[:processes_started]}"
puts "Ended #{@last_stats[:processes_ended]}"
puts "Avg Elapsed Time #{@last_stats[:avg_elapsed_time]}"
puts "Errors #{@last_stats[:errors]}"
puts "Logs #{@logdir}"
puts " #{@msg}"
puts ""
exit(0)
end
|