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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
.\" $NetBSD: curses_screen.3,v 1.30 2025/04/11 23:57:20 uwe Exp $
.\"
.\" Copyright (c) 2002
.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au)
.\"
.\" This code is donated to the NetBSD Foundation by the Author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"
.Dd May 16, 2024
.Dt CURSES_SCREEN 3
.Os
.Sh NAME
.Nm curses_screen ,
.Nm filter ,
.Nm ripoffline ,
.Nm use_env ,
.Nm newterm ,
.Nm set_term ,
.Nm delscreen ,
.Nm endwin ,
.Nm initscr ,
.Nm isendwin ,
.Nm is_term_resized ,
.Nm resize_term ,
.Nm resizeterm ,
.Nm setterm ,
.Nm set_tabsize
.Nd curses terminal and screen routines
.Sh LIBRARY
.Lb libcurses
.Sh SYNOPSIS
.In curses.h
.Ft void
.Fn filter "void"
.Ft int
.Fn ripoffline "int line" "int (*init)(WINDOW *win, int cols)"
.Ft void
.Fn use_env "bool value"
.Ft SCREEN *
.Fn newterm "const char *type" "FILE *outfd" "FILE *infd"
.Ft SCREEN *
.Fn set_term "SCREEN *screen"
.Ft void
.Fn delscreen "SCREEN *screen"
.Ft int
.Fn endwin "void"
.Ft WINDOW *
.Fn initscr "void"
.Ft bool
.Fn isendwin "void"
.Ft bool
.Fn is_term_resized "int lines" "int cols"
.Ft int
.Fn resize_term "int lines" "int cols"
.Ft int
.Fn resizeterm "int lines" "int cols"
.Ft int
.Fn setterm "const char *name"
.Ft int
.Fn set_tabsize "int value"
.Pp
.Va extern int LINES ;
.Pp
.Va extern int COLS ;
.Sh DESCRIPTION
These functions initialize terminals and screens.
.Pp
The
.Fn newterm
function initialises the curses data structures and pointers ready for
use by curses.
The
.Fa type
argument points to a
.Xr terminfo 5
entry, or it may be
.Dv NULL
in which case the
.Ev TERM
environment variable is used.
The
.Fa outfd
and
.Fa infd
are the output and input file descriptors for the terminal.
The
.Fn newterm
function must only be called once per terminal.
.Pp
The
.Fn set_term
function can be used to switch between the screens defined by calling
.Fn newterm ,
a pointer to the previous screen structure that was in use will be
returned on success.
.Pp
Calling
.Fn delscreen
will destroy the given screen and free all allocated resources.
.Pp
Calling
.Fn endwin
will end the curses session and restore the saved terminal settings.
.Pp
The curses session must be initialised by calling
.Fn initscr
which saves the current terminal state and sets up the terminal and
internal data structures to support the curses application.
This
function call must be, with few exceptions, the first Curses library
call made.
The exception to this rule is the
.Fn newterm
call which may be called prior to
.Fn initscr .
The size of the curses screen is determined by checking the
.Xr tty 4
size and then the
.Xr terminfo 5
entries for the terminal type.
If the environment variables
.Ev LINES
or
.Ev COLUMNS
are set, then these will be used instead.
.Pp
When either
.Fn newterm
or
.Fn initscr
are called, the Curses library sets up signal handlers for
.Dv SIGTSTP
and
.Dv SIGWINCH .
If a signal handler is already installed for
.Dv SIGWINCH ,
this will also be called when the Curses library handler is called.
.Pp
The
.Fn isendwin
function can be used to determine whether or not a refresh of the
screen has occurred since the last call to
.Fn endwin .
.Pp
The size of the screen may be changed by calling
.Fn resize_term
with the updated number of lines and columns.
This will resize the curses internal data structures to accommodate the
changed terminal geometry.
The
.Dv curscr
and
.Va stdscr
windows and any of their subwindows will be resized to fit the new
screen size.
The application must redraw the screen after a call to
.Fn resize_term .
The
.Fn resizeterm
function is a wrapper for
.Fn resize_term
and adjusts other structure data that handles window dimensions.
The
.Fn is_term_resized
function tests if either of the above functions need to be called.
.Pp
The
.Fn setterm
function sets the terminal type for the current screen to the one
passed, initialising all the curses internal data structures with
information related to the named terminal.
The
.Fa name
argument must be a valid name or alias in the
.Xr terminfo 5
database for this function to succeed.
.Pp
The
.Fn filter
function changes the way the terminal is initialised.
A subsequent call to
.Fn initscr
or
.Fn newterm
performs the following additional actions:
.Bl -bullet -compact
.It
Disable use of clear, cud, cud1, cup, cuu, cuu1 and vpa.
.It
Set the value of the home string to the value of the cr string.
.It
Set lines equal to 1.
.El
.Pp
The
.Fn ripoffline
function will rip a line from
.Va stdscr
at the top if
.Fa line
is positive, or at the bottom if negative.
When
.Fn initscr
or
.Fn newterm
is called, a window will be created for each line ripped and passed
to the
.Fa init
function pointer alongwith the number of columns in the window.
This init function cannot use the
.Dv LINES
or
.Dv COLS
variables and cannot call
.Xr wrefresh 3
or
.Xr doupdate 3 ,
but may call
.Xr wnoutrefresh 3 .
.Fn ripoffline
can be called up to five times.
.Pp
The
.Fn use_env
function determines whether the environment variables
.Ev LINES
and
.Ev COLUMNS
override the normal values.
The default is true.
Any call to
.Fn use_env
must precede calls to
.Fn initscr ,
.Fn newterm ,
or
.Fn setupterm .
.Pp
The
.Fn set_tabsize
function will set
.Va TABSIZE
of the current screen to
.Va tabsize .
.Sh RETURN VALUES
Functions returning pointers will return
.Dv NULL
if an error is detected with the exception of
.Fn initscr
which will log a diagnostic to standard error output and then call
.Xr exit 3 .
The functions that return an int will return one of the following
values:
.Pp
.Bl -tag -width ERR -compact
.It Er OK
The function completed successfully.
.It Er ERR
An error occurred in the function.
.El
.Sh SEE ALSO
.Xr curses_window 3 ,
.Xr tty 4 ,
.Xr terminfo 5 ,
.Xr signal 7
.Sh STANDARDS
The
.Nx
Curses library complies with the X/Open Curses specification, part of the
Single Unix Specification.
.Sh HISTORY
The Curses package appeared in
.Bx 4.0 .
The
.Fn resizeterm
function is an
.Em ncurses
extension to the Curses library and was added in
.Nx 1.6 .
The
.Fn is_term_resized ,
.Fn resize_term
and
.Fn set_tabsize
functions are
.Em ncurses
extensions to the Curses library and were added in
.Nx 8.0 .
.Sh BUGS
There is currently an issue with cursor movement in a 1 line sized window
which causes the screen to scroll up.
This can obviously be seen when using
.Fn ripoffline .
|