scr_dump(5)
โจ NAME โจ
Bestie, this is scr_dump(5) from the File formats manual section, and it's literally the page for scr_dump โ aka curses screen dump. Periodt. ๐พ๐
๐ DESCRIPTION ๐
The curses library gives applications the ability to write the contents of a window to an external file using scr_dump or putwin, and read it back using scr_restore or getwin. Iconic behavior, honestly. โจ
The putwin and getwin functions do the work; while scr_dump and scr_restore conveniently save and restore the whole screen, i.e., stdscr. Main character energy fr fr. ๐ซ
๐ ncurses6 ๐
A longstanding implementation of screen-dump was revised with ncurses6 to remedy problems with the earlier approach. Here's the tea: ๐ซ
- A โmagic numberโ is written to the beginning of the dump file, allowing applications (such as
file(1)) to recognize curses dump files.
Because ncurses6 uses a new format, that required a new magic number that was unused by other applications. This 16-bit number was unused:
0x8888 (octal โ\210\210โ)
but to be more certain, this 32-bit number was chosen:
0x88888888 (octal โ\210\210\210\210โ)
This is the pattern submitted to the maintainers of the file program:
#
# ncurses5 (and before) did not use a magic number,
# making screen dumps "data".
#
# ncurses6 (2015) uses this format, ignoring byte-order
0 string \210\210\210\210ncurses ncurses6 screen image
#
- The screen dumps are written in textual form, so that internal data sizes are not directly related to the dump-format, and enabling the library to read dumps from either narrow- or wide-character-configurations.
The narrow library configuration holds characters and video attributes in a 32-bit chtype, while the wide-character library stores this information in the cchar_t structure, which is much larger than 32-bits. Structure tea! ๐ซถ
- It is possible to read a screen dump into a terminal with a different screen-size, because the library truncates or fills the screen as necessary. Slay. ๐ฆ
- The
ncurses6getwinreads the legacy screen dumps fromncurses5. Legacy-support queen. ๐
๐ฐ๏ธ ncurses5 (Legacy) ๐ฐ๏ธ
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
WINDOWstructure was written in binary form. - The
WINDOWstructure refers to lines of data, which were written as an array of binary data following theWINDOW. - When
getwinrestored the window, it would keep track of offsets into the array of line-data and adjust theWINDOWstructure which was read back into memory.
This is similar to Unix System V, but does not write a โmagic numberโ to identify the file format. Lowkey important. ๐
๐ PORTABILITY ๐
There is no standard format for curses screen dumps. A brief survey of the existing implementations follows. Buckle up, bestie. ๐ข
๐ X/Open Curses ๐
X/Open Curses Issue 7 specifies little. It says (boldface emphasis added):
โ[t]hegetwin()function reads window-related data stored in the file byputwin(). The function then creates and initializes a new window using that data. Theputwin()function writes all data associated withwininto thestdiostream to whichfileppoints, using an unspecified format. This information can be retrieved later usinggetwin().โ
In the mid-1990s when the X/Open Curses document was written, there were still System V systems using older, less capable curses libraries. BSD curses was not relevant to X/Open because it did not meet the criteria for base-level conformance; see ncurses(3X). Receipts! ๐งพ
๐บ System V ๐บ
System V curses identified the file format by writing a โmagic numberโ at the beginning of the dump. The WINDOW data and the lines of text follow, all in binary form. Very old-school. ๐ฏ๏ธ
Solaris curses has the following definitions.
/* terminfo magic number */
#define MAGNUM 0432
/* curses screen dump magic number */
#define SVR2_DUMP_MAGIC_NUMBER 0433
#define SVR3_DUMP_MAGIC_NUMBER 0434
That is, the feature was likely introduced in SVr2 (1984), and improved in SVr3 (1987). Solaris curses has no magic number for SVr4 (1989). Other System V operating systems (AIX and HP-UX) use a magic number that would correspond to the following.
/* curses screen dump magic number */
#define SVR4_DUMP_MAGIC_NUMBER 0435
That octal number in bytes is 001, 035. Because most Unix vendors at the time used big-endian hardware, the magic number is written with the high-order byte first.
\001\035
After the magic number, the WINDOW structure and line data are written in binary format. While the magic number used by these systems can be observed with od(1), none of them documents the format used for screen dumps. Mysterious! ๐
Nor do they use an identical format, even with the System V family. The ncurses savescreen test program was used to collect information for this manual page. It produced dumps of different size (all on 64-bit hardware, on 40x80 screens):
- AIX (51817 bytes)
- HP-UX (90093 bytes)
- Solaris 10 (13273 bytes)
- ncurses5 (12888 bytes)
โ๏ธ Solaris โ๏ธ
As noted above, Solaris curses has no magic number corresponding to SVr4 curses. This is odd, since Solaris was the first operating system to meet the SVr4 guidelines. Solaris furthermore supplies two versions of curses. Plot twist! ๐
- The default curses library uses the SVr3 magic number.
- An alternate curses library (which we term
xcurses), available in/usr/xpg4, uses a textual format with no magic number.
According to its copyright notice, this xcurses library was developed by MKS (Mortice Kern Systems) from 1990 to 1995.
Like ncurses6, it includes a header with parameters. Unlike ncurses6, the contents of the window are written piecemeal, with coordinates and attributes for each chunk of text rather than writing the whole window from top to bottom. Different vibe entirely. ๐ง
๐งธ PDCurses ๐งธ
PDCurses added support for screen dumps in version 2.7 (2005). Like System V and ncurses5, it writes the WINDOW structure in binary, but begins the file with its three-byte identifier โPDCโ, followed by a single-byte version number.
โPDC\001โ
๐ NetBSD ๐
As of April 2017, NetBSD curses does not support scr_dump and scr_restore (or scr_init, scr_set), although it has putwin and getwin. We love a partial feature set. ๐ญ
Like ncurses5, NetBSD putwin does not identify its dumps with a useful magic number. It writes
- the curses shared library major and minor versions as the first two bytes (for example, 7 and 1),
- followed by a binary dump of the
WINDOW, - some data for wide characters referenced by the
WINDOWstructure, and - finally, lines as done by other implementations.
๐ธ EXAMPLES ๐ธ
Okay so picture a simple program that writes text to the screen โ and for the sake of example, we're limiting the screen-size to 10x20, bestie:
#include <curses.h>
int
main(void)
{
putenv("LINES=10");
putenv("COLUMNS=20");
initscr();
start_color();
init_pair(1, COLOR_WHITE, COLOR_BLUE);
init_pair(2, COLOR_RED, COLOR_BLACK);
bkgd(COLOR_PAIR(1));
move(4, 5);
attron(A_BOLD);
addstr("Hello");
move(5, 5);
attroff(A_BOLD);
attrset(A_REVERSE | COLOR_PAIR(2));
addstr("World!");
refresh();
scr_dump("foo.out");
endwin();
return 0;
}
When you run it using ncurses6, the output is literally giving this:
\210\210\210\210ncurses 6.0.20170415
_cury=5
_curx=11
_maxy=9
_maxx=19
_flags=14
_attrs=\{REVERSE|C2}
flag=_idcok
_delay=-1
_regbottom=9
_bkgrnd=\{NORMAL|C1}\s
rows:
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
The first four octal escapes are actually nonprinting characters, while the rest of the file is printable text. You might clock these:
- The actual color pair values are not written to the file.
- All characters are shown in printable form; spaces are
\sso they don't get overlooked, periodt. - Attributes are written in escaped curly braces, e.g.,
\{BOLD}, and may include a color pair (C1orC2in this example). - The parameters in the header are written out only if they are nonzero. When reading back, order does not matter.
Running the same program with Solaris xpg4 curses gives this dump:
MAX=10,20
BEG=0,0
SCROLL=0,10
VMIN=1
VTIME=0
FLAGS=0x1000
FG=0,0
BG=0,0,
0,0,0,1,
0,19,0,0,
1,0,0,1,
1,19,0,0,
2,0,0,1,
2,19,0,0,
3,0,0,1,
3,19,0,0,
4,0,0,1,
4,5,0x20,0,Hello
4,10,0,1,
4,19,0,0,
5,0,0,1,
5,5,0x4,2,World!
5,11,0,1,
5,19,0,0,
6,0,0,1,
6,19,0,0,
7,0,0,1,
7,19,0,0,
8,0,0,1,
8,19,0,0,
9,0,0,1,
9,19,0,0,
CUR=11,5
Solaris getwin requires that all parameters are present, and in the same order. The xpg4 curses library does not know about the bce (back color erase) capability, and does not color the window background.
On the other hand, the SVr4 curses library does know about the background color. However, its screen dumps are in binary. Here is the corresponding dump (using od -t x1):
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
0000060 00 00 00 80 00 00 20 00 00 00 ff ff ff ff 00 00
0000100 ff ff ff ff 00 00 00 00 20 80 00 00 20 80 00 00
0000120 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
*
0000620 20 80 00 00 20 80 00 00 20 80 00 00 48 80 00 04
0000640 65 80 00 04 6c 80 00 04 6c 80 00 04 6f 80 00 04
0000660 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
*
0000740 20 80 00 00 20 80 00 00 20 80 00 00 57 00 81 00
0000760 6f 00 81 00 72 00 81 00 6c 00 81 00 64 00 81 00
0001000 21 00 81 00 20 80 00 00 20 80 00 00 20 80 00 00
0001020 20 80 00 00 20 80 00 00 20 80 00 00 20 80 00 00
*
0001540 20 80 00 00 20 80 00 00 00 00 f6 d1 01 00 f6 d1
0001560 08 00 00 00 40 00 00 00 00 00 00 00 00 00 00 07
0001600 00 04 00 01 00 01 00 00 00 01 00 00 00 00 00 00
0001620 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*
0002371
๐ AUTHORS ๐
- Thomas E. Dickey โ extended screen-dump format for ncurses 6.0 (2015)
- Eric S. Raymond โ screen dump feature in ncurses 1.9.2d (1995)
๐ SEE ALSO ๐
curs_scr_dump(3X)curs_util(3X)
That's the whole scr_dump(5) manual page, bestie โ from the ncurses 6.6 source, dated 2025-04-05. Go dump some screens and slay ๐
โจ
๐ฆ where this page comes from
- alpine 3.24: ncurses-doc 6.6_p20260516-r0 ยท X11
- arch rolling: ncurses 6.6-2 ยท MIT-open-group
- fedora 44: ncurses 6.6-1.fc44 ยท MIT-open-group
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 2017 Free Software Foundation, Inc
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms