From a77a2d5d1f72d943f3c00d804875acd98aed0847 Mon Sep 17 00:00:00 2001 From: Martin Price Date: Sat, 26 Apr 2025 16:27:57 +0100 Subject: [PATCH 1/2] Provide default terminal width if tput cols fails --- includes/render.inc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/includes/render.inc b/includes/render.inc index 0b729a5..f4984e6 100644 --- a/includes/render.inc +++ b/includes/render.inc @@ -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; From 2e370b8a6af4ea8c2a79bcd005a82d14eb897b55 Mon Sep 17 00:00:00 2001 From: Martin Price Date: Sat, 26 Apr 2025 16:53:00 +0100 Subject: [PATCH 2/2] Update Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f464a4b..5fc54e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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