summaryrefslogtreecommitdiff
path: root/console-tools/reset.c (plain)
blob: 57cebb4ea9ce59105a7aab38aad203ea01cee2b5
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini reset implementation for busybox
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 * Written by Erik Andersen and Kent Robotti <robotti@metconnect.com>
7 *
8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
9 */
10/* "Standard" version of this tool is in ncurses package */
11
12//config:config RESET
13//config: bool "reset"
14//config: default y
15//config: help
16//config: This program is used to reset the terminal screen, if it
17//config: gets messed up.
18
19//applet:IF_RESET(APPLET(reset, BB_DIR_USR_BIN, BB_SUID_DROP))
20
21//kbuild:lib-$(CONFIG_RESET) += reset.o
22
23//usage:#define reset_trivial_usage
24//usage: ""
25//usage:#define reset_full_usage "\n\n"
26//usage: "Reset the screen"
27
28#include "libbb.h"
29
30#define ESC "\033"
31
32#if ENABLE_STTY
33int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
34#endif
35
36int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
37int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
38{
39 static const char *const args[] = {
40 "stty", "sane", NULL
41 };
42
43 /* no options, no getopt */
44
45 if (/*isatty(STDIN_FILENO) &&*/ isatty(STDOUT_FILENO)) {
46 /* See 'man 4 console_codes' for details:
47 * "ESC c" -- Reset
48 * "ESC ( B" -- Select G0 Character Set (B = US)
49 * "ESC [ 0 m" -- Reset all display attributes
50 * "ESC [ J" -- Erase to the end of screen
51 * "ESC [ ? 25 h" -- Make cursor visible
52 */
53 printf(ESC"c" ESC"(B" ESC"[0m" ESC"[J" ESC"[?25h");
54 /* http://bugs.busybox.net/view.php?id=1414:
55 * people want it to reset echo etc: */
56#if ENABLE_STTY
57 return stty_main(2, (char**)args);
58#else
59 execvp("stty", (char**)args);
60#endif
61 }
62 return EXIT_SUCCESS;
63}
64