selectel / pyte

Simple VTXXX-compatible linux terminal emulator
http://pyte.readthedocs.org/
GNU Lesser General Public License v3.0
653 stars 101 forks source link

Mode reset on screen resize #95

Closed acroz closed 7 years ago

acroz commented 7 years ago

I'm trying to understand the screen resizing logic in pyte and could use a little guidance. On screen resize, pyte resets the DECOM mode:

https://github.com/selectel/pyte/blob/26866c70e37b7ba00aaea3cf89fed50cd4f5cd7f/pyte/screens.py#L325

This has the effect of resetting the cursor position:

https://github.com/selectel/pyte/blob/26866c70e37b7ba00aaea3cf89fed50cd4f5cd7f/pyte/screens.py#L386

A comment in Screen.set_mode indicates that resetting the cursor is required by vttest, however it's not clear to me why resetting the DECOM mode is necessary on every resize.

Effect of cursor reset

The main reason this is of interest to me is that resetting the cursor on every screen resize gives undesirable behaviour. Consider this example:

import pyte

screen = pyte.Screen(20, 6)
stream = pyte.Stream(screen)

for _ in range(4):
    stream.feed('foo foo foo\r\n')

for line in screen.display:
    print('|{}|'.format(line))

This writes some lines to a small screen and gives the output:

|foo foo foo         |
|foo foo foo         |
|foo foo foo         |
|foo foo foo         |
|                    |
|                    |

If I then resize the screen and write more content:

screen.resize(6, 24)

for _ in range(2):
    stream.feed('  bar!\r\n')

for line in screen.display:
    print('|{}|'.format(line))

the cursor is reset, and further writes to the screen overwrite previous lines rather than continuing at the bottom as expected:

|  bar!o foo             |
|  bar!o foo             |
|foo foo foo             |
|foo foo foo             |
|                        |
|                        |

What's the point?

My current solution to this is to subclass Screen and override resize with the reset_mode call removed, but I would like to understand if this is a reasonable thing to do.

Thanks for any assistance you can give!

superbobry commented 7 years ago

Hi Andrew,

This is very old code and frankly I don't remember the original motivation. The only mention of that in VT220 manual I've found is

4.6.10 Column Mode (DECCOLM)

Column mode selects the number of columns per line (80 or 132) on the screen. The screen can > display 24 lines of text with either selection.

You select the number of columns per line as follows.

NOTE: When the terminal receives the sequence, the screen is erased and the cursor moves to the home position. This also sets the scrolling region for full screen (24 lines).

it doesn't say anything about DECOM and I too can't justify the need to reset it. After the scrolling region is updated, DECOM should work fine.

I've pushed a commit removing the reset. Thank you for drawing my attention to this.

acroz commented 7 years ago

Thanks for looking in to this.