Skip to content

Commit

Permalink
Fix: term: unset env COLUMNS and ROWS
Browse files Browse the repository at this point in the history
A bug in python stardard library, python/cpython#100516, make
environment variables, `COLUMNS` and `ROWS` to be added at fork. These
environment variables may make some of the commands called by crmsh to
truncate its output even if those commands are not writing to the
terminal.

These variables is set when bash enables its `checkwinsize` option. As
crmsh is able to read terminal size with curses, these variables are
unneeded and may be out of sync with actual terminal size.
  • Loading branch information
nicholasyang2022 committed Mar 13, 2024
1 parent b901b4e commit ad10dad
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crmsh/term.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (C) 2008-2011 Dejan Muhamedagic <[email protected]>
# See COPYING for license information.

import os
import sys
import re
# from: http://code.activestate.com/recipes/475116/
Expand Down Expand Up @@ -151,6 +151,7 @@ def init():
from . import config
if not _term_stream.isatty() and 'color-always' not in config.color.style:
return
_ignore_environ()
# Check the terminal type. If we fail, then assume that the
# terminal has no capabilities.
try:
Expand All @@ -177,4 +178,12 @@ def is_color(s):
return hasattr(colors, s.upper())


def _ignore_environ():
"""Ignore environment variable COLUMNS and ROWS"""
# See https://bugzilla.suse.com/show_bug.cgi?id=1205925
# and https://gitlab.com/procps-ng/procps/-/blob/c415fc86452c933716053a50ab1777a343190dcc/src/ps/global.c#L279
for name in ["COLUMNS", "ROWS"]:
if name in os.environ:
del os.environ[name]

# vim:ts=4:sw=4:et:

0 comments on commit ad10dad

Please sign in to comment.