1 .\"***************************************************************************
2 .\" Copyright 2018-2023,2024 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.46 2024/03/23 20:42:29 tom Exp $
31 .TH scr_dump 5 2024-03-23 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "File formats"
49 \fIcurses\fR screen dump
52 The curses library provides applications with the ability to write the
53 contents of a window to an external file using \fBscr_dump\fP or \fBputwin\fP,
54 and read it back using \fBscr_restore\fP or \fBgetwin\fP.
56 The \fBputwin\fP and \fBgetwin\fP functions do the work;
57 while \fBscr_dump\fP and \fBscr_restore\fP conveniently save and restore
58 the whole screen, i.e., \fBstdscr\fP.
60 A longstanding implementation of screen-dump was
61 revised with ncurses6 to remedy problems with the earlier approach:
63 A \*(``magic number\*('' is written to the beginning of the dump file,
64 allowing applications (such as \fBfile\fP(1)) to recognize curses dump files.
66 Because ncurses6 uses a new format,
67 that requires a new magic number
68 was unused by other applications.
69 This 16-bit number was unused:
74 0x8888 (octal \*(``\e210\e210\*('')
78 but to be more certain, this 32-bit number was chosen:
82 0x88888888 (octal \*(``\e210\e210\e210\e210\*('')
86 This is the pattern submitted to the maintainers of the \fBfile\fP program:
91 # ncurses5 (and before) did not use a magic number,
92 # making screen dumps "data".
94 # ncurses6 (2015) uses this format, ignoring byte-order
95 0 string \e210\e210\e210\e210ncurses ncurses6 screen image
101 The screen dumps are written in textual form,
102 so that internal data sizes are not directly related to the dump-format, and
103 enabling the library to read dumps from either narrow- or wide-character-
106 The \fInarrow\fP library configuration holds characters and video attributes
107 in a 32-bit \fBchtype\fP, while the \fIwide-character\fP library stores
108 this information in the \fBcchar_t\fP structure, which is much larger than
111 It is possible to read a screen dump into a terminal with a different
113 because the library truncates or fills the screen as necessary.
115 The ncurses6 \fBgetwin\fP reads the legacy screen dumps from ncurses5.
116 .SS "ncurses5 (Legacy)"
117 The screen-dump feature was added to \fI\%ncurses\fP in June 1995.
118 While there were fixes and improvements in succeeding years,
119 the basic scheme was unchanged:
121 The \fI\%WINDOW\fP structure was written in binary form.
123 The \fI\%WINDOW\fP structure refers to lines of data,
124 which were written as an array of binary data following the \fI\%WINDOW\fP.
126 When \fBgetwin\fP restored the window,
127 it would keep track of offsets into the array of line-data
128 and adjust the \fI\%WINDOW\fP structure which was read back into memory.
130 This is similar to Unix System\ V,
131 but does not write a \*(``magic number\*('' to identify the file format.
133 There is no standard format for
136 A brief survey of the existing implementations follows.
138 X/Open Curses, Issue 7 specifies little.
140 (boldface emphasis added)
143 \*(``[t]he \fI\%getwin()\fP function reads window-related data stored in
144 the file by \fI\%putwin()\fP.
145 The function then creates and initializes a new window using that data.
147 The \fI\%putwin()\fP function writes all data associated with \fIwin\fP
148 into the \fI\%stdio\fP stream to which \fIfilep\fP points,
149 using an \fBunspecified format\fP.
150 This information can be retrieved later using \fI\%getwin()\fP.\*(''
153 In the mid-1990s when the X/Open Curses document was written,
154 there were still System\ V systems using older,
160 was not relevant to X/Open because it did not meet the criteria
161 for base-level conformance;
162 see \fB\%ncurses\fP(3X).
166 identified the file format by writing a \*(``magic number\*('' at the
167 beginning of the dump.
168 The \fI\%WINDOW\fP data and the lines of text follow, all in binary form.
172 has the following definitions.
176 /* terminfo magic number */
179 /* curses screen dump magic number */
180 #define SVR2_DUMP_MAGIC_NUMBER 0433
181 #define SVR3_DUMP_MAGIC_NUMBER 0434
185 That is, the feature was likely introduced in SVr2 (1984),
186 and improved in SVr3 (1987).
189 has no magic number for SVr4 (1989).
190 Other System\ V operating systems
192 use a magic number that would correspond to the following.
196 /* curses screen dump magic number */
197 #define SVR4_DUMP_MAGIC_NUMBER 0435
201 That octal number in bytes is 001, 035.
202 Because most Unix vendors at the time used big-endian hardware,
203 the magic number is written with the high-order byte first.
211 After the magic number,
212 the \fI\%WINDOW\fP structure and line data are written in binary format.
213 While the magic number used by these systems can be observed with
215 none of them documents the format used for screen dumps.
217 Nor do they use an identical format,
218 even with the System\ V family.
222 test program was used to collect information for this manual page.
223 It produced dumps of different size
224 (all on 64-bit hardware,
231 Solaris 10 (13273 bytes)
233 \fI\%ncurses\fP5 (12888 bytes)
238 has no magic number corresponding to SVr4
241 since Solaris was the first operating system to meet the SVr4
243 Solaris furthermore supplies two versions of
248 library uses the SVr3 magic number.
257 uses a textual format with no magic number.
259 According to its copyright notice,
262 library was developed by MKS
263 (Mortice Kern Systems) from 1990 to 1995.
266 it includes a header with parameters.
268 the contents of the window are written piecemeal,
269 with coordinates and attributes for each chunk of text rather than
270 writing the whole window from top to bottom.
273 added support for screen dumps in version 2.7 (2005).
274 Like System\ V and ncurses5,
275 it writes the \fI\%WINDOW\fP structure in binary,
276 but begins the file with its three-byte identifier \*(``PDC\*('',
277 followed by a single-byte version number.
288 does not support \fB\%scr_dump\fP and \fB\%scr_restore\fP
289 (or \fB\%scr_init\fP,
291 although it has \fB\%putwin\fP and \fB\%getwin\fP.
294 NetBSD \fB\%putwin\fP does not identify its dumps with a useful magic
300 shared library major and minor versions as the first two bytes
304 followed by a binary dump of the \fI\%WINDOW\fP,
306 some data for wide characters referenced by the \fI\%WINDOW\fP
311 lines as done by other implementations.
313 Given a simple program which writes text to the screen
314 (and for the sake of example, limiting the screen-size to 10x20):
324 putenv("COLUMNS=20");
327 init_pair(1, COLOR_WHITE, COLOR_BLUE);
328 init_pair(2, COLOR_RED, COLOR_BLACK);
335 attrset(A_REVERSE | COLOR_PAIR(2));
345 When run using ncurses6, the output looks like this:
349 \e210\e210\e210\e210ncurses 6.0.20170415
355 _attrs=\e{REVERSE|C2}
359 _bkgrnd=\e{NORMAL|C1}\es
361 1:\e{NORMAL|C1}\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
362 2:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
363 3:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
364 4:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
365 5:\es\es\es\es\es\e{BOLD}Hello\e{NORMAL}\es\es\es\es\es\es\es\es\es\es
366 6:\es\es\es\es\es\e{REVERSE|C2}World!\e{NORMAL|C1}\es\es\es\es\es\es\es\es\es
367 7:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
368 8:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
369 9:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
370 10:\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es\es
374 The first four octal escapes are actually nonprinting characters,
375 while the remainder of the file is printable text.
378 The actual color pair values are not written to the file.
380 All characters are shown in printable form; spaces are \*(``\es\*('' to
381 ensure they are not overlooked.
383 Attributes are written in escaped curly braces, e.g., \*(``\e{BOLD}\*('',
384 and may include a color pair (C1 or C2 in this example).
386 The parameters in the header are written out only if they are nonzero.
387 When reading back, order does not matter.
390 Running the same program with Solaris \fIxpg4\fP curses gives this dump:
430 Solaris \fBgetwin\fP requires that all parameters are present, and
432 The \fIxpg4\fP curses library does not know about the \fBbce\fP
433 (back color erase) capability, and does not color the window background.
436 On the other hand, the SVr4 curses library does know about the background color.
437 However, its screen dumps are in binary.
438 Here is the corresponding dump (using \*(``od \-t x1\*(''):
442 0000000 1c 01 c3 d6 f3 58 05 00 0b 00 0a 00 14 00 00 00
443 0000020 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00
444 0000040 00 00 b8 1a 06 08 cc 1a 06 08 00 00 09 00 10 00
445 0000060 00 00 00 80 00 00 20 00 00 00 ff ff ff ff 00 00
446 0000100 ff ff ff ff 00 00 00 00 20 80 00 00 20 80 00 00
447 0000120 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
449 0000620 20 80 00 00 20 80 00 00 20 80 00 00 48 80 00 04
450 0000640 65 80 00 04 6c 80 00 04 6c 80 00 04 6f 80 00 04
451 0000660 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
453 0000740 20 80 00 00 20 80 00 00 20 80 00 00 57 00 81 00
454 0000760 6f 00 81 00 72 00 81 00 6c 00 81 00 64 00 81 00
455 0001000 21 00 81 00 20 80 00 00 20 80 00 00 20 80 00 00
456 0001020 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
458 0001540 20 80 00 00 20 80 00 00 00 00 f6 d1 01 00 f6 d1
459 0001560 08 00 00 00 40 00 00 00 00 00 00 00 00 00 00 07
460 0001600 00 04 00 01 00 01 00 00 00 01 00 00 00 00 00 00
461 0001620 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
469 extended screen-dump format for \fI\%ncurses\fP 6.0 (2015)
473 screen dump feature in \fI\%ncurses\fP 1.9.2d (1995)
475 \fB\%curs_scr_dump\fP(3X),
476 \fB\%curs_util\fP(3X)