Todo #13268
closedDynamically adjust the interface name maximum width in the login banner
Added by → luckman212 over 2 years ago. Updated 10 months ago.
100%
Description
small change to add some width and better align things if interface names are longer than just "WAN", "WAN2" etc.
before:
after:
Files
clipboard-202206121808-4jxbu.png (248 KB) clipboard-202206121808-4jxbu.png | → luckman212, 06/12/2022 05:08 PM | ||
clipboard-202206121808-5x6eg.png (193 KB) clipboard-202206121808-5x6eg.png | → luckman212, 06/12/2022 05:08 PM |
Updated by → luckman212 over 2 years ago
I wanted to auto size the columns based on the terminal width, but the shell doesn't seem to export the $COLUMNS
variable that would be required to do that.
anyway- PR: https://github.com/pfsense/pfsense/pull/4598
Updated by Marcos M about 1 year ago
- Status changed from Ready To Test to Pull Request Review
- Assignee set to Marcos M
The max interface description is known (31 iirc), and the real interface name is almost always relatively short, hence I think we can rely on the line-wrapping feature and not introduce a fixed width. We can calculate the max width and go with that, e.g.: ShowHide
diff --git a/src/etc/rc.banner b/src/etc/rc.banner index 8209b68eef7749fd77f2dd773713072f675c90ba..97474d05a9c20e127c13f51906dda1367b6b61ed 100755 --- a/src/etc/rc.banner +++ b/src/etc/rc.banner @@ -44,6 +44,25 @@ printf("%s: %s\n\n", gettext("Netgate Device ID"), system_get_uniqueid()); print "*** Welcome to {$g['product_label']} {$g['product_version_string']} ({$machine}) on {$hostname} ***\n"; $iflist = get_configured_interface_with_descr(true); + +// calculate max string widths for the banner +$realif_wdith = 1; +$tobanner_wdith = 1; +foreach ($iflist as $ifname => $friendly) { + $realif = get_real_interface($ifname); + $realif_length = strlen($realif); + if ($realif_length > $realif_wdith) { + $realif_wdith = $realif_length; + } + $tobanner = "{$friendly} ({$ifname})"; + $tobanner_length = strlen($tobanner); + if ($tobanner_length > $tobanner_wdith) { + $tobanner_wdith = $tobanner_length; + } +} +$v6line_width = $realif_wdith + $tobanner_wdith + 9; + +// print the banner foreach ($iflist as $ifname => $friendly) { /* point to this interface's config */ $ifconf = $config['interfaces'][$ifname]; @@ -92,7 +111,7 @@ foreach ($iflist as $ifname => $friendly) { $realif = get_real_interface($ifname); $tobanner = "{$friendly} ({$ifname})"; - printf("\n %-15s -> %-10s -> ", + printf("\n %-{$tobanner_wdith}s -> %-{$realif_wdith}s -> ", $tobanner, $realif ); @@ -108,7 +127,7 @@ foreach ($iflist as $ifname => $friendly) { } if (!empty($ipaddr6) && !empty($subnet6)) { if (!$v6first) { - printf("\n%s", str_repeat(" ", 34)); + printf("\n%s", str_repeat(" ", $v6line_width)); } printf("v6%s: %s/%s", $class6,
https://gitlab.netgate.com/pfSense/pfSense/-/merge_requests/1097
Updated by Marcos M about 1 year ago
- Subject changed from columns don't align nicely in console with medium-long interface names to Dynamically adjust tHe interface text max wdith for the login banner
Updated by Marcos M almost 1 year ago
- Status changed from Pull Request Review to Feedback
Applied in changeset f15e8e4fb1db624c04eeda8671c6b7fb34a87b03.
Updated by Danilo Zrenjanin 12 months ago
- Status changed from Feedback to Resolved
Tested the patch on the 23.09.1
It looks good.
I am marking this case resolved.
Updated by Jim Pingle 10 months ago
- Subject changed from Dynamically adjust the interface text max width in the login banner to Dynamically adjust the interface name maximum width in the login banner