Fix WPS and CLI column alignment in scan display#451
Conversation
The to_str() method used inconsistent column widths and separators that didn't match the header defined in scanner.py, causing WPS values to appear under the CLI header and client counts to overflow past the table. - Add _pad_colored() helper to pad ANSI-colored strings to exact visible widths - Use consistent 2-space separators between all columns - Match column widths (ESSID:26, BSSID:19, MFG:23, CH:4, ENCR:9, PWR:7, WPS:5, CLI:7) - Fix classic.py header to use same column order and widths as scanner.py https://claude.ai/code/session_019ijpUyTX2ZGrr1123Hteea
There was a problem hiding this comment.
Pull request overview
This PR standardizes the classic scan table formatting so Target row strings (Target.to_str()) use consistent fixed-width columns and separators that match the header layout used by the scanner display, preventing WPS/CLI values from appearing under the wrong headers.
Changes:
- Add a
_pad_colored()helper inTargetto pad ANSI-colored strings by visible width. - Rebuild
Target.to_str()using fixed column widths and consistent 2-space separators. - Update the classic UI header to use the same column order and widths as the scanner view.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| wifite/ui/classic.py | Rebuilds the classic “Targets” header to match the fixed-width scan table columns. |
| wifite/model/target.py | Adds ANSI-aware padding and rewrites to_str() to emit consistently aligned, fixed-width columns. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Column widths must match scanner.py header | ||
| COL_ESSID = 26 | ||
| COL_BSSID = 19 | ||
| COL_MFG = 23 | ||
| COL_CH = 4 | ||
| COL_ENC = 9 | ||
| COL_PWR = 7 | ||
| COL_WPS = 5 | ||
| COL_CLI = 7 | ||
| SEP = ' ' | ||
|
|
||
| parts = [self._pad_colored(essid, COL_ESSID)] | ||
| if show_bssid: | ||
| parts.append(self._pad_colored(bssid, COL_BSSID)) | ||
| if show_manufacturer: | ||
| parts.append(self._pad_colored(manufacturer, COL_MFG)) | ||
| parts.append(self._pad_colored(channel, COL_CH, 'right')) | ||
| parts.append(self._pad_colored(encryption_display_string, COL_ENC)) | ||
| parts.append(self._pad_colored(power, COL_PWR, 'right')) | ||
| parts.append(self._pad_colored(wps, COL_WPS, 'center')) | ||
| parts.append(self._pad_colored(clients, COL_CLI, 'right')) | ||
|
|
||
| result = SEP.join(parts) |
There was a problem hiding this comment.
The new fixed-width column formatting in Target.to_str() is meant to prevent header/data drift, but there are no tests asserting the exact column widths/separators (after stripping ANSI) for common combinations (with/without BSSID/MFG, different WPS states, different client counts). Adding a regression test that strips ANSI and checks column start positions/widths would help prevent this alignment bug from returning.
| # Column widths must match scanner.py header | ||
| COL_ESSID = 26 | ||
| COL_BSSID = 19 | ||
| COL_MFG = 23 | ||
| COL_CH = 4 | ||
| COL_ENC = 9 | ||
| COL_PWR = 7 | ||
| COL_WPS = 5 | ||
| COL_CLI = 7 | ||
| SEP = ' ' |
There was a problem hiding this comment.
Column width constants are now duplicated across wifite/util/scanner.py, wifite/ui/classic.py, and Target.to_str(). This creates an ongoing risk of the alignment bug recurring if one location changes without updating the others. Consider centralizing these widths/separator into a shared constant (or a small helper) that both header builders and to_str() reference.
| for idx, target in enumerate(targets, start=1): | ||
| target_str = target.to_str(show_bssid=show_bssid, show_manufacturer=show_manufacturer) | ||
| Color.pl(' {G}%3d{W} %s' % (idx, target_str)) | ||
| Color.pl(' {G}%s{W} %s' % (str(idx).rjust(col_num), target_str)) |
There was a problem hiding this comment.
In display_targets(), the table header starts with two leading spaces (header = ' ' + ...), but each row starts with a single leading space (Color.pl(' {G}%s{W} %s' ...)). This shifts the NUM column one character left relative to the header and can reintroduce alignment issues. Make the left padding consistent between header/separator and rows (either add one leading space to the row format string or drop one from the header/separator).
| Color.pl(' {G}%s{W} %s' % (str(idx).rjust(col_num), target_str)) | |
| Color.pl(' {G}%s{W} %s' % (str(idx).rjust(col_num), target_str)) |
The to_str() method used inconsistent column widths and separators that didn't match the header defined in scanner.py, causing WPS values to appear under the CLI header and client counts to overflow past the table.