BUU has asked for the wisdom of the Perl Monks concerning the following question:

This is more of a theoretical question really, but recently I've been pondering rewriting screen in perl, just because. So naturally I've been looking at Curses.pm and IO::Pty and such, but I was wondering if anyone had any better ideas or areas I should look at it?

I'm mostly interested in "multiple terminal" aspect of screen, as in, launching a full screen app then switching to another one at the press of a key. Obviously one can use system and fork and so on, but then you have problems with reading keys past whatever app you launch in system, launching other system apps at the same time, and so on. So, any one have any ideas or notions I could explore? Be as vague as you like.

Replies are listed 'Best First'.
Re: "Faking" screen in perl?
by Fletch (Bishop) on Dec 13, 2005 at 13:22 UTC

    You'd do multiple terminals the same way screen does it: fork off child processes on their own PTY. Your program would remain in charge of reading from the user's PTY and pass the relevant keystrokes to the child via whatever the corresponding PTY was. See chapters 19 and 9 of Stevens (Advanced Programming in the UNIX Environment) for more details, but it's not going to be a trivial undertaking.

Re: "Faking" screen in perl?
by Celada (Monk) on Dec 13, 2005 at 16:49 UTC

    That's quite ambitious, BUU!

    screen has to implement not only the functionality to write the contents of the screen to a user (curses can help you with that) but also the other side of this translation: functionality to interpret the output of other programs and render it to a virtual screen. This is of course a terminal emulator.

    You will be able to experience all the joys of VT100. (Actually you can choose to emulate some other kind of terminal instead, but VT100 is so ubiquitous...) You can learn about all of the various deviations from the standard (if there is such a thing). You can emulate xterm so as to be bug compatible with it! Support for Unicode (UTF-8 encoding, certainly) in a terminal emulator with its combining characters, bidirectional text and wide/narrow characters is a lot of fun too!

    I congratulate you if that's your idea of a "just because" project for fun. It's not really mine! screen is quite hackable and extensible (through its scriptability and features like coprocesses) so to me it's an excellent invitation to build on top of existing work.

    Anyway one of the important functions you need is that you need to emulate several terminals at the same time (with one at a time being displayed on the "real" terminal). In order to accomplish this you should either look at an event loop or threads. If you want to support detaching or multi attaching like screen does, you need to choose an IPC mechanism to support this. screen uses UNIX domain sockets.

      Term::VT102

      --
      In Bob We Trust, All Others Bring Data.

Re: "Faking" screen in perl?
by tphyahoo (Vicar) on Dec 13, 2005 at 11:16 UTC
    I'm not sure if this is relevant to your project, but are you aware of the recent security alerts concerning screen? I'm only aware of it because I like this utility a lot, but had a lot of stress installing it on SUSE and then came across the security warnings when looking for a fix. Google on "screen vulnerability."

    I wonder if having this in perl would make things better, worse, or no change.

      Could you give me a pointer? I was unable to find a recent screen vulnerability.

      Ordinary morality is for ordinary people. -- Aleister Crowley
      SuSE: 'screen' vulnerability

      - Posted by: LinuxSecurity.com Team

      Date: Wednesday, 05 September 2001
      You mean that one?
        Sounds right. You reckon it matters? I'm pretty ignorant, and wouldn't be surprised if it doesn't...