[PATCH 24/26] lucid: use Display.columns for terminal width
Daniel Gomez <[email protected]> Tue, 19 May 2026 15:28:21 +0200
| Newsgroups | dev.linux.lists.kdevops |
|---|---|
| Message-ID | <[email protected]> |
From: Daniel Gomez <[email protected]> Ansible's Display object keeps a columns attribute initialized from the controlling TTY during startup, which is the same value the built-in callbacks consult when they frame banners. Lucid was calling shutil.get_terminal_size on its own, which added roughly ten lines of custom width detection and a DEFAULT_TERMINAL_WIDTH constant that duplicated behavior already provided by Display. Replacing the helper with a direct read of self._display.columns aligns lucid with how core callbacks discover terminal geometry and removes the parallel code path. Access goes through getattr with an 80 column fallback so the plugin still renders sensibly on any hypothetical Display object that lacks the attribute, and the now unused shutil import is dropped. No other call sites depended on DEFAULT_TERMINAL_WIDTH, so the class constant is removed as well. Generated-by: Claude AI Signed-off-by: Daniel Gomez <[email protected]> --- callback_plugins/lucid.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/callback_plugins/lucid.py b/callback_plugins/lucid.py index d48276aa..df74a6f4 100644 --- a/callback_plugins/lucid.py +++ b/callback_plugins/lucid.py @@ -15,7 +15,6 @@ from __future__ import annotations import atexit import json import os -import shutil import sys import time import threading @@ -90,9 +89,6 @@ class CallbackModule(CallbackBase): "unreachable": C.COLOR_UNREACHABLE, } - # Default terminal width when detection fails - DEFAULT_TERMINAL_WIDTH = 80 - def __init__(self): super(CallbackModule, self).__init__() @@ -361,18 +357,10 @@ class CallbackModule(CallbackBase): or (res.get("msg") and not res.get("stdout")) ) - def _get_terminal_width(self) -> int: - """Get current terminal width, with fallback to default""" - try: - size = shutil.get_terminal_size(fallback=(self.DEFAULT_TERMINAL_WIDTH, 24)) - return size.columns - except Exception: - return self.DEFAULT_TERMINAL_WIDTH - def _truncate_line(self, line: str, max_width: Optional[int] = None) -> str: """Truncate line to fit terminal width, adding ellipsis if needed""" if max_width is None: - max_width = self._get_terminal_width() + max_width = getattr(self._display, "columns", 80) if len(line) <= max_width: return line @@ -1202,7 +1190,7 @@ class CallbackModule(CallbackBase): self._clear_display() # Get terminal width once for all lines - term_width = self._get_terminal_width() + term_width = getattr(self._display, "columns", 80) # Build new display lines = [] -- 2.53.0