Class: CursesProcessController
Instance Method Summary
collapse
#info, #run_process
#info, #run_process, #time_running
Constructor Details
Returns a new instance of CursesProcessController.
6
7
8
9
10
11
12
13
14
|
# File 'lib/curses_process_controller.rb', line 6
def initialize(size, script, logdir)
super(script, logdir)
@finishing = false
@finished = false
@size = size
@msg = ""
@last_stats = {}
init_window
end
|
Instance Method Details
#delay ⇒ Object
69
70
71
|
# File 'lib/curses_process_controller.rb', line 69
def delay
return 0.1
end
|
#draw_window ⇒ Object
101
102
103
104
105
106
107
|
# File 'lib/curses_process_controller.rb', line 101
def draw_window
@win.clear
@win.attron(Curses.color_pair(1)|Curses::A_NORMAL) {
@win.box('|', '-')
}
end
|
#finished ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/curses_process_controller.rb', line 109
def finished
info "finished"
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 "Errors #{@last_stats[:errors]}"
puts "Logs #{@logdir}"
puts " #{@msg}"
puts ""
exit(0)
end
|
#init_window ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/curses_process_controller.rb', line 74
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
|
#num_processes ⇒ Object
20
21
22
|
# File 'lib/curses_process_controller.rb', line 20
def num_processes
return @size
end
|
#process_ended(pid, status) ⇒ Object
28
29
30
|
# File 'lib/curses_process_controller.rb', line 28
def process_ended(pid, status)
end
|
#process_keys ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/curses_process_controller.rb', line 128
def process_keys
Curses.noecho
Curses.cbreak
Curses.nonl
Curses.curs_set(0)
@win.keypad = true
@win.nodelay = true
case @win.getch
when '+', Curses::KEY_UP
@size = @size + 1
when '-', Curses::KEY_DOWN
@size = @size - 1
if @size < 0
@size = 0
end
when 'q', 'Q'
@size = 0
@finishing = true
when 'x', 'X'
finished
end
end
|
#process_started(pid, num_processes) ⇒ Object
25
26
|
# File 'lib/curses_process_controller.rb', line 25
def process_started(pid, num_processes)
end
|
#progress(stats) ⇒ Object
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
|
# File 'lib/curses_process_controller.rb', line 32
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("Errors #{stats[:errors]}")
@win.setpos(8 , 5)
@win.addstr("Logs #{@logdir}")
@win.setpos(9 , 5)
@win.addstr(" #{@msg}")
}
process_keys
if @finishing
info "finishing #{stats[:active_processes]}"
if stats[:active_processes] == 0
@finished = true
end
end
@win.refresh
end
|
#running? ⇒ Boolean
16
17
18
|
# File 'lib/curses_process_controller.rb', line 16
def running?
return !@finished
end
|