set_colors() {
COLS=${COLUMNS:-0} # bash's internal COLUMNS variable
- (( COLS == 0 )) && COLS=$(set -- $(stty size 2>/dev/null) ; echo $2)
+ # Avoid wasteful stty calls during the "depend" phases.
+ # If stdout is a pipe, the parent process can export COLUMNS
+ # if it's relevant.
+ [[ $COLS == 0 && $EBUILD_PHASE != depend ]] && \
+ COLS=$(set -- $(stty size 2>/dev/null) ; echo $2)
(( COLS > 0 )) || (( COLS = 80 ))
# Now, ${ENDCOL} will move us to the end of the
RC_DEFAULT_INDENT=2
RC_DOT_PATTERN=''
-if [[ $EBUILD_PHASE == depend ]] ; then
- # avoid unneeded stty call in set_colors during "depend" phase
- unset_colors
-else
- case "${NOCOLOR:-false}" in
- yes|true)
- unset_colors
- ;;
- no|false)
- set_colors
- ;;
- esac
-fi
+case "${NOCOLOR:-false}" in
+ yes|true)
+ unset_colors
+ ;;
+ no|false)
+ set_colors
+ ;;
+esac
if [[ -z ${USERLAND} ]] ; then
case $(uname -s) in
(c, style_to_ansi_code(c)))
mysettings["PORTAGE_COLORMAP"] = "\n".join(mycolors)
+ if "COLUMNS" not in mysettings:
+ # Set COLUMNS, in order to prevent unnecessary stty calls
+ # inside the set_colors function of isolated-functions.sh.
+ # We cache the result in os.environ, in order to avoid
+ # multiple stty calls in cases when get_term_size() falls
+ # back to stty due to a missing or broken curses module.
+ columns = os.environ.get("COLUMNS")
+ if columns is None:
+ rows, columns = portage.output.get_term_size()
+ columns = str(columns)
+ os.environ["COLUMNS"] = columns
+ mysettings["COLUMNS"] = columns
+
# All EAPI dependent code comes last, so that essential variables
# like PORTAGE_BUILDDIR are still initialized even in cases when
# UnsupportedAPIException needs to be raised, which can be useful