blob: 57cebb4ea9ce59105a7aab38aad203ea01cee2b5 [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 */
Denys Vlasenko6d932992016-11-23 10:39:27 +010010/* "Standard" version of this tool is in ncurses package */
Eric Andersendc746162000-08-21 21:26:33 +000011
Denys Vlasenko6d932992016-11-23 10:39:27 +010012//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
Denis Vlasenkod4f0b942008-02-26 15:33:10 +000022
Pere Orga55068c42011-03-27 23:42:28 +020023//usage:#define reset_trivial_usage
24//usage: ""
25//usage:#define reset_full_usage "\n\n"
26//usage: "Reset the screen"
27
Marek Polacek7b181072010-10-28 21:34:56 +020028#include "libbb.h"
29
30#define ESC "\033"
31
Denis Vlasenkod4f0b942008-02-26 15:33:10 +000032#if ENABLE_STTY
33int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
34#endif
35
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000036int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000037int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
Eric Andersendc746162000-08-21 21:26:33 +000038{
Denis Vlasenkod4f0b942008-02-26 15:33:10 +000039 static const char *const args[] = {
40 "stty", "sane", NULL
41 };
42
43 /* no options, no getopt */
44
Marek Polacek7b181072010-10-28 21:34:56 +020045 if (/*isatty(STDIN_FILENO) &&*/ isatty(STDOUT_FILENO)) {
Eric Andersen08573e02003-12-20 07:07:22 +000046 /* See 'man 4 console_codes' for details:
Denys Vlasenkod9a3e892010-05-16 23:42:13 +020047 * "ESC c" -- Reset
Denys Vlasenkob2f00ac2011-02-10 10:18:22 +010048 * "ESC ( B" -- Select G0 Character Set (B = US)
Denys Vlasenkod9a3e892010-05-16 23:42:13 +020049 * "ESC [ 0 m" -- Reset all display attributes
Marek Polacek7b181072010-10-28 21:34:56 +020050 * "ESC [ J" -- Erase to the end of screen
Denys Vlasenkod9a3e892010-05-16 23:42:13 +020051 * "ESC [ ? 25 h" -- Make cursor visible
Eric Andersen08573e02003-12-20 07:07:22 +000052 */
Denys Vlasenkob2f00ac2011-02-10 10:18:22 +010053 printf(ESC"c" ESC"(B" ESC"[0m" ESC"[J" ESC"[?25h");
Denis Vlasenkod4f0b942008-02-26 15:33:10 +000054 /* 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
Denis Vlasenko85c24712008-03-17 09:04:04 +000059 execvp("stty", (char**)args);
Denis Vlasenkod4f0b942008-02-26 15:33:10 +000060#endif
Eric Andersen08573e02003-12-20 07:07:22 +000061 }
Eric Andersen7f6295f2003-10-22 10:34:15 +000062 return EXIT_SUCCESS;
Eric Andersendc746162000-08-21 21:26:33 +000063}