1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
.\"***************************************************************************
.\" Copyright 2018-2024,2025 Thomas E. Dickey *
.\" Copyright 1998-2010,2017 Free Software Foundation, Inc. *
.\" *
.\" Permission is hereby granted, free of charge, to any person obtaining a *
.\" copy of this software and associated documentation files (the *
.\" "Software"), to deal in the Software without restriction, including *
.\" without limitation the rights to use, copy, modify, merge, publish, *
.\" distribute, distribute with modifications, sublicense, and/or sell *
.\" copies of the Software, and to permit persons to whom the Software is *
.\" furnished to do so, subject to the following conditions: *
.\" *
.\" The above copyright notice and this permission notice shall be included *
.\" in all copies or substantial portions of the Software. *
.\" *
.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
.\" *
.\" Except as contained in this notice, the name(s) of the above copyright *
.\" holders shall not be used in advertising or otherwise to promote the *
.\" sale, use or other dealings in this Software without prior written *
.\" authorization. *
.\"***************************************************************************
.\"
.\" $Id: curs_scr_dump.3x,v 1.55 2025/01/19 00:51:10 tom Exp $
.TH curs_scr_dump 3X 2025-01-18 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "Library calls"
.ie \n(.g \{\
.ds `` \(lq
.ds '' \(rq
.\}
.el \{\
.ie t .ds `` ``
.el .ds `` ""
.ie t .ds '' ''
.el .ds '' ""
.\}
.
.de bP
.ie n .IP \(bu 4
.el .IP \(bu 2
..
.SH NAME
\fB\%scr_dump\fP,
\fB\%scr_restore\fP,
\fB\%scr_init\fP,
\fB\%scr_set\fP \-
read/write a \fIcurses\fR screen from/to a file
.SH SYNOPSIS
.nf
\fB#include <curses.h>
.PP
\fBint scr_dump(const char * \fIfilename\fP);
\fBint scr_restore(const char * \fIfilename\fP);
\fBint scr_init(const char * \fIfilename\fP);
\fBint scr_set(const char * \fIfilename\fP);
.fi
.SH DESCRIPTION
.I curses
provides applications the ability to write the contents of the screen
to a file and read them back.
To read/write a window
(rather than the whole screen)
from/to a file,
use \fB\%getwin\fP(3X) and
\fB\%putwin\fP(3X),
respectively.
.SS scr_dump
.B \%scr_dump
writes to
.I filename
the contents of the virtual screen;
see \fB\%curscr\fP(3X).
.SS scr_restore
.B \%scr_restore
updates the virtual screen to match the contents of
.I filename
(if validly written with
.BR \%scr_dump ")."
.I curses
does not perform a refresh;
after making any desired changes,
call \fB\%doupdate\fP(3X) or similar.
.SS scr_init
.B \%scr_init
reads
.IR filename ","
using it to initialize
.I curses
data structures describing the state of the terminal screen.
.I curses
then,
if it decides the terminal state is valid,
bases its next update of the screen on this information rather than
clearing it and starting from scratch.
.PP
.I curses
regards the terminal as in an invalid state for computation of updates
based on the contents of
.I filename
if
.bP
.I curses
knows that the terminal has been written to since the preceding
.B \%scr_dump
call,
or
.bP
the terminal type supports the
.I \%term\%info
capabilities
.B \%exit_ca_mode
.RB \%( rmcup )
or
.B \%non_rev_rmcup
.RB \%( nrrmc ).
.PP
Either of the foregoing conditions means that
.I curses
cannot assume that the terminal's contents
match their representation in
.IR filename "."
The former is due to terminal features
(such as \fI\%xterm\fP(1)'s \*(``alternate screen\*('')
that couple cursor-positioning mode with a local cache of screen
contents.
.I curses
cannot know whether the terminal is displaying from that local cache
at the time the application calls
.BR \%scr_init ","
so it makes a pessimistic assumption that a full redraw is required;
see subsection \*(``Cursor Motions\*('' of \fB\%terminfo\fP(5).
.PP
.B \%scr_init
could be used after \fB\%initscr\fP(3X) or \fI\%system\fP(3) to share
the screen with another process that has done a
.B \%scr_dump
after \fB\%endwin\fP(3X).
An application that supports suspending its state on exit and subsequent
resumption upon later execution might use
.B \%scr_dump
and
.B \%scr_init
thus.
.SS scr_set
.B \%scr_set
combines
.B \%scr_restore
and
.BR \%scr_init ","
synchronizing the contents of
.I filename
with the virtual screen.
It can be regarded as a screen inheritance function;
consider a real-time screen-sharing application.
.SH RETURN VALUE
These functions return
.B OK
on success and
.B ERR
on failure.
.PP
In
.IR \%ncurses ","
each function returns
.B ERR
if it cannot open
.IR filename "."
.BR \%scr_init ","
.BR \%scr_restore ","
and
.B \%scr_set
return
.B ERR
if the contents of
.I filename
are invalid.
.SH NOTES
.BR \%scr_init ","
.BR \%scr_restore ","
and
.B \%scr_set
may be implemented as macros.
.SH PORTABILITY
X/Open Curses Issue\ 4 describes these functions.
It specifies no error conditions for them.
.\" Unusually, SVID 4 explicitly indicated "OK" as a possible return
.\" value, rather than the "integer other than ERR" refrain (p. 529).
.PP
.\" SVID 4, p. 529
SVr4 omitted the
.I \%const
qualifiers.
.PP
SVr4 documentation describes
.I \%scr_init
such that the dump data is also considered invalid
\*(``if the time-stamp of the tty is old\*(''
but does not define \*(``old\*(''.
.PP
As of 2024,
.I \%PDCurses
provides these functions.
NetBSD
.I curses
does not.
.PP
Other implementations of
.I curses
store the window in binary form,
which makes the dump dependent
upon the
.I curses
library's internal data structures.
.I \%ncurses
avoids this drawback by storing the dump in textual form,
allowing more flexible use of the data.
For instance,
the
.I \%scr_restore
of SVr4
.I curses
requires that the dumped window have the same dimensions
as the restored window.
.I \%ncurses
uses its
\fB\%wresize\fP(3X)
extension
to adjust the restored window size.
.SH HISTORY
SVr3 (1987) introduced
.IR \%scr_dump ","
.IR \%scr_init ","
and
.IR \%scr_restore "."
SVr3.1 added
.IR \%scr_set "."
.SH SEE ALSO
.na
\fB\%curses\fP(3X),
\fB\%curs_initscr\fP(3X),
\fB\%curs_refresh\fP(3X),
\fB\%curs_util\fP(3X),
\fB\%system\fP(3),
\fB\%scr_dump\fP(5),
\fB\%terminfo\fP(5),
\fB\%wresize\fP(3X)
.ad
|