Skip to content

Commit

Permalink
Issues #430 and #360: Fix notice or warning for long column values in…
Browse files Browse the repository at this point in the history
… table (#433)

* Fix notice or warning for long column values in table
* Update CHANGELOG.md
  • Loading branch information
yorkshire-pudding authored Sep 6, 2024
1 parent 6a532f4 commit a4f6bfb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and this project follows the
which is based on the major version of Backdrop CMS with a semantic version
system for each contributed module, theme and layout.

## [Unreleased]
## [Unreleased] - 2024-09-06

### Added
- A new function to check whether or not an executable exists in the system.
Expand Down Expand Up @@ -39,6 +39,8 @@ not exist.
- Unhandled Warning if argument for 'cache-clear' wasn't in the list.
- Error if config-set used to set a new configuration item.
- Unhandled Warning on `user-create` with mail option.
- Notice/Warning when long values (e.g. long module names, long config
filenames) are included in table output.

## [1.x-1.0.2] - 2024-05-23

Expand Down
4 changes: 3 additions & 1 deletion includes/render.inc
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ function bee_get_column_widths($rows, $header, $delimiter, $delimiter_left, $del
}
}
}
bee_instant_message(bt('Column widths:'), 'debug', $widths);

// Get the widest column, and calculate the width of the table.
$widest_column = 0;
Expand All @@ -379,6 +380,7 @@ function bee_get_column_widths($rows, $header, $delimiter, $delimiter_left, $del
// 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');
bee_instant_message(bt('The terminal width is: ') . $terminal_width, 'debug');
if ($terminal_width && $table_width > $terminal_width) {
$diff = $table_width - $terminal_width;
$widths[$widest_column] -= $diff;
Expand Down Expand Up @@ -432,7 +434,7 @@ function bee_get_remaining_rows(array $row, array $column_widths) {
$row_rendered = array();

foreach ($column_widths as $index => $width) {
if ($index == $row['index']) {
if ($row && $index == $row['index']) {
$column = $row;

if (mb_strlen((string) $column['value']) > $width) {
Expand Down

0 comments on commit a4f6bfb

Please sign in to comment.