1 .\"***************************************************************************
2 .\" Copyright 2018-2021,2023 Thomas E. Dickey *
3 .\" Copyright 2017 Free Software Foundation, Inc. *
5 .\" Permission is hereby granted, free of charge, to any person obtaining a *
6 .\" copy of this software and associated documentation files (the *
7 .\" "Software"), to deal in the Software without restriction, including *
8 .\" without limitation the rights to use, copy, modify, merge, publish, *
9 .\" distribute, distribute with modifications, sublicense, and/or sell *
10 .\" copies of the Software, and to permit persons to whom the Software is *
11 .\" furnished to do so, subject to the following conditions: *
13 .\" The above copyright notice and this permission notice shall be included *
14 .\" in all copies or substantial portions of the Software. *
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 .\" Except as contained in this notice, the name(s) of the above copyright *
25 .\" holders shall not be used in advertising or otherwise to promote the *
26 .\" sale, use or other dealings in this Software without prior written *
28 .\"***************************************************************************
30 .\" $Id: scr_dump.5,v 1.31 2023/09/16 23:38:39 tom Exp $
31 .TH scr_dump 5 2023-09-16 "ncurses 6.4" "File formats"
61 \fIcurses\fR screen dump
65 The curses library provides applications with the ability to write the
66 contents of a window to an external file using \fBscr_dump\fP or \fBputwin\fP,
67 and read it back using \fBscr_restore\fP or \fBgetwin\fP.
69 The \fBputwin\fP and \fBgetwin\fP functions do the work;
70 while \fBscr_dump\fP and \fBscr_restore\fP conveniently save and restore
71 the whole screen, i.e., \fBstdscr\fP.
73 A longstanding implementation of screen-dump was
74 revised with ncurses6 to remedy problems with the earlier approach:
76 A \*(``magic number\*('' is written to the beginning of the dump file,
77 allowing applications (such as \fBfile\fP(1)) to recognize curses dump files.
79 Because ncurses6 uses a new format,
80 that requires a new magic number
81 was unused by other applications.
82 This 16-bit number was unused:
84 0x8888 (octal \*(``\\210\\210\*('')
87 but to be more certain, this 32-bit number was chosen:
89 0x88888888 (octal \*(``\\210\\210\\210\\210\*('')
92 This is the pattern submitted to the maintainers of the \fBfile\fP program:
95 # ncurses5 (and before) did not use a magic number,
96 # making screen dumps "data".
98 # ncurses6 (2015) uses this format, ignoring byte-order
99 0 string \\210\\210\\210\\210ncurses ncurses6 screen image
103 The screen dumps are written in textual form,
104 so that internal data sizes are not directly related to the dump-format, and
105 enabling the library to read dumps from either narrow- or wide-character-
108 The \fInarrow\fP library configuration holds characters and video attributes
109 in a 32-bit \fBchtype\fP, while the \fIwide-character\fP library stores
110 this information in the \fBcchar_t\fP structure, which is much larger than
113 It is possible to read a screen dump into a terminal with a different
115 because the library truncates or fills the screen as necessary.
117 The ncurses6 \fBgetwin\fP reads the legacy screen dumps from ncurses5.
118 .SS ncurses5 (legacy)
119 The screen-dump feature was added to ncurses in June 1995.
120 While there were fixes and improvements in succeeding years,
121 the basic scheme was unchanged:
123 The \fBWINDOW\fP structure was written in binary form.
125 The \fBWINDOW\fP structure refers to lines of data,
126 which were written as an array of binary data following the \fBWINDOW\fP.
128 When \fBgetwin\fP restored the window,
129 it would keep track of offsets into the array of line-data
130 and adjust the \fBWINDOW\fP structure which was read back into memory.
132 This is similar to Unix SystemV,
133 but does not write a \*(``magic number\*('' to identify the file format.
135 There is no standard format for \fBputwin\fP.
136 This section gives a brief description of the existing formats.
138 Refer to \fIX/Open Curses, Issue 7\fP (2009).
140 X/Open's documentation for \fIenhanced curses\fP says only:
143 The \fBgetwin(\ ) \fPfunction reads window-related data
144 stored in the file by \fIputwin(\ )\fP.
146 then creates and initializes a new window using that data.
148 The \fBputwin(\ )\fP function writes all data associated
149 with \fIwin\fP into the \fBstdio\fP(3) stream to which \fIfilep\fP
150 points, using an \fBunspecified format\fP.
151 This information can be retrieved later using \fBgetwin(\ )\fP.
154 In the mid-1990s when the X/Open Curses document was written,
155 there were still systems using older, less capable curses libraries
156 (aside from the BSD curses library which was not relevant to X/Open
157 because it did not meet the criteria for \fIbase curses\fP).
158 The document explained the term \*(``enhanced\*('' as follows:
161 Shading is used to identify \fIX/Open Enhanced Curses\fP material,
162 relating to interfaces included to provide enhanced capabilities
163 for applications originally written to be compiled on systems
164 based on the UNIX operating system.
165 Therefore, the features described may not be present on systems
166 that conform to \fBXPG4 or to earlier XPG releases\fP.
167 The relevant reference pages may provide additional
168 or more specific portability warnings about use of the material.
171 In the foregoing, emphasis was added to \fBunspecified format\fP
172 and to \fBXPG4 or to earlier XPG releases\fP,
175 Unix SystemV curses identified the file format by writing a
176 \*(``magic number\*('' at the beginning of the dump.
177 The \fBWINDOW\fP data and the lines of text follow, all in binary form.
179 The Solaris curses source has these definitions:
181 /* terminfo magic number */
184 /* curses screen dump magic number */
185 #define SVR2_DUMP_MAGIC_NUMBER 0433
186 #define SVR3_DUMP_MAGIC_NUMBER 0434
189 That is, the feature was likely introduced in SVr2 (1984),
190 and improved in SVr3 (1987).
191 The Solaris curses source has no magic number for SVr4 (1989).
192 Other operating systems (AIX and HPUX) use a magic number which would
193 correspond to this definition:
195 /* curses screen dump magic number */
196 #define SVR4_DUMP_MAGIC_NUMBER 0435
199 That octal number in bytes is 001, 035.
200 Because most Unix vendors use big-endian hardware,
201 the magic number is written with the high-order byte first, e.g.,
206 After the magic number, the \fBWINDOW\fP structure and line-data are
207 written in binary format.
208 While the magic number used by the Unix systems can be seen using \fBod\fP(1),
209 none of the Unix systems documents the format used for screen-dumps.
211 The Unix systems do not use identical formats.
212 While collecting information for for this manual page,
213 the \fIsavescreen\fP test-program
214 produced dumps of different size
215 (all on 64-bit hardware, on 40x80 screens):
221 Solaris 10 (13273 bytes)
223 ncurses5 (12888 bytes)
225 As noted above, Solaris curses has no magic number corresponding
227 This is odd since Solaris was the first operating system
228 to pass the SVr4 guidelines.
229 Solaris has two versions of curses:
231 The default curses library uses the SVr3 magic number.
233 There is an alternate curses library in \fB/usr/xpg4\fP.
234 This uses a textual format with no magic number.
236 According to the copyright notice, the \fIxpg4\fP Solaris curses library was
237 developed by MKS (Mortice Kern Systems) from 1990 to 1995.
239 Like ncurses6, there is a file-header with parameters.
240 Unlike ncurses6, the contents of the window are written piecemeal,
241 with coordinates and attributes for each chunk of text rather
242 than writing the whole window from top to bottom.
244 PDCurses added support for screen dumps in version 2.7 (2005).
245 Like Unix SystemV and ncurses5,
246 it writes the \fBWINDOW\fP structure in binary,
247 but begins the file with its three-byte identifier \*(``PDC\*('',
248 followed by a one-byte version,
254 As of April 2017, NetBSD curses does
255 not support \fBscr_dump\fP and \fBscr_restore\fP
256 (or \fBscr_init\fP, \fBscr_set\fP),
257 although it has \fBputwin\fP and \fBgetwin\fP.
259 Like ncurses5, NetBSD \fBputwin\fP does not identify its dumps with a
263 the curses shared library major and minor versions
264 as the first two bytes (e.g., 7 and 1),
266 followed by a binary dump of the \fBWINDOW\fP,
268 some data for wide-characters referenced by the \fBWINDOW\fP structure, and
270 finally, lines as done by other implementations.
272 Given a simple program which writes text to the screen
273 (and for the sake of example, limiting the screen-size to 10x20):
281 putenv("COLUMNS=20");
284 init_pair(1, COLOR_WHITE, COLOR_BLUE);
285 init_pair(2, COLOR_RED, COLOR_BLACK);
292 attrset(A_REVERSE | COLOR_PAIR(2));
301 When run using ncurses6, the output looks like this:
303 \\210\\210\\210\\210ncurses 6.0.20170415
309 _attrs=\\{REVERSE|C2}
313 _bkgrnd=\\{NORMAL|C1}\\s
315 1:\\{NORMAL|C1}\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
316 2:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
317 3:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
318 4:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
319 5:\\s\\s\\s\\s\\s\\{BOLD}Hello\\{NORMAL}\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
320 6:\\s\\s\\s\\s\\s\\{REVERSE|C2}World!\\{NORMAL|C1}\\s\\s\\s\\s\\s\\s\\s\\s\\s
321 7:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
322 8:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
323 9:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
324 10:\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s\\s
327 The first four octal escapes are actually nonprinting characters,
328 while the remainder of the file is printable text.
331 The actual color pair values are not written to the file.
333 All characters are shown in printable form; spaces are \*(``\\s\*('' to
334 ensure they are not overlooked.
336 Attributes are written in escaped curly braces, e.g., \*(``\\{BOLD}\*('',
337 and may include a color-pair (C1 or C2 in this example).
339 The parameters in the header are written out only if they are nonzero.
340 When reading back, order does not matter.
343 Running the same program with Solaris \fIxpg4\fP curses gives this dump:
380 Solaris \fBgetwin\fP requires that all parameters are present, and
382 The \fIxpg4\fP curses library does not know about the \fBbce\fP
383 (back color erase) capability, and does not color the window background.
386 On the other hand, the SVr4 curses library does know about the background color.
387 However, its screen dumps are in binary.
388 Here is the corresponding dump (using \*(``od -t x1\*(''):
390 0000000 1c 01 c3 d6 f3 58 05 00 0b 00 0a 00 14 00 00 00
391 0000020 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00
392 0000040 00 00 b8 1a 06 08 cc 1a 06 08 00 00 09 00 10 00
393 0000060 00 00 00 80 00 00 20 00 00 00 ff ff ff ff 00 00
394 0000100 ff ff ff ff 00 00 00 00 20 80 00 00 20 80 00 00
395 0000120 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
397 0000620 20 80 00 00 20 80 00 00 20 80 00 00 48 80 00 04
398 0000640 65 80 00 04 6c 80 00 04 6c 80 00 04 6f 80 00 04
399 0000660 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
401 0000740 20 80 00 00 20 80 00 00 20 80 00 00 57 00 81 00
402 0000760 6f 00 81 00 72 00 81 00 6c 00 81 00 64 00 81 00
403 0001000 21 00 81 00 20 80 00 00 20 80 00 00 20 80 00 00
404 0001020 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
406 0001540 20 80 00 00 20 80 00 00 00 00 f6 d1 01 00 f6 d1
407 0001560 08 00 00 00 40 00 00 00 00 00 00 00 00 00 00 07
408 0001600 00 04 00 01 00 01 00 00 00 01 00 00 00 00 00 00
409 0001620 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
414 \fBcurs_scr_dump\fP(3X),
419 extended screen-dump format for ncurses 6.0 (2015)
423 screen dump feature in ncurses 1.9.2d (1995)