2000-08-21 21:26:33 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Mini reset implementation for busybox
|
|
|
|
*
|
2004-03-15 08:29:22 +00:00
|
|
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
2001-10-24 05:00:29 +00:00
|
|
|
* Written by Erik Andersen and Kent Robotti <robotti@metconnect.com>
|
2000-08-21 21:26:33 +00:00
|
|
|
*
|
2010-08-16 20:14:46 +02:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2000-08-21 21:26:33 +00:00
|
|
|
*/
|
2016-11-23 10:39:27 +01:00
|
|
|
//config:config RESET
|
2017-07-18 22:01:24 +02:00
|
|
|
//config: bool "reset (275 bytes)"
|
2016-11-23 10:39:27 +01:00
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 09:50:55 +02:00
|
|
|
//config: This program is used to reset the terminal screen, if it
|
|
|
|
//config: gets messed up.
|
2016-11-23 10:39:27 +01:00
|
|
|
|
2017-08-04 19:55:01 +02:00
|
|
|
//applet:IF_RESET(APPLET_NOEXEC(reset, reset, BB_DIR_USR_BIN, BB_SUID_DROP, reset))
|
2016-11-23 10:39:27 +01:00
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_RESET) += reset.o
|
2008-02-26 15:33:10 +00:00
|
|
|
|
2011-03-27 23:42:28 +02:00
|
|
|
//usage:#define reset_trivial_usage
|
|
|
|
//usage: ""
|
|
|
|
//usage:#define reset_full_usage "\n\n"
|
|
|
|
//usage: "Reset the screen"
|
|
|
|
|
2017-09-18 16:28:43 +02:00
|
|
|
/* "Standard" version of this tool is in ncurses package */
|
|
|
|
|
2010-10-28 21:34:56 +02:00
|
|
|
#include "libbb.h"
|
|
|
|
|
|
|
|
#define ESC "\033"
|
|
|
|
|
2008-02-26 15:33:10 +00:00
|
|
|
#if ENABLE_STTY
|
|
|
|
int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
#endif
|
|
|
|
|
2007-10-11 10:05:36 +00:00
|
|
|
int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 09:18:54 +00:00
|
|
|
int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
2000-08-21 21:26:33 +00:00
|
|
|
{
|
2008-02-26 15:33:10 +00:00
|
|
|
static const char *const args[] = {
|
|
|
|
"stty", "sane", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* no options, no getopt */
|
|
|
|
|
2010-10-28 21:34:56 +02:00
|
|
|
if (/*isatty(STDIN_FILENO) &&*/ isatty(STDOUT_FILENO)) {
|
2003-12-20 07:07:22 +00:00
|
|
|
/* See 'man 4 console_codes' for details:
|
2010-05-16 23:42:13 +02:00
|
|
|
* "ESC c" -- Reset
|
2011-02-10 10:18:22 +01:00
|
|
|
* "ESC ( B" -- Select G0 Character Set (B = US)
|
2017-09-13 22:48:30 +02:00
|
|
|
* "ESC [ m" -- Reset all display attributes
|
2010-10-28 21:34:56 +02:00
|
|
|
* "ESC [ J" -- Erase to the end of screen
|
2010-05-16 23:42:13 +02:00
|
|
|
* "ESC [ ? 25 h" -- Make cursor visible
|
2003-12-20 07:07:22 +00:00
|
|
|
*/
|
2017-09-13 22:48:30 +02:00
|
|
|
printf(ESC"c" ESC"(B" ESC"[m" ESC"[J" ESC"[?25h");
|
2008-02-26 15:33:10 +00:00
|
|
|
/* http://bugs.busybox.net/view.php?id=1414:
|
|
|
|
* people want it to reset echo etc: */
|
|
|
|
#if ENABLE_STTY
|
|
|
|
return stty_main(2, (char**)args);
|
|
|
|
#else
|
2017-02-17 23:01:13 +01:00
|
|
|
/* Make sure stdout gets drained before we execvp */
|
|
|
|
fflush_all();
|
2008-03-17 09:04:04 +00:00
|
|
|
execvp("stty", (char**)args);
|
2008-02-26 15:33:10 +00:00
|
|
|
#endif
|
2003-12-20 07:07:22 +00:00
|
|
|
}
|
2003-10-22 10:34:15 +00:00
|
|
|
return EXIT_SUCCESS;
|
2000-08-21 21:26:33 +00:00
|
|
|
}
|