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