@@ -25,23 +25,23 @@ class Ascii extends Renderer {
25
25
'padding ' => ' ' ,
26
26
);
27
27
protected $ _border = null ;
28
+ protected $ _constraintWidth = null ;
28
29
29
30
/**
30
31
* Set the widths of each column in the table.
31
32
*
32
33
* @param array $widths The widths of the columns.
33
34
*/
34
35
public function setWidths (array $ widths ) {
35
- static $ terminal_width ;
36
36
37
- if ( ! isset ( $ terminal_width ) ) {
38
- $ terminal_width = (int ) shell_exec ( 'tput cols ' );
37
+ if ( is_null ( $ this -> _constraintWidth ) ) {
38
+ $ this -> _constraintWidth = (int ) shell_exec ( 'tput cols ' );
39
39
}
40
40
$ col_count = count ( $ widths );
41
41
$ col_borders_count = $ col_count * strlen ( $ this ->_characters ['border ' ] );
42
42
$ table_borders_count = strlen ( $ this ->_characters ['border ' ] ) * 1 ;
43
43
$ col_padding_count = $ col_count * strlen ( $ this ->_characters ['padding ' ] ) * 2 ;
44
- $ max_width = $ terminal_width - $ col_borders_count - $ table_borders_count - $ col_padding_count ;
44
+ $ max_width = $ this -> _constraintWidth - $ col_borders_count - $ table_borders_count - $ col_padding_count ;
45
45
46
46
if ( $ widths && $ max_width && array_sum ( $ widths ) > $ max_width ) {
47
47
@@ -76,6 +76,15 @@ public function setWidths(array $widths) {
76
76
$ this ->_widths = $ widths ;
77
77
}
78
78
79
+ /**
80
+ * Set the contraint width for the table
81
+ *
82
+ * @param int $constraintWidth
83
+ */
84
+ public function setConstraintWidth ( $ constraintWidth ) {
85
+ $ this ->_constraintWidth = $ constraintWidth ;
86
+ }
87
+
79
88
/**
80
89
* Set the characters used for rendering the Ascii table.
81
90
*
0 commit comments