From bd22339cb8969ac75cbef024447cb6a546a77401 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 23 Dec 2024 14:55:01 -0500 Subject: [PATCH] actually fix info formatting --- asdf/_display.py | 48 ++++++++++-------------------------------------- asdf/search.py | 4 ++-- 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/asdf/_display.py b/asdf/_display.py index 5ddd8c397..5bb42e8e3 100644 --- a/asdf/_display.py +++ b/asdf/_display.py @@ -20,9 +20,6 @@ "DEFAULT_MAX_COLS", "DEFAULT_SHOW_VALUES", "render_tree", - "format_bold", - "format_faint", - "format_italic", ] @@ -63,31 +60,6 @@ def render_tree( return renderer.render(info) -def format_bold(value): - """ - Wrap the input value in the ANSI escape sequence for increased intensity. - """ - return _format_code(value, 1) - - -def format_faint(value): - """ - Wrap the input value in the ANSI escape sequence for decreased intensity. - """ - return _format_code(value, 2) - - -def format_italic(value): - """ - Wrap the input value in the ANSI escape sequence for italic. - """ - return _format_code(value, 3) - - -def _format_code(value, code): - return f"\x1B[{code}m{value}\x1B[0m" - - class _TreeRenderer: """ Render a _NodeInfo tree with indent showing depth. @@ -118,7 +90,7 @@ def format_italic(self, value): return self._format_code(value, 3) def _format_code(self, value, code): - if not self._isattry: + if not self._isatty: return f"{value}" return f"\x1B[{code}m{value}\x1B[0m" @@ -128,7 +100,7 @@ def render(self, info): lines, elided = self._render(info, set(), True) if elided: - lines.append(format_faint(format_italic("Some nodes not shown."))) + lines.append(self.format_faint(self.format_italic("Some nodes not shown."))) return lines @@ -246,7 +218,7 @@ def _render(self, info, active_depths, is_tail): if num_visible_children > 0 and num_visible_children != len(info.children): hidden_count = len(info.children) - num_visible_children prefix = self._make_prefix(info.depth + 1, active_depths, True) - message = format_faint(format_italic(str(hidden_count) + " not shown")) + message = self.format_faint(self.format_italic(str(hidden_count) + " not shown")) lines.append(f"{prefix}{message}") return lines, elided @@ -256,23 +228,23 @@ def _render_node(self, info, active_depths, is_tail): value = self._render_node_value(info) line = ( - f"{prefix}[{format_bold(info.identifier)}] {value}" + f"{prefix}[{self.format_bold(info.identifier)}] {value}" if isinstance(info.parent_node, (list, tuple)) - else f"{prefix}{format_bold(info.identifier)} {value}" + else f"{prefix}{self.format_bold(info.identifier)} {value}" ) if info.info is not None: - line = line + format_faint(format_italic(" # " + info.info)) + line = line + self.format_faint(self.format_italic(" # " + info.info)) visible_children = info.visible_children if len(visible_children) == 0 and len(info.children) > 0: - line = line + format_italic(" ...") + line = line + self.format_italic(" ...") if info.recursive: - line = line + " " + format_faint(format_italic("(recursive reference)")) + line = line + " " + self.format_faint(self.format_italic("(recursive reference)")) if self._max_cols is not None and len(line) > self._max_cols: message = " (truncated)" - line = line[0 : (self._max_cols - len(message))] + format_faint(format_italic(message)) + line = line[0 : (self._max_cols - len(message))] + self.format_faint(self.format_italic(message)) return line @@ -313,4 +285,4 @@ def _make_prefix(self, depth, active_depths, is_tail): prefix = prefix + "└─" if is_tail else prefix + "├─" - return format_faint(prefix) + return self.format_faint(prefix) diff --git a/asdf/search.py b/asdf/search.py index 7f6626a69..fd0b6d448 100644 --- a/asdf/search.py +++ b/asdf/search.py @@ -7,7 +7,7 @@ import re import typing -from ._display import DEFAULT_MAX_COLS, DEFAULT_MAX_ROWS, DEFAULT_SHOW_VALUES, format_faint, format_italic, render_tree +from ._display import DEFAULT_MAX_COLS, DEFAULT_MAX_ROWS, DEFAULT_SHOW_VALUES, render_tree from ._node_info import collect_schema_info from .treeutil import get_children, is_container from .util import NotSet @@ -322,7 +322,7 @@ def __repr__(self): ) if len(lines) == 0: - return format_faint(format_italic("No results found.")) + return "No results found." return "\n".join(lines)