private function _window_with_lines($name, $lines, $x = 5, $y = 5, $set_width = false)
    {

        // Need an array of lines.
        $lines = (array) $lines;

        // Ignore disabled liens
        $lines = array_filter($lines);

        // Do we not have a specific set width? Calculate the longest line
        if (!is_numeric($set_width)) {
            $longest_line = strlen($name) + 10;
            foreach ($lines as $line) {
                $length = strlen(implode('', $line));
                $longest_line = $length > $longest_line ? $length : $longest_line;
            }
            $width = $longest_line + 4;
        }

        // Otherwise we do have a set with
        else {
            $width = $set_width;
        }

        // Calculate window hight
        $height = 3 + count($lines);

        // Create window
        $win = ncurses_newwin($height, $width, $x, $y);

        // This character will be the side borders
        $side = ord('|');

        // Do the borders of the window
        ncurses_wborder($win, $side, $side, ord('-'), ord('-'), ord('/'), ord('\\'), ord('\\'), ord('/'));

        // Add window title string
        ncurses_mvwaddstr($win, 1, 1, $this->_charpad($name, $width, 'c', '='));

        // Keep track of vertical position for each line
        $v = 1;

        // Go through and output each line, while incrementing line position counter
        foreach ($lines as $line) {
            ncurses_mvwaddstr($win, $v + 1, 1, $this->_charpad($line[0].$this->_charpad($line[1], $width - strlen($line[0]), 'r', '.'), $width, 'n'));
            ++$v;
        }

        // Show it
        ncurses_wrefresh($win);

        // Store it so we can kill it later
        $this->_windows[] = &$win;

        // Return window dimensions
        return array($width, $height);
    }
private function _window_with_lines($name, $lines, $x = 5, $y = 5, $set_width = false)
    {

        // Need an array of lines.
        $lines = (array) $lines;

        // Ignore disabled liens
        $lines = array_filter($lines);

        // Do we not have a specific set width? Calculate the longest line
        if (!is_numeric($set_width)) {
            $longest_line = strlen($name) + 10;
            foreach ($lines as $line) {
                $length = strlen(implode('', $line));
                $longest_line = $length > $longest_line ? $length : $longest_line;
            }
            $width = $longest_line + 4;
        }

        // Otherwise we do have a set with
        else {
            $width = $set_width;
        }

        // Calculate window hight
        $height = 3 + count($lines);

        // Create window
        $win = ncurses_newwin($height, $width, $x, $y);

        // This character will be the side borders
        $side = ord('|');

        // Do the borders of the window
        ncurses_wborder($win, $side, $side, ord('-'), ord('-'), ord('/'), ord('\\'), ord('\\'), ord('/'));

        // Add window title string
        ncurses_mvwaddstr($win, 1, 1, $this->_charpad($name, $width, 'c', '='));

        // Keep track of vertical position for each line
        $v = 1;

        // Go through and output each line, while incrementing line position counter
        foreach ($lines as $line) {
            ncurses_mvwaddstr($win, $v + 1, 1, $this->_charpad($line[0].$this->_charpad($line[1], $width - strlen($line[0]), 'r', '.'), $width, 'n'));
            ++$v;
        }

        // Show it
        ncurses_wrefresh($win);

        // Store it so we can kill it later
        $this->_windows[] = &$win;

        // Return window dimensions
        return array($width, $height);
    }
private function _window_with_lines ( $ name , $ lines , $ x = 5 , $ y = 5 , $ set_width = false ) { // Need an array of lines. $ lines = ( array ) $ lines ; // Ignore disabled liens $ lines = array_filter ( $ lines ) ; // Do we not have a specific set width? Calculate the longest line if ( ! is_numeric ( $ set_width ) ) { $ longest_line = strlen ( $ name ) + 10 ; foreach ( $ lines as $ line ) { $ length = strlen ( implode ( '' , $ line ) ) ; $ longest_line = $ length > $ longest_line ? $ length : $ longest_line ; } $ width = $ longest_line + 4 ; } // Otherwise we do have a set with else { $ width = $ set_width ; } // Calculate window hight $ height = 3 + count ( $ lines ) ; // Create window $ win = ncurses_newwin ( $ height , $ width , $ x , $ y ) ; // This character will be the side borders $ side = ord ( '|' ) ; // Do the borders of the window ncurses_wborder ( $ win , $ side , $ side , ord ( '-' ) , ord ( '-' ) , ord ( '/' ) , ord ( '\\' ) , ord ( '\\' ) , ord ( '/' ) ) ; // Add window title string ncurses_mvwaddstr ( $ win , 1 , 1 , $ this -> _charpad ( $ name , $ width , 'c' , '=' ) ) ; // Keep track of vertical position for each line $ v = 1 ; // Go through and output each line, while incrementing line position counter foreach ( $ lines as $ line ) { ncurses_mvwaddstr ( $ win , $ v + 1 , 1 , $ this -> _charpad ( $ line [ 0 ] . $ this -> _charpad ( $ line [ 1 ] , $ width - strlen ( $ line [ 0 ] ) , 'r' , '.' ) , $ width , 'n' ) ) ; ++ $ v ; } // Show it ncurses_wrefresh ( $ win ) ; // Store it so we can kill it later $ this -> _windows [ ] = & $ win ; // Return window dimensions return array ( $ width , $ height ) ; }
Create a window with various lines as content
Create a window with various lines as content