Eric Andersen | dc74616 | 2000-08-21 21:26:33 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Mini reset implementation for busybox |
| 4 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 6 | * Written by Erik Andersen and Kent Robotti <robotti@metconnect.com> |
Eric Andersen | dc74616 | 2000-08-21 21:26:33 +0000 | [diff] [blame] | 7 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Eric Andersen | dc74616 | 2000-08-21 21:26:33 +0000 | [diff] [blame] | 9 | */ |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame] | 10 | //config:config RESET |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 11 | //config: bool "reset (275 bytes)" |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame] | 12 | //config: default y |
| 13 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 14 | //config: This program is used to reset the terminal screen, if it |
| 15 | //config: gets messed up. |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame] | 16 | |
Denys Vlasenko | 5c527dc | 2017-08-04 19:55:01 +0200 | [diff] [blame] | 17 | //applet:IF_RESET(APPLET_NOEXEC(reset, reset, BB_DIR_USR_BIN, BB_SUID_DROP, reset)) |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame] | 18 | |
| 19 | //kbuild:lib-$(CONFIG_RESET) += reset.o |
Denis Vlasenko | d4f0b94 | 2008-02-26 15:33:10 +0000 | [diff] [blame] | 20 | |
Pere Orga | 55068c4 | 2011-03-27 23:42:28 +0200 | [diff] [blame] | 21 | //usage:#define reset_trivial_usage |
| 22 | //usage: "" |
| 23 | //usage:#define reset_full_usage "\n\n" |
| 24 | //usage: "Reset the screen" |
| 25 | |
Denys Vlasenko | 0c4dbd4 | 2017-09-18 16:28:43 +0200 | [diff] [blame^] | 26 | /* "Standard" version of this tool is in ncurses package */ |
| 27 | |
Marek Polacek | 7b18107 | 2010-10-28 21:34:56 +0200 | [diff] [blame] | 28 | #include "libbb.h" |
| 29 | |
| 30 | #define ESC "\033" |
| 31 | |
Denis Vlasenko | d4f0b94 | 2008-02-26 15:33:10 +0000 | [diff] [blame] | 32 | #if ENABLE_STTY |
| 33 | int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 34 | #endif |
| 35 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 36 | int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 37 | int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
Eric Andersen | dc74616 | 2000-08-21 21:26:33 +0000 | [diff] [blame] | 38 | { |
Denis Vlasenko | d4f0b94 | 2008-02-26 15:33:10 +0000 | [diff] [blame] | 39 | static const char *const args[] = { |
| 40 | "stty", "sane", NULL |
| 41 | }; |
| 42 | |
| 43 | /* no options, no getopt */ |
| 44 | |
Marek Polacek | 7b18107 | 2010-10-28 21:34:56 +0200 | [diff] [blame] | 45 | if (/*isatty(STDIN_FILENO) &&*/ isatty(STDOUT_FILENO)) { |
Eric Andersen | 08573e0 | 2003-12-20 07:07:22 +0000 | [diff] [blame] | 46 | /* See 'man 4 console_codes' for details: |
Denys Vlasenko | d9a3e89 | 2010-05-16 23:42:13 +0200 | [diff] [blame] | 47 | * "ESC c" -- Reset |
Denys Vlasenko | b2f00ac | 2011-02-10 10:18:22 +0100 | [diff] [blame] | 48 | * "ESC ( B" -- Select G0 Character Set (B = US) |
Denys Vlasenko | 8187e01 | 2017-09-13 22:48:30 +0200 | [diff] [blame] | 49 | * "ESC [ m" -- Reset all display attributes |
Marek Polacek | 7b18107 | 2010-10-28 21:34:56 +0200 | [diff] [blame] | 50 | * "ESC [ J" -- Erase to the end of screen |
Denys Vlasenko | d9a3e89 | 2010-05-16 23:42:13 +0200 | [diff] [blame] | 51 | * "ESC [ ? 25 h" -- Make cursor visible |
Eric Andersen | 08573e0 | 2003-12-20 07:07:22 +0000 | [diff] [blame] | 52 | */ |
Denys Vlasenko | 8187e01 | 2017-09-13 22:48:30 +0200 | [diff] [blame] | 53 | printf(ESC"c" ESC"(B" ESC"[m" ESC"[J" ESC"[?25h"); |
Denis Vlasenko | d4f0b94 | 2008-02-26 15:33:10 +0000 | [diff] [blame] | 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 |
Glenn Matthews | 02a2a27 | 2017-02-17 23:01:13 +0100 | [diff] [blame] | 59 | /* Make sure stdout gets drained before we execvp */ |
| 60 | fflush_all(); |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 61 | execvp("stty", (char**)args); |
Denis Vlasenko | d4f0b94 | 2008-02-26 15:33:10 +0000 | [diff] [blame] | 62 | #endif |
Eric Andersen | 08573e0 | 2003-12-20 07:07:22 +0000 | [diff] [blame] | 63 | } |
Eric Andersen | 7f6295f | 2003-10-22 10:34:15 +0000 | [diff] [blame] | 64 | return EXIT_SUCCESS; |
Eric Andersen | dc74616 | 2000-08-21 21:26:33 +0000 | [diff] [blame] | 65 | } |