[Aptitude-devel] Bug#497970: aptitude: display-width calculation in command-line mode seems backwards

Manuel A. Fernandez Montecelo manuel.montezelo at gmail.com
Fri Aug 28 12:23:37 UTC 2015


Control: retitle -1 Line wraps with "emacs -f shell" in 80-column wide terminals
Control: severity -1 wishlist
Control: tags -1 + wontfix

Commenting on original comments of both bug reports that were later
merged:


2002-04-08 02:49 Miles Bader:
>Package: aptitude
>Version: 0.2.11-1
>Severity: minor
>
>
>If I run do an aptitude non-interactive search in an xterm, I get this:
>
>$ echo $TERM
>xterm
>$ stty size
>33 80
>$ apt search 'libc6!-'
>i   libc6                           - GNU C Library: Shared libraries and Timez
>
>Note the line-width is 79 characters (which is fine, though an xterm
>could display an 80-character line just fine).
>
>But if I do the same search in an emacs shell buffer, I get this:
>
>$ echo $TERM
>dumb
>$ stty size
>0 0
>$ apt search 'libc6!-'
>i   libc6                           - GNU C Library: Shared libraries and Timezo
>Note that the line-width is now 80 characters, causing ugly wrapping.
>
>The same thing happens if I redirect aptitude's output into a file or
>pipe (it has 80 character lines).
>
>It would be nice if aptitude defaulted to 79-character lines when the
>terminal type doesn't indicate any more reasonable default.
>
>[I know I can get the same behavior by using a `-w79' option, but I
> think default behavior should be better.]

(comments below)


2008-09-05 21:07 Sven Joachim:
>On 2008-09-05 20:13 +0200, jidanni at jidanni.org wrote:
>
>> On your Linux console tty1 (not inside X Windows), do
>> $ emacs -Q -f shell
>> and then inside it
>> $ aptitude search aptitude
>> You'll see it is 1 character too wide and wraps ugly.
>> Same with the show command.
>
>For the record, this is not connected to special tty's, it is
>reproducible on terminals (or Emacs frames) that are 80 characters wide.
>This is due to an Emacs oddity, it wraps the line even if it is short
>enough to just fit on screen, because Emacs needs room for positioning
>the cursor behind the last character or the line.
>
>Another problem is that the output of "aptitude search/show" is always
>truncated after line 80 in Emacs shell buffers, even if the window is
>much wider.  That's because aptitude doesn't use the COLUMNS environment
>variable to initialize the screen width, but unconditionally sets it to
>80, and changing it later doesn't work on a dumb terminal.

After reviewing the situation, I agree with Sven's characterisation of
the problem.

The problem with emacs and 80-column terminals looks like a special
characteristic of emacs in handling EOLs and cursors in "shell" mode
(does not happen in "term" modes).  Even if emacs is a widely used and
standard tool, I think we should not bend the behaviour of aptitude to
match the implementation details of emacs, specially now that the
implementation of aptitude has been like that for more than a decade
since the original bug report.

As Miles said in the original bug report, there's the easy workaround to
set the width to 79 (or "-w$((${COLUMNS}-1))" in general, with Bash
syntax) when running aptitude inside emacs shell if one is too bothered
with the default behaviour, or even alias the command if one is using it
all of the time.

-----------------------------
(inside "emacs -Q -f shell" on a 80x25 x-based term)

$ echo $COLUMNS
80

$ aptitude search '^aptitude$' | tail
i   aptitude                        - terminal-based package manager           \

p   aptitude:i386                   - terminal-based package manager           \

$ aptitude -w$((${COLUMNS}-1)) search '^aptitude$' | tail
i   aptitude                        - terminal-based package manager
p   aptitude:i386                   - terminal-based package manager
-----------------------------



The problem that Miles also commented about redirecting the output or
piping also happens only in emacs and not in regular xterms/shells, I
think, because of the same behaviour of emacs with widths.  At least I
could not reproduce it in 80x25 xterms (and old tty* on this computer
are not 80x25).

When running aptitude in a xterm (not inside emacs) narrower than 80
columns, the width of the output gets narrowed accordingly; when piping
to 'less' or a file it uses the 80 columns by default (if one does not
pass "-w${COLUMNS}").  There is no ugly wrapping in any case, as with
the '\' of emacs, it is just that it uses 80 as default.

Inside a 80x25 term with emacs shell mode, if one outputs to a file
(without specifying -w) and then cats the output file, the same wrapping
happens at the end of the line, again because of the implementation of
emacs shell mode.  Passing the width of "columns-1" with '-w' again
solves the issue.

It is perhaps worthy to note that this is not only a problem with
aptitude and emacs shell mode.  "top", "less" and other tools do not
work the same way inside emacs shell mode than they do in regular
terminals, in particular top uses 80x25 and appends to the output rather
than redraw the current contents.


>More from: 2008-09-05 21:07 Sven Joachim:
>
>Another problem is that the output of "aptitude search/show" is always
>truncated after line 80 in Emacs shell buffers, even if the window is
>much wider.  That's because aptitude doesn't use the COLUMNS environment
>variable to initialize the screen width, but unconditionally sets it to
>80, and changing it later doesn't work on a dumb terminal.

aptitude does try to determine the size of the terminal with a ioctl()
and uses it as long as width is equal or bigger than 5, and defaults to
80 otherwise.  As Miles said, "stty size" reports "0 0", so aptitude
does not try to use that.

I was considering if there was a way to solve this part of the problem,
for example trying to detect if we are running inside emacs shell mode.
But I don't see how to solve this in a generic way.  Trying to set width
to the value of COLUMNS before defaulting to 80 has its own
complications.  For example, I think that having a default of 80 when
outputting to a file makes some sense, at least preferrable to using
$COLUMNS, because if one wants to then attach to an e-mail or view in
other terminal, 80 makes more sense than a random value (80 is used as
default in many areas).  Unlimited width could be sensible too, but this
this has been the default for many years so I don't think that there is
a compelling reason to change this default (and one can change to
"unlimited" with "-w", again).



So, as a summary of all of the above, I think that:

a) this is not a bug in aptitude itself, but derived from the fact that
   emacs shell uses a dumb terminal and the way in which it treats EOLs
   (thus marking wishlist)

b) I could be persuaded to do otherwise, but at the moment I think that
   it is better to address this with the "-w" option than to change the
   implementation and risk breaking the current behaviour stablished
   long ago for other use-cases (e.g. getting 80-wide files by default).


Cheers.
--
Manuel A. Fernandez Montecelo <manuel.montezelo at gmail.com>



More information about the Aptitude-devel mailing list