xref: /dflybsd-src/contrib/ncurses/progs/clear_cmd.c (revision 0cadad7e49c6219b0de0675ef6a6f44683d177d4)
1*32bb5217SDaniel Fojt /****************************************************************************
2*32bb5217SDaniel Fojt  * Copyright 2018,2020 Thomas E. Dickey                                     *
3*32bb5217SDaniel Fojt  * Copyright 2016,2017 Free Software Foundation, Inc.                       *
4*32bb5217SDaniel Fojt  *                                                                          *
5*32bb5217SDaniel Fojt  * Permission is hereby granted, free of charge, to any person obtaining a  *
6*32bb5217SDaniel Fojt  * copy of this software and associated documentation files (the            *
7*32bb5217SDaniel Fojt  * "Software"), to deal in the Software without restriction, including      *
8*32bb5217SDaniel Fojt  * without limitation the rights to use, copy, modify, merge, publish,      *
9*32bb5217SDaniel Fojt  * distribute, distribute with modifications, sublicense, and/or sell       *
10*32bb5217SDaniel Fojt  * copies of the Software, and to permit persons to whom the Software is    *
11*32bb5217SDaniel Fojt  * furnished to do so, subject to the following conditions:                 *
12*32bb5217SDaniel Fojt  *                                                                          *
13*32bb5217SDaniel Fojt  * The above copyright notice and this permission notice shall be included  *
14*32bb5217SDaniel Fojt  * in all copies or substantial portions of the Software.                   *
15*32bb5217SDaniel Fojt  *                                                                          *
16*32bb5217SDaniel Fojt  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17*32bb5217SDaniel Fojt  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18*32bb5217SDaniel Fojt  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19*32bb5217SDaniel Fojt  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20*32bb5217SDaniel Fojt  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21*32bb5217SDaniel Fojt  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22*32bb5217SDaniel Fojt  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23*32bb5217SDaniel Fojt  *                                                                          *
24*32bb5217SDaniel Fojt  * Except as contained in this notice, the name(s) of the above copyright   *
25*32bb5217SDaniel Fojt  * holders shall not be used in advertising or otherwise to promote the     *
26*32bb5217SDaniel Fojt  * sale, use or other dealings in this Software without prior written       *
27*32bb5217SDaniel Fojt  * authorization.                                                           *
28*32bb5217SDaniel Fojt  ****************************************************************************/
29*32bb5217SDaniel Fojt 
30*32bb5217SDaniel Fojt /****************************************************************************
31*32bb5217SDaniel Fojt  *  Author: Thomas E. Dickey                                                *
32*32bb5217SDaniel Fojt  ****************************************************************************/
33*32bb5217SDaniel Fojt 
34*32bb5217SDaniel Fojt /*
35*32bb5217SDaniel Fojt  * clear.c --  clears the terminal's screen
36*32bb5217SDaniel Fojt  */
37*32bb5217SDaniel Fojt 
38*32bb5217SDaniel Fojt #define USE_LIBTINFO
39*32bb5217SDaniel Fojt #include <clear_cmd.h>
40*32bb5217SDaniel Fojt 
41*32bb5217SDaniel Fojt MODULE_ID("$Id: clear_cmd.c,v 1.5 2020/02/02 23:34:34 tom Exp $")
42*32bb5217SDaniel Fojt 
43*32bb5217SDaniel Fojt static int
putch(int c)44*32bb5217SDaniel Fojt putch(int c)
45*32bb5217SDaniel Fojt {
46*32bb5217SDaniel Fojt     return putchar(c);
47*32bb5217SDaniel Fojt }
48*32bb5217SDaniel Fojt 
49*32bb5217SDaniel Fojt int
clear_cmd(bool legacy)50*32bb5217SDaniel Fojt clear_cmd(bool legacy)
51*32bb5217SDaniel Fojt {
52*32bb5217SDaniel Fojt     int retval = tputs(clear_screen, lines > 0 ? lines : 1, putch);
53*32bb5217SDaniel Fojt     if (!legacy) {
54*32bb5217SDaniel Fojt 	/* Clear the scrollback buffer if possible. */
55*32bb5217SDaniel Fojt 	char *E3 = tigetstr("E3");
56*32bb5217SDaniel Fojt 	if (E3)
57*32bb5217SDaniel Fojt 	    (void) tputs(E3, lines > 0 ? lines : 1, putch);
58*32bb5217SDaniel Fojt     }
59*32bb5217SDaniel Fojt     return retval;
60*32bb5217SDaniel Fojt }
61