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 | */ |
| 10 | |
Denis Vlasenko | d4f0b94 | 2008-02-26 15:33:10 +0000 | [diff] [blame] | 11 | /* BTW, which "standard" package has this utility? It doesn't seem |
| 12 | * to be ncurses, coreutils, console-tools... then what? */ |
| 13 | |
Pere Orga | 55068c4 | 2011-03-27 23:42:28 +0200 | [diff] [blame] | 14 | //usage:#define reset_trivial_usage |
| 15 | //usage: "" |
| 16 | //usage:#define reset_full_usage "\n\n" |
| 17 | //usage: "Reset the screen" |
| 18 | |
Marek Polacek | 7b18107 | 2010-10-28 21:34:56 +0200 | [diff] [blame] | 19 | #include "libbb.h" |
| 20 | |
| 21 | #define ESC "\033" |
| 22 | |
Denis Vlasenko | d4f0b94 | 2008-02-26 15:33:10 +0000 | [diff] [blame] | 23 | #if ENABLE_STTY |
| 24 | int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 25 | #endif |
| 26 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 27 | int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 28 | int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
Eric Andersen | dc74616 | 2000-08-21 21:26:33 +0000 | [diff] [blame] | 29 | { |
Denis Vlasenko | d4f0b94 | 2008-02-26 15:33:10 +0000 | [diff] [blame] | 30 | static const char *const args[] = { |
| 31 | "stty", "sane", NULL |
| 32 | }; |
| 33 | |
| 34 | /* no options, no getopt */ |
| 35 | |
Marek Polacek | 7b18107 | 2010-10-28 21:34:56 +0200 | [diff] [blame] | 36 | if (/*isatty(STDIN_FILENO) &&*/ isatty(STDOUT_FILENO)) { |
Eric Andersen | 08573e0 | 2003-12-20 07:07:22 +0000 | [diff] [blame] | 37 | /* See 'man 4 console_codes' for details: |
Denys Vlasenko | d9a3e89 | 2010-05-16 23:42:13 +0200 | [diff] [blame] | 38 | * "ESC c" -- Reset |
Denys Vlasenko | b2f00ac | 2011-02-10 10:18:22 +0100 | [diff] [blame] | 39 | * "ESC ( B" -- Select G0 Character Set (B = US) |
Denys Vlasenko | d9a3e89 | 2010-05-16 23:42:13 +0200 | [diff] [blame] | 40 | * "ESC [ 0 m" -- Reset all display attributes |
Marek Polacek | 7b18107 | 2010-10-28 21:34:56 +0200 | [diff] [blame] | 41 | * "ESC [ J" -- Erase to the end of screen |
Denys Vlasenko | d9a3e89 | 2010-05-16 23:42:13 +0200 | [diff] [blame] | 42 | * "ESC [ ? 25 h" -- Make cursor visible |
Eric Andersen | 08573e0 | 2003-12-20 07:07:22 +0000 | [diff] [blame] | 43 | */ |
Denys Vlasenko | b2f00ac | 2011-02-10 10:18:22 +0100 | [diff] [blame] | 44 | printf(ESC"c" ESC"(B" ESC"[0m" ESC"[J" ESC"[?25h"); |
Denis Vlasenko | d4f0b94 | 2008-02-26 15:33:10 +0000 | [diff] [blame] | 45 | /* http://bugs.busybox.net/view.php?id=1414: |
| 46 | * people want it to reset echo etc: */ |
| 47 | #if ENABLE_STTY |
| 48 | return stty_main(2, (char**)args); |
| 49 | #else |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 50 | execvp("stty", (char**)args); |
Denis Vlasenko | d4f0b94 | 2008-02-26 15:33:10 +0000 | [diff] [blame] | 51 | #endif |
Eric Andersen | 08573e0 | 2003-12-20 07:07:22 +0000 | [diff] [blame] | 52 | } |
Eric Andersen | 7f6295f | 2003-10-22 10:34:15 +0000 | [diff] [blame] | 53 | return EXIT_SUCCESS; |
Eric Andersen | dc74616 | 2000-08-21 21:26:33 +0000 | [diff] [blame] | 54 | } |