Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function sizeText($text)
- {
- // Try to guess how many lines the text will take up in the dialog. This is difficult because long lines are
- // wrapped. So what I'll do is pre-wrap the text and then just look at the number of lines it takes up
- $columns = $this->_screenWidth - $this->_borderWidth - $this->_columnSpacer;
- // Dialog do not add litteral newline at text begin like whiptail do, so we must add it manually
- if ($this->_program == 'dialog') {
- $text = "\n$text";
- }
- $encodingProgPath = realpath(__DIR__ . '/../bin/encoding.pl');
- $text = shell_exec("$encodingProgPath wrap " . escapeshellarg($text) . ' ' . $columns);
- $lines = explode("\n", $text);
- // Now figure out what's the longest line. Use perl Text::CharWidth module for that purpose
- $windowColumns = shell_exec("$encodingProgPath width " . escapeshellarg($this->_title)) + $this->_titleSpacer;
- array_map(
- function($_) use(&$windowColumns, $encodingProgPath)
- {
- $w = shell_exec("$encodingProgPath width " . escapeshellarg($_));
- if ($w > $windowColumns) {
- $windowColumns = $w;
- }
- },
- $lines
- );
- return array($text, count($lines) + 1 + $this->_borderHeight, $windowColumns + $this->_borderWidth);
- }
Advertisement
Add Comment
Please, Sign In to add comment