blob: f36ef544ce41608e38cec4129d4dc7c8fa505036 [file] [log] [blame]
Eric Andersendc746162000-08-21 21:26:33 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Mini reset implementation for busybox
4 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Eric Andersenbdfd0d72001-10-24 05:00:29 +00006 * Written by Erik Andersen and Kent Robotti <robotti@metconnect.com>
Eric Andersendc746162000-08-21 21:26:33 +00007 *
"Robert P. J. Day"801ab142006-07-12 07:56:04 +00008 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersendc746162000-08-21 21:26:33 +00009 */
10
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000011#include "libbb.h"
Eric Andersendc746162000-08-21 21:26:33 +000012
Denis Vlasenkod4f0b942008-02-26 15:33:10 +000013/* BTW, which "standard" package has this utility? It doesn't seem
14 * to be ncurses, coreutils, console-tools... then what? */
15
16#if ENABLE_STTY
17int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
18#endif
19
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000020int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenko68404f12008-03-17 09:00:54 +000021int reset_main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
Eric Andersendc746162000-08-21 21:26:33 +000022{
Denis Vlasenkod4f0b942008-02-26 15:33:10 +000023 static const char *const args[] = {
24 "stty", "sane", NULL
25 };
26
27 /* no options, no getopt */
28
29 if (isatty(0) && isatty(1)) {
Eric Andersen08573e02003-12-20 07:07:22 +000030 /* See 'man 4 console_codes' for details:
31 * "ESC c" -- Reset
32 * "ESC ( K" -- Select user mapping
33 * "ESC [ J" -- Erase display
"Vladimir N. Oleynik"ffe17b52005-10-12 08:38:28 +000034 * "ESC [ 0 m" -- Reset all display attributes
Eric Andersen08573e02003-12-20 07:07:22 +000035 * "ESC [ ? 25 h" -- Make cursor visible.
36 */
37 printf("\033c\033(K\033[J\033[0m\033[?25h");
Denis Vlasenkod4f0b942008-02-26 15:33:10 +000038 /* http://bugs.busybox.net/view.php?id=1414:
39 * people want it to reset echo etc: */
40#if ENABLE_STTY
41 return stty_main(2, (char**)args);
42#else
43 execvp("stty", args);
44#endif
Eric Andersen08573e02003-12-20 07:07:22 +000045 }
Eric Andersen7f6295f2003-10-22 10:34:15 +000046 return EXIT_SUCCESS;
Eric Andersendc746162000-08-21 21:26:33 +000047}