1
/*===========================================================================
2
Copyright (C) 1986-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
19
Corresponding concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
.IDENTIFICATION tvclear.c
32
.AUTHOR Francois Ochsenbein [ESO-IPG]
34
.KEYWORDS Terminal Independant i/o Package.
35
.ENVIRONMENT TermWindows
36
.COMMENTS This module includes clear functions.
39
$$\begin{tabular}{|lp{30em}|} \hline
40
{\tt cl=} & Clear whole screen (and cursor to home position) \\
41
{\tt cu=} & Clear Up (from top of screen to cursor inclusive) \\
42
{\tt cd=} & Clear Down (from cursor inclusive to bottom of screen)\\
43
{\tt ce=} & Clear from cursor to end of line \\
44
{\tt cs=} & Clear from start of line to cursor inclusive \\
48
.VERSION 1.0 07-Jul-1986: Creation
49
.VERSION 1.1 12-Aug-1986: Clearing lines or screen also means stop insert mode.
51
.VERSION 1.2 23-Oct-1986: Take care of possible existing scrolling region
53
.VERSION 2.0 03-Dec-1986 New terminal-independant graphic characters
54
with output buffering version.
55
.VERSION 2.1 11-Jun-1987 Modify a bit for hard_copy terminals:
56
Useless to clear characters!!!
57
.VERSION 2.2 23-Jun-1987 Adapted to UNIX
58
.VERSION 3.0 20-Mar-1988 Version '3' of TermWindows.
61
----------------------------------------------------------------------------*/
63
#define DEBUG 0 /* Only for debugging */
65
#define PM_LEVEL LEVEL_TV
67
#include <midas_def.h>
70
#define TW_MACROS 0 /* Don't use TermWindows Macros */
72
#define TW_STRUCT 0 /* Do not use window Structures */
76
extern int tv_buffer(), tv_send(), tv_goto(), tv_out();
77
extern int tv_line(), tv_where(), tv_open(), tv_attr();
78
extern int tv_nl(), tv_sr0(), tv_home();
80
extern int pm_ed_i(), pm_iexit(), pm_enter();
83
MID_RSTATIC char clear_cap[] = "cucdcbce";
84
MID_STATIC short int old_pos[2] = {0,0};
87
# define TERMTEST if(!terms->version) tv_gopen();\
90
# define TERMTEST if(!terms->version) tv_gopen()
93
#define FIN_CURSOR goto RESET_CURSOR
95
#define ENTER_TV(x) static int state_buffer; \
97
state_buffer = tv_buffer(TRUE);
98
#define EXIT_TV(f) FIN: \
99
tv_buffer(state_buffer); \
102
MID_EXTERN TERM *terms ;
104
#define SEND(p) tv_send(p,1)
106
/* Macros just to improve readibility */
108
#define oldl old_pos[0]
109
#define oldc old_pos[1]
110
#define curl (terms->pos[0])
111
#define curc (terms->pos[1])
112
#define diml (terms->dim[0])
113
#define dimc (terms->dim[1])
114
#define BUFS (terms->bufs)
119
/*==========================================================================
121
*==========================================================================*/
122
static int clear_h(dir)
123
/*++++++++++++++++++++++++
124
.DES Clear at left / right of cursor (inclusive)
126
.REM Not traced. Never called for hard-copy terminals. Cursor moves
128
-----------------------*/
129
int dir; /* IN: Direction (left or right) */
134
/* Use TermCapabilities when possible */
135
p = SearchCap(&clear_cap[dir*2]);
136
if (p) return(SEND(p));
144
else i = dimc - curc;
147
{ oscfill(BUFS,i,' ');
148
s = tv_line(BUFS, i);
154
/*==========================================================================
156
*==========================================================================*/
159
.DES Clear n chars from the cursor inclusive.
161
.REM The cursor position remains unchanged. Simply write blanks ---
162
or do nothing for hard_copy terminals!
163
If nchar<0, clear chars at the left of the cursor.
165
int nchar; /* IN: Number of chars to clear */
168
unsigned char old_attr;
172
TRACE_ED_I("Clearing chars: ", nchar);
175
if (nchar == 0) FINISH;
176
if (terms->flags & TERM_hard) FINISH;
179
old_attr = terms->attr;
180
tv_attr(terms->attr_init);
182
n = 0; /* Number of blanks to issue */
184
{ if (oldc + nchar < 0) /* Optimize */
185
status = clear_h(_LEFT_);
186
else tv_goto(oldl, oldc + nchar +1), n = -nchar;
189
{ if (oldc + n >= dimc) /* Optimize */
190
status = clear_h(_RIGHT_);
194
/* Can't clear with optimized TermCapabilities;
198
{ oscfill(BUFS,n,' ');
199
status = tv_line(BUFS, n);
208
/*==========================================================================
210
*==========================================================================*/
213
.DES Clear the complete line; the cursor is moved to the left margin.
218
unsigned char old_attr;
225
/* For hard-copy terminals, issue a new line */
227
if (terms->flags & TERM_hard)
229
curl--; /* ... but line unchanged */
234
/* Simply go to line beginning, and clear it */
236
old_attr = terms->attr;
237
tv_attr(terms->attr_init);
238
tv_out("\r", 1); curc = 0;
239
status = clear_h(_RIGHT_);
246
/*==========================================================================
248
*==========================================================================*/
249
int tv_clear(direction)
251
.DES Clear the terminal, according to the specified direction:
254
\item \_UP\_ : from the top of the screen, to the cursor (inclusive).
255
The cursor does not move.
256
\item \_DOWN\_ : from the cursor (inclusive) to the end of the screen.
257
The cursor does not move.
258
\item \_LEFT\_ : from the left margin of the current line
259
to the cursor (inclusive) .
260
The cursor does not move.
261
\item \_RIGHT\_ : from the cursor (inclusive) to the end of the line.
262
The cursor does not move.
263
\item \_WHOLE\_ : the complete screen (the cursor goes to home, \ie [0,0]
268
.REM Insert Mode turned off. For hard-copy terminals, only _WHOLE_
269
has some signification.
270
-------------------*/
271
int direction; /* IN: Clearing direction _WHOLE_, _UP_, _DOWN_, etc */
274
unsigned char old_attr;
276
ENTER_TV("tv_clear");
279
terms->flags &= (~TERM_IMODE);
281
tv_where(old_pos); /* Save present position */
282
curc = oldc; /* For wrap (cursor passed right margin) */
283
old_attr = terms->attr;
284
tv_attr(terms->attr_init);
286
if ( (direction < 0) || (direction > 3) )
287
{ /* Whole screen is the default */
288
/* Reset the scrolling region to whole screen */
291
/* Look if "cl" cap exists (already stored in TERM)
292
otherwise, simply put a new line */
297
else status = tv_nl(); /* No cap: Simply go to newline ... */
299
oldc = 0; oldl = 0; /* New cursor position */
303
if (terms->flags & TERM_hard) FINISH;
306
/* Change the direction for optimisation */
310
if (curl != 0) break;
311
case _LEFT_ : /* Cont. _UP_ */
312
status = clear_h(_LEFT_); FIN_CURSOR;
314
if (curl != diml-1) break;
315
case _RIGHT_: /* Cont. _DOWN_ */
316
status = clear_h(_RIGHT_); FIN_CURSOR;
319
/* Here only in case of _UP_/_DOWN_ clearing */
321
/* Test if a scrolling region exists --- Use tv_sr0 */
323
if ( (terms->scregion[0] != 0) || (terms->scregion[1] < diml-1) )
328
/* Use TermCapabilities when possible */
329
p = SearchCap(&clear_cap[direction*2]);
330
if (p) { status = SEND(p); FIN_CURSOR;}
332
/* Simulate Clearing with blanks */
334
{ case _UP_: /* Clear from top left corner */
335
tv_home(); /* ... Cursor position is updated */
339
} /* We are on original line... */
340
tv_goto(oldl, oldc); /* ... and continue with _LEFT_ */
341
status = clear_h(_LEFT_);
344
case _DOWN_: /* `cd' capability doesn't exist */
345
status = clear_h(_RIGHT_); /* clear current line...*/
346
while (curl < diml-1)
347
tv_nl(), clear_h(_RIGHT_);