Utility to Save/Restore current screen

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
Hello !

I have a kind of a project manager built upon 4NT (now TCC).

When I run it it shows a list of projects (@select). Then I pick one and enter into that project.

The project for me is a "context". So, when I enter it, it brings back to me all the histories from THAT project. So, directories for all drives are set according to that project . Also ALIAS and many other things.

When I leave the project, it saves it all back.

So far, so good.

However, I'd like to restore the SCREEN of the project, as I left it last time I entered it.

Currently I do it using an EXE of my onw.

But I found a BTM for doing that. This is an old BTM that I inserted at the end of this message.

The BTM work but, it DOES not reposition the cursor position (the prompt) where it was.

Do you have something similar ? Or other idea ?

Follows the original btm :

---------------------

:: SCAP.BTM Utility to capture and restore the screen contents
:: By: Frederick Sohn
:: Date: 27 Mar 96 05:18:00
::
:: Slightly modified from SCREEN.BAT by Stian Jakobsen, DOS World May
:: 1996 p. 22
::
:: Here's a neat little *.BAT, just copied from a magazine and slightly
:: modified. It captures and then restores the current screen. Anybody
:: want to improve upon it as a 4DOS *.BTM? The magazine editors would
:: like to find the author; all they know is that he posted it from Norway.

@echo off
*setlocal
*unalias *
if "%1"=="r" .or. "%1" == "/r" goto RESTORE
if "%1"=="s" .or. "%1" == "/s" goto SAVE

:SYNTAX
echo.
echo SCAP /R = Restore Screen.
echo /S = Save Screen.
goto END

:RESTORE
if not exist %temp\screen.tmp goto nofile
echo N%temp\screen.tmp > %temp\restore.scr
echo L >> %temp\restore.scr
echo M CS:100 FA0 B800:0 >> %temp\restore.scr
echo Q >> %temp\restore.scr
debug < %temp\restore.scr>nul
*del /q %temp\restore.scr
*del /q %temp\screen.tmp
echo 
goto END

:SAVE
echo N%temp\screen.tmp > %temp\save.scr
echo R BX >> %temp\save.scr
echo 0 >> %temp\save.scr
echo R CX >> %temp\save.scr
echo FA0 >> %temp\save.scr
echo W B800:0 >> %temp\save.scr
echo Q >> %temp\save.scr
debug < %temp\save.scr>nul
*del /q %temp\save.scr
goto END

:NOFILE
echo.
echo Could not find %temp\SCREEN.TMP

:END
echo.
quit
 

samintz

Scott Mintz
May 20, 2008
1,203
11
Solon, OH, USA
#2
I have an old BTM file that I wrote some time ago that works to restore
the text to the screen but not the attributes. In other words, you lose
whatever colors may have been displayed.

setlocal
setdos /x-4

>savescn.txt
do row=0 to %@dec[%_rows]
set L="%@readscr[%row,0,%_columns]"
echo.%L >> savescn.txt
enddo
endlocal

Then to restore the screen, just TYPE savescn.txt.

You can get the current cursor position using the %_ROW and %_COLUMN
variables. And restore the cursor using SCREEN

-Scott


JOSE ADRIANO BALTIERI <> wrote on 07/28/2010 10:00:42
AM:


> Hello !
>
> I have a kind of a project manager built upon 4NT (now TCC).
>
> When I run it it shows a list of projects (@select). Then I pick one
> and enter into that project.
>
> The project for me is a "context". So, when I enter it, it brings
> back to me all the histories from THAT project. So, directories for
> all drives are set according to that project . Also ALIAS and many
> other things.
>
> When I leave the project, it saves it all back.
>
> So far, so good.
>
> However, I'd like to restore the SCREEN of the project, as I left it
> last time I entered it.
>
> Currently I do it using an EXE of my onw.
>
> But I found a BTM for doing that. This is an old BTM that I inserted
> at the end of this message.
>
> The BTM work but, it DOES not reposition the cursor position (the
> prompt) where it was.
>
> Do you have something similar ? Or other idea ?
>
> Follows the original btm :
>
> ---------------------
>
> :: SCAP.BTM Utility to capture and restore the screen
contents

> :: By: Frederick Sohn
> :: Date: 27 Mar 96 05:18:00
> ::
> :: Slightly modified from SCREEN.BAT by Stian Jakobsen, DOS World May
> :: 1996 p. 22
> ::
> :: Here's a neat little *.BAT, just copied from a magazine and slightly
> :: modified. It captures and then restores the current screen. Anybody
> :: want to improve upon it as a 4DOS *.BTM? The magazine editors would
> :: like to find the author; all they know is that he posted it from
Norway.

>
> @echo off
> *setlocal
> *unalias *
> if "%1"=="r" .or. "%1" == "/r" goto RESTORE
> if "%1"=="s" .or. "%1" == "/s" goto SAVE
>
> :SYNTAX
> echo.
> echo SCAP /R = Restore Screen.
> echo /S = Save Screen.
> goto END
>
> :RESTORE
> if not exist %temp\screen.tmp goto nofile
> echo N%temp\screen.tmp > %temp\restore.scr
> echo L >> %temp\restore.scr
> echo M CS:100 FA0 B800:0 >> %temp\restore.scr
> echo Q >> %temp\restore.scr
> debug < %temp\restore.scr>nul
> *del /q %temp\restore.scr
> *del /q %temp\screen.tmp
> echo 
> goto END
>
> :SAVE
> echo N%temp\screen.tmp > %temp\save.scr
> echo R BX >> %temp\save.scr
> echo 0 >> %temp\save.scr
> echo R CX >> %temp\save.scr
> echo FA0 >> %temp\save.scr
> echo W B800:0 >> %temp\save.scr
> echo Q >> %temp\save.scr
> debug < %temp\save.scr>nul
> *del /q %temp\save.scr
> goto END
>
> :NOFILE
> echo.
> echo Could not find %temp\SCREEN.TMP
>
> :END
> echo.
> quit
>
>
>
>
 
#5
Have you looked at @CONSOLEB?

Rex Conn
JP Software
Nope. But I need to save the screen buffer into a file, to restore it later.

Guess @CONSOLEB cant do that.

Would you have an example ? Docs has none...

I also saw some stuff about saving (capturing) screen as BMP.

Nice it would be to have as JPG.

There's an utility called GadWin Print Screen.

I'd be glad if I had GadWin's facilites as a command line call...

For instance : on my BTMs I could have somehing like :

IFF "I had some sort of unknown error ..." THEN
Capture this screen as a JPG file onto C:\TEMP\SCREENSHOT.JPG
SENDMAIL /A C:\TEMP\SCREENSHOT.JPG to myself
DEL /Q /K C:\TEMP\SCREENSHOT.JPG
ENDIF

This would be nice as well.

But doesnt solve my original post, which is to restore current screen and cursor position. IOW the working environment (prompts/colors/screens/cursor position/etc).

Thanks !
 
#7
But you said you were using an .EXE of your own already. Why not just add the missing features to your .EXE?
The EXE works fine.

However it's written in Clipper (5.2e).

And I'd like to replace it with "TCC only stuff". Plain. No external resources...

Also think this feature (restoring screen status) may be interesting to other users.

That is, it should be a TCC Product feature...


This is my original code inside my project manager BTM :

-----------------
IFF EXIST %_STARTPATH\LOCAL\%PRONUMBER.MEM THEN
ECHO RESTORING SCREEN...
REM 'SSAVE.EXE' IS MY SCREEN SAVE/RESTORE UTILITY
REM BUT IT DOESNT KNOW ABOUT CURSOR POSITION (PROMPT)...
REM PRONUMBER IS THE PROJECT NO
%TEMPTCC%\SSAVE.EXE RESTORE %PRONUMBER
ENDIFF
REM NOW I NEED TO RESTORE THE SCREEN POSITION (.SC)
REM THAT WAS SAVED ALONG WITH THE SCREEN INTO THE PROJECT
REM PARTICULAR DATA
IFF EXIST %_STARTPATH\LOCAL\%PRONUMBER.SC THEN
SET /R %_STARTPATH\LOCAL\%PRONUMBER.SC
SET /R %_STARTPATH\LOCAL\%PRONUMBER%.SES
SET ROW=%@EVAL[%ROW-1]
IFF "%ROW"=="-1" THEN
SET ROW=0
ENDIFF
SET SFG=%_FG
SET SBG=%_BG
COLOR BRI RED ON BLACK
SCREEN %ROW 0 %PREFIX%%SESSIONs
COLOR %SFG% ON %SBG%
UNSET /Q PREFIX,SESSION,SFG,SBG
ENDIFF
 
#8
On Wed, 28 Jul 2010 13:02:13 -0400, JOSE ADRIANO BALTIERI
<> wrote:

|---End Quote---
|OK !
|However, for me it would be nice to have colors restored...
|
|Let's listen to other suggestions, shall we ?

My 4CONSOLE plugin's SAVECSB saves the plain text to a file ...
advantage: it's readable by a human.

I'm tempted to (tonight perhaps) write a pair of functions for
4CONSOLE) to save/restore the console together with buffer size,
window size, attributes (colors), and cursor position. It wouldn't be
hard (probably fun). The file would have to be in a binary format,
probably not readable.
 
#9
On Wed, 28 Jul 2010 13:02:13 -0400, JOSE ADRIANO BALTIERI
<> wrote:

|---End Quote---
|OK !
|However, for me it would be nice to have colors restored...
|
|Let's listen to other suggestions, shall we ?

My 4CONSOLE plugin's SAVECSB saves the plain text to a file ...
advantage: it's readable by a human.

I'm tempted to (tonight perhaps) write a pair of functions for
4CONSOLE) to save/restore the console together with buffer size,
window size, attributes (colors), and cursor position. It wouldn't be
hard (probably fun). The file would have to be in a binary format,
probably not readable.
Sounds great !

Notice that I only use console mode stuff (as if it were 4NT)..

Thanks!
 

samintz

Scott Mintz
May 20, 2008
1,203
11
Solon, OH, USA
#10
Actually, if you put the text into the file first, followed by the
attributes and separated the two with a NULL, you could TYPE the file or
LIST it to see the contents in a human readable form.

-Scott

vefatica <> wrote on 07/28/2010 02:59:17 PM:


> On Wed, 28 Jul 2010 13:02:13 -0400, JOSE ADRIANO BALTIERI
> <> wrote:
>
> |---End Quote---
> |OK !
> |However, for me it would be nice to have colors restored...
> |
> |Let's listen to other suggestions, shall we ?
>
> My 4CONSOLE plugin's SAVECSB saves the plain text to a file ...
> advantage: it's readable by a human.
>
> I'm tempted to (tonight perhaps) write a pair of functions for
> 4CONSOLE) to save/restore the console together with buffer size,
> window size, attributes (colors), and cursor position. It wouldn't be
> hard (probably fun). The file would have to be in a binary format,
> probably not readable.
>
>
>
>
 
#11
| Actually, if you put the text into the file first, followed by the
| attributes and separated the two with a NULL, you could TYPE the
| file or LIST it to see the contents in a human readable form.

Even better, to keep the format fixed, the attributes (buffer and window
sizes, etc.) could be in front (with numeric information in decimal),
followed by the buffer contents.
This brings up an interesting point: if I understand things correctly,
the following relationships are always true between TCC and 4console.dll
internal variables:

visible (DLL) TCC buffer (DLL)
%_winrows EQ %_rows LE %_bufrows
%_wincols LE %_columns EQ %_bufcols

In other words, _winrows and _bufcols are superfluous.
--
Steve
 
#12
On Wed, 28 Jul 2010 15:14:30 -0400, samintz <>
wrote:

|Actually, if you put the text into the file first, followed by the
|attributes and separated the two with a NULL, you could TYPE the file or
|LIST it to see the contents in a human readable form.

I suppose, but ReadConsoleOutput() gets them both in an array of
CHAR_INFO structures. It'd be easiest, most efficient, and fastest to
WriteFile() that whole array to a file. And they can be restored all
at once with WriteConsoleOutput(). And there's always SAVECSB if you
want just the text.

I could also restore

1. buffer size
2. window size
3. window position
4. window title
5. cursor position

... I suppose even the command history, dir history, aliases, and
functions but that might be going overboard and I doubt a
one-size-fits-all approach to doing that would really fit all.
 

samintz

Scott Mintz
May 20, 2008
1,203
11
Solon, OH, USA
#13
That's true. However, I was thinking of separate API calls to
ReadConsoleOutputCharacter() and ReadConsoleOutputAttribute() and the
correspondng Write calls. If you don't really care about the actual
contents then your method is better.

-Scott

vefatica <> wrote on 07/28/2010 04:47:54 PM:


> On Wed, 28 Jul 2010 15:14:30 -0400, samintz <>
> wrote:
>
> |Actually, if you put the text into the file first, followed by the
> |attributes and separated the two with a NULL, you could TYPE the file
or

> |LIST it to see the contents in a human readable form.
>
> I suppose, but ReadConsoleOutput() gets them both in an array of
> CHAR_INFO structures. It'd be easiest, most efficient, and fastest to
> WriteFile() that whole array to a file. And they can be restored all
> at once with WriteConsoleOutput(). And there's always SAVECSB if you
> want just the text.
>
> I could also restore
>
> 1. buffer size
> 2. window size
> 3. window position
> 4. window title
> 5. cursor position
>
> ... I suppose even the command history, dir history, aliases, and
> functions but that might be going overboard and I doubt a
> one-size-fits-all approach to doing that would really fit all.
>
>
>
>
 
#14
| I suppose, but ReadConsoleOutput() gets them both in an array of
| CHAR_INFO structures. It'd be easiest, most efficient, and fastest
| to WriteFile() that whole array to a file. And they can be restored
| all at once with WriteConsoleOutput(). And there's always SAVECSB
| if you want just the text.
||
| I could also restore
|
| 1. buffer size
| 2. window size
| 3. window position
| 4. window title
| 5. cursor position
|
| ... I suppose even the command history, dir history, aliases, and
| functions but that might be going overboard and I doubt a
| one-size-fits-all approach to doing that would really fit all.

The OP states that he uses alternatate set of environment variables and
aliases for each project, but already has code to save and restore them.
However, he also was interested in restoring not only the text on the
screen, but also its colors. That job was much simpler in the old days when
screen buffers were stored at 0xB0000 in readable graphics adapters, with
one byte for color and another byte for text character. If something like
that is possible with current systems, that's what I understand the OP's
desire to be.
--
Steve
 
#15
The OP states that he uses alternatate set of environment variables and
aliases for each project, but already has code to save and restore them.
However, he also was interested in restoring not only the text on the
screen, but also its colors. That job was much simpler in the old days when
screen buffers were stored at 0xB0000 in readable graphics adapters, with
one byte for color and another byte for text character. If something like
that is possible with current systems, that's what I understand the OP's
desire to be.
--
Steve
This can be done with PowerBASIC, thus;
Code:
#COMPILE EXE
#DIM ALL

%USEMACROS = 1
#INCLUDE "Win32API.inc"

FUNCTION PBMAIN()
  DIM row AS LONG
  DIM col AS LONG
  DIM TheFile AS INTEGER
  DIM ur AS LONG
  DIM lr AS LONG
  DIM uc AS LONG
  DIM lc AS LONG

  TheFile = FREEFILE

  ur = 1
  lr = 25
  uc = 1
  lc = 80

  OPEN "Screen.dat" FOR OUTPUT AS #TheFile

  FOR row = ur TO lr
    FOR col = uc TO lc
      WRITE #TheFile, row,col, SCREEN(row,col),SCREENATTR(row,col)
    NEXT col
  NEXT row

  CLOSE #TheFile

END FUNCTION
To restore the screen;

Code:
#COMPILE EXE
#DIM ALL

%USEMACROS = 1
#INCLUDE "Win32API.inc"

FUNCTION PBMAIN()
  DIM row AS LONG
  DIM col AS LONG
  DIM TheFile AS INTEGER
  DIM ur AS LONG
  DIM lr AS LONG
  DIM uc AS LONG
  DIM lc AS LONG
  DIM TheChar AS INTEGER
  DIM TheAttr AS INTEGER

  TheFile = FREEFILE

  ur = 1
  lr = 25
  uc = 1
  lc = 80

  OPEN "Screen.dat" FOR INPUT AS #TheFile

  FOR row = ur TO lr
    FOR col = uc TO lc
      INPUT #TheFile, row,col, TheChar, TheAttr
      LOCATE row,col
      COLOR TheAttr MOD 16, TheAttr \ 16
      PRINT CHR$(TheChar);
    NEXT col
  NEXT row

  CLOSE #TheFile

END FUNCTION
While this could be run as an .EXE, I could put it into a .DLL, which could be called with @winapi. The ultimate would be to have it as a plugin, but I tried once to convert the Delphi Plugin Template to PowerBASIC, but my skills are not that good for that. Thank goodness that the Plugin SDK came with a Delphi template, at least. Come to think of it, this should be fairly easy to implement as a plugin with Delphi.

I will tinker and see what I can come up with.

Joe
 
#16
On Wed, 28 Jul 2010 19:47:30 -0400, Steve Fábián
<> wrote:

| The OP states that he uses alternatate set of environment variables and
|aliases for each project, but already has code to save and restore them.
|However, he also was interested in restoring not only the text on the
|screen, but also its colors. That job was much simpler in the old days when
|screen buffers were stored at 0xB0000 in readable graphics adapters, with
|one byte for color and another byte for text character. If something like
|that is possible with current systems, that's what I understand the OP's
|desire to be.

The console is truly a window. I doubt it has anything comparable to
the old hardware video buffer. And the console screen buffer may be
much larger than the part you see.

I have something that works ("SAVECON filename" and "RSTRCON
filename"). It has absolutely no error control yet (but I think
little can go wrong as long as you give them filenames) and the only
help is via the CONHELP command. And I might have fixed a bug in
CONSIZE inadvertantly.

There are new (32-bit) 4console.zip files at

ftp://lucky.syr.edu/4plugins/4console.zip

and

ftp://barnyard.syr.edu/pub/vefatica/4plugins/4console.zip

I'd like some feedback (thanks).

As it turned out, with my big (80 x 9999) screen buffer, I couldn't
read/write the whole thing at once (neither as CHAR_INFOs nor as CHARs
and attributes separately. The APIs just won't do it. So I'm doing
it line by line. It's still fast, in my case under 1 sec. For that
buffer size, the file is just over 3MB.
 
#17
I have something that works ("SAVECON filename" and "RSTRCON filename"). It has absolutely no error control yet (but I think
little can go wrong as long as you give them filenames) and the only
help is via the CONHELP command. And I might have fixed a bug in
CONSIZE inadvertantly.

There are new (32-bit) 4console.zip files at

ftp://lucky.syr.edu/4plugins/4console.zip

and

ftp://barnyard.syr.edu/pub/vefatica/4plugins/4console.zip
Has anyone tried these? I updated them a couple times; they're more robust. One thought is to save the console screen buffer only as far as the current cursor row; presumably it will be empty thereafter. That can make it quicker (though it's already fast) and make the files smaller. Upon restoring, it'd redimension/reposition the console as it was but only write down to the saved old cursor row (I could precede that with a "CLS /C" in case the current console has output past the restore point.