diff options
author | David Kalnischkies <david@kalnischkies.de> | 2017-11-18 03:48:59 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2017-11-19 18:26:19 +0100 |
commit | 3f8664036e63d2a2d58120ab6c1e8a0a09937c71 (patch) | |
tree | 492e0eddd4d4555293f092eb1c21ecb3dad2bbf7 /apt-private/private-output.cc | |
parent | 7fba4e0df1768703ce657d8bf8200472c2dd825f (diff) |
support COLUMNS environment variable in apt tools
apt usually gets the width of the window from the terminal or failing
that has a default value, but especially for testing it can be handy
to control the size as you can't be sure that variable sized content
will always be linebreaked as expected in the testcases.
Diffstat (limited to 'apt-private/private-output.cc')
-rw-r--r-- | apt-private/private-output.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 6bc18516d..eb9a34abe 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -67,8 +67,24 @@ bool InitOutput(std::basic_streambuf<char> * const out) /*{{{*/ c1out.rdbuf(devnull.rdbuf()); // deal with window size changes - signal(SIGWINCH,SigWinch); - SigWinch(0); + auto cols = getenv("COLUMNS"); + if (cols != nullptr) + { + char * colends; + auto const sw = strtoul(cols, &colends, 10); + if (*colends != '\0' || sw == 0) + { + _error->Warning("Environment variable COLUMNS was ignored as it has an invalid value: \"%s\"", cols); + cols = nullptr; + } + else + ScreenWidth = sw; + } + if (cols == nullptr) + { + signal(SIGWINCH,SigWinch); + SigWinch(0); + } if(!isatty(1)) { |