Class: PPool::CursesProcessController

Inherits:
TimedProcessController show all
Defined in:
lib/curses_process_controller.rb

Instance Method Summary collapse

Methods inherited from TimedProcessController

#dec_size, #delay, #finished, #finishing, #finishing?, #inc_size, #num_processes, #process_started, #running?, #set_size

Methods inherited from ShellProcessController

#delete_log_file, #info, #process_ended, #run_process

Methods inherited from BasicProcessController

#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_windowObject



95
96
97
98
99
100
101
# File 'lib/curses_process_controller.rb', line 95

def draw_window
   @win.clear
   @win.attron(Curses.color_pair(1)|Curses::A_NORMAL) {
	 @win.box('|', '-')
   }

end

#init_windowObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# 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

#process_keysObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/curses_process_controller.rb', line 123

def process_keys 

   # Need to reset keyboard handling after a process
   # has been forked.
   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
# 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("Errors    #{stats[:errors]}")
	@win.setpos(8 , 5)
	@win.addstr("Logs      #{@logdir}")
	@win.setpos(9 , 5)
	@win.addstr("          #{@msg}")
  }

  process_keys

  if finishing?
	if stats[:active_processes] == 0
	  finished
	end
  end
  @win.refresh

end

#terminateObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/curses_process_controller.rb', line 103

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 "Errors   #{@last_stats[:errors]}"
  puts "Logs     #{@logdir}"
  puts "         #{@msg}"
  puts ""

  exit(0)
end