Subject: Re: less -F ubuntu dapper.

From: Sergey Vlasov <[email-masked]>
Date: Sat, 21 Oct 2006 20:01:10 +0400

On Sat, 21 Oct 2006 18:53:35 +0530 Aneesh Kumar wrote:

> -F option for less in ubuntu Dapper is broken. It doesn't display
> anyting if the file can be displayed in one page.

Same here in ALT Linux (less-382-alt2).  The problem appears only
when the terminal supports alternate screen, and less uses it.

BTW, try this (needs bash or zsh):

  (for ((i=0; i < 20; ++i)) do echo $i; sleep 0.1; done) | less -F

You'll see that the text appears on the screen while the loop
outputs it, but disappears once the output finishes.  If you use
"less -FX" instead, the text will not disappear, but in this case
less will not use the alternate screen, which is inconvenient when
the text is large (e.g., when you browse the text, parts of it
will be put into the scrollback buffer).

Because less must start displaying the text immediately after it
got some data, it cannot decide whether to use the alternate
screen depending on the text size.  Therefore, if you want to use
the -F option on a terminal with alternate screen, you need to
turn off the alternate screen support with -X.  But less cannot do
this automatically, because it does not really know about the
alternate screen (the -X option disables termcap initialization
and deinitialization strings, which can do arbitrary things, and
may actually be required on some obscure terminals).

It should be possible to add yet another option to less to make it
initially display the text on the alternate screen, and on EOF, if
the text fits on the screen, turn off the alternate screen,
_redisplay the text_ and exit.  However, this option will have
even more assumptions about the terminal than -X (if the terminal
does not turn on alternate screen in its termcap initialization
string, there will be a horrible mess on screen), and you will get
flicker when the text is displayed multiple times.

> Because of this the recent chages to
> 96a035d1db9082d244867033020d0ceb571cf94e results in commands
> like git show not showing the changes.

Adding the -X option might break some terminals (and will irritate
users which used alternate screen before), so apparently the only
way to fix this breakage is to remove the -F option again...