Guest User

Untitled

a guest
Jun 29th, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1.     public function sizeText($text)
  2.     {
  3.         // Try to guess how many lines the text will take up in the dialog. This is difficult because long lines are
  4.         // wrapped. So what I'll do is pre-wrap the text and then just look at the number of lines it takes up
  5.         $columns = $this->_screenWidth - $this->_borderWidth - $this->_columnSpacer;
  6.  
  7.         // Dialog do not add litteral newline at text begin like whiptail do, so we must add it manually
  8.         if ($this->_program == 'dialog') {
  9.             $text = "\n$text";
  10.         }
  11.  
  12.         $encodingProgPath = realpath(__DIR__ . '/../bin/encoding.pl');
  13.         $text = shell_exec("$encodingProgPath wrap " . escapeshellarg($text) . ' ' . $columns);
  14.         $lines = explode("\n", $text);
  15.  
  16.         // Now figure out what's the longest line. Use perl Text::CharWidth module for that purpose
  17.         $windowColumns = shell_exec("$encodingProgPath width " . escapeshellarg($this->_title)) + $this->_titleSpacer;
  18.  
  19.         array_map(
  20.             function($_) use(&$windowColumns, $encodingProgPath)
  21.             {
  22.                 $w = shell_exec("$encodingProgPath width " . escapeshellarg($_));
  23.  
  24.                 if ($w > $windowColumns) {
  25.                     $windowColumns = $w;
  26.                 }
  27.             },
  28.  
  29.             $lines
  30.         );
  31.  
  32.         return array($text, count($lines) + 1 + $this->_borderHeight, $windowColumns + $this->_borderWidth);
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment