enabled = false; // Cannot accept focus $this->max = $max; $this->show_pct = $show_pct; $this->pos( 0 ); } /** * Set or get the current value * * @param float $value New value * @return float Current value */ public function pos( $value = false ) { if( $value === false ) { return $this->value; } else { $value = $value > $this->max ? $this->max : $value; $this->value = $value; $this->write( 0, 0, '[', false ); $width = $this->width - ( $this->show_pct ? 7 : 2 ); $width = $width >= 0 ? $width : 0; $complete = floor( $width * $value / $this->max ); $this->write( 0, 1, str_repeat( '#', $complete ), false ); $this->write( 0, 1 + $complete, str_repeat( ' ', $width - $complete ), false ); $this->write( 0, $width + 1, ']', false ); if( $this->show_pct ) { $this->write( 0, $width + 3, sprintf( '%3d%%', floor( $value / $this->max * 100 ) ), false ); } ncurses_update_panels(); ncurses_doupdate(); } } /** * Get or set maximum value * * @param float $value New maximum * @return float Current maximum */ public function max( $value = false ) { if( $value === false ) { return $this->max; } else { $this->max = $value > 0 ? $value : $this->max; $this->pos( $this->value ); } } } ?>