[comp.unix.programmer] save and regerate the current screen before and after a command

ping@cubmol.bio.columbia.edu (Shiping Zhang) (01/03/91)

I want to write a software in C in such a way that when it is invoked,
it will save the current screen, and when it exits, it will regenerate
the original screen. I use a Sun 3 with os4.  I don't know how to get
the current screen. Is the screen pattern saved somewhere in the system
accessible to the programmer?  Thanks for any information.
 
-ping    ping@cubmol.bio.columbia.edu  (128.59.128.3)

cliffs@playroom.East.Sun.COM (Clifford C. Skolnick) (01/04/91)

In article <1991Jan3.164022.9108@cubmol.bio.columbia.edu> ping@cubmol.bio.columbia.edu (Shiping Zhang) writes:
+Sorry I did not state my question clearly. I want to save the screen of
+a regular tty terminal, not a workstation. The command screendump does
+not work on such terminal. I don't know if the system keeps a similar
+frame buffer for such a terminal, or if there is a way to directly
+"read" or scan the screen. On an IBM pc, the print/screen key let you
+print whatever on the screen. I'm wondering if there is a similar
+function or routine in UNIX, but instead of being sent to the printer,
+the output is sent to a file or allocated memory.  Thanks.
+
UNIX does nothing of the sort, but perhaps your terminal may support
multiple screens.  Certain escapes code will switch the terminal between
the screens.  I wrote a program that did this with a wyse terminal many
moons ago.
To the person who suggested curses, it does not read the screen as the
program invokes.  Curses will only know about what curses wrote to the
screen.


--
Cliff Skolnick | "It all seems so stupid, it makes me want to
cliffs@sun.com | give up.  But why should I give up, when it all
(716) 385-5049 | seems so stupid." -- Depeche Mode
I think. I am. | "If you must sell out to play the game, you will loose."

mike@bria.AIX (Mike Stefanik/78125) (01/04/91)

In article <SPOT.91Jan3022313@WOOZLE.GRAPHICS.CS.CMU.EDU> spot@CS.CMU.EDU (Scott Draves) writes:

[question about saving the screen]

>That saves and restores (with screenload) the framebuffer; I think
>Shiping meant the terminal.  Curses(3v) does this for you
>automatically.

I don't think this is what was being asked; curses will allow you to preserve
your screen when *inside* an application, but I believe that the question
revolves around preserving the screen "as is" prior to the application
starting, and then restoring the screen when the application exits.  Unless
you have a bitmapped device which you could open and read, or your tty
driver uses streams, I don't think this could be done.

-----------------------------------------------------------------------------
Michael Stefanik, Systems Engineer (JOAT), Briareus Corporation
UUCP: ...!uunet!bria!mike
"If it was hard to code, it should be harder to use!"

guy@auspex.auspex.com (Guy Harris) (01/06/91)

>no, but it does switch to and use the alternate screen, thus
>preserving the terminal's previous contents.  At least that what it
>does for me...

Probably because you're using a terminal, or a terminal emulator, that
*has* an alternate screen; not all do.  "xterm" does; Sun "shelltool"
doesn't; Sun "cmdtool" has something that, in some circumstances, acts
like one (the "ti" and "te" capabilities switch a "cmdtool" from
"cmdtool mode" to "shelltool mode", or from "shelltool mode" to "cmdtool
mode", respectively, and those modes have independent screen images). 

mike@bria.AIX (Mike Stefanik/78125) (01/07/91)

>no, but it does switch to and use the alternate screen, thus
>preserving the terminal's previous contents.  At least that what it
>does for me...

Yes, but not all terminals provide the ability to copy one screen to another,
thus making the screen switching solution terminal-dependant (and therefore
unusable by the general public).

One solution would be for the kernel to map all characters written to tty's,
but this would involve linking terminal capability into the kernel which would
mean re-linking every time a terminal was changed around (yuck!).

-----------------------------------------------------------------------------
Michael Stefanik, Systems Engineer (JOAT), Briareus Corporation
UUCP: ...!uunet!bria!mike
"If it was hard to code, it should be harder to use!"

rags@hpcuhc.cup.hp.com (Balakrishna Raghunath) (01/12/91)

If you wish to save a screen from an application; exit the application and
then regenerate the screen when you restart the application; then I think the
only way out is to program it yourself. The unix kernel does not retain any
state on the layout of the current screen....and it would be stupid to try 
and do so within the kernel. It is really not too much of trouble to do this
in a program...I have done it. All you have to do is to maintain the state
of the screen in a text buffer and write it out to a file. When you restart
the application; read this back in and use the curses functions to redisplay 
the screen. Of course; when you have highlighting etc. in a screen the 
scheme has to be somewhat more complicated. But there are not many additional 
data structures required. All you have to remember now is that instead
of using a char buffer use a chtype buffer. 'chtype' is the curses defined
type for characters with attributes(at least in sys V curses). It is 
probably typedefed to a long in curses.h 

If you need something to do this save and restart from outside of the 
application (i.e if you need something more generic), you mave have a more
difficult time...You could still do it if you write a program to checkpoint
the state of a program and restart it. I think a public domain checkpointing
program was posted to the net sometime back.

If what you want is a way of taking a screen dump(a la printscreen); your   
application can make use of the curses function screendump() (I think...
I know there is a curses function for dumping the screen, at least in sys V
curses..I have used it).

rags