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

erase_in_display fails if the argument is 3 #79

Closed choldrim closed 7 years ago

choldrim commented 7 years ago

https://github.com/selectel/pyte/blob/master/pyte/screens.py#L700

    def erase_in_display(self, how=0, private=False):
        """Erases display in a specific way.
        :param int how: defines the way the line should be erased in:
            * ``0`` -- Erases from cursor to end of screen, including
              cursor position.
            * ``1`` -- Erases from beginning of screen to cursor,
              including cursor position.
            * ``2`` -- Erases complete display. All lines are erased
              and changed to single-width. Cursor does not move.
        :param bool private: when ``True`` character attributes are left
                             unchanged **not implemented**.
        """
        if how == 0:
            # a) erase from cursor to the end of the display, including
            #    the cursor,
            interval = range(self.cursor.y + 1, self.lines)
        elif how == 1:
            # b) erase from the beginning of the display to the cursor,
            #    including it,
            interval = range(self.cursor.y)
        elif how == 2:
            # c) erase the whole display.
            interval = range(self.lines)

        for line in interval:
            self.buffer[line][:] = \
                (self.cursor.attrs for _ in range(self.columns))

        # In case of 0 or 1 we have to erase the line with the cursor.
        if how == 0 or how == 1:
            self.erase_in_line(how)

There is a potential bug here, which will be triggered while how var isn't in the list [0, 1, 2].

choldrim commented 7 years ago

So is this, https://github.com/selectel/pyte/blob/master/pyte/screens.py#L672

superbobry commented 7 years ago

Could you give an example of the input which triggers the bug along with the expected/observed behaviour?

superbobry commented 7 years ago

Hi @choldrim, could you have a look at #80 and tell me if this is the bug you've experienced?

choldrim commented 7 years ago

Hi @superbobry I'm sorry for replying this so late. This string \x1b[3J\x1b[H\x1b[2J\x1b]0;, which is replied from server while I input clear in terminal, trigger this bug, and I get the value how which is 4, not in [0, 1, 2].

superbobry commented 7 years ago

Thanks! #80 mentions how == 3, which is a fairly recent addition to TERM=linux. Which TERM do you have?

choldrim commented 7 years ago

TERM=xterm

superbobry commented 7 years ago

pyte only aims to support TERM=linux for now with some minor extensions pulled from xterm (like colour support). Therefore, it is recommended to use TERM=linux for running apps inside pyte.

Ideally, we should not handle how > 3 at all, and just render the CSI sequence as-is. It is probably best to do this directly in Screen without complicating the already complex parser in Stream.

Thank you for reporting this.

choldrim commented 7 years ago

I am using pyte with paramiko(something like ssh), and I tried to change the TERM with export TERM=linux, however it didn't work(it might be a wrong way to do this).

I am not really clear about the difference between TERM=linux and TERM=xterm. As for me, I just feel nothing different excepting the clear command.

Well, in short, I mean, is there any way to use pyte under ssh?

ps: Re: TERM=linux vs. TERM=xterm

superbobry commented 7 years ago

Well, in short, I mean, is there any way to use pyte under ssh?

I think the value of TERM variable should be defined on the machine you're connecting to, i.e. somewhere in the remote .bashrc. Could you confirm that you've exported it remotely and not locally?

If the TERM trick still doesn't work, I can add a quickhack so that pyte ignores inputs it cannot interpret.

choldrim commented 7 years ago

Could you confirm that you've exported it remotely and not locally?

Yes, I am sure it has been exported remotely. But, event if exporting TERM=linux on the server, I get the same problem, and the value of how is also 3.

image

Or you can try it by yourself with some python ssh lib like paramiko before adding a patch for this.

Thanks 👍

superbobry commented 7 years ago

Hi @choldrim, could you give the master version a try? I've added support for how=3, so TERM=linux should now work.

choldrim commented 7 years ago

Hi @superbobry , the master branch works well now. 👍

superbobry commented 7 years ago

Awesome! Closing the issue.

By the way, don't hesitate to add your project to Pyte users section here.

choldrim commented 7 years ago

By the way, don't hesitate to add your project to Pyte users section here.

Okay, I will push a PR later. :)

choldrim commented 7 years ago

https://github.com/selectel/pyte/pull/87