Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ before installing Backdrop.
based on module dependencies when using the enable and disable commands.
- The functions within the download command have been made more flexible and
better able to support the coming 'update' command.
- Provide default terminal width if `tput cols` fails to get the value.

## [1.x-1.1.0] - 2024-09-07

Expand Down
11 changes: 6 additions & 5 deletions includes/render.inc
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,13 @@ function bee_get_column_widths($rows, $header, $delimiter, $delimiter_left, $del
$table_width += mb_strlen((string) $delimiter_right);
$table_width += (count($widths) - 1) * mb_strlen((string) $delimiter);

// Adjust the width of the widest column to fit in the terminal. If a command
// outputting a table is run in a non-interactive shell (e.g. as part of an
// SSH command) then 'tput cols' on its own will create an error. This
// provides an alternative if 'tput cols' create an error.
$terminal_width = exec('if tput cols &>/dev/null; then echo $(tput cols); else $(echo $COLUMNS); fi');
// Get the terminal width or set a reasonable default.
$terminal_width = (int) exec('echo "$(tput cols 2>/dev/null)"');
if (!is_integer($terminal_width) || $terminal_width == 0) {
$terminal_width = 140;
}
bee_instant_message(bt('The terminal width is: ') . $terminal_width, 'debug');
// Adjust the width of the widest column to fit in the terminal.
if ($terminal_width && $table_width > $terminal_width) {
$diff = $table_width - $terminal_width;
$widths[$widest_column] -= $diff;
Expand Down
Loading