.\" Copyright 2017 Free Software Foundation, Inc. *
.\" *
.\" Permission is hereby granted, free of charge, to any person obtaining a *
.\" Copyright 2017 Free Software Foundation, Inc. *
.\" *
.\" Permission is hereby granted, free of charge, to any person obtaining a *
The curses library provides applications with the ability to write the
contents of a window to an external file using \fBscr_dump\fP or \fBputwin\fP,
and read it back using \fBscr_restore\fP or \fBgetwin\fP.
The curses library provides applications with the ability to write the
contents of a window to an external file using \fBscr_dump\fP or \fBputwin\fP,
and read it back using \fBscr_restore\fP or \fBgetwin\fP.
while \fBscr_dump\fP and \fBscr_restore\fP conveniently save and restore
the whole screen, i.e., \fBstdscr\fP.
.SS ncurses6
while \fBscr_dump\fP and \fBscr_restore\fP conveniently save and restore
the whole screen, i.e., \fBstdscr\fP.
.SS ncurses6
A longstanding implementation of screen-dump was
revised with ncurses6 to remedy problems with the earlier approach:
A longstanding implementation of screen-dump was
revised with ncurses6 to remedy problems with the earlier approach:
A \*(``magic number\*('' is written to the beginning of the dump file,
allowing applications (such as \fBfile\fP(1)) to recognize curses dump files.
.IP
A \*(``magic number\*('' is written to the beginning of the dump file,
allowing applications (such as \fBfile\fP(1)) to recognize curses dump files.
.IP
that requires a new magic number
was unused by other applications.
This 16-bit number was unused:
that requires a new magic number
was unused by other applications.
This 16-bit number was unused:
#
# ncurses5 (and before) did not use a magic number,
# making screen dumps "data".
#
# ncurses6 (2015) uses this format, ignoring byte-order
#
# ncurses5 (and before) did not use a magic number,
# making screen dumps "data".
#
# ncurses6 (2015) uses this format, ignoring byte-order
.bP
The screen dumps are written in textual form,
so that internal data sizes are not directly related to the dump-format, and
.bP
The screen dumps are written in textual form,
so that internal data sizes are not directly related to the dump-format, and
The screen-dump feature was added to ncurses in June 1995.
While there were fixes and improvements in succeeding years,
the basic scheme was unchanged:
The screen-dump feature was added to ncurses in June 1995.
While there were fixes and improvements in succeeding years,
the basic scheme was unchanged:
it would keep track of offsets into the array of line-data
and adjust the \fBWINDOW\fP structure which was read back into memory.
.PP
it would keep track of offsets into the array of line-data
and adjust the \fBWINDOW\fP structure which was read back into memory.
.PP
There is no standard format for \fBputwin\fP.
This section gives a brief description of the existing formats.
.SS X/Open Curses
There is no standard format for \fBputwin\fP.
This section gives a brief description of the existing formats.
.SS X/Open Curses
Refer to \fIX/Open Curses, Issue 7\fP (2009).
.PP
X/Open's documentation for \fIenhanced curses\fP says only:
Refer to \fIX/Open Curses, Issue 7\fP (2009).
.PP
X/Open's documentation for \fIenhanced curses\fP says only:
In the foregoing, emphasis was added to \fBunspecified format\fP
and to \fBXPG4 or to earlier XPG releases\fP,
for clarity.
In the foregoing, emphasis was added to \fBunspecified format\fP
and to \fBXPG4 or to earlier XPG releases\fP,
for clarity.
\*(``magic number\*('' at the beginning of the dump.
The \fBWINDOW\fP data and the lines of text follow, all in binary form.
.PP
The Solaris curses source has these definitions:
\*(``magic number\*('' at the beginning of the dump.
The \fBWINDOW\fP data and the lines of text follow, all in binary form.
.PP
The Solaris curses source has these definitions:
/* terminfo magic number */
#define MAGNUM 0432
/* curses screen dump magic number */
#define SVR2_DUMP_MAGIC_NUMBER 0433
#define SVR3_DUMP_MAGIC_NUMBER 0434
/* terminfo magic number */
#define MAGNUM 0432
/* curses screen dump magic number */
#define SVR2_DUMP_MAGIC_NUMBER 0433
#define SVR3_DUMP_MAGIC_NUMBER 0434
.PP
That is, the feature was likely introduced in SVr2 (1984),
and improved in SVr3 (1987).
The Solaris curses source has no magic number for SVr4 (1989).
Other operating systems (AIX and HPUX) use a magic number which would
correspond to this definition:
.PP
That is, the feature was likely introduced in SVr2 (1984),
and improved in SVr3 (1987).
The Solaris curses source has no magic number for SVr4 (1989).
Other operating systems (AIX and HPUX) use a magic number which would
correspond to this definition:
.PP
That octal number in bytes is 001, 035.
Because most Unix vendors use big-endian hardware,
the magic number is written with the high-order byte first, e.g.,
.PP
That octal number in bytes is 001, 035.
Because most Unix vendors use big-endian hardware,
the magic number is written with the high-order byte first, e.g.,
.PP
After the magic number, the \fBWINDOW\fP structure and line-data are
written in binary format.
.PP
After the magic number, the \fBWINDOW\fP structure and line-data are
written in binary format.
As noted above, Solaris curses has no magic number corresponding
to SVr4 curses.
This is odd since Solaris was the first operating system
As noted above, Solaris curses has no magic number corresponding
to SVr4 curses.
This is odd since Solaris was the first operating system
with coordinates and attributes for each chunk of text rather
than writing the whole window from top to bottom.
.SS PDCurses
with coordinates and attributes for each chunk of text rather
than writing the whole window from top to bottom.
.SS PDCurses
it writes the \fBWINDOW\fP structure in binary,
but begins the file with its three-byte identifier \*(``PDC\*('',
followed by a one-byte version,
e.g.,
it writes the \fBWINDOW\fP structure in binary,
but begins the file with its three-byte identifier \*(``PDC\*('',
followed by a one-byte version,
e.g.,
As of April 2017, NetBSD curses does
not support \fBscr_dump\fP and \fBscr_restore\fP
(or \fBscr_init\fP, \fBscr_set\fP),
As of April 2017, NetBSD curses does
not support \fBscr_dump\fP and \fBscr_restore\fP
(or \fBscr_init\fP, \fBscr_set\fP),
Given a simple program which writes text to the screen
(and for the sake of example, limiting the screen-size to 10x20):
Given a simple program which writes text to the screen
(and for the sake of example, limiting the screen-size to 10x20):
-1:\\{NORMAL|C1}\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
-2:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
-3:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
-4:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
-5:\\s\\s\\s\\s\\s\\{BOLD}Hello\\{NORMAL}\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
-6:\\s\\s\\s\\s\\s\\{REVERSE|C2}World!\\{NORMAL|C1}\\s\\s\\s\\s\\s\\s\\s\\s\\s
-7:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
-8:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
-9:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
-10:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
-.NE
+1:\e{NORMAL|C1}\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
+2:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
+3:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
+4:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
+5:\es\es\es\es\es\e{BOLD}Hello\e{NORMAL}\es\es\es\es\es\es\es\es\es\es
+6:\es\es\es\es\es\e{REVERSE|C2}World!\e{NORMAL|C1}\es\es\es\es\es\es\es\es\es
+7:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
+8:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
+9:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
+10:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
+.EE
+.RE
.PP
The first four octal escapes are actually nonprinting characters,
while the remainder of the file is printable text.
.PP
The first four octal escapes are actually nonprinting characters,
while the remainder of the file is printable text.
-Attributes are written in escaped curly braces, e.g., \*(``\\{BOLD}\*('',
+Attributes are written in escaped curly braces, e.g., \*(``\e{BOLD}\*('',
and may include a color-pair (C1 or C2 in this example).
.bP
The parameters in the header are written out only if they are nonzero.
and may include a color-pair (C1 or C2 in this example).
.bP
The parameters in the header are written out only if they are nonzero.
.PP
On the other hand, the SVr4 curses library does know about the background color.
However, its screen dumps are in binary.
.PP
On the other hand, the SVr4 curses library does know about the background color.
However, its screen dumps are in binary.
0000000 1c 01 c3 d6 f3 58 05 00 0b 00 0a 00 14 00 00 00
0000020 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00
0000040 00 00 b8 1a 06 08 cc 1a 06 08 00 00 09 00 10 00
0000000 1c 01 c3 d6 f3 58 05 00 0b 00 0a 00 14 00 00 00
0000020 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00
0000040 00 00 b8 1a 06 08 cc 1a 06 08 00 00 09 00 10 00