Example #1
0
 public function draw($map)
 {
     foreach ($map as $i => $line) {
         foreach ($line as $j => $item) {
             //$lineStr .= $this->format($item);
             ncurses_wmove($this->getWindow(), $i + 1, $j + 1);
             ncurses_wcolor_set($this->getWindow(), $this->formatColor($item));
             ncurses_waddstr($this->getWindow(), $this->format($item));
         }
         //ncurses_color_set(62);
         // ncurses_mvwaddstr($this->getWindow(), $i+1, 1, $lineStr);
     }
 }
 /**
  * Draw an array of text to a given panel, with line wraps.
  * This makes sure we only draw text within the panel borders, not over
  * the top of them.
  *
  * @param $panel Panel we are drawing text on.
  * @param Array of text to draw.
  */
 public function drawTextToWindow($panel, $text)
 {
     $y = 1;
     $x = 2;
     ncurses_getmaxyx($panel, $height, $width);
     $arrayStart = 0 - $height + 2;
     $out = array();
     foreach (array_slice($text, $arrayStart) as $line) {
         $line = wordwrap($line, $width - 4, "\n", true);
         foreach (explode("\n", $line) as $l) {
             $out[] = $l;
         }
     }
     foreach (array_slice($out, $arrayStart) as $line) {
         ncurses_wmove($panel, $y, $x);
         ncurses_waddstr($panel, $line);
         $y++;
     }
 }
 /**
  * Prints a text to the pad
  * @param string $text text to print
  * @param int $color [optional] text color. One of the VarDumpNcurses::COLOR_* constants. Defaults to VarDumpNcurses::COLOR_DEFAULT.
  * @return int number of characters printed
  */
 protected function printRawText($text, $color = VarDumpNcurses::COLOR_DEFAULT)
 {
     if ($this->internalWriteEnabled) {
         return $this->printRawTextInternal($text);
     }
     // print the text
     ncurses_wcolor_set($this->pad, $color);
     ncurses_waddstr($this->pad, $text);
     return strlen($text);
 }
Example #4
0
 /**
  * Prints a text to the pad
  * @param string $text text to print
  * @param int $color [optional] text color. One of the VarDumpNcurses::COLOR_* constants. Defaults to VarDumpNcurses::COLOR_DEFAULT.
  * @return int number of characters printed
  */
 protected function printRawText($text, $color = VarDumpNcurses::COLOR_DEFAULT)
 {
     if ($this->internalWriteEnabled) {
         return $this->printRawTextInternal($text);
     }
     // verify if the color must be bolded
     $bold = false;
     if (in_array($color, $this->boldColorList)) {
         ncurses_wattron($this->pad, NCURSES_A_BOLD);
         $bold = true;
     }
     // print the text
     ncurses_wcolor_set($this->pad, $color);
     ncurses_waddstr($this->pad, $text);
     // unbold
     if ($bold) {
         ncurses_wattroff($this->pad, NCURSES_A_BOLD);
     }
     return strlen($text);
 }
Example #5
0
 /**
  * Draws a string at current position
  * @param string $string String
  * @param integer $attributes Ncurses attributes (eg. NCURSES_A_REVERSE)
  * @see http://pubs.opengroup.org/onlinepubs/007908799/xcurses/curses.h.html for available attributes (WA_LOW => NCURSES_A_LOW)
  * @return Window This object
  */
 public function drawStringHere($string, $attributes = 0)
 {
     ncurses_wattron($this->windowResource, $attributes);
     ncurses_waddstr($this->windowResource, $string);
     ncurses_wattroff($this->windowResource, $attributes);
     return $this;
 }
 /**
  * Refresh the footer window
  */
 protected function refreshFooter()
 {
     $length = 1;
     $labels = array("F1" => "Help", "F2" => "Var dump", "F3" => "Stack trace", "Q" => "Quit");
     if (null === $this->rendererStackTrace) {
         unset($labels["F3"]);
     }
     ncurses_werase($this->windowFooter);
     // write an empty space
     ncurses_wattron($this->windowFooter, NCURSES_A_REVERSE);
     ncurses_wcolor_set($this->windowFooter, NCURSES_COLOR_CYAN);
     ncurses_waddstr($this->windowFooter, " ");
     ncurses_wattroff($this->windowFooter, NCURSES_A_REVERSE);
     // write key/labels
     foreach ($labels as $key => $label) {
         ncurses_wcolor_set($this->windowFooter, 0);
         ncurses_waddstr($this->windowFooter, $key);
         ncurses_wattron($this->windowFooter, NCURSES_A_REVERSE);
         ncurses_wcolor_set($this->windowFooter, NCURSES_COLOR_CYAN);
         ncurses_waddstr($this->windowFooter, "{$label} ");
         ncurses_wattroff($this->windowFooter, NCURSES_A_REVERSE);
         $length += strlen($key);
         $length += strlen($label);
         $length += 1;
     }
     // fill the line
     $fillStr = str_repeat(" ", $this->windowFooterWidth - $length);
     ncurses_wattron($this->windowFooter, NCURSES_A_REVERSE);
     ncurses_wcolor_set($this->windowFooter, NCURSES_COLOR_CYAN);
     ncurses_waddstr($this->windowFooter, $fillStr);
     ncurses_wattroff($this->windowFooter, NCURSES_A_REVERSE);
     ncurses_wrefresh($this->windowFooter);
 }
Example #7
0
 function setuserinput()
 {
     $sStatus = date("[H:i:s] ") . "[" . $this->aDisplayVars['nick'] . "] [Win: ";
     ncurses_mvwaddstr($this->userinputw, 0, 0, $this->cl);
     ncurses_mvwaddstr($this->userinputw, 0, 0, $sStatus);
     /* Now we need to draw states for our various windows. */
     $bShow = false;
     $aInactive = array();
     $aActive = array();
     $iChans = 0;
     // Draw a list of all windows. First, get two arrays of which are active and not.
     foreach ($this->aBuffers as $iBuffer => $oBuffer) {
         if ($oBuffer->active == true) {
             $aActive[] = $iBuffer;
         } else {
             $aInactive[] = $iBuffer;
         }
     }
     // Now generate out list. First of all, we want to draw only active windows. We also want them to stand out.
     foreach ($aActive as $iActive) {
         if ($bShow == false) {
             ncurses_wcolor_set($this->userinputw, NC_PAIR_INPUT_ACTIVE);
             ncurses_waddstr($this->userinputw, $iActive);
             ncurses_wcolor_set($this->userinputw, NC_PAIR_INPUT);
             $bShow = true;
         } else {
             ncurses_waddstr($this->userinputw, ",");
             ncurses_wcolor_set($this->userinputw, NC_PAIR_INPUT_ACTIVE);
             ncurses_waddstr($this->userinputw, $iActive);
             ncurses_wcolor_set($this->userinputw, NC_PAIR_INPUT);
         }
     }
     /*
      * Now append inactive windows. We don't make these stand out of course.
      */
     foreach ($aInactive as $iInactive) {
         if ($bShow == false) {
             ncurses_waddstr($this->userinputw, $iInactive);
             $bShow = true;
         } else {
             ncurses_waddstr($this->userinputw, ",");
             ncurses_waddstr($this->userinputw, $iInactive);
         }
     }
     ncurses_waddstr($this->userinputw, "]");
     ncurses_mvwaddstr($this->userinputw, 1, 0, $this->cl);
     ncurses_mvwaddstr($this->userinputw, 1, 0, "[" . $this->aDisplayVars['window'] . "] " . $this->userinputt . '_');
     ncurses_wrefresh($this->userinputw);
 }
Example #8
0
function dlg_input($params = array())
{
    ###############################################################################################
    $title = isset($params['title']) ? $params['title'] : NULL;
    $max_length = isset($params['max_len']) ? (int) $params['max_len'] : 10;
    $dlg_rows = isset($params['dlg_cols']) ? (int) $params['dlg_cols'] : 3;
    $dlg_cols = isset($params['dlg_cols']) ? (int) $params['dlg_cols'] : 40;
    $parent_cols = isset($params['cols']) ? (int) $params['cols'] : NULL;
    $parent_rows = isset($params['rows']) ? (int) $params['rows'] : NULL;
    $dlg_x = (int) (($parent_cols - $dlg_cols) / 2);
    if ($dlg_x < 0) {
        $dlg_x = 0;
    }
    $dlg_y = (int) (($parent_rows - $dlg_rows) / 2);
    if ($dlg_y < 0) {
        $dlg_y = 0;
    }
    if ($max_length <= 0 || $dlg_rows <= 0 || $dlg_cols <= 0) {
        trigger_error('wrong params');
        return NULL;
    }
    $dlg_window = ncurses_newwin($dlg_rows, $dlg_cols, $dlg_y, $dlg_x);
    if (empty($dlg_window)) {
        return NULL;
    }
    ncurses_wborder($dlg_window, 0, 0, 0, 0, 0, 0, 0, 0);
    if ($title) {
        ncurses_wattron($dlg_window, NCURSES_A_REVERSE);
        ncurses_mvwaddstr($dlg_window, 0, 2, ' ' . $title . ' ');
        ncurses_wattroff($dlg_window, NCURSES_A_REVERSE);
    }
    ncurses_curs_set(1);
    ncurses_wmove($dlg_window, 2, 2);
    ncurses_wrefresh($dlg_window);
    $do_getch = 1;
    $input_val = '';
    $input_char = '';
    $input_len = 0;
    $cursor_x = 2;
    $cursor_y = 1;
    ncurses_wmove($dlg_window, $cursor_y, $cursor_x);
    ncurses_noecho();
    ncurses_keypad($dlg_window, TRUE);
    while ($do_getch) {
        $key_code = ncurses_wgetch($dlg_window);
        if ($key_code == XCURSES_KEY_CR || $key_code == XCURSES_KEY_LF) {
            $do_getch = 0;
        } elseif ($key_code == NCURSES_KEY_BACKSPACE) {
            if ($input_len > 0) {
                $input_len--;
                $input_val = substr($input_val, 0, $input_len);
                $cursor_x--;
                ncurses_mvwaddstr($dlg_window, $cursor_y, $cursor_x, ' ');
                ncurses_wmove($dlg_window, $cursor_y, $cursor_x);
            }
        } elseif ($key_code < XCURSES_KEY_PRINTABLE_MIN || $key_code > XCURSES_KEY_PRINTABLE_MAX) {
            continue;
        } elseif ($input_len < $max_length) {
            $input_val .= $input_char = chr($key_code);
            $input_len++;
            $cursor_x++;
            ncurses_waddstr($dlg_window, $input_char);
        }
    }
    ncurses_delwin($dlg_window);
    return $input_val;
}
 /**
  * Prints a text to the pad
  * @param string $text text to print
  * @param int $color [optional] text color. One of the VarDumpNcurses::COLOR_* constants. Defaults to VarDumpNcurses::COLOR_DEFAULT.
  * @return int number of characters printed
  */
 protected function printRawText($text, $color = VarDumpNcurses::COLOR_DEFAULT)
 {
     if ($this->disablePrint) {
         return;
     }
     // if the line being printed is the one pointed by the cursor, highlight it
     if ($this->posY == $this->highlightedPositionY && $this->cursorHighlight) {
         $color += 10;
     }
     // verify if the color must be bolded
     $bold = false;
     if (in_array($color, $this->boldColorList)) {
         ncurses_wattron($this->pad, NCURSES_A_BOLD);
         $bold = true;
     }
     // print the text line by line
     // each line is checked for its visibility
     // we save the current Y position to be able to restore it
     $lines = explode("\n", $text);
     $nLines = count($lines);
     $posY = $this->posY;
     foreach ($lines as $k => $line) {
         if ($this->isBeingPrintedOutside(1)) {
             // the line is outside of the viewport
             // we increment the current Y position and skip drawing it
             $this->posY++;
             continue;
         } elseif ($k !== $nLines - 1) {
             // re-add the newline character for each line but the last
             $line .= "\n";
         }
         ncurses_wcolor_set($this->pad, $color);
         ncurses_waddstr($this->pad, $line);
         $this->posY++;
     }
     $this->posY = $posY;
     // unbold
     if ($bold) {
         ncurses_wattroff($this->pad, NCURSES_A_BOLD);
     }
     return strlen($text);
 }
Example #10
0
 public function draw()
 {
     ncurses_wmove($this->getWindow(), 1, 1);
     ncurses_waddstr($this->getWindow(), date("H:i:s"));
 }