Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/cmpdcurses/pdcurses/refresh.c
3153 views
1
/* PDCurses */
2
3
#include <curspriv.h>
4
5
/*man-start**************************************************************
6
7
refresh
8
-------
9
10
### Synopsis
11
12
int refresh(void);
13
int wrefresh(WINDOW *win);
14
int wnoutrefresh(WINDOW *win);
15
int doupdate(void);
16
int redrawwin(WINDOW *win);
17
int wredrawln(WINDOW *win, int beg_line, int num_lines);
18
19
### Description
20
21
wrefresh() copies the named window to the physical terminal screen,
22
taking into account what is already there in order to optimize cursor
23
movement. refresh() does the same, using stdscr. These routines must
24
be called to get any output on the terminal, as other routines only
25
manipulate data structures. Unless leaveok() has been enabled, the
26
physical cursor of the terminal is left at the location of the
27
window's cursor.
28
29
wnoutrefresh() and doupdate() allow multiple updates with more
30
efficiency than wrefresh() alone. wrefresh() works by first calling
31
wnoutrefresh(), which copies the named window to the virtual screen.
32
It then calls doupdate(), which compares the virtual screen to the
33
physical screen and does the actual update. A series of calls to
34
wrefresh() will result in alternating calls to wnoutrefresh() and
35
doupdate(), causing several bursts of output to the screen. By first
36
calling wnoutrefresh() for each window, it is then possible to call
37
doupdate() only once.
38
39
In PDCurses, redrawwin() is equivalent to touchwin(), and wredrawln()
40
is the same as touchline(). In some other curses implementations,
41
there's a subtle distinction, but it has no meaning in PDCurses.
42
43
### Return Value
44
45
All functions return OK on success and ERR on error.
46
47
### Portability
48
X/Open ncurses NetBSD
49
refresh Y Y Y
50
wrefresh Y Y Y
51
wnoutrefresh Y Y Y
52
doupdate Y Y Y
53
redrawwin Y Y Y
54
wredrawln Y Y Y
55
56
**man-end****************************************************************/
57
58
#include <string.h>
59
60
int wnoutrefresh(WINDOW *win)
61
{
62
int begy, begx; /* window's place on screen */
63
int i, j;
64
65
PDC_LOG(("wnoutrefresh() - called: win=%p\n", win));
66
67
if ( !win || (win->_flags & (_PAD|_SUBPAD)) )
68
return ERR;
69
70
begy = win->_begy;
71
begx = win->_begx;
72
73
for (i = 0, j = begy; i < win->_maxy; i++, j++)
74
{
75
if (win->_firstch[i] != _NO_CHANGE)
76
{
77
chtype *src = win->_y[i];
78
chtype *dest = curscr->_y[j] + begx;
79
80
int first = win->_firstch[i]; /* first changed */
81
int last = win->_lastch[i]; /* last changed */
82
83
/* ignore areas on the outside that are marked as changed,
84
but really aren't */
85
86
while (first <= last && src[first] == dest[first])
87
first++;
88
89
while (last >= first && src[last] == dest[last])
90
last--;
91
92
/* if any have really changed... */
93
94
if (first <= last)
95
{
96
memcpy(dest + first, src + first,
97
(last - first + 1) * sizeof(chtype));
98
99
first += begx;
100
last += begx;
101
102
if (first < curscr->_firstch[j] ||
103
curscr->_firstch[j] == _NO_CHANGE)
104
curscr->_firstch[j] = first;
105
106
if (last > curscr->_lastch[j])
107
curscr->_lastch[j] = last;
108
}
109
110
win->_firstch[i] = _NO_CHANGE; /* updated now */
111
}
112
113
win->_lastch[i] = _NO_CHANGE; /* updated now */
114
}
115
116
if (win->_clear)
117
win->_clear = FALSE;
118
119
if (!win->_leaveit)
120
{
121
curscr->_cury = win->_cury + begy;
122
curscr->_curx = win->_curx + begx;
123
}
124
125
return OK;
126
}
127
128
int doupdate(void)
129
{
130
int y;
131
bool clearall;
132
133
PDC_LOG(("doupdate() - called\n"));
134
135
if (!SP || !curscr)
136
return ERR;
137
138
if (isendwin()) /* coming back after endwin() called */
139
{
140
reset_prog_mode();
141
clearall = TRUE;
142
SP->alive = TRUE; /* so isendwin() result is correct */
143
}
144
else
145
clearall = curscr->_clear;
146
147
for (y = 0; y < SP->lines; y++)
148
{
149
PDC_LOG(("doupdate() - Transforming line %d of %d: %s\n",
150
y, SP->lines, (curscr->_firstch[y] != _NO_CHANGE) ?
151
"Yes" : "No"));
152
153
if (clearall || curscr->_firstch[y] != _NO_CHANGE)
154
{
155
int first, last;
156
157
chtype *src = curscr->_y[y];
158
chtype *dest = SP->lastscr->_y[y];
159
160
if (clearall)
161
{
162
first = 0;
163
last = COLS - 1;
164
}
165
else
166
{
167
first = curscr->_firstch[y];
168
last = curscr->_lastch[y];
169
}
170
171
while (first <= last)
172
{
173
int len = 0;
174
175
/* build up a run of changed cells; if two runs are
176
separated by a single unchanged cell, ignore the
177
break */
178
179
if (clearall)
180
len = last - first + 1;
181
else
182
while (first + len <= last &&
183
(src[first + len] != dest[first + len] ||
184
(len && first + len < last &&
185
src[first + len + 1] != dest[first + len + 1])
186
)
187
)
188
len++;
189
190
/* update the screen, and SP->lastscr */
191
192
if (len)
193
{
194
PDC_transform_line(y, first, len, src + first);
195
memcpy(dest + first, src + first, len * sizeof(chtype));
196
first += len;
197
}
198
199
/* skip over runs of unchanged cells */
200
201
while (first <= last && src[first] == dest[first])
202
first++;
203
}
204
205
curscr->_firstch[y] = _NO_CHANGE;
206
curscr->_lastch[y] = _NO_CHANGE;
207
}
208
}
209
210
curscr->_clear = FALSE;
211
212
if (SP->visibility)
213
PDC_gotoyx(curscr->_cury, curscr->_curx);
214
215
SP->cursrow = curscr->_cury;
216
SP->curscol = curscr->_curx;
217
218
PDC_doupdate();
219
220
return OK;
221
}
222
223
int wrefresh(WINDOW *win)
224
{
225
bool save_clear;
226
227
PDC_LOG(("wrefresh() - called\n"));
228
229
if ( !win || (win->_flags & (_PAD|_SUBPAD)) )
230
return ERR;
231
232
save_clear = win->_clear;
233
234
if (win == curscr)
235
curscr->_clear = TRUE;
236
else
237
wnoutrefresh(win);
238
239
if (save_clear && win->_maxy == SP->lines && win->_maxx == SP->cols)
240
curscr->_clear = TRUE;
241
242
return doupdate();
243
}
244
245
int refresh(void)
246
{
247
PDC_LOG(("refresh() - called\n"));
248
249
return wrefresh(stdscr);
250
}
251
252
int wredrawln(WINDOW *win, int start, int num)
253
{
254
int i;
255
256
PDC_LOG(("wredrawln() - called: win=%p start=%d num=%d\n",
257
win, start, num));
258
259
if (!win || start > win->_maxy || start + num > win->_maxy)
260
return ERR;
261
262
for (i = start; i < start + num; i++)
263
{
264
win->_firstch[i] = 0;
265
win->_lastch[i] = win->_maxx - 1;
266
}
267
268
return OK;
269
}
270
271
int redrawwin(WINDOW *win)
272
{
273
PDC_LOG(("redrawwin() - called: win=%p\n", win));
274
275
if (!win)
276
return ERR;
277
278
return wredrawln(win, 0, win->_maxy);
279
}
280
281