Why does nano not redraw the screen correctly on some systems?

0

This is a weird one.

On some of my Debian systems - but not all - I get strange corruption in certain terminal programs, such as nano. It does not happen, however, when using less. In this particular case, I'm using Debian 7.9 "Wheezy" 64-bit. I have installed a bunch of packages, but IIRC this problem has been known to happen even on a fresh installation.

The problem is as follows. I open a large text document (i.e. one with multiple pages) in nano and, using the cursor keys, scroll through it. Whenever the cursor passes below the bottom of the screen, the document jumps down by half a page. This is, of course, normal. What isn't normal however, is the fact that only the lower half of the screen updates!

Similarly, when I move the cursor to the top, the previous page is shown, but only the upper half of the screen updates.

This is best illustrated, I reckon, with actual illustrations. Please consider the following image of a dummy file containing only line numbers:

illustration 1

It has to be a photograph, because the problem does not occur over ssh. It also, oddly, doesn't occur if I first issue the screen command.

I move the cursor down below line 43, and the following happens:

illustration 2

Notice how the lower half of the screen updates, to now show lines starting from 44, while the upper half remains unchanged.

If I again move the cursor to the bottom of the screen, it happens again:

illustration 3

Once again, the lower half of the screen has updated to show lines beginning from 66, whilst the upper half of the screen remains unaltered.

If I then move the cursor past the top of the screen, the upper half exhibits the same problem:

illustration 4

As you can see, the upper half of the screen has updated to show lines from 23 to 44, whilst the lower half has not changed, and still shows lines beginning with 67.

I am currently using the zsh shell, but the exact same problem occurs in bash. Therefore it is not a shell-specific issue.

The $lines and $columns variables are empty; and the TERM variable is set to xterm-256color.

So....why does this happen, and what can I do about it? Thanks.

Sod Almighty

Posted 2016-02-09T06:32:51.970

Reputation: 462

What size does stty size report? Is this a serial tty? Are you really using xterm – the photos look more like the Linux console? (It cannot possibly be shell-specific because the shell has no say in this, it just interprets commands.) – user1686 – 2016-02-09T06:43:36.877

@grawity Well, I never said I was using xterm. I am, indeed, using the Linux text-mode console. stty size reports '48 128'. – Sod Almighty – 2016-02-09T07:16:45.297

No, you did say that you have TERM=xterm-256color, which implies xterm or compatible, and the Linux text-mode console is not xterm-compatible. It needs TERM=linux. – user1686 – 2016-02-09T07:20:27.417

@grawity Wow, that fixed it, thanks. But uh....don't I need TERM=xterm-256color or somesuch when sshing in, so I get colours displayed properly? How do I ensure that this is set when sshing in? – Sod Almighty – 2016-02-09T07:24:47.493

Answers

1

So the problem is that you have TERM=xterm-256color but are using the Linux console, which is not an xterm-compatible terminal. (And does not support 256 colors, either.)

If you are setting $TERM from within your ~/.bashrc or similar file, make sure to check the previous value before setting the new one. For example:

case $TERM in
    xterm|screen|tmux|rxvt-unicode)
        TERM="$TERM-256color";;
esac

user1686

Posted 2016-02-09T06:32:51.970

Reputation: 283 655