blob: 1806ce742ba25fe11167d47ac55144a05d7e6643 [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 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02008 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Eric Andersendc746162000-08-21 21:26:33 +00009 */
10
Denis Vlasenkod4f0b942008-02-26 15:33:10 +000011/* BTW, which "standard" package has this utility? It doesn't seem
12 * to be ncurses, coreutils, console-tools... then what? */
13
Marek Polacek7b181072010-10-28 21:34:56 +020014#include "libbb.h"
15
16#define ESC "\033"
17
Denis Vlasenkod4f0b942008-02-26 15:33:10 +000018#if ENABLE_STTY
19int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
20#endif
21
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000022int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000023int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
Eric Andersendc746162000-08-21 21:26:33 +000024{
Denis Vlasenkod4f0b942008-02-26 15:33:10 +000025 static const char *const args[] = {
26 "stty", "sane", NULL
27 };
28
29 /* no options, no getopt */
30
Marek Polacek7b181072010-10-28 21:34:56 +020031 if (/*isatty(STDIN_FILENO) &&*/ isatty(STDOUT_FILENO)) {
Eric Andersen08573e02003-12-20 07:07:22 +000032 /* See 'man 4 console_codes' for details:
Denys Vlasenkod9a3e892010-05-16 23:42:13 +020033 * "ESC c" -- Reset
34 * "ESC ( K" -- Select user mapping
Denys Vlasenkod9a3e892010-05-16 23:42:13 +020035 * "ESC [ 0 m" -- Reset all display attributes
Marek Polacek7b181072010-10-28 21:34:56 +020036 * "ESC [ J" -- Erase to the end of screen
Denys Vlasenkod9a3e892010-05-16 23:42:13 +020037 * "ESC [ ? 25 h" -- Make cursor visible
Eric Andersen08573e02003-12-20 07:07:22 +000038 */
Marek Polacek7b181072010-10-28 21:34:56 +020039 printf(ESC"c" ESC"(K" ESC"[0m" ESC"[J" ESC"[?25h");
Denis Vlasenkod4f0b942008-02-26 15:33:10 +000040 /* http://bugs.busybox.net/view.php?id=1414:
41 * people want it to reset echo etc: */
42#if ENABLE_STTY
43 return stty_main(2, (char**)args);
44#else
Denis Vlasenko85c24712008-03-17 09:04:04 +000045 execvp("stty", (char**)args);
Denis Vlasenkod4f0b942008-02-26 15:33:10 +000046#endif
Eric Andersen08573e02003-12-20 07:07:22 +000047 }
Eric Andersen7f6295f2003-10-22 10:34:15 +000048 return EXIT_SUCCESS;
Eric Andersendc746162000-08-21 21:26:33 +000049}