mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-27 23:47:46 +00:00
df5d72bcf7
* feat: Add stdout context length setting and improve text shrinking logic * lint
29 lines
739 B
Python
29 lines
739 B
Python
"""
|
|
Tools that support generating better formats.
|
|
"""
|
|
|
|
|
|
def shrink_text(text: str, context_lines: int = 200) -> str:
|
|
"""
|
|
When the context is too long, hide the part in the middle.
|
|
|
|
text before
|
|
... (XXXXX lines are hidden) ...
|
|
text after
|
|
"""
|
|
lines = text.splitlines()
|
|
total_lines = len(lines)
|
|
|
|
if total_lines <= context_lines:
|
|
return text
|
|
|
|
# Calculate how many lines to show from start and end
|
|
half_lines = context_lines // 2
|
|
start = "\n".join(lines[:half_lines])
|
|
end = "\n".join(lines[-half_lines:])
|
|
|
|
# Count the number of lines we're hiding
|
|
hidden_lines = total_lines - half_lines * 2
|
|
|
|
return f"{start}\n... ({hidden_lines} lines are hidden) ...\n{end}"
|