limit = $limit; ncurses_init(); // Border the screen. ncurses_border(0,0, 0,0, 0,0, 0,0); // Get the size of the screen. ncurses_getmaxyx(STDSCR, $lines, $columns); // Make a window in the middle that's half the width of the screen. $width = $columns / 2; $this->window = ncurses_newwin(15, $width, $lines/4, $width/2); ncurses_wborder($this->window, 0,0, 0,0, 0,0, 0,0); // Title it. ncurses_mvwaddstr($this->window, 0, 5, $title); // Show progress bar boundaries. ncurses_mvwaddstr($this->window, 12, 1, '|'); ncurses_mvwaddstr($this->window, 12, $width-2, '|'); // Figure out what one character is worth based on the above. $this->unit = round($limit / ($width - 3)); ncurses_refresh(); } /** * @param int $place - number of the current task */ public function update ($place) { if (! function_exists('ncurses_init')) return; ncurses_mvwaddstr($this->window, 5, 5, 'Processing record '.$place.' of '.$this->limit); $percent = (round($place / $this->limit, 2) * 100) . '%'; ncurses_mvwaddstr($this->window, 10, 5, $percent); if ($place % $this->unit == 0) { $this->bar_x += 1; ncurses_mvwaddstr($this->window, 12, $this->bar_x, '=>'); } ncurses_wrefresh($this->window); if ($place >= $this->limit) ncurses_end(); } public function __destruct () { if (! ncurses_isendwin()) { ncurses_end(); } } }